automatically attacking hostle units

This commit is contained in:
devZoGok
2024-02-16 15:22:53 +02:00
parent 781f1649b0
commit ef290ee880
3 changed files with 26 additions and 2 deletions
@@ -63,7 +63,7 @@ units = {
cost = 500,
size = {x = 2.9, y = 8.22, z = 2.42},
hitboxOffset = {x = 0, y = 0, z = 0},
lineOfSight = 5,
lineOfSight = 20,
name = 'War mech',
basePath = PATH .. vehiclePrefix .. 'WarMechs/',
meshPath = 'warMech.xml',
+20
View File
@@ -295,12 +295,32 @@ namespace battleship{
}
}
void Unit::targetUnitsAutomatically(){
vector<Player*> players = Game::getSingleton()->getPlayers();
vector<Unit*> units;
for(Player *pl : players)
if(!(pl == player || pl->getTeam() == player->getTeam())){
vector<Unit*> un = pl->getUnits();
units.insert(units.end(), un.begin(), un.end());
}
if(orders.empty())
for(Unit *unit : units)
if(unit->getPos().getDistanceFrom(pos) < lineOfSight){
setOrder(Order(Order::TYPE::ATTACK, vector<Order::Target>{Order::Target(unit)}, Vector3::VEC_ZERO, false));
break;
}
}
void Unit::update() {
GameObject::update();
ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE);
Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr);
targetUnitsAutomatically();
vector<Player*> selectingPlayers = getSelectingPlayers();
bool mainPlayerSelecting = (find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end());
bool mainPlayerOwner = (player == mainPlayer);
+5 -1
View File
@@ -46,11 +46,12 @@ namespace battleship{
TYPE type;
int lineId = -1;
bool playerAssigned = true;
vb01::Vector3 direction;
std::vector<Target> targets;
Order(){}
Order(TYPE t, std::vector<Target> targ, vb01::Vector3 dir, int lid = -1) : type(t), lineId(lid), targets(targ), direction(dir){}
Order(TYPE t, std::vector<Target> targ, vb01::Vector3 dir, bool pa = true, int lid = -1) : type(t), playerAssigned(pa), lineId(lid), targets(targ), direction(dir){}
};
enum class MoveDir {LEFT, UP, FORW};
@@ -116,6 +117,7 @@ namespace battleship{
};
enum class Armor {CAST, COMBINED, MECHANIC, SHELL, STEEL};
enum class State {CHASE, STAND_GROUND, HOLD_FIRE};
Unit(Player*, int, vb01::Vector3, vb01::Quaternion);
virtual ~Unit();
@@ -168,9 +170,11 @@ namespace battleship{
std::vector<GarrisonSlot> garrisonSlots;
std::vector<Armor> armorTypes;
std::vector<Weapon*> weapons;
State state = State::STAND_GROUND;
std::vector<Player*> getSelectingPlayers();
void removeOrder(int);
virtual void targetUnitsAutomatically();
virtual void reinit();
virtual void initProperties();
virtual void destroySound();