Skip to content

Commit

Permalink
gamestate: Init new XorSwitchGate activity node type from nyan.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Nov 18, 2024
1 parent 759b944 commit 35d4f37
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
23 changes: 23 additions & 0 deletions libopenage/gamestate/api/activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ std::vector<nyan::Object> APIActivityNode::get_next(const nyan::Object &node) {

return next_nodes;
}
case activity::node_t::XOR_SWITCH_GATE: {
auto switch_condition = node.get<nyan::ObjectValue>("XORSwitchGate.switch");
std::shared_ptr<nyan::View> db_view = node.get_view();

auto switch_condition_obj = db_view->get_object(switch_condition->get_name());
auto switch_condition_parent = switch_condition_obj.get_parents()[0];
auto switch_condition_type = ACTIVITY_SWITCH_CONDITION_TYPES.get(switch_condition_parent);

switch (switch_condition_type) {
case switch_condition_t::NEXT_COMMAND: {
auto next = switch_condition_obj.get_dict("NextCommand.next");
std::vector<nyan::Object> next_nodes;
for (auto next_node : next) {
auto next_node_value = std::dynamic_pointer_cast<nyan::ObjectValue>(next_node.second.get_ptr());
next_nodes.push_back(db_view->get_object(next_node_value->get_name()));
}

return next_nodes;
}
default:
throw Error(MSG(err) << "Unknown switch condition type.");
}
}
default:
throw Error(MSG(err) << "Unknown activity node type.");
}
Expand Down
22 changes: 21 additions & 1 deletion libopenage/gamestate/api/definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
#include "datastructure/constexpr_map.h"
#include "gamestate/activity/condition/command_in_queue.h"
#include "gamestate/activity/condition/next_command.h"
#include "gamestate/activity/condition/next_command_switch.h"
#include "gamestate/activity/event/command_in_queue.h"
#include "gamestate/activity/event/wait.h"
#include "gamestate/activity/types.h"
#include "gamestate/activity/xor_event_gate.h"
#include "gamestate/activity/xor_gate.h"
#include "gamestate/activity/xor_switch_gate.h"
#include "gamestate/api/types.h"
#include "gamestate/system/types.h"

Expand Down Expand Up @@ -237,7 +239,9 @@ static const auto ACTIVITY_NODE_DEFS = datastructure::create_const_map<std::stri
std::pair("engine.util.activity.node.type.XORGate",
activity::node_t::XOR_GATE),
std::pair("engine.util.activity.node.type.XOREventGate",
activity::node_t::XOR_EVENT_GATE));
activity::node_t::XOR_EVENT_GATE),
std::pair("engine.util.activity.node.type.XORSwitchGate",
activity::node_t::XOR_SWITCH_GATE));

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

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

/**
* Maps API activity switch condition types to lookup functions.
*/
static const auto ACTIVITY_SWITCH_CONDITIONS = datastructure::create_const_map<std::string,
activity::XorSwitchGate::lookup_function_t>(
std::pair("engine.util.activity.switch_condition.type.NextCommand",
std::function(gamestate::activity::next_command_switch)));

static const auto ACTIVITY_SWITCH_CONDITION_TYPES = datastructure::create_const_map<std::string,
switch_condition_t>(
std::pair("engine.util.activity.switch_condition.type.NextCommand",
switch_condition_t::NEXT_COMMAND));

/**
* Maps internal patch property types to nyan API values.
*/
Expand Down
7 changes: 7 additions & 0 deletions libopenage/gamestate/api/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ enum class patch_property_t {
DIPLOMATIC,
};

/**
* Types of conditions for the XORSwitchGate API activity node.
*/
enum class switch_condition_t {
NEXT_COMMAND,
};

} // namespace openage::gamestate::api
4 changes: 4 additions & 0 deletions libopenage/gamestate/entity_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "gamestate/activity/task_system_node.h"
#include "gamestate/activity/xor_event_gate.h"
#include "gamestate/activity/xor_gate.h"
#include "gamestate/activity/xor_switch_gate.h"
#include "gamestate/api/activity.h"
#include "gamestate/component/api/apply_effect.h"
#include "gamestate/component/api/idle.h"
Expand Down Expand Up @@ -295,6 +296,9 @@ void EntityFactory::init_activity(const std::shared_ptr<openage::event::EventLoo
case activity::node_t::XOR_EVENT_GATE:
node_id_map[node_id] = std::make_shared<activity::XorEventGate>(node_id);
break;
case activity::node_t::XOR_SWITCH_GATE:
node_id_map[node_id] = std::make_shared<activity::XorSwitchGate>(node_id);
break;
default:
throw Error{ERR << "Unknown activity node type of node: " << node.get_name()};
}
Expand Down

0 comments on commit 35d4f37

Please sign in to comment.