Browse Source

Convert final remaining structs to snake_case (ProductionState, SpawnParams, pathfinding)

Co-authored-by: djeada <[email protected]>
copilot-swe-agent[bot] 1 week ago
parent
commit
cf48d12d4b

+ 1 - 1
app/core/game_engine.cpp

@@ -973,7 +973,7 @@ auto GameEngine::get_selected_production_state() const -> QVariantMap {
   m["producedCount"] = st.produced_count;
   m["maxUnits"] = st.max_units;
   m["villagerCost"] = st.villager_cost;
-  m["queueSize"] = st.queueSize;
+  m["queueSize"] = st.queue_size;
   m["nation_id"] =
       QString::fromStdString(Game::Systems::nationIDToString(st.nation_id));
 

+ 3 - 3
game/map/level_loader.cpp

@@ -87,7 +87,7 @@ auto LevelLoader::loadFromAssets(
         sp.position = QVector3D(0.0F, 0.0F, 0.0F);
         sp.player_id = 0;
         sp.spawn_type = Game::Units::SpawnType::Archer;
-        sp.aiControlled = !owners.isPlayer(sp.player_id);
+        sp.ai_controlled = !owners.isPlayer(sp.player_id);
         if (const auto *nation =
                 nationRegistry.getNationForPlayer(sp.player_id)) {
           sp.nation_id = nation->id;
@@ -121,7 +121,7 @@ auto LevelLoader::loadFromAssets(
         sp.position = QVector3D(-4.0F, 0.0F, -3.0F);
         sp.player_id = owners.getLocalPlayerId();
         sp.spawn_type = Game::Units::SpawnType::Barracks;
-        sp.aiControlled = !owners.isPlayer(sp.player_id);
+        sp.ai_controlled = !owners.isPlayer(sp.player_id);
         if (const auto *nation =
                 nationRegistry.getNationForPlayer(sp.player_id)) {
           sp.nation_id = nation->id;
@@ -153,7 +153,7 @@ auto LevelLoader::loadFromAssets(
       sp.position = QVector3D(0.0F, 0.0F, 0.0F);
       sp.player_id = 0;
       sp.spawn_type = Game::Units::SpawnType::Archer;
-      sp.aiControlled = !owners.isPlayer(sp.player_id);
+      sp.ai_controlled = !owners.isPlayer(sp.player_id);
       if (const auto *nation =
               nationRegistry.getNationForPlayer(sp.player_id)) {
         sp.nation_id = nation->id;

+ 1 - 1
game/map/map_loader.cpp

@@ -280,7 +280,7 @@ void readSpawns(const QJsonArray &arr, std::vector<UnitSpawn> &out) {
 
     spawn.team_id = spawn_obj.value(TEAM_ID).toInt(0);
     constexpr int default_max_population = 100;
-    spawn.maxPopulation =
+    spawn.max_population =
         spawn_obj.value(MAX_POPULATION).toInt(default_max_population);
 
     if (spawn_obj.contains(NATION)) {

+ 2 - 2
game/map/map_transformer.cpp

@@ -175,8 +175,8 @@ auto MapTransformer::applyToWorld(
       sp.position = QVector3D(world_x, 0.0F, world_z);
       sp.player_id = effective_player_id;
       sp.spawn_type = s.type;
-      sp.aiControlled = !owner_registry.isPlayer(effective_player_id);
-      sp.maxPopulation = s.maxPopulation;
+      sp.ai_controlled = !owner_registry.isPlayer(effective_player_id);
+      sp.max_population = s.max_population;
 
       if (s.nation.has_value()) {
         sp.nation_id = s.nation.value();

+ 1 - 1
game/systems/ai_system/ai_snapshot_builder.cpp

@@ -69,7 +69,7 @@ auto AISnapshotBuilder::build(const Engine::Core::World &world,
       data.production.rally_set = production->rally_set;
       data.production.rally_x = production->rally_x;
       data.production.rally_z = production->rally_z;
-      data.production.queueSize =
+      data.production.queue_size =
           static_cast<int>(production->production_queue.size());
     }
 

+ 1 - 1
game/systems/ai_system/behaviors/production_behavior.cpp

@@ -78,7 +78,7 @@ void ProductionBehavior::execute(const AISnapshot &snapshot, AIContext &context,
     }
 
     const int max_queue_size = 5;
-    int const total_in_queue = (prod.in_progress ? 1 : 0) + prod.queueSize;
+    int const total_in_queue = (prod.in_progress ? 1 : 0) + prod.queue_size;
     if (total_in_queue >= max_queue_size) {
       continue;
     }

+ 31 - 31
game/systems/pathfinding.cpp

@@ -175,7 +175,7 @@ auto Pathfinding::findPathInternal(const Point &start,
   setGCost(start_idx, generation, 0);
   setParent(start_idx, generation, start_idx);
 
-  pushOpenNode({start_idx, calculateHeuristic(start, end), 0});
+  push_open_node({start_idx, calculateHeuristic(start, end), 0});
 
   const int max_iterations = std::max(m_width * m_height, 1);
   int iterations = 0;
@@ -185,9 +185,9 @@ auto Pathfinding::findPathInternal(const Point &start,
   while (!m_openHeap.empty() && iterations < max_iterations) {
     ++iterations;
 
-    QueueNode const current = popOpenNode();
+    QueueNode const current = pop_open_node();
 
-    if (current.gCost > getGCost(current.index, generation)) {
+    if (current.g_cost > getGCost(current.index, generation)) {
       continue;
     }
 
@@ -198,14 +198,14 @@ auto Pathfinding::findPathInternal(const Point &start,
     setClosed(current.index, generation);
 
     if (current.index == end_idx) {
-      final_cost = current.gCost;
+      final_cost = current.g_cost;
       break;
     }
 
     const Point current_point = toPoint(current.index);
     std::array<Point, 8> neighbors{};
     const std::size_t neighbor_count =
-        collectNeighbors(current_point, neighbors);
+        collect_neighbors(current_point, neighbors);
 
     for (std::size_t i = 0; i < neighbor_count; ++i) {
       const Point &neighbor = neighbors[i];
@@ -218,7 +218,7 @@ auto Pathfinding::findPathInternal(const Point &start,
         continue;
       }
 
-      const int tentative_gcost = current.gCost + 1;
+      const int tentative_gcost = current.g_cost + 1;
       if (tentative_gcost >= getGCost(neighbor_idx, generation)) {
         continue;
       }
@@ -227,7 +227,7 @@ auto Pathfinding::findPathInternal(const Point &start,
       setParent(neighbor_idx, generation, current.index);
 
       const int h_cost = calculateHeuristic(neighbor, end);
-      pushOpenNode({neighbor_idx, tentative_gcost + h_cost, tentative_gcost});
+      push_open_node({neighbor_idx, tentative_gcost + h_cost, tentative_gcost});
     }
   }
 
@@ -237,7 +237,7 @@ auto Pathfinding::findPathInternal(const Point &start,
 
   std::vector<Point> path;
   path.reserve(final_cost + 1);
-  buildPath(start_idx, end_idx, generation, final_cost + 1, path);
+  build_path(start_idx, end_idx, generation, final_cost + 1, path);
   return path;
 }
 
@@ -339,7 +339,7 @@ void Pathfinding::setParent(int index, std::uint32_t generation,
   }
 }
 
-auto Pathfinding::collectNeighbors(
+auto Pathfinding::collect_neighbors(
     const Point &point, std::array<Point, 8> &buffer) const -> std::size_t {
   std::size_t count = 0;
   for (int dx = -1; dx <= 1; ++dx) {
@@ -368,51 +368,51 @@ auto Pathfinding::collectNeighbors(
   return count;
 }
 
-void Pathfinding::buildPath(int startIndex, int endIndex,
-                            std::uint32_t generation, int expectedLength,
-                            std::vector<Point> &outPath) const {
-  outPath.clear();
-  if (expectedLength > 0) {
-    outPath.reserve(static_cast<std::size_t>(expectedLength));
+void Pathfinding::build_path(int start_index, int end_index,
+                            std::uint32_t generation, int expected_length,
+                            std::vector<Point> &out_path) const {
+  out_path.clear();
+  if (expected_length > 0) {
+    out_path.reserve(static_cast<std::size_t>(expected_length));
   }
-  int current = endIndex;
+  int current = end_index;
 
   while (current >= 0) {
-    outPath.push_back(toPoint(current));
-    if (current == startIndex) {
-      std::reverse(outPath.begin(), outPath.end());
+    out_path.push_back(toPoint(current));
+    if (current == start_index) {
+      std::reverse(out_path.begin(), out_path.end());
       return;
     }
 
     if (!hasParent(current, generation)) {
-      outPath.clear();
+      out_path.clear();
       return;
     }
 
     const int parent = getParent(current, generation);
     if (parent == current || parent < 0) {
-      outPath.clear();
+      out_path.clear();
       return;
     }
     current = parent;
   }
 
-  outPath.clear();
+  out_path.clear();
 }
 
-auto Pathfinding::heapLess(const QueueNode &lhs, const QueueNode &rhs) -> bool {
-  if (lhs.fCost != rhs.fCost) {
-    return lhs.fCost < rhs.fCost;
+auto Pathfinding::heap_less(const QueueNode &lhs, const QueueNode &rhs) -> bool {
+  if (lhs.f_cost != rhs.f_cost) {
+    return lhs.f_cost < rhs.f_cost;
   }
-  return lhs.gCost < rhs.gCost;
+  return lhs.g_cost < rhs.g_cost;
 }
 
-void Pathfinding::pushOpenNode(const QueueNode &node) {
+void Pathfinding::push_open_node(const QueueNode &node) {
   m_openHeap.push_back(node);
   std::size_t index = m_openHeap.size() - 1;
   while (index > 0) {
     std::size_t const parent = (index - 1) / 2;
-    if (heapLess(m_openHeap[parent], m_openHeap[index])) {
+    if (heap_less(m_openHeap[parent], m_openHeap[index])) {
       break;
     }
     std::swap(m_openHeap[parent], m_openHeap[index]);
@@ -420,7 +420,7 @@ void Pathfinding::pushOpenNode(const QueueNode &node) {
   }
 }
 
-auto Pathfinding::popOpenNode() -> Pathfinding::QueueNode {
+auto Pathfinding::pop_open_node() -> Pathfinding::QueueNode {
   QueueNode top = m_openHeap.front();
   QueueNode const last = m_openHeap.back();
   m_openHeap.pop_back();
@@ -433,10 +433,10 @@ auto Pathfinding::popOpenNode() -> Pathfinding::QueueNode {
       std::size_t const right = left + 1;
       std::size_t smallest = index;
 
-      if (left < size && !heapLess(m_openHeap[smallest], m_openHeap[left])) {
+      if (left < size && !heap_less(m_openHeap[smallest], m_openHeap[left])) {
         smallest = left;
       }
-      if (right < size && !heapLess(m_openHeap[smallest], m_openHeap[right])) {
+      if (right < size && !heap_less(m_openHeap[smallest], m_openHeap[right])) {
         smallest = right;
       }
       if (smallest == index) {

+ 8 - 8
game/systems/pathfinding.h

@@ -83,20 +83,20 @@ private:
   auto getParent(int index, std::uint32_t generation) const -> int;
   void setParent(int index, std::uint32_t generation, int parentIndex);
 
-  auto collectNeighbors(const Point &point,
+  auto collect_neighbors(const Point &point,
                         std::array<Point, 8> &buffer) const -> std::size_t;
-  void buildPath(int startIndex, int endIndex, std::uint32_t generation,
-                 int expectedLength, std::vector<Point> &outPath) const;
+  void build_path(int start_index, int end_index, std::uint32_t generation,
+                 int expected_length, std::vector<Point> &out_path) const;
 
   struct QueueNode {
     int index;
-    int fCost;
-    int gCost;
+    int f_cost;
+    int g_cost;
   };
 
-  static auto heapLess(const QueueNode &lhs, const QueueNode &rhs) -> bool;
-  void pushOpenNode(const QueueNode &node);
-  auto popOpenNode() -> QueueNode;
+  static auto heap_less(const QueueNode &lhs, const QueueNode &rhs) -> bool;
+  void push_open_node(const QueueNode &node);
+  auto pop_open_node() -> QueueNode;
 
   void workerLoop();
 

+ 1 - 1
game/systems/production_service.cpp

@@ -153,7 +153,7 @@ auto ProductionService::getSelectedBarracksState(
     outState.produced_count = p->produced_count;
     outState.max_units = p->max_units;
     outState.villager_cost = p->villager_cost;
-    outState.queueSize = static_cast<int>(p->production_queue.size());
+    outState.queue_size = static_cast<int>(p->production_queue.size());
     outState.production_queue = p->production_queue;
   }
   return true;

+ 8 - 8
game/systems/production_service.h

@@ -23,16 +23,16 @@ enum class ProductionResult {
 
 struct ProductionState {
   bool has_barracks = false;
-  bool inProgress = false;
+  bool in_progress = false;
   NationID nation_id = NationID::RomanRepublic;
   Game::Units::TroopType product_type = Game::Units::TroopType::Archer;
-  float timeRemaining = 0.0F;
-  float buildTime = 0.0F;
-  int producedCount = 0;
-  int maxUnits = 0;
-  int villagerCost = 1;
-  int queueSize = 0;
-  std::vector<Game::Units::TroopType> productionQueue;
+  float time_remaining = 0.0F;
+  float build_time = 0.0F;
+  int produced_count = 0;
+  int max_units = 0;
+  int villager_cost = 1;
+  int queue_size = 0;
+  std::vector<Game::Units::TroopType> production_queue;
 };
 
 class ProductionService {

+ 1 - 1
game/systems/production_system.cpp

@@ -101,7 +101,7 @@ void ProductionSystem::update(Engine::Core::World *world, float delta_time) {
           sp.player_id = u->owner_id;
           sp.spawn_type =
               Game::Units::spawn_typeFromTroopType(prod->product_type);
-          sp.aiControlled =
+          sp.ai_controlled =
               e->has_component<Engine::Core::AIControlledComponent>();
           sp.nation_id = nation_id;
           auto unit = reg->create(sp.spawn_type, *world, sp);

+ 1 - 1
game/units/archer.cpp

@@ -62,7 +62,7 @@ void Archer::init(const SpawnParams &params) {
   m_u->vision_range = profile.combat.vision_range;
   m_u->nation_id = nation_id;
 
-  if (params.aiControlled) {
+  if (params.ai_controlled) {
     e->add_component<Engine::Core::AIControlledComponent>();
   } else {
   }

+ 1 - 1
game/units/ballista.cpp

@@ -63,7 +63,7 @@ void Ballista::init(const SpawnParams &params) {
   m_u->vision_range = profile.combat.vision_range;
   m_u->nation_id = nation_id;
 
-  if (params.aiControlled) {
+  if (params.ai_controlled) {
     e->add_component<Engine::Core::AIControlledComponent>();
   }
 

+ 2 - 2
game/units/barracks.cpp

@@ -46,7 +46,7 @@ void Barracks::init(const SpawnParams &params) {
   m_u->vision_range = 22.0F;
   m_u->nation_id = nation_id;
 
-  if (params.aiControlled) {
+  if (params.ai_controlled) {
     e->add_component<Engine::Core::AIControlledComponent>();
   } else {
   }
@@ -65,7 +65,7 @@ void Barracks::init(const SpawnParams &params) {
     if (auto *prod = e->add_component<Engine::Core::ProductionComponent>()) {
       prod->product_type = TroopType::Archer;
       prod->build_time = 10.0F;
-      prod->max_units = params.maxPopulation;
+      prod->max_units = params.max_population;
       prod->in_progress = false;
       prod->time_remaining = 0.0F;
       prod->produced_count = 0;

+ 1 - 1
game/units/catapult.cpp

@@ -63,7 +63,7 @@ void Catapult::init(const SpawnParams &params) {
   m_u->vision_range = profile.combat.vision_range;
   m_u->nation_id = nation_id;
 
-  if (params.aiControlled) {
+  if (params.ai_controlled) {
     e->add_component<Engine::Core::AIControlledComponent>();
   }
 

+ 1 - 1
game/units/healer.cpp

@@ -62,7 +62,7 @@ void Healer::init(const SpawnParams &params) {
   m_u->vision_range = profile.combat.vision_range;
   m_u->nation_id = nation_id;
 
-  if (params.aiControlled) {
+  if (params.ai_controlled) {
     e->add_component<Engine::Core::AIControlledComponent>();
   }
 

+ 1 - 1
game/units/horse_archer.cpp

@@ -63,7 +63,7 @@ void HorseArcher::init(const SpawnParams &params) {
   m_u->vision_range = profile.combat.vision_range;
   m_u->nation_id = nation_id;
 
-  if (params.aiControlled) {
+  if (params.ai_controlled) {
     e->add_component<Engine::Core::AIControlledComponent>();
   } else {
   }

+ 1 - 1
game/units/horse_spearman.cpp

@@ -64,7 +64,7 @@ void HorseSpearman::init(const SpawnParams &params) {
   m_u->vision_range = profile.combat.vision_range;
   m_u->nation_id = nation_id;
 
-  if (params.aiControlled) {
+  if (params.ai_controlled) {
     e->add_component<Engine::Core::AIControlledComponent>();
   } else {
   }

+ 1 - 1
game/units/horse_swordsman.cpp

@@ -64,7 +64,7 @@ void MountedKnight::init(const SpawnParams &params) {
   m_u->vision_range = profile.combat.vision_range;
   m_u->nation_id = nation_id;
 
-  if (params.aiControlled) {
+  if (params.ai_controlled) {
     e->add_component<Engine::Core::AIControlledComponent>();
   } else {
   }

+ 1 - 1
game/units/spearman.cpp

@@ -63,7 +63,7 @@ void Spearman::init(const SpawnParams &params) {
   m_u->vision_range = profile.combat.vision_range;
   m_u->nation_id = nation_id;
 
-  if (params.aiControlled) {
+  if (params.ai_controlled) {
     e->add_component<Engine::Core::AIControlledComponent>();
   } else {
   }

+ 1 - 1
game/units/swordsman.cpp

@@ -63,7 +63,7 @@ void Swordsman::init(const SpawnParams &params) {
   m_u->vision_range = profile.combat.vision_range;
   m_u->nation_id = nation_id;
 
-  if (params.aiControlled) {
+  if (params.ai_controlled) {
     e->add_component<Engine::Core::AIControlledComponent>();
   } else {
   }

+ 2 - 2
game/units/unit.h

@@ -26,8 +26,8 @@ struct SpawnParams {
   QVector3D position{0, 0, 0};
   int player_id = 0;
   SpawnType spawn_type = SpawnType::Archer;
-  bool aiControlled = false;
-  int maxPopulation = 100;
+  bool ai_controlled = false;
+  int max_population = 100;
   Game::Systems::NationID nation_id = Game::Systems::NationID::RomanRepublic;
 };