Skip to content

Commit

Permalink
feat: Event triggers
Browse files Browse the repository at this point in the history
Added event trigger for building caught fire
Added event trigger for building collapse poor maintenance
  • Loading branch information
UberWaffe committed Feb 4, 2025
1 parent 52b15f9 commit 9be117d
Show file tree
Hide file tree
Showing 70 changed files with 513 additions and 960 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,9 @@ set(SCENARIO_FILES
${PROJECT_SOURCE_DIR}/src/scenario/event/parameter_data.c
${PROJECT_SOURCE_DIR}/src/scenario/event/action_handler.c
${PROJECT_SOURCE_DIR}/src/scenario/event/action_types.c
${PROJECT_SOURCE_DIR}/src/scenario/event/condition_comparison_helper.c
${PROJECT_SOURCE_DIR}/src/scenario/event/condition_handler.c
${PROJECT_SOURCE_DIR}/src/scenario/event/condition_types.c
${PROJECT_SOURCE_DIR}/src/scenario/event/conditions/comparison_helper.c
${PROJECT_SOURCE_DIR}/src/scenario/event/conditions/handler.c
${PROJECT_SOURCE_DIR}/src/scenario/event/conditions/types.c
)
set(GRAPHICS_FILES
${PROJECT_SOURCE_DIR}/src/graphics/arrow_button.c
Expand Down
8 changes: 4 additions & 4 deletions res/editor_examples/example_events_with_custom_variables.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?xml version="1.0"?>
<!DOCTYPE events>
<events version="2">
<events version="3">
<variables>
<variable uid="ConsecutiveMonthsNotInDebt" initial_value="0"/>
<variable uid="TotalMonthsInDebt" initial_value="0"/>
</variables>
<!-- Repeats forever -->
<event repeat_months_min="1" repeat_months_max="1">
<event repeat_triggers_min="1" repeat_triggers_max="1">
<conditions>
<money check="gte" min="0" max="0"/>
</conditions>
Expand All @@ -16,7 +16,7 @@
</actions>
</event>
<!-- Repeats forever -->
<event repeat_months_min="1" repeat_months_max="1">
<event repeat_triggers_min="1" repeat_triggers_max="1">
<conditions>
<money check="lt" min="0" max="0"/>
</conditions>
Expand All @@ -27,7 +27,7 @@
</actions>
</event>
<!-- Repeats forever -->
<event repeat_months_min="1" repeat_months_max="1">
<event repeat_triggers_min="1" repeat_triggers_max="1">
<conditions>
<!-- 5 years of no debt -->
<variable_check variable_uid="ConsecutiveMonthsNotInDebt" check="gte" value="60"/>
Expand Down
20 changes: 10 additions & 10 deletions res/editor_examples/example_events_xml.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0"?>
<!DOCTYPE events>
<events version="1">
<events version="3">
<!-- This event is setup to repeat randomly every 1 to 4 months.
How many months it takes before repeating is randomly chosen between min and max each time it triggers. -->
<event repeat_months_min="1" repeat_months_max="4">
<event repeat_triggers_min="1" repeat_triggers_max="4">
<!-- Even though the event can repeat 1 to 4 months, we also have a time check here.
This is checking that the months passed since the start of the game is equal or greater than a random number between 4 and 6.
Once the scenario starts, this number will be determined (say it picks 5), and it will then start checking if that number of months have passed.
Expand Down Expand Up @@ -62,7 +62,7 @@
</actions>
</event>
<!-- Every month, if the player's city has less than 2000 money in its coffers, give money but reduce favour. -->
<event repeat_months_min="1" repeat_months_max="1" max_number_of_repeats="2">
<event repeat_triggers_min="1" repeat_triggers_max="1" max_number_of_repeats="2">
<conditions>
<money check="lte" value="0"/>
</conditions>
Expand All @@ -82,7 +82,7 @@
</actions>
</event>
<!-- ... this second event runs randomly every (4 to 7) months while the wheat price is above 28, decreasing it by 2 each time. -->
<event repeat_months_min="4" repeat_months_max="7">
<event repeat_triggers_min="4" repeat_triggers_max="7">
<conditions>
<trade_sell_price resource="wheat" check="gte" value="28"/>
</conditions>
Expand All @@ -91,7 +91,7 @@
</actions>
</event>
<!-- While Caesar loves us, and the trade price of wine is below 270, slowly increase it silently (no message shown) -->
<event repeat_months_min="1" repeat_months_max="6">
<event repeat_triggers_min="1" repeat_triggers_max="6">
<conditions>
<stats_favor check="gte" value="80"/>
</conditions>
Expand Down Expand Up @@ -127,7 +127,7 @@
</actions>
</event>
<!-- For the first two years Rome lowers wages consistently until it gets as low as 15. -->
<event repeat_months_min="1" repeat_months_max="1">
<event repeat_triggers_min="1" repeat_triggers_max="1">
<conditions>
<time check="lte" amount="24"/>
<rome_wages check="gte" value="15"/>
Expand All @@ -137,7 +137,7 @@
</actions>
</event>
<!-- After two years, Rome's wages rises until it hits about 37. -->
<event repeat_months_min="1" repeat_months_max="5">
<event repeat_triggers_min="1" repeat_triggers_max="5">
<conditions>
<time check="gte" amount="24"/>
<rome_wages check="lte" value="37"/>
Expand All @@ -147,7 +147,7 @@
</actions>
</event>
<!-- Once we have more than 1000 patricians, then we get start receiving some personal gifts. Totally legit. -->
<event repeat_months_min="7" repeat_months_max="12">
<event repeat_triggers_min="7" repeat_triggers_max="12">
<conditions>
<city_population check="gte" value="1000" class="patrician"/>
</conditions>
Expand Down Expand Up @@ -247,7 +247,7 @@
</event>
<!-- After 2 months, force start the first request (which we will use as a repeating request).
And about every 9 months, try and start the request again (will do nothing if already active.) -->
<event repeat_months_min="7" repeat_months_max="11">
<event repeat_triggers_min="7" repeat_triggers_max="11">
<conditions>
<time check="gte" amount="2"/>
</conditions>
Expand All @@ -263,7 +263,7 @@
Note: For an request like this that repeat quickly, you probably want the request itself to have
a long leeway in its deadline, so that the player can leave it be for a bit and not get constant
request spam. -->
<event repeat_months_min="1" repeat_months_max="1" max_number_of_repeats="4">
<event repeat_triggers_min="1" repeat_triggers_max="1" max_number_of_repeats="4">
<conditions>
<request_is_ongoing request_id="1" check_for_ongoing="false"/>
</conditions>
Expand Down
14 changes: 7 additions & 7 deletions res/editor_examples/repeating_requests_examples.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
After that we want the new request to be the one that repeats, and since it will be the main way to get favour with Caesar, repeat as often as possible.
That way, if the player wants to get high favour, they will have to ship loads of wheat, as you only get 1 favour per request.
However, since it has a long deadline, the player can ignore it for a while if they don't want to worry about favour at that moment. -->
<events version="1">
<events version="3">
<!-- First request (id = 0) -->
<event repeat_months_min="12" repeat_months_max="12"> <!-- At most once per year -->
<event repeat_triggers_min="12" repeat_triggers_max="12"> <!-- At most once per year -->
<conditions>
<time check="gte" amount="24"/> <!-- 2 years -->
<time check="lte" amount="120"/> <!-- 10 years -->
Expand All @@ -34,7 +34,7 @@
</actions>
</event>
<!-- Second request (id = 1) -->
<event repeat_months_min="1" repeat_months_max="1"> <!-- Immediately repeated upon completion / ignored -->
<event repeat_triggers_min="1" repeat_triggers_max="1"> <!-- Immediately repeated upon completion / ignored -->
<conditions>
<time check="gte" amount="120"/> <!-- 10 years -->
<request_is_ongoing request_id="1" check_for_ongoing="false"/>
Expand All @@ -44,7 +44,7 @@
</actions>
</event>
<!-- Third request (id = 2) -->
<event repeat_months_min="1" repeat_months_max="1"> <!-- Immediately repeated upon completion / ignored -->
<event repeat_triggers_min="1" repeat_triggers_max="1"> <!-- Immediately repeated upon completion / ignored -->
<conditions>
<time check="gte" amount="144"/> <!-- 12 years -->
<request_is_ongoing request_id="2" check_for_ongoing="false"/>
Expand All @@ -54,7 +54,7 @@
</actions>
</event>
<!-- Fourth request (id = 3) -->
<event repeat_months_min="8" repeat_months_max="12"> <!-- Random, roughly 10 months -->
<event repeat_triggers_min="8" repeat_triggers_max="12"> <!-- Random, roughly 10 months -->
<conditions>
<time check="gte" amount="144"/>
<request_is_ongoing request_id="3" check_for_ongoing="false"/>
Expand All @@ -64,7 +64,7 @@
</actions>
</event>
<!-- Fifth request (id = 4) -->
<event repeat_months_min="8" repeat_months_max="12"> <!-- Random, roughly 10 months -->
<event repeat_triggers_min="8" repeat_triggers_max="12"> <!-- Random, roughly 10 months -->
<conditions>
<time check="gte" amount="144"/>
<request_is_ongoing request_id="4" check_for_ongoing="false"/>
Expand All @@ -77,7 +77,7 @@
This way the player has to make use of the repeatng requests to get to the target of 95 favour.
If fact, since the player will lose 1 favour per month, they will have to be constantly fulfilling multiple repeating requests to
get to the target favor -->
<event repeat_months_min="1" repeat_months_max="1"> <!-- Every month... -->
<event repeat_triggers_min="1" repeat_triggers_max="1"> <!-- Every month... -->
<conditions>
<stats_favor check="gte" value="40"/> <!-- when Caesar's favour is above 40, then... -->
</conditions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE events>
<!-- This example shows how you can manually control Rome's wage adjustments, giving more precise control of when
they happen, and even taking things like difficulty into account. -->
<events version="1">
<events version="3">
<!-- START OF very easy ==================================================================================
We start off with wages at 26,
and then increase it by 1 once every two years,
Expand All @@ -18,7 +18,7 @@
</event>
<!-- We make this event that increases the Rome wages repeat,
that way we don't need to make a new event for every two years. -->
<event repeat_months_min="24" repeat_months_max="24">
<event repeat_triggers_min="24" repeat_triggers_max="24">
<conditions>
<time check="gte" amount="24"/> <!-- "gte" = greater than or equal -->
<difficulty check="eq" value="very_easy"/>
Expand Down Expand Up @@ -46,7 +46,7 @@
<change_rome_wages amount="28" set_to_value="true"/>
</actions>
</event>
<event repeat_months_min="15" repeat_months_max="21">
<event repeat_triggers_min="15" repeat_triggers_max="21">
<conditions>
<time check="gte" min="18" max="24"/>
<difficulty check="eq" value="easy"/>
Expand All @@ -71,7 +71,7 @@
<change_rome_wages amount="30" set_to_value="true"/>
</actions>
</event>
<event repeat_months_min="15" repeat_months_max="21" max_number_of_repeats="4">
<event repeat_triggers_min="15" repeat_triggers_max="21" max_number_of_repeats="4">
<conditions>
<time check="gte" min="18" max="24"/>
<difficulty check="eq" value="normal"/>
Expand All @@ -97,7 +97,7 @@
<change_rome_wages amount="32" set_to_value="true"/>
</actions>
</event>
<event repeat_months_min="9" repeat_months_max="15">
<event repeat_triggers_min="9" repeat_triggers_max="15">
<conditions>
<time check="gte" min="18" max="24"/>
<difficulty check="eq" value="hard"/>
Expand Down Expand Up @@ -133,7 +133,7 @@
<change_rome_wages amount="32" set_to_value="true"/>
</actions>
</event>
<event repeat_months_min="9" repeat_months_max="15">
<event repeat_triggers_min="9" repeat_triggers_max="15">
<conditions>
<time check="gte" min="18" max="24"/>
<difficulty check="eq" value="very_hard"/>
Expand All @@ -143,7 +143,7 @@
<change_rome_wages min="2" max="5" set_to_value="false"/>
</actions>
</event>
<event repeat_months_min="3" repeat_months_max="6">
<event repeat_triggers_min="3" repeat_triggers_max="6">
<conditions>
<difficulty check="eq" value="very_hard"/>
<rome_wages check="gte" value="46"/>
Expand Down
2 changes: 1 addition & 1 deletion res/editor_examples/scenario_start_difficulty_tweaks.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!-- This example document can be used for adjusting various things (money, favor, Rome wages, trade prices) at the start of the scenario based on the difficulty the player is playing on.
Keep in mind the money and favour changes happen over and above what the game will already adjust based on difficulty.
But you can also put in other changes, like trade price changes, or how much certain trade routes demand / supply for each difficulty. -->
<events version="1">
<events version="3">
<!-- Very easy -->
<event>
<conditions>
Expand Down
4 changes: 2 additions & 2 deletions res/manual/README_map_editor_scenario_events.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Every time the month ticks over (changes to the next month).
There are a few settings we can set on the event itself.

Making the event repeat
+ "repeat_months_min" = If this is greater than 0, and max is equal or greater than min, then this event will repeat (it becomes paused instead of disabled after running.)
+ "repeat_months_max" = The event will become active again after a random number of months between min and max (if the two are equal, then the number is not random).
+ "repeat_triggers_min" = If this is greater than 0, and max is equal or greater than min, then this event will repeat (it becomes paused instead of disabled after running.)
+ "repeat_triggers_max" = The event will become active again after a random number of triggers between min and max (if the two are equal, then the number is not random).
+ "max_number_of_repeats" = This is the maximum number of times the event is allowed to trigger. Settings this to 0 will allow the event to trigger infinitely.


Expand Down
3 changes: 3 additions & 0 deletions src/building/construction.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "map/water.h"
#include "map/water_supply.h"
#include "scenario/allowed_building.h"
#include "scenario/event/controller.h"

#define MAX_CYCLE_SIZE 10

Expand Down Expand Up @@ -685,6 +686,8 @@ void building_construction_start(int x, int y, int grid_offset)
}
if (!can_start) {
building_construction_cancel();
} else {
scenario_events_full_process(EVENT_TRIGGER_BUILDING_PLACED_BY_PLAYER, 1, data.type);
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion src/building/construction_clear.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "map/routing_terrain.h"
#include "map/terrain.h"
#include "map/tiles.h"
#include "scenario/event/controller.h"
#include "translation/translation.h"
#include "window/popup_dialog.h"

Expand All @@ -30,6 +31,12 @@ static struct {
int monument_confirmed;
} confirm;

static void event_process_clearing(int building_type)
{
scenario_events_full_process(EVENT_TRIGGER_BUILDING_CLEARED_BY_PLAYER, 1, building_type);
scenario_events_full_process(EVENT_TRIGGER_BUILDING_DESTROYED_BY_ANYTHING, 1, building_type);
}

static building *get_deletable_building(int grid_offset)
{
int building_id = map_building_at(grid_offset);
Expand Down Expand Up @@ -144,10 +151,12 @@ static int clear_land_confirmed(int measure_only, int x_start, int y_start, int
game_undo_add_building(space);
space->state = BUILDING_STATE_DELETED_BY_PLAYER;
}
event_process_clearing(b->type);
} else if (map_terrain_is(grid_offset, TERRAIN_AQUEDUCT)) {
map_terrain_remove(grid_offset, TERRAIN_CLEARABLE & ~TERRAIN_HIGHWAY);
items_placed++;
map_aqueduct_remove(grid_offset);
event_process_clearing(BUILDING_AQUEDUCT);
} else if (map_terrain_is(grid_offset, TERRAIN_WATER)) {
if (!measure_only && map_bridge_count_figures(grid_offset) > 0) {
city_warning_show(WARNING_PEOPLE_ON_BRIDGE, NEW_WARNING_SLOT);
Expand All @@ -159,8 +168,17 @@ static int clear_land_confirmed(int measure_only, int x_start, int y_start, int
int next_highways_removed = map_tiles_clear_highway(grid_offset, measure_only);
highways_removed += next_highways_removed;
items_placed += next_highways_removed;
event_process_clearing(BUILDING_HIGHWAY);
} else if (map_terrain_is(grid_offset, TERRAIN_NOT_CLEAR)) {
if (map_terrain_is(grid_offset, TERRAIN_ROAD | TERRAIN_GARDEN)) {
int is_road = map_terrain_is(grid_offset, TERRAIN_ROAD);
int is_garden = map_terrain_is(grid_offset, TERRAIN_GARDEN);
if (is_road) {
event_process_clearing(BUILDING_ROAD);
}
if (is_garden) {
event_process_clearing(BUILDING_GARDENS);
}
if (is_road || is_garden) {
map_property_clear_plaza_earthquake_or_overgrown_garden(grid_offset);
}
map_terrain_remove(grid_offset, TERRAIN_CLEARABLE);
Expand Down
Loading

0 comments on commit 9be117d

Please sign in to comment.