Skip to content

Commit 63bc382

Browse files
committed
gamestate: Init new XorSwitchGate activity node type from nyan.
1 parent 754ad80 commit 63bc382

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

libopenage/gamestate/api/activity.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,29 @@ std::vector<nyan::Object> APIActivityNode::get_next(const nyan::Object &node) {
7878

7979
return next_nodes;
8080
}
81+
case activity::node_t::XOR_SWITCH_GATE: {
82+
auto switch_condition = node.get<nyan::ObjectValue>("XORSwitchGate.switch");
83+
std::shared_ptr<nyan::View> db_view = node.get_view();
84+
85+
auto switch_condition_obj = db_view->get_object(switch_condition->get_name());
86+
auto switch_condition_parent = switch_condition_obj.get_parents()[0];
87+
auto switch_condition_type = ACTIVITY_SWITCH_CONDITION_TYPES.get(switch_condition_parent);
88+
89+
switch (switch_condition_type) {
90+
case switch_condition_t::NEXT_COMMAND: {
91+
auto next = switch_condition_obj.get_dict("NextCommand.next");
92+
std::vector<nyan::Object> next_nodes;
93+
for (auto next_node : next) {
94+
auto next_node_value = std::dynamic_pointer_cast<nyan::ObjectValue>(next_node.second.get_ptr());
95+
next_nodes.push_back(db_view->get_object(next_node_value->get_name()));
96+
}
97+
98+
return next_nodes;
99+
}
100+
default:
101+
throw Error(MSG(err) << "Unknown switch condition type.");
102+
}
103+
}
81104
default:
82105
throw Error(MSG(err) << "Unknown activity node type.");
83106
}

libopenage/gamestate/api/definitions.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
#include "datastructure/constexpr_map.h"
1111
#include "gamestate/activity/condition/command_in_queue.h"
1212
#include "gamestate/activity/condition/next_command.h"
13+
#include "gamestate/activity/condition/next_command_switch.h"
1314
#include "gamestate/activity/event/command_in_queue.h"
1415
#include "gamestate/activity/event/wait.h"
1516
#include "gamestate/activity/types.h"
1617
#include "gamestate/activity/xor_event_gate.h"
1718
#include "gamestate/activity/xor_gate.h"
19+
#include "gamestate/activity/xor_switch_gate.h"
1820
#include "gamestate/api/types.h"
1921
#include "gamestate/system/types.h"
2022

@@ -237,7 +239,9 @@ static const auto ACTIVITY_NODE_DEFS = datastructure::create_const_map<std::stri
237239
std::pair("engine.util.activity.node.type.XORGate",
238240
activity::node_t::XOR_GATE),
239241
std::pair("engine.util.activity.node.type.XOREventGate",
240-
activity::node_t::XOR_EVENT_GATE));
242+
activity::node_t::XOR_EVENT_GATE),
243+
std::pair("engine.util.activity.node.type.XORSwitchGate",
244+
activity::node_t::XOR_SWITCH_GATE));
241245

242246
/**
243247
* Maps API activity task system types to engine system types.
@@ -265,6 +269,9 @@ static const auto ACTIVITY_CONDITIONS = datastructure::create_const_map<std::str
265269
std::pair("engine.util.activity.condition.type.NextCommandMove",
266270
std::function(gamestate::activity::next_command_move)));
267271

272+
/**
273+
* Maps API activity event types to event primer functions.
274+
*/
268275
static const auto ACTIVITY_EVENT_PRIMERS = datastructure::create_const_map<std::string, activity::event_primer_t>(
269276
std::pair("engine.util.activity.event.type.CommandInQueue",
270277
std::function(gamestate::activity::primer_command_in_queue)),
@@ -273,6 +280,19 @@ static const auto ACTIVITY_EVENT_PRIMERS = datastructure::create_const_map<std::
273280
std::pair("engine.util.activity.event.type.WaitAbility",
274281
std::function(gamestate::activity::primer_wait)));
275282

283+
/**
284+
* Maps API activity switch condition types to lookup functions.
285+
*/
286+
static const auto ACTIVITY_SWITCH_CONDITIONS = datastructure::create_const_map<std::string,
287+
activity::XorSwitchGate::lookup_function_t>(
288+
std::pair("engine.util.activity.switch_condition.type.NextCommand",
289+
std::function(gamestate::activity::next_command_switch)));
290+
291+
static const auto ACTIVITY_SWITCH_CONDITION_TYPES = datastructure::create_const_map<std::string,
292+
switch_condition_t>(
293+
std::pair("engine.util.activity.switch_condition.type.NextCommand",
294+
switch_condition_t::NEXT_COMMAND));
295+
276296
/**
277297
* Maps internal patch property types to nyan API values.
278298
*/

libopenage/gamestate/api/types.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,11 @@ enum class patch_property_t {
8181
DIPLOMATIC,
8282
};
8383

84+
/**
85+
* Types of conditions for the XORSwitchGate API activity node.
86+
*/
87+
enum class switch_condition_t {
88+
NEXT_COMMAND,
89+
};
90+
8491
} // namespace openage::gamestate::api

libopenage/gamestate/entity_factory.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "gamestate/activity/task_system_node.h"
2323
#include "gamestate/activity/xor_event_gate.h"
2424
#include "gamestate/activity/xor_gate.h"
25+
#include "gamestate/activity/xor_switch_gate.h"
2526
#include "gamestate/api/activity.h"
2627
#include "gamestate/component/api/apply_effect.h"
2728
#include "gamestate/component/api/idle.h"
@@ -295,6 +296,9 @@ void EntityFactory::init_activity(const std::shared_ptr<openage::event::EventLoo
295296
case activity::node_t::XOR_EVENT_GATE:
296297
node_id_map[node_id] = std::make_shared<activity::XorEventGate>(node_id);
297298
break;
299+
case activity::node_t::XOR_SWITCH_GATE:
300+
node_id_map[node_id] = std::make_shared<activity::XorSwitchGate>(node_id);
301+
break;
298302
default:
299303
throw Error{ERR << "Unknown activity node type of node: " << node.get_name()};
300304
}

0 commit comments

Comments
 (0)