Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
schombert committed Jan 7, 2024
2 parents 96e45da + dd4c8af commit 5b8d9e2
Show file tree
Hide file tree
Showing 15 changed files with 935 additions and 184 deletions.
14 changes: 14 additions & 0 deletions assets/alice.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,20 @@ aml_civ_s2;Uncolonized
aml_civ_s3;100% Westernized
aml_civ_s4;0% Westernized
aml_civ_s5;Colony
macro_builder;Macro-builder;;;Macro-constructor
macro_total_desc;Total unit stats:
macro_remove_template;Delete
macro_switch_type_land;Switch to: Land
macro_switch_type_naval;Switch to: Naval
macro_save_template;Save template;;;Guardar plantilla
macro_new_template;New template;;;Nueva plantila
macro_warn_overseas;�RCan't build this unit overseas!�W
macro_warn_culture;�RCan only build using primary culture POPs!�W
macro_warn_unlocked;�RUsing units not unlocked yet!�W
macro_select_province;Please select a province on the map
macro_warn_insuff;�RCan't build $x$ $name$ (only $y$)�W
macro_warn_invalid_province;�RProvince not part of a region�W
macro_apply_template;Apply
aml_col_s1;Potential
aml_col_s2;NA
aml_col_s3;Can Invest
Expand Down
132 changes: 126 additions & 6 deletions assets/alice.gui
Original file line number Diff line number Diff line change
Expand Up @@ -3560,23 +3560,143 @@ guiTypes = {

windowType = {
name = "alice_macro_builder"
position = { 0 200 }
size = { 320 320 }
position = { 420 400 }
size = { 640 320 }
guiButtonType = {
name = "background"
position = { 0 0 }
size = { 320 320 }
size = { 640 320 }
quadTextureSprite = "console_background"
}
guiButtonType = {
name = "close"
position = { -32 0 }
orientation = "UPPER_RIGHT"
quadTextureSprite = "GFX_main_close_button"
}
instantTextBoxType = {
name = "title"
text = "Macro builder"
text = "macro_builder"
position = { 0 4 }
font = "vic_22"
borderSize = { 0 0 }
maxsize = { 320 24 }
orientation = "UPPER_LEFT"
maxsize = { 640 24 }
format = center
}
listboxType = {
name = "template_listbox"
position = { 0 28 }
size = { 105 240 }
spacing = 0
borderSize = { 0 0 }
}
listboxType = {
name = "unit_listbox"
position = { 108 28 }
size = { 210 240 }
spacing = 0
borderSize = { 0 0 }
}
guiButtonType = {
name = "new_template"
position = { 2 288 }
size = { 128 24 }
quadTextureSprite = "GFX_button_128wide"
buttonText = "macro_new_template"
buttonFont = "vic_22_black"
}
guiButtonType = {
name = "save_template"
position = { 130 288 }
size = { 128 24 }
quadTextureSprite = "GFX_button_128wide"
buttonText = "macro_save_template"
buttonFont = "vic_22_black"
}
guiButtonType = {
name = "remove_template"
position = { 260 288 }
size = { 128 24 }
quadTextureSprite = "GFX_button_128wide"
buttonText = "macro_remove_template"
buttonFont = "vic_22_black"
}
guiButtonType = {
name = "switch_type"
position = { 390 288 }
size = { 128 24 }
quadTextureSprite = "GFX_button_128wide"
buttonText = ""
buttonFont = "vic_22_black"
}
guiButtonType = {
name = "apply"
position = { 520 288 }
size = { 128 24 }
quadTextureSprite = "GFX_button_128wide"
buttonText = "macro_apply_template"
buttonFont = "vic_22_black"
}
editBoxType = {
name = "input"
position = { 330 28 }
textureFile = "gfx\\interface\\small_tiles_dialog.dds"
font = "FPS_Font"
borderSize = { 10 10 }
maxsize = { 308 40 }
format = center
}
instantTextBoxType = {
name = "details"
position = { 330 72 }
font = "vic_22"
borderSize = { 0 0 }
maxsize = { 288 172 }
format = center
}
}
windowType = {
name = "alice_macro_builder_template_entry"
position = { 0 0 }
size = { 105 24 }
guiButtonType = {
name = "background"
position = { 0 0 }
size = { 105 24 }
quadTextureSprite = "console_background"
}
instantTextBoxType = {
name = "name"
position = { 32 0 }
font = "vic_22"
borderSize = { 0 0 }
maxsize = { 70 24 }
format = center
}
guiButtonType = {
name = "shield"
position = { 4 4 }
quadTextureSprite = "GFX_flag_new"
Orientation = "UPPER_LEFT"
}
}
windowType = {
name = "alice_macro_builder_unit_entry"
position = { 0 0 }
size = { 210 24 }
guiButtonType = {
name = "background"
position = { 0 0 }
size = { 210 24 }
quadTextureSprite = "console_background"
}
instantTextBoxType = {
name = "name"
position = { 4 0 }
font = "vic_22"
borderSize = { 0 0 }
maxsize = { 128 24 }
format = left
}
}
}
12 changes: 12 additions & 0 deletions src/common_types/container_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,16 @@ struct player_name {
};
static_assert(sizeof(player_name) == sizeof(player_name::data));

struct macro_builder_template {
static constexpr uint32_t max_types = 48;
sys::checksum_key scenario_checksum;
dcon::nation_id source;
char name[8] = { 0 };
uint8_t amounts[max_types] = { 0 };

bool operator!=(macro_builder_template& o) {
return std::memcmp(this, &o, sizeof(*this));
}
};

} // namespace sys
8 changes: 4 additions & 4 deletions src/culture/rebels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,8 +789,8 @@ void sort_hunting_targets(sys::state& state, dcon::army_id ar, std::vector<dcon:
auto our_str = ai::estimate_army_strength(state, ar);
auto loc = state.world.army_get_location_from_army_location(ar);
std::sort(rebel_provs.begin(), rebel_provs.end(), [&](dcon::province_id a, dcon::province_id b) {
auto aa = 0.02f * -(our_str - ai::estimate_rebel_strength(state, a));
auto ab = 0.02f * -(our_str - ai::estimate_rebel_strength(state, b));
auto aa = 0.001f * -(our_str - ai::estimate_rebel_strength(state, a));
auto ab = 0.001f * -(our_str - ai::estimate_rebel_strength(state, b));
auto da = province::sorting_distance(state, a, loc) + aa;
auto db = province::sorting_distance(state, b, loc) + ab;
if(da != db)
Expand Down Expand Up @@ -831,8 +831,8 @@ void rebel_hunting_check(sys::state& state) {
std::sort(rebel_hunters.begin(), rebel_hunters.end(), [&](dcon::army_id a, dcon::army_id b) {
auto pa = state.world.army_get_location_from_army_location(a);
auto pb = state.world.army_get_location_from_army_location(b);
auto as = 0.02f * std::max<float>(ai::estimate_army_strength(state, a), 1.f);
auto bs = 0.02f * std::max<float>(ai::estimate_army_strength(state, b), 1.f);
auto as = 0.001f * std::max<float>(ai::estimate_army_strength(state, a), 1.f);
auto bs = 0.001f * std::max<float>(ai::estimate_army_strength(state, b), 1.f);
auto da = province::sorting_distance(state, pa, closest_prov) + as;
auto db = province::sorting_distance(state, pb, closest_prov) + bs;
if(da != db)
Expand Down
1 change: 1 addition & 0 deletions src/filesystem/simple_fs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ native_string get_full_name(file const& f);

// functions that operate outside of a filesystem object
directory get_or_create_save_game_directory();
directory get_or_create_templates_directory();
directory get_or_create_oos_directory();
directory get_or_create_scenario_directory();
directory get_or_create_settings_directory();
Expand Down
7 changes: 7 additions & 0 deletions src/filesystem/simple_fs_nix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,13 @@ directory get_or_create_save_game_directory() {
return directory(nullptr, path);
}

directory get_or_create_templates_directory() {
native_string path = native_string(getenv("HOME")) + "/.local/share/Alice/templates/";
make_directories(path);

return directory(nullptr, path);
}

directory get_or_create_oos_directory() {
native_string path = native_string(getenv("HOME")) + "/.local/share/Alice/oos/";
make_directories(path);
Expand Down
15 changes: 15 additions & 0 deletions src/filesystem/simple_fs_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,21 @@ directory get_or_create_save_game_directory() {
return directory(nullptr, base_path);
}

directory get_or_create_templates_directory() {
wchar_t* local_path_out = nullptr;
std::wstring base_path;
if(SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &local_path_out) == S_OK) {
base_path = std::wstring(local_path_out) + NATIVE("\\Project Alice");
}
CoTaskMemFree(local_path_out);
if(base_path.length() > 0) {
CreateDirectoryW(base_path.c_str(), nullptr);
base_path += NATIVE("\\templates");
CreateDirectoryW(base_path.c_str(), nullptr);
}
return directory(nullptr, base_path);
}

directory get_or_create_oos_directory() {
wchar_t* local_path_out = nullptr;
std::wstring base_path;
Expand Down
24 changes: 14 additions & 10 deletions src/gamestate/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,17 +589,18 @@ void execute_begin_factory_building_construction(sys::state& state, dcon::nation
}
}

void start_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type) {
void start_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type, dcon::province_id template_province) {
payload p;
memset(&p, 0, sizeof(payload));
p.type = command_type::begin_naval_unit_construction;
p.source = source;
p.data.naval_unit_construction.location = location;
p.data.naval_unit_construction.type = type;
p.data.naval_unit_construction.template_province = template_province;
add_to_command_queue(state, p);
}

bool can_start_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type) {
bool can_start_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type, dcon::province_id template_province) {
/*
The province must be owned and controlled by the building nation, without an ongoing siege.
The unit type must be available from start / unlocked by the nation
Expand Down Expand Up @@ -641,22 +642,24 @@ bool can_start_naval_unit_construction(sys::state& state, dcon::nation_id source
}
}

void execute_start_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type) {
void execute_start_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type, dcon::province_id template_province) {
auto c = fatten(state.world, state.world.try_create_province_naval_construction(location, source));
c.set_type(type);
c.set_template_province(template_province);
}

void start_land_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type) {
void start_land_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type, dcon::province_id template_province) {
payload p;
memset(&p, 0, sizeof(payload));
p.type = command_type::begin_land_unit_construction;
p.source = source;
p.data.land_unit_construction.location = location;
p.data.land_unit_construction.type = type;
p.data.land_unit_construction.pop_culture = soldier_culture;
p.data.land_unit_construction.template_province = template_province;
add_to_command_queue(state, p);
}
bool can_start_land_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type) {
bool can_start_land_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type, dcon::province_id template_province) {
/*
The province must be owned and controlled by the building nation, without an ongoing siege.
The unit type must be available from start / unlocked by the nation
Expand Down Expand Up @@ -687,11 +690,12 @@ bool can_start_land_unit_construction(sys::state& state, dcon::nation_id source,
return false;
}
}
void execute_start_land_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type) {
void execute_start_land_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type, dcon::province_id template_province) {
auto soldier = military::find_available_soldier(state, location, soldier_culture);

auto c = fatten(state.world, state.world.try_create_province_land_construction(soldier, source));
c.set_type(type);
c.set_template_province(template_province);
}

void cancel_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type) {
Expand Down Expand Up @@ -4457,15 +4461,15 @@ bool can_perform_command(sys::state& state, payload& c) {

case command_type::begin_naval_unit_construction:
return can_start_naval_unit_construction(state, c.source, c.data.naval_unit_construction.location,
c.data.naval_unit_construction.type);
c.data.naval_unit_construction.type, c.data.naval_unit_construction.template_province);

case command_type::cancel_naval_unit_construction:
return can_cancel_naval_unit_construction(state, c.source, c.data.naval_unit_construction.location,
c.data.naval_unit_construction.type);

case command_type::begin_land_unit_construction:
return can_start_land_unit_construction(state, c.source, c.data.land_unit_construction.location,
c.data.land_unit_construction.pop_culture, c.data.land_unit_construction.type);
c.data.land_unit_construction.pop_culture, c.data.land_unit_construction.type, c.data.land_unit_construction.template_province);

case command_type::cancel_land_unit_construction:
return can_cancel_land_unit_construction(state, c.source, c.data.land_unit_construction.location,
Expand Down Expand Up @@ -4817,15 +4821,15 @@ void execute_command(sys::state& state, payload& c) {
break;
case command_type::begin_naval_unit_construction:
execute_start_naval_unit_construction(state, c.source, c.data.naval_unit_construction.location,
c.data.naval_unit_construction.type);
c.data.naval_unit_construction.type, c.data.naval_unit_construction.template_province);
break;
case command_type::cancel_naval_unit_construction:
execute_cancel_naval_unit_construction(state, c.source, c.data.naval_unit_construction.location,
c.data.naval_unit_construction.type);
break;
case command_type::begin_land_unit_construction:
execute_start_land_unit_construction(state, c.source, c.data.land_unit_construction.location,
c.data.land_unit_construction.pop_culture, c.data.land_unit_construction.type);
c.data.land_unit_construction.pop_culture, c.data.land_unit_construction.type, c.data.land_unit_construction.template_province);
break;
case command_type::cancel_land_unit_construction:
execute_cancel_land_unit_construction(state, c.source, c.data.land_unit_construction.location,
Expand Down
10 changes: 6 additions & 4 deletions src/gamestate/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ struct diplo_action_data {
struct naval_unit_construction_data {
dcon::province_id location;
dcon::unit_type_id type;
dcon::province_id template_province;
};

struct rally_point_data {
Expand All @@ -185,6 +186,7 @@ struct land_unit_construction_data {
dcon::province_id location;
dcon::culture_id pop_culture;
dcon::unit_type_id type;
dcon::province_id template_province;
};

struct factory_data {
Expand Down Expand Up @@ -534,11 +536,11 @@ bool can_begin_factory_building_construction(sys::state& state, dcon::nation_id
void cancel_factory_building_construction(sys::state& state, dcon::nation_id source, dcon::state_instance_id location, dcon::factory_type_id type);
bool can_cancel_factory_building_construction(sys::state& state, dcon::nation_id source, dcon::state_instance_id location, dcon::factory_type_id type);

void start_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type);
bool can_start_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type);
void start_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type, dcon::province_id template_province = dcon::province_id{});
bool can_start_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type, dcon::province_id template_province = dcon::province_id{});

void start_land_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type);
bool can_start_land_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type);
void start_land_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type, dcon::province_id template_province = dcon::province_id{});
bool can_start_land_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::culture_id soldier_culture, dcon::unit_type_id type, dcon::province_id template_province = dcon::province_id{});

void cancel_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type);
bool can_cancel_naval_unit_construction(sys::state& state, dcon::nation_id source, dcon::province_id location, dcon::unit_type_id type);
Expand Down
Loading

0 comments on commit 5b8d9e2

Please sign in to comment.