diff --git a/source/core/Data.hpp b/source/core/Data.hpp index 6c8efddb..57dfbc14 100644 --- a/source/core/Data.hpp +++ b/source/core/Data.hpp @@ -52,7 +52,7 @@ class AgentBase; using agent_map_t = std::map>; /// @brief Common types of properties in network serialization -enum class PropertyType { t_double, t_int, t_char, t_string, t_position, t_other }; +enum class PropertyType { t_double, t_int, t_char, t_string, t_position, t_bool, t_other }; /// @brief Enum for World types in network serialization enum class WorldType { w_maze, w_second, w_generative, w_manual }; diff --git a/source/core/Entity.hpp b/source/core/Entity.hpp index 54a74fa1..65afdf8e 100644 --- a/source/core/Entity.hpp +++ b/source/core/Entity.hpp @@ -193,10 +193,14 @@ class Entity : public CoreObject { case t_char: SetProperty(name, DeserializeAs(is)); break; case t_double: SetProperty(name, DeserializeAs(is)); break; case t_int: SetProperty(name, DeserializeAs(is)); break; + case t_bool: SetProperty(name, DeserializeAs(is)); break; case t_string: SetProperty(name, DeserializeAs(is)); break; case t_position: SetProperty(name, DeserializeAs(is)); break; case t_other: std::cerr << "Warning: Cannot deserialize property'" << name << "'." << std::endl; + std::string tmp_str; + std::getline(is, tmp_str, '\n'); + std::cerr << " Data for that property: \"" << tmp_str << "\"." << std::endl; } } } diff --git a/source/core/Property.hpp b/source/core/Property.hpp index b055586a..7f870ec9 100644 --- a/source/core/Property.hpp +++ b/source/core/Property.hpp @@ -36,6 +36,7 @@ struct Property : public PropertyBase { PropertyType GetType() const override { if constexpr (std::is_same()) return PropertyType::t_char; if constexpr (std::is_same()) return PropertyType::t_int; + if constexpr (std::is_same()) return PropertyType::t_bool; if constexpr (std::is_same()) return PropertyType::t_double; if constexpr (std::is_same()) return PropertyType::t_string; if constexpr (std::is_same()) return PropertyType::t_position; @@ -45,6 +46,7 @@ struct Property : public PropertyBase { std::string GetTypeName() const override { if constexpr (std::is_same()) return "char"; if constexpr (std::is_same()) return "int"; + if constexpr (std::is_same()) return "bool"; if constexpr (std::is_same()) return "double"; if constexpr (std::is_same()) return "string"; if constexpr (std::is_same()) return "GridPosition"; diff --git a/source/core/WorldBase.hpp b/source/core/WorldBase.hpp index c14f1049..fd425226 100644 --- a/source/core/WorldBase.hpp +++ b/source/core/WorldBase.hpp @@ -547,19 +547,29 @@ class WorldBase { last_entity_id = 0; // Load the number of agents saved. - size_t size = DeserializeAs(is); + size_t server_last_entity_id = DeserializeAs(is); // client id NOT in agent map yet if ID = 0 // append to end of set - if (client_id == 0) client_id = size; + if (client_id == 0) client_id = server_last_entity_id; // Load back in all agents. - for (size_t i = 0; i < size; i++) { + for (size_t i = 0; i < server_last_entity_id; i++) { + // First, check to see if we've hit the end of the agent_set + // Because we are looking at last entity id (and not total size), we may have + // gaps in our agent_set + auto tmp_pos = is.tellg(); + std::getline(is, read, '\n'); + if(read == ":::END agent_set"){ + if(last_entity_id < client_id) last_entity_id = client_id; + return; + } + else is.seekg(tmp_pos); auto agent_ptr = std::make_unique(0, "temp"); DeserializeValue(is, *agent_ptr); agent_ptr->SetProperty("manager", manager); - if (agent_ptr->GetID() >= last_entity_id) last_entity_id = agent_ptr->GetID() + 1; + if (agent_ptr->GetID() >= last_entity_id) last_entity_id = agent_ptr->GetID(); // If this agent is the client interface, skip it (we already have it). if (agent_ptr->GetID() == client_id) { continue; } diff --git a/source/group_5_client_main.cpp b/source/group_5_client_main.cpp index b26f528d..b89602d7 100644 --- a/source/group_5_client_main.cpp +++ b/source/group_5_client_main.cpp @@ -113,8 +113,10 @@ bool runGenerativeWorldDemo(std::istream &is, const std::string &ipString, unsig world.Deserialize(is, &manager); clientKillPort = port; clientKillIP = ipString; - cse491::Entity & interface = world.AddAgent(interfaceName, "server_ip", ipString, - "server_port", port, "manager", &manager, + cse491::Entity & interface = world.AddAgent(interfaceName, + "server_ip", ipString, + "server_port", port, + "manager", &manager, "socket", socket) .SetProperty("symbol", '@') .SetPosition(startX, startY); @@ -144,8 +146,10 @@ bool runManualWorldDemo(std::istream &is, const std::string &ipString, unsigned world.Deserialize(is, &manager); clientKillPort = port; clientKillIP = ipString; - cse491::Entity & interface = world.AddAgent(interface_name, "server_ip", ipString, - "server_port", port, "manager", &manager, + cse491::Entity & interface = world.AddAgent(interface_name, + "server_ip", ipString, + "server_port", port, + "manager", &manager, "socket", socket) .SetProperty("symbol", '@') .SetPosition(startX, startY); diff --git a/source/group_5_server_main.cpp b/source/group_5_server_main.cpp index 39a10af7..3c7ef9f4 100644 --- a/source/group_5_server_main.cpp +++ b/source/group_5_server_main.cpp @@ -78,7 +78,7 @@ void handleConnection(netWorth::ServerManager &serverManager, cse491::WorldBase cse491::Entity & interface = world.AddAgent (serverInterfaceName, "client_ip", sender->toString(), "client_port", port, "server_port", serverManager.m_max_client_port, "server_manager", &serverManager) - .SetProperty("symbol", '@'); + .SetProperty("symbol", '@').SetPosition(startX, startY); auto & serverInterface = dynamic_cast(interface); @@ -199,13 +199,33 @@ int runManualWorldDemo() { cse491_team8::ManualWorld world; int startX = 80, startY = 63; - // Add agents - world.AddAgent("Pacer 1").SetPosition(3,1); - world.AddAgent("Pacer 2").SetPosition(6,1); - // Add items - world.AddItem("Axe", "Chop", 5, "symbol", 'P').SetPosition(37, 3); - world.AddItem("Boat", "Swim", 7, "symbol", 'U').SetPosition(18, 4); + world.AddItem("Axe", "Uses", 5, "symbol", 'P').SetPosition(80, 120); + world.AddItem("Axe", "Uses", 10, "symbol", 'P').SetPosition(97, 40); + world.AddItem("Boat", "Uses", 7, "symbol", 'U').SetPosition(55, 11); + world.AddItem("Sword", "Strength", 8, "symbol", 't').SetPosition(18, 4); + world.AddItem("Sword", "Strength", 5, "symbol", 't').SetPosition(27, 11); + world.AddItem("Sword", "Strength", 4, "symbol", 't').SetPosition(65, 89); + world.AddItem("Health Potion", "Healing", 25, "symbol", 'j').SetPosition(38, 16); + world.AddItem("Health Potion", "Healing", 30, "symbol", 'j').SetPosition(1, 18); + + world.AddAgent("Pacer 1").SetPosition(97, 45); + world.AddAgent("Pacer 5").SetPosition(3,14); + world.AddAgent("Pacer 2").SetPosition(7,30); + world.AddAgent("Pacer 6").SetPosition(27, 10); + world.AddAgent("Pacer 7").SetPosition(38, 10); + world.AddAgent("Pacer 3").SetPosition(18,3); + world.AddAgent("Pacer 4").SetPosition(45,17); + + auto & a_star_agent = static_cast(world.AddAgent("AStar 1")); + a_star_agent.SetPosition(80, 111); + a_star_agent.SetGoalPosition(80, 63); + + world.AddAgent("Shark", "OnlyWater", 1).SetPosition(125, 140); + + auto & pacer_1 = world.GetAgent(world.GetAgentID("Pacer 1")); + world.AddItem("Sword", "Strength", 15, "symbol", 't').SetPosition(pacer_1.GetPosition()); + world.DoActionAttemptItemPickup(pacer_1, pacer_1.GetPosition()); // Ensure client successfully connects std::thread connectionThread(handleConnection, std::ref(manager), std::ref(world), startX, startY, cse491::WorldType::w_manual);