Skip to content

Commit 98f9abf

Browse files
committed
gamestate: Handle ApplyEffect in activity system.
1 parent 3db02b9 commit 98f9abf

File tree

4 files changed

+32
-22
lines changed

4 files changed

+32
-22
lines changed

libopenage/gamestate/api/definitions.h

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,29 +157,31 @@ static const auto EFFECT_TYPE_LOOKUP = datastructure::create_const_map<nyan::fqo
157157
* Maps API resistance types to internal effect types.
158158
*/
159159
static const auto RESISTANCE_TYPE_LOOKUP = datastructure::create_const_map<nyan::fqon_t, effect_t>(
160-
std::pair("engine.resistance.type.ContinuousFlatAttributeChangeDecrease",
160+
std::pair("engine.resistance.continuous.flat_attribute_change.type.FlatAttributeChangeDecrease",
161161
effect_t::CONTINUOUS_FLAC_DECREASE),
162-
std::pair("engine.resistance.type.ContinuousFlatAttributeChangeIncrease",
162+
std::pair("engine.resistance.continuous.flat_attribute_change.type.FlatAttributeChangeIncrease",
163163
effect_t::CONTINUOUS_FLAC_INCREASE),
164-
std::pair("engine.resistance.type.Lure",
164+
std::pair("engine.resistance.continuous.type.Lure",
165165
effect_t::CONTINUOUS_LURE),
166-
std::pair("engine.resistance.type.ContinuousTimeRelativeAttributeChangeDecrease",
166+
std::pair("engine.resistance.continuous.type.TimeRelativeAttributeChangeDecrease",
167167
effect_t::CONTINUOUS_TRAC_DECREASE),
168-
std::pair("engine.resistance.type.ContinuousTimeRelativeAttributeChangeIncrease",
168+
std::pair("engine.resistance.continuous.type.TimeRelativeAttributeChangeIncrease",
169169
effect_t::CONTINUOUS_TRAC_INCREASE),
170-
std::pair("engine.resistance.type.ContinuousTimeRelativeProgressChangeDecrease",
170+
std::pair("engine.resistance.continuous.type.TimeRelativeProgressChangeDecrease",
171171
effect_t::CONTINUOUS_TRPC_DECREASE),
172-
std::pair("engine.resistance.type.ContinuousTimeRelativeProgressChangeIncrease",
172+
std::pair("engine.resistance.continuous.type.TimeRelativeProgressChangeIncrease",
173173
effect_t::CONTINUOUS_TRPC_INCREASE),
174-
std::pair("engine.resistance.type.Convert",
174+
std::pair("engine.resistance.discrete.type.Convert",
175175
effect_t::DISCRETE_CONVERT),
176-
std::pair("engine.resistance.type.DiscreteFlatAttributeChangeDecrease",
176+
std::pair("engine.resistance.discrete.convert.type.AoE2Convert", // TODO: Remove from API
177+
effect_t::DISCRETE_CONVERT),
178+
std::pair("engine.resistance.discrete.flat_attribute_change.type.FlatAttributeChangeDecrease",
177179
effect_t::DISCRETE_FLAC_DECREASE),
178-
std::pair("engine.resistance.type.DiscreteFlatAttributeChangeIncrease",
180+
std::pair("engine.resistance.discrete.flat_attribute_change.type.FlatAttributeChangeIncrease",
179181
effect_t::DISCRETE_FLAC_INCREASE),
180-
std::pair("engine.resistance.type.MakeHarvestable",
182+
std::pair("engine.resistance.discrete.type.MakeHarvestable",
181183
effect_t::DISCRETE_MAKE_HARVESTABLE),
182-
std::pair("engine.resistance.type.SendToContainer",
184+
std::pair("engine.resistance.discrete.type.SendToContainer",
183185
effect_t::DISCRETE_SEND_TO_CONTAINER));
184186

185187

@@ -243,6 +245,8 @@ static const auto ACTIVITY_NODE_DEFS = datastructure::create_const_map<std::stri
243245
* TODO: Expand this to include all systems.
244246
*/
245247
static const auto ACTIVITY_TASK_SYSTEM_DEFS = datastructure::create_const_map<std::string, system::system_id_t>(
248+
std::pair("engine.ability.type.ApplyDiscreteEffect",
249+
system::system_id_t::APPLY_EFFECT),
246250
std::pair("engine.ability.type.Idle",
247251
system::system_id_t::IDLE),
248252
std::pair("engine.ability.type.Move",
@@ -254,6 +258,8 @@ static const auto ACTIVITY_TASK_SYSTEM_DEFS = datastructure::create_const_map<st
254258
static const auto ACTIVITY_CONDITIONS = datastructure::create_const_map<std::string, activity::condition_t>(
255259
std::pair("engine.util.activity.condition.type.CommandInQueue",
256260
std::function(gamestate::activity::command_in_queue)),
261+
std::pair("engine.util.activity.condition.type.NextCommandApplyEffect",
262+
std::function(gamestate::activity::next_command_apply_effect)),
257263
std::pair("engine.util.activity.condition.type.NextCommandIdle",
258264
std::function(gamestate::activity::next_command_idle)),
259265
std::pair("engine.util.activity.condition.type.NextCommandMove",

libopenage/gamestate/system/activity.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "gamestate/component/internal/activity.h"
2020
#include "gamestate/component/types.h"
2121
#include "gamestate/game_entity.h"
22+
#include "gamestate/system/apply_effect.h"
2223
#include "gamestate/system/idle.h"
2324
#include "gamestate/system/move.h"
2425
#include "util/fixed_point.h"
@@ -125,6 +126,9 @@ const time::time_t Activity::handle_subsystem(const time::time_t &start_time,
125126
const std::shared_ptr<openage::gamestate::GameState> &state,
126127
system_id_t system_id) {
127128
switch (system_id) {
129+
case system_id_t::APPLY_EFFECT:
130+
return ApplyEffect::apply_effect(entity, state, entity, start_time);
131+
break;
128132
case system_id_t::IDLE:
129133
return Idle::idle(entity, start_time);
130134
break;

libopenage/gamestate/system/apply_effect.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const time::time_t ApplyEffect::apply_effect(const std::shared_ptr<gamestate::Ga
2626
auto effects_component = std::dynamic_pointer_cast<component::ApplyEffect>(
2727
effector->get_component(component::component_t::APPLY_EFFECT));
2828
auto effect_ability = effects_component->get_ability();
29-
auto batches = effect_ability.get_set("ApplyEffect.batches");
29+
auto batches = effect_ability.get_set("ApplyDiscreteEffect.batches");
3030

3131
auto resistance_component = std::dynamic_pointer_cast<component::Resistance>(
3232
resistor->get_component(component::component_t::RESISTANCE));
@@ -48,7 +48,7 @@ const time::time_t ApplyEffect::apply_effect(const std::shared_ptr<gamestate::Ga
4848
auto effect_obj = effect_ability.get_view()->get_object(effect_obj_val->get_name());
4949
auto effect_type = api::APIEffect::get_type(effect_obj);
5050

51-
if (effects.contains(effect_type)) {
51+
if (not effects.contains(effect_type)) {
5252
effects.emplace(effect_type, std::vector<nyan::Object>{});
5353
}
5454

@@ -63,7 +63,7 @@ const time::time_t ApplyEffect::apply_effect(const std::shared_ptr<gamestate::Ga
6363
auto resistance_obj = resistance_ability.get_view()->get_object(resistance_obj_val->get_name());
6464
auto resistance_type = api::APIResistance::get_effect_type(resistance_obj);
6565

66-
if (resistances.contains(resistance_type)) {
66+
if (not resistances.contains(resistance_type)) {
6767
resistances.emplace(resistance_type, std::vector<nyan::Object>{});
6868
}
6969

@@ -77,7 +77,7 @@ const time::time_t ApplyEffect::apply_effect(const std::shared_ptr<gamestate::Ga
7777
auto effect_type = effect.first;
7878
auto effect_objs = effect.second;
7979

80-
if (!resistances.contains(effect_type)) {
80+
if (not resistances.contains(effect_type)) {
8181
continue;
8282
}
8383

@@ -119,9 +119,9 @@ const component::attribute_value_t ApplyEffect::get_applied_discrete_flac(const
119119
component::attribute_value_t max_change = component::attribute_value_t::max_value();
120120

121121
for (auto &effect : effects) {
122-
auto change_amount = effect.get_object("FlatAttributeChange.value");
122+
auto change_amount = effect.get_object("FlatAttributeChange.change_value");
123123
auto min_change_amount = effect.get_optional<nyan::Object>("FlatAttributeChange.min_change_value");
124-
auto max_change_amount = effect.get_optional<nyan::Object>("FlatAttributeChange.max_change_value");
124+
auto max_change_amount = effect.get_optional<nyan::Object, true>("max_change_value");
125125

126126
// Get value from change amount
127127
// TODO: Ensure that the attribute is the same for all effects
@@ -149,9 +149,7 @@ const component::attribute_value_t ApplyEffect::get_applied_discrete_flac(const
149149
// idea: move effect type to Effect object and make Resistance.resistances a dict.
150150

151151
for (auto &resistance : resistances) {
152-
auto block_amount = resistance.get_object("FlatAttributeChange.value");
153-
auto min_block_amount = resistance.get_optional<nyan::Object>("FlatAttributeChange.min_change_value");
154-
auto max_block_amount = resistance.get_optional<nyan::Object>("FlatAttributeChange.max_change_value");
152+
auto block_amount = resistance.get_object("FlatAttributeChange.block_value");
155153

156154
// Get value from block amount
157155
// TODO: Ensure that the attribute is the same attribute used in the effects

libopenage/gamestate/system/types.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023-2023 the openage authors. See copying.md for legal info.
1+
// Copyright 2023-2024 the openage authors. See copying.md for legal info.
22

33
#pragma once
44

@@ -11,6 +11,8 @@ namespace openage::gamestate::system {
1111
enum class system_id_t {
1212
NONE,
1313

14+
APPLY_EFFECT,
15+
1416
IDLE,
1517

1618
MOVE_COMMAND,

0 commit comments

Comments
 (0)