Skip to content

Commit

Permalink
Start adding support for allowing/disallowing any building
Browse files Browse the repository at this point in the history
  • Loading branch information
crudelios committed Jan 19, 2025
1 parent 43770c3 commit 3f8e838
Show file tree
Hide file tree
Showing 33 changed files with 235 additions and 422 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ set(ASSETS_FILES
${PROJECT_SOURCE_DIR}/src/assets/xml.c
)
set(SCENARIO_FILES
${PROJECT_SOURCE_DIR}/src/scenario/building.c
${PROJECT_SOURCE_DIR}/src/scenario/allowed_building.c
${PROJECT_SOURCE_DIR}/src/scenario/criteria.c
${PROJECT_SOURCE_DIR}/src/scenario/custom_media.c
${PROJECT_SOURCE_DIR}/src/scenario/custom_messages_export_xml.c
Expand Down
4 changes: 2 additions & 2 deletions src/building/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "core/config.h"
#include "empire/city.h"
#include "game/tutorial.h"
#include "scenario/building.h"
#include "scenario/allowed_building.h"
#include "scenario/property.h"

#define BUILD_MENU_ITEM_MAX 30
Expand Down Expand Up @@ -133,7 +133,7 @@ static int can_get_required_resource(building_type type)

static int is_building_type_allowed(building_type type)
{
return scenario_building_allowed(type) && can_get_required_resource(type);
return scenario_allowed_building(type) && can_get_required_resource(type);
}

static void enable_if_allowed(int *enabled, building_type menu_building_type, building_type type)
Expand Down
2 changes: 1 addition & 1 deletion src/city/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "game/resource.h"
#include "game/tutorial.h"
#include "map/road_access.h"
#include "scenario/building.h"
#include "scenario/allowed_building.h"
#include "scenario/property.h"

#include <math.h>
Expand Down
1 change: 0 additions & 1 deletion src/core/lang.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "core/io.h"
#include "core/log.h"
#include "core/string.h"
#include "scenario/building.h"
#include "translation/translation.h"

#include <stdlib.h>
Expand Down
10 changes: 5 additions & 5 deletions src/empire/city.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include "game/campaign.h"
#include "game/resource.h"
#include "game/save_version.h"
#include "scenario/building.h"
#include "scenario/allowed_building.h"
#include "scenario/empire.h"
#include "scenario/map.h"
#include "scenario/property.h"
Expand Down Expand Up @@ -157,14 +157,14 @@ int empire_can_produce_resource_locally(int resource)
// Wine can also be produced via Venus Grand Temple
if (resource == RESOURCE_WINE) {
return !building_monument_requires_resource(BUILDING_GRAND_TEMPLE_VENUS, RESOURCE_WINE) &&
scenario_building_allowed(BUILDING_MENU_GRAND_TEMPLES) &&
scenario_building_allowed(BUILDING_GRAND_TEMPLE_VENUS) &&
scenario_allowed_building(BUILDING_MENU_GRAND_TEMPLES) &&
scenario_allowed_building(BUILDING_GRAND_TEMPLE_VENUS) &&
building_monument_has_required_resources_to_build(BUILDING_GRAND_TEMPLE_VENUS);
}
// Gold can also be produced via City Mint
if (resource == RESOURCE_GOLD) {
return !building_monument_requires_resource(BUILDING_CITY_MINT, RESOURCE_GOLD) &&
scenario_building_allowed(BUILDING_CITY_MINT) &&
scenario_allowed_building(BUILDING_CITY_MINT) &&
building_monument_has_required_resources_to_build(BUILDING_CITY_MINT);
}
return 0;
Expand Down Expand Up @@ -618,7 +618,7 @@ void empire_city_update_trading_data(int empire_id)
if (city->type == EMPIRE_CITY_OURS) {
if (city->sells_resource[RESOURCE_FISH]) {
empire_city_change_selling_of_resource(city, RESOURCE_MEAT, !NOT_SELLING);
} else if (scenario_building_allowed(BUILDING_WHARF)) {
} else if (scenario_allowed_building(BUILDING_WHARF)) {
empire_city_change_selling_of_resource(city, RESOURCE_FISH, !NOT_SELLING);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/empire/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include "empire/type.h"
#include "game/animation.h"
#include "game/save_version.h"
#include "scenario/building.h"
#include "scenario/data.h"
#include "scenario/empire.h"

Expand Down
18 changes: 10 additions & 8 deletions src/game/file_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@
#include "map/sprite.h"
#include "map/terrain.h"
#include "map/tiles.h"
#include "scenario/allowed_building.h"
#include "scenario/criteria.h"
#include "scenario/custom_media.h"
#include "scenario/custom_messages.h"
#include "scenario/custom_variable.h"
#include "scenario/demand_change.h"
#include "scenario/earthquake.h"
#include "scenario/emperor_change.h"
Expand Down Expand Up @@ -683,8 +685,8 @@ static void scenario_load_from_state(scenario_state *file, scenario_version_t ve
scenario_invasion_load_state(file->invasions);
scenario_demand_change_load_state(file->demand_changes);
scenario_price_change_load_state(file->price_changes);
// scenario_building_load_state(file->allowed_buildings);
// scenario_custom_variable_load_state(file->custom_variables);
scenario_allowed_building_load_state(file->allowed_buildings);
scenario_custom_variable_load_state(file->custom_variables);
}
if (version > SCENARIO_LAST_NO_EVENTS) {
scenario_events_load_state(file->scenario_events, file->scenario_conditions, file->scenario_actions,
Expand Down Expand Up @@ -719,8 +721,8 @@ static void scenario_save_to_state(scenario_state *file)
scenario_invasion_save_state(file->invasions);
scenario_demand_change_save_state(file->demand_changes);
scenario_price_change_save_state(file->price_changes);
// scenario_building_save_state(file->allowed_buildings);
// scenario_custom_variable_save_state(file->custom_variables);
scenario_allowed_building_save_state(file->allowed_buildings);
scenario_custom_variable_save_state(file->custom_variables);
scenario_events_save_state(file->scenario_events, file->scenario_conditions, file->scenario_actions);
custom_messages_save_state(file->custom_messages);
custom_media_save_state(file->custom_media);
Expand Down Expand Up @@ -769,8 +771,8 @@ static void savegame_load_from_state(savegame_state *state, savegame_version_t v
scenario_invasion_load_state(state->invasions);
scenario_demand_change_load_state(state->demand_changes);
scenario_price_change_load_state(state->price_changes);
// scenario_building_load_state(state->allowed_buildings);
// scenario_custom_variable_load_state(state->custom_variables);
scenario_allowed_building_load_state(state->allowed_buildings);
scenario_custom_variable_load_state(state->custom_variables);
}

if (scenario_version > SCENARIO_LAST_NO_EVENTS) {
Expand Down Expand Up @@ -916,8 +918,8 @@ static void savegame_save_to_state(savegame_state *state)
scenario_invasion_save_state(state->invasions);
scenario_demand_change_save_state(state->demand_changes);
scenario_price_change_save_state(state->price_changes);
// scenario_building_save_state(state->allowed_buildings);
// scenario_custom_variable_save_state(state->custom_variables);
scenario_allowed_building_save_state(state->allowed_buildings);
scenario_custom_variable_save_state(state->custom_variables);
scenario_events_save_state(state->scenario_events, state->scenario_conditions, state->scenario_actions);
custom_messages_save_state(state->custom_messages);
custom_media_save_state(state->custom_media);
Expand Down
6 changes: 3 additions & 3 deletions src/game/resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "core/image.h"
#include "core/image_group_editor.h"
#include "game/save_version.h"
#include "scenario/building.h"
#include "scenario/allowed_building.h"
#include "scenario/property.h"
#include "translation/translation.h"

Expand Down Expand Up @@ -314,7 +314,7 @@ void resource_set_mapping(int version)
resource_type resource_map_legacy_inventory(int id)
{
resource_type resource = mapping.inventory ? mapping.inventory[id] : id;
if (mapping.joined_meat_and_fish && resource == RESOURCE_MEAT && scenario_building_allowed(BUILDING_WHARF)) {
if (mapping.joined_meat_and_fish && resource == RESOURCE_MEAT && scenario_allowed_building(BUILDING_WHARF)) {
return RESOURCE_FISH;
}
return resource;
Expand All @@ -337,7 +337,7 @@ int resource_production_per_month(resource_type resource)
resource_type resource_remap(int id)
{
resource_type resource = mapping.resources ? mapping.resources[id] : id;
if (mapping.joined_meat_and_fish && resource == RESOURCE_MEAT && scenario_building_allowed(BUILDING_WHARF)) {
if (mapping.joined_meat_and_fish && resource == RESOURCE_MEAT && scenario_allowed_building(BUILDING_WHARF)) {
return RESOURCE_FISH;
}
return resource;
Expand Down
14 changes: 7 additions & 7 deletions src/map/natives.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "map/property.h"
#include "map/random.h"
#include "map/terrain.h"
#include "scenario/building.h"
#include "scenario/data.h" // TODO remove this dependency

static void mark_native_land(int x, int y, int size, int radius)
{
Expand Down Expand Up @@ -77,9 +77,9 @@ static void determine_meeting_center(void)

void map_natives_init(void)
{
int image_hut = scenario_building_image_native_hut();
int image_meeting = scenario_building_image_native_meeting();
int image_crops = scenario_building_image_native_crops();
int image_hut = scenario.native_images.hut;
int image_meeting = scenario.native_images.meeting;
int image_crops = scenario.native_images.crops;
int native_image = image_group(GROUP_BUILDING_NATIVE);
int grid_offset = map_data.start_offset;
for (int y = 0; y < map_data.height; y++, grid_offset += map_data.border_size) {
Expand Down Expand Up @@ -138,9 +138,9 @@ void map_natives_init(void)

void map_natives_init_editor(void)
{
int image_hut = scenario_building_image_native_hut();
int image_meeting = scenario_building_image_native_meeting();
int image_crops = scenario_building_image_native_crops();
int image_hut = scenario.native_images.hut;
int image_meeting = scenario.native_images.meeting;
int image_crops = scenario.native_images.crops;
int native_image = image_group(GROUP_EDITOR_BUILDING_NATIVE);
int grid_offset = map_data.start_offset;
for (int y = 0; y < map_data.height; y++, grid_offset += map_data.border_size) {
Expand Down
18 changes: 17 additions & 1 deletion src/scenario/action_types/action_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ void scenario_action_type_save_state(buffer *buf, const scenario_action_t *actio
buffer_write_i32(buf, action->parameter5);
}

void scenario_action_type_load_state(buffer *buf, scenario_action_t *action, int *link_type, int32_t *link_id)
unsigned int scenario_action_type_load_state(buffer *buf, scenario_action_t *action, int *link_type, int32_t *link_id,
int is_new_version)
{
*link_type = buffer_read_i16(buf);
*link_id = buffer_read_i32(buf);
Expand All @@ -138,7 +139,22 @@ void scenario_action_type_load_state(buffer *buf, scenario_action_t *action, int
action->parameter1 = resource_remap(action->parameter1);
} else if (action->type == ACTION_TYPE_TRADE_SET_SELL_PRICE_ONLY) {
action->parameter1 = resource_remap(action->parameter1);
} else if (action->type == ACTION_TYPE_CHANGE_ALLOWED_BUILDINGS) {
const building_type *building_list = scenario_allowed_building_get_buildings_from_original_id(action->parameter1);
action->parameter1 = building_list[0];
return building_list[1] != BUILDING_NONE;
}
return 0;
}

unsigned int scenario_action_type_load_more(unsigned int index, scenario_action_t *action)
{
if (!index || action->type != ACTION_TYPE_CHANGE_ALLOWED_BUILDINGS) {
return 0;
}
const building_type *building_list = scenario_allowed_building_get_buildings_from_original_id(action->parameter1);
action->parameter1 = building_list[index];
return building_list[index + 1] != BUILDING_NONE ? index + 1 : 0;
}

int scenario_action_uses_custom_variable(const scenario_action_t *action, int custom_variable_id)
Expand Down
4 changes: 3 additions & 1 deletion src/scenario/action_types/action_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ int scenario_action_type_execute(scenario_action_t *action);

void scenario_action_type_delete(scenario_action_t *action);
void scenario_action_type_save_state(buffer *buf, const scenario_action_t *action, int link_type, int32_t link_id);
void scenario_action_type_load_state(buffer *buf, scenario_action_t *action, int *link_type, int32_t *link_id);
unsigned int scenario_action_type_load_state(buffer *buf, scenario_action_t *action, int *link_type, int32_t *link_id,
int is_new_version);
unsigned int scenario_action_type_load_more(unsigned int index, scenario_action_t *action);
int scenario_action_uses_custom_variable(const scenario_action_t *action, int custom_variable_id);

#endif // ACTION_HANDLER_H
5 changes: 3 additions & 2 deletions src/scenario/action_types/action_types.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "game/resource.h"
#include "map/building.h"
#include "map/grid.h"
#include "scenario/allowed_building.h"
#include "scenario/custom_variable.h"
#include "scenario/gladiator_revolt.h"
#include "scenario/custom_messages.h"
Expand All @@ -34,10 +35,10 @@

int scenario_action_type_change_allowed_buildings_execute(scenario_action_t *action)
{
int allowed_id = action->parameter1;
int building_id = action->parameter1;
int allowed = action->parameter2;

scenario.allowed_buildings[allowed_id] = allowed;
scenario_allowed_building_set(building_id, allowed);
building_menu_update();

return 1;
Expand Down
Loading

0 comments on commit 3f8e838

Please sign in to comment.