diff --git a/Assets/Scripts/Core/player.lua b/Assets/Scripts/Core/player.lua index 1f34437..0d5f16b 100644 --- a/Assets/Scripts/Core/player.lua +++ b/Assets/Scripts/Core/player.lua @@ -6,6 +6,7 @@ Player.behaviour = {} Player.pointDefenseTrans = {} Player.spawnPointData = {} Player.navalFactoryCellId = nil +Player.navalRallyPoint = nil Player.unitClassMappings = { {UnitId.ACS_MECH, UnitId.AINC_MECH, UnitId.ER_MECH}, @@ -39,7 +40,7 @@ Player.landTaskForceData = { } Player.navalTaskForceData = { - {class = UnitClass.TRANSPORT, numUnits = 2}, + {class = UnitClass.TRANSPORT, numUnits = 3}, --{class = UnitClass.CRUISER, numUnits = 1}, --{class = UnitClass.ANTI_SUB_CRUISER, numUnits = 1} } @@ -250,6 +251,8 @@ function Player:buildLandFactory(arguments) if pos then self:buildStructure(self:findIdleEngineer(), factId, pos, self.baseQuat:getAngle()) + factory = self:getUnitsByClass(UnitClass.LAND_FACTORY, 1)[1]:toFactory() + factory:setRallyPoint(factory:getPos():add(factory:getDirVec():mult(40))) return BTNodeResult.RUNNING else return BTNodeResult.FAILURE end end @@ -282,9 +285,9 @@ function Player:buildRefinery(arguments) refId = self.unitClassMappings[UnitClass.REFINERY + 1][self:getFaction() + 1] factId = self.unitClassMappings[UnitClass.LAND_FACTORY + 1][self:getFaction() + 1] - rd = self.baseQuat:multVec(Vector3:new(0, 0, 1)):mult(-.5 * (units[factId + 1].size.z + units[refId + 1].size.z)) - sp = Map.getSingleton():getSpawnPoint(self:getSpawnPointId()) - buildPos = sp:add(rd) + rd = self.baseQuat:multVec(Vector3:new(0, 0, 1)):mult(-.6 * (units[factId + 1].size.z + units[refId + 1].size.z)) + fp = self:getUnitsByClass(UnitClass.LAND_FACTORY, 1)[1]:getPos() + buildPos = fp:add(rd) pos = self:findSuitableSpot(refId, buildPos) @@ -393,6 +396,7 @@ function Player:buildNavalFactory(arguments) if pos then self:buildStructure(self:findIdleEngineer(), navalFactId, pos, self.baseQuat:getAngle()) + self.navalRallyPoint = self:getUnitsByClass(UnitClass.NAVAL_FACTORY, 1)[1]:toFactory():getRallyPoint() return BTNodeResult.RUNNING else return BTNodeResult.FAILURE end end @@ -492,7 +496,7 @@ function Player:formLandTaskForces(arguments) unitTbl = table.move( unitGroups[j], subArrId, - subArrId + self.landTaskForceData[j].numUnits, + math.max(subArrId + self.landTaskForceData[j].numUnits - 1, 1), #self.taskForces[tfId].units + 1, self.taskForces[tfId].units ) @@ -525,6 +529,7 @@ function Player:getTransportData(transports) end function Player:boardTransports(arguments) + print('executing BOARD ' .. arguments.taskForceId) taskForce = self.taskForces[arguments.taskForceId] if taskForce.landed then return BTNodeResult.SUCCESS end @@ -570,6 +575,8 @@ function Player:boardTransports(arguments) end function Player:moveTransports(arguments) + if self.taskForces[arguments.taskForceId].landed then return BTNodeResult.SUCCESS end + transports = self:getUnitsByClass(UnitClass.TRANSPORT, -1) for i = 1, #transports do @@ -593,6 +600,7 @@ function Player:moveTransports(arguments) self:selectUnits(transports) self:issueOrder(OrderType.EJECT, Vector3:new(0, 0, 0), {}, false) self.taskForces[arguments.taskForceId].landed = true + self:issueOrder(OrderType.MOVE, Vector3:new(0, 0, 0), {Target:new(nil, self.navalRallyPoint)}, false) return BTNodeResult.SUCCESS elseif not nearDisembarkPoint then break end end @@ -608,6 +616,10 @@ end function Player:occupySpawnPoint(arguments) tfId = arguments.taskForceId + if not self.spawnPointData[self.taskForces[tfId].spawnPointId + 1].reachable and not self.taskForces[tfId].landed then + return BTNodeResult.FAILURE + end + if #self.taskForces[tfId].units > 0 then if self.taskForces[tfId].moving then return BTNodeResult.RUNNING @@ -640,35 +652,34 @@ function Player:occupySpawnPoint(arguments) end function Player:generateTaskForceActions() - children = {} - tfId = 1 + children = { + {type = BTNodeType.SEQUENCE, children = {}}, + {type = BTNodeType.PARALLEL, children = {}}, + } numSpawnPoints = Map.getSingleton():getNumSpawnPoints() + tfId = 1 for i = 1, numSpawnPoints do if i - 1 == self:getSpawnPointId() then goto continue end arguments = {taskForceId = tfId} - children[#children + 1] = { - type = BTNodeType.SEQUENCE, - children = { - { - type = BTNodeType.SELECTOR, - children = { - {type = BTNodeType.FUNCTION, func = self.landRouteToSpawnpoint, args = arguments}, - { - type = BTNodeType.SEQUENCE, - children = { - {type = BTNodeType.FUNCTION, func = self.boardTransports, args = arguments}, - {type = BTNodeType.FUNCTION, func = self.moveTransports, args = arguments}, - } + table.insert( + children[1].children, + { + type = BTNodeType.SELECTOR, + children = { + {type = BTNodeType.FUNCTION, func = self.landRouteToSpawnpoint, args = arguments}, + { + type = BTNodeType.SEQUENCE, + children = { + {type = BTNodeType.FUNCTION, func = self.boardTransports, args = arguments}, + {type = BTNodeType.FUNCTION, func = self.moveTransports, args = arguments}, } } - }, - {type = BTNodeType.FUNCTION, func = self.occupySpawnPoint, args = arguments} - --[[ - ]]-- + } } - } + ) + table.insert(children[2].children, {type = BTNodeType.FUNCTION, func = self.occupySpawnPoint, args = arguments}) tfId = tfId + 1 ::continue:: diff --git a/factory.cpp b/factory.cpp index aacf115..9390bdc 100644 --- a/factory.cpp +++ b/factory.cpp @@ -15,7 +15,7 @@ namespace battleship{ using namespace std; using namespace gameBase; - Factory::Factory(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, Unit::State state) : Structure(player, id, pos, rot, buildStatus, state){} + Factory::Factory(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, Unit::State state) : Structure(player, id, pos, rot, buildStatus, state), rallyPoint(pos + 30 * dirVec){} void Factory::update(){ Structure::update(); @@ -70,7 +70,7 @@ namespace battleship{ if(trainingStatus >= 100){ Unit *unit = GameObjectFactory::createUnit(player, unitQueue[0], pos, rot); player->addUnit(unit); - unit->receiveOrder(Order(Order::TYPE::MOVE, vector{Order::Target(nullptr, pos + 30 * dirVec)}, Vector3::VEC_ZERO), false); + unit->receiveOrder(Order(Order::TYPE::MOVE, vector{Order::Target(nullptr, rallyPoint)}, Vector3::VEC_ZERO), false); unitQueue.erase(unitQueue.begin()); trainingStatus = 0; diff --git a/factory.h b/factory.h index 586eab8..d9a2128 100644 --- a/factory.h +++ b/factory.h @@ -20,11 +20,14 @@ namespace battleship{ void update(); int getNumQueueUnitsById(int); void appendToQueue(int); + inline void setRallyPoint(vb01::Vector3 rp){this->rallyPoint = rp;} + inline vb01::Vector3 getRallyPoint(){return rallyPoint;} inline std::vector getQueue(){return unitQueue;} private: std::vector unitQueue; int maxLenQueue, trainingStatus = 0; vb01::s64 lastTrainTime = 0; + vb01::Vector3 rallyPoint; void initProperties(); void train(); diff --git a/gameManager.cpp b/gameManager.cpp index 0e5bbc0..3ec792e 100755 --- a/gameManager.cpp +++ b/gameManager.cpp @@ -76,19 +76,20 @@ namespace battleship{ "isGarrisonEmpty", &Unit::isGarrisonEmpty, "getOrder", &Unit::getOrder, "getNumOrders", &Unit::getNumOrders, + "getDirVec", &GameObject::getDirVec, + "getLeftVec", &GameObject::getLeftVec, "getPos", &GameObject::getPos, "getUnitClass", &Unit::getUnitClass, "getLineOfSight", &Unit::getLineOfSight, - "toEngineer", &Unit::toEngineer, - "toPointDefense", &Unit::toPointDefense, - "toStructure", &Unit::toStructure, - "toFactory", &Unit::toFactory, - "toGameObject", &Unit::toGameObject, - "toVehicle", &Unit::toVehicle, - //"toVehicle", [](Unit *u){return (Vehicle*)u;}, "getBuildableUnit", &Unit::getBuildableUnit, "getBuildableUnits", &Unit::getBuildableUnits, - "getNumBuildableUnits", &Unit::getNumBuildableUnits + "getNumBuildableUnits", &Unit::getNumBuildableUnits, + "toGameObject", [](Unit *u){return (GameObject*)u;}, + "toVehicle", [](Unit *u){return (Vehicle*)u;}, + "toEngineer", [](Unit *u){return (Engineer*)u;}, + "toStructure", [](Unit *u){return (Structure*)u;}, + "toFactory", [](Unit *u){return (Factory*)u;}, + "toPointDefense", [](Unit *u){return (PointDefense*)u;} ); SOL_LUA_STATE.new_usertype( @@ -121,10 +122,14 @@ namespace battleship{ "getBuildableUnit", &Unit::getBuildableUnit, "getBuildableUnits", &Unit::getBuildableUnits, "getNumBuildableUnits", &Unit::getNumBuildableUnits, + "getDirVec", &GameObject::getDirVec, + "getLeftVec", &GameObject::getLeftVec, "getPos", &GameObject::getPos, "appendToQueue", &Factory::appendToQueue, "getBuildStatus", &Structure::getBuildStatus, "getNumQueueUnitsById", &Factory::getNumQueueUnitsById, + "getRallyPoint", &Factory::getRallyPoint, + "setRallyPoint", &Factory::setRallyPoint, "getQueue", &Factory::getQueue ); diff --git a/unit.h b/unit.h index 82acd3e..0bcf425 100755 --- a/unit.h +++ b/unit.h @@ -28,16 +28,9 @@ namespace vb01{ namespace battleship{ class Player; class Weapon; - class Unit; - class Vehicle; - class Vehicle; - class Structure; - class Factory; - class Cruiser; - class Engineer; - class PointDefense; - class Projectile; class GameObject; + class Vehicle; + class Projectile; struct Order { enum class TYPE {ATTACK, BUILD, MOVE, GARRISON, EJECT, PATROL, LAUNCH, SUPPLY, LOAD, UNLOAD, HACK}; @@ -122,13 +115,6 @@ namespace battleship{ int getNumFreeGarrisonSlots(); inline void setState(State s){state = s;} inline State getState(){return state;} - inline Vehicle* toVehicle(){return (Vehicle*)this;} - inline Engineer* toEngineer(){return (Engineer*)this;} - inline Structure* toStructure(){return (Structure*)this;} - inline Factory* toFactory(){return (Factory*)this;} - inline Cruiser* toCruiser(){return (Cruiser*)this;} - inline PointDefense* toPointDefense(){return (PointDefense*)this;} - inline GameObject* toGameObject(){return (GameObject*)this;} inline int getNumGarrisonSlots(){return garrisonSlots.size();} inline bool isGarrisonEmpty(){return getNumFreeGarrisonSlots() == getNumGarrisonSlots();} inline const std::vector& getGarrisonSlots(){return garrisonSlots;}