77 lines
2.6 KiB
C++
77 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include <functional>
|
|
#include <vector>
|
|
|
|
#include <QVector2D>
|
|
|
|
#include "EntityId.h"
|
|
#include "GameConfig.h"
|
|
#include "Ship.h"
|
|
|
|
class BuildingSystem;
|
|
class ScrapSystem;
|
|
|
|
class ShipSystem
|
|
{
|
|
public:
|
|
ShipSystem(const GameConfig& config,
|
|
std::function<EntityId()> allocateId);
|
|
|
|
// isEnemy defaults to false; set true for enemy-faction ships (step 7 wave spawning).
|
|
EntityId spawn(const std::string& schematicId, int level, QVector2D position,
|
|
bool isEnemy = false);
|
|
void despawn(EntityId id);
|
|
|
|
const Ship* findShip(EntityId id) const;
|
|
std::vector<Ship> allShips() const;
|
|
void forEach(std::function<void(Ship&)> fn);
|
|
|
|
// -- Behavior tick methods (tick-order step 7) ---------------------------
|
|
|
|
// Reset all movement intents to priority 0 before behavior systems run.
|
|
void clearMovementIntents();
|
|
|
|
// Priority 4: low-HP ships retreat to homePos.
|
|
void tickHomeReturn();
|
|
|
|
// Priority 3: combat ships acquire targets and advance toward them.
|
|
void tickThreatResponse(const BuildingSystem& buildings);
|
|
|
|
// Priority 2: repair ships find and heal damaged friendly ships/stations.
|
|
void tickRepairBehavior(BuildingSystem& buildings);
|
|
|
|
// Priority 1: salvage ships collect scrap and deliver it.
|
|
void tickScrapCollector(ScrapSystem& scraps, const BuildingSystem& buildings);
|
|
|
|
// -- Movement (tick-order step 10) ---------------------------------------
|
|
void tickMovement();
|
|
|
|
// Set the rally point that newly spawned player combat ships will loiter at.
|
|
void setRallyPoint(QVector2D point);
|
|
|
|
// Release all gathered player combat ships to advance toward the enemy.
|
|
void triggerRallyDeparture();
|
|
|
|
// Reduce ship HP by amount. Does not remove the ship; step 9 handles death.
|
|
// Returns false if ship not found.
|
|
bool damageShip(EntityId id, float amount);
|
|
|
|
private:
|
|
const ShipDef* findShipDef(const std::string& schematicId) const;
|
|
|
|
// True if the entity identified by id is alive and within range of ship.
|
|
// Searches both the ship list and (for buildings) the supplied BuildingSystem.
|
|
bool isTargetValid(EntityId id, float range, const Ship& ship,
|
|
const BuildingSystem& buildings) const;
|
|
|
|
// Heal the ship with the given id by amount, clamped to maxHp.
|
|
// Returns false if the ship is not found.
|
|
bool healShip(EntityId id, float amount);
|
|
|
|
const GameConfig& m_config;
|
|
std::function<EntityId()> m_allocateId;
|
|
std::vector<Ship> m_ships;
|
|
QVector2D m_rallyPoint;
|
|
};
|