mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
naval transports disembark troops on the other side of the sea
bugfix for selecting garrisoned units bugfix for selecting cell id with depth check
This commit is contained in:
@@ -4,7 +4,7 @@ Player.baseRadius = 180
|
||||
Player.numDefWarMechs = 1
|
||||
Player.behaviour = {}
|
||||
Player.pointDefenseTrans = {}
|
||||
Player.canReachSpawnPoint = {}
|
||||
Player.spawnPointData = {}
|
||||
Player.navalFactoryCellId = nil
|
||||
|
||||
Player.unitClassMappings = {
|
||||
@@ -129,19 +129,32 @@ function Player:landRouteToSpawnpoint_(mapPoint)
|
||||
heurs = pf:calcHeuristics(cells, dest)
|
||||
path = pf:findPath(cells, heurs, source, dest, nil)
|
||||
|
||||
embarkCellId = nil
|
||||
disembarkCellId = nil
|
||||
|
||||
for i = 1, #path do
|
||||
if cells[path[i]].type == 1 then
|
||||
if map:getCell(path[i]).type == 1 then
|
||||
embarkCellId = path[i - 1]
|
||||
if not self.navalFactoryCellId then self.navalFactoryCellId = path[i] end
|
||||
return false
|
||||
break;
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
for i = #path, 1, -1 do
|
||||
if map:getCell(path[i]).type == 1 then
|
||||
disembarkCellId = path[i + 1]
|
||||
break;
|
||||
end
|
||||
end
|
||||
|
||||
if embarkCellId or disembarkCellId then
|
||||
return {reachable = false, embarkCellId = embarkCellId, disembarkCellId = disembarkCellId}
|
||||
else return {reachable = true} end
|
||||
end
|
||||
|
||||
function Player:landRouteToSpawnpoint(arguments)
|
||||
spId = self.taskForces[arguments.taskForceId].spawnPointId + 1
|
||||
return self.canReachSpawnPoint[spId] and BTNodeType.SUCCESS or BTNodeType.FAILURE
|
||||
return self.spawnPointData[spId].reachable == true and BTNodeResult.SUCCESS or BTNodeResult.FAILURE
|
||||
end
|
||||
|
||||
function Player:init()
|
||||
@@ -149,10 +162,10 @@ function Player:init()
|
||||
self:initPdSpots()
|
||||
|
||||
for i = 1, Map.getSingleton():getNumSpawnPoints() do
|
||||
if i - 1 == self:getSpawnPointId() then self.canReachSpawnPoint[i] = true end
|
||||
if i - 1 == self:getSpawnPointId() then self.spawnPointData[i] = {reachable = true} end
|
||||
|
||||
spawnPoint = Map.getSingleton():getSpawnPoint(i - 1)
|
||||
self.canReachSpawnPoint[i] = self:landRouteToSpawnpoint_(spawnPoint)
|
||||
self.spawnPointData[i] = self:landRouteToSpawnpoint_(spawnPoint)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -193,7 +206,6 @@ end
|
||||
|
||||
function Player:buildStructure(engineer, buildingId, buildPos, buildAngle)
|
||||
if not engineer then return BTNodeResult.FAILURE end
|
||||
print(buildAngle)
|
||||
|
||||
self:deselectUnits()
|
||||
self:selectUnits({engineer})
|
||||
@@ -495,11 +507,57 @@ function Player:formLandTaskForces(arguments)
|
||||
end
|
||||
|
||||
function Player:boardTransports(arguments)
|
||||
return BTNodeResult.FAILURE
|
||||
transports = self:getUnitsByClass(UnitClass.TRANSPORT, -1)
|
||||
|
||||
if not transports[1] then return BTNodeResult.FAILURE end
|
||||
|
||||
map = Map.getSingleton()
|
||||
currTransportCell = map:getCell(map:getCellId(transports[1]:getPos(), false))
|
||||
|
||||
if transports[1]:getNumOrders() == 0 and currTransportCell.type == 1 then
|
||||
self:deselectUnits()
|
||||
self:selectUnits(transports)
|
||||
self:issueOrder(OrderType.MOVE, Vector3:new(0, 0, 0), {Target:new(nil, map:getSpawnPoint(self:getSpawnPointId()))}, false)
|
||||
elseif currTransportCell.type == 0 and not self.taskForces[arguments.taskForceId].moving then
|
||||
self:deselectUnits()
|
||||
self:selectUnits(transports)
|
||||
self:haltUnits()
|
||||
self:deselectUnits()
|
||||
self:selectUnits(self.taskForces[arguments.taskForceId].units)
|
||||
self:issueOrder(OrderType.GARRISON, Vector3:new(0, 0, 0), {Target:new(transports[1]:toGameObject(), Vector3:new(0, 0, 0))}, false)
|
||||
self.taskForces[arguments.taskForceId].moving = true
|
||||
end
|
||||
|
||||
garrisonSlots = transports[1]:getGarrisonSlots()
|
||||
|
||||
for i = 1, #garrisonSlots do
|
||||
if not garrisonSlots[i].vehicle then
|
||||
return BTNodeResult.RUNNING
|
||||
end
|
||||
end
|
||||
|
||||
self.taskForces[arguments.taskForceId].moving = false
|
||||
return BTNodeResult.SUCCESS
|
||||
end
|
||||
|
||||
function Player:moveTransports(arguments)
|
||||
return BTNodeResult.FAILURE
|
||||
transports = self:getUnitsByClass(UnitClass.TRANSPORT, -1)
|
||||
map = Map.getSingleton()
|
||||
spId = self.taskForces[arguments.taskForceId].spawnPointId
|
||||
|
||||
if map:getCellId(transports[1]:getPos(), false) == self.spawnPointData[spId + 1].disembarkCellId then
|
||||
self:deselectUnits()
|
||||
self:selectUnits(transports)
|
||||
self:issueOrder(OrderType.EJECT, Vector3:new(0, 0, 0), {}, false)
|
||||
return BTNodeResult.SUCCESS
|
||||
elseif transports[1]:getNumOrders() > 0 then return BTNodeResult.RUNNING end
|
||||
|
||||
self:deselectUnits()
|
||||
self:selectUnits(transports)
|
||||
targ = Target:new(nil, map:getCell(self.spawnPointData[spId + 1].disembarkCellId).pos)
|
||||
self:issueOrder(OrderType.MOVE, Vector3:new(0, 0, 0), {targ}, false)
|
||||
|
||||
return BTNodeResult.RUNNING
|
||||
end
|
||||
|
||||
function Player:unloadTransports(arguments)
|
||||
@@ -561,12 +619,13 @@ function Player:generateTaskForceActions()
|
||||
children = {
|
||||
{type = BTNodeType.FUNCTION, func = self.boardTransports, args = arguments},
|
||||
{type = BTNodeType.FUNCTION, func = self.moveTransports, args = arguments},
|
||||
{type = BTNodeType.FUNCTION, func = self.unloadTransports, args = arguments},
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{type = BTNodeType.FUNCTION, func = self.occupySpawnPoint, args = arguments}
|
||||
--[[
|
||||
]]--
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ for i = 1, #game.cpuPlayers do
|
||||
},
|
||||
{
|
||||
type = BTNodeType.PARALLEL,
|
||||
children = game.cpuPlayers[i]:generateTaskForceActions()
|
||||
children = player:generateTaskForceActions()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-3
@@ -751,9 +751,7 @@ namespace battleship{
|
||||
CameraController::getSingleton()->setLookingAround(isPressed);
|
||||
break;
|
||||
case Bind::HALT:
|
||||
if(isPressed)
|
||||
for (Unit *u : mainPlayer->getSelectedUnits())
|
||||
u->halt();
|
||||
if(isPressed) mainPlayer->haltUnits();
|
||||
break;
|
||||
//TODO reimplement submarine diving mechanic
|
||||
case Bind::LEFT_CONTROL:
|
||||
|
||||
@@ -59,10 +59,18 @@ namespace battleship{
|
||||
"createResourceDeposit", &GameObjectFactory::createResourceDeposit
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Unit::GarrisonSlot>(
|
||||
"GarrisonSlot",
|
||||
"vehicle", &Unit::GarrisonSlot::vehicle,
|
||||
"category", &Unit::GarrisonSlot::category
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Unit>(
|
||||
"Unit", sol::constructors<Unit(Player*, int, Vector3, Quaternion)>(),
|
||||
"setState", &Unit::setState,
|
||||
"getDestructable", &Unit::getDestructable,
|
||||
"getGarrisonSlots", &Unit::getGarrisonSlots,
|
||||
"getNumGarrisonSlots", &Unit::getNumGarrisonSlots,
|
||||
"getOrder", &Unit::getOrder,
|
||||
"getNumOrders", &Unit::getNumOrders,
|
||||
"getPos", &GameObject::getPos,
|
||||
@@ -113,6 +121,7 @@ namespace battleship{
|
||||
SOL_LUA_STATE.new_usertype<Player>(
|
||||
"Player", sol::constructors<Player(int, int, int, Vector3, bool, int, string)>(),
|
||||
"getSelectedUnits", &Player::getSelectedUnits,
|
||||
"haltUnits", &Player::haltUnits,
|
||||
"addUnit", &Player::addUnit,
|
||||
"getUnit", &Player::getUnit,
|
||||
"getNumUnits", &Player::getNumUnits,
|
||||
|
||||
@@ -747,9 +747,8 @@ namespace battleship{
|
||||
return cellId;
|
||||
}
|
||||
|
||||
return cellId;
|
||||
}
|
||||
else
|
||||
return surfaceCellId;
|
||||
}
|
||||
else return surfaceCellId;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-2
@@ -4,6 +4,7 @@
|
||||
#include "player.h"
|
||||
#include "game.h"
|
||||
#include "structure.h"
|
||||
#include "vehicle.h"
|
||||
#include "projectile.h"
|
||||
#include "tradeOffer.h"
|
||||
#include "destructable.h"
|
||||
@@ -71,6 +72,11 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
void Player::haltUnits(){
|
||||
for (Unit *u : selectedUnits)
|
||||
u->halt();
|
||||
}
|
||||
|
||||
int Player::getOrderLineId(Order::TYPE type, Vector3 startPos, Vector3 endPos){
|
||||
Vector3 color;
|
||||
|
||||
@@ -169,11 +175,15 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void Player::selectUnits(vector<Unit*> selUnits){
|
||||
for(Unit *u : selUnits)
|
||||
if(find(selectedUnits.begin(), selectedUnits.end(), u) == selectedUnits.end()){
|
||||
for(Unit *u : selUnits){
|
||||
bool garrisonable = (!u->isVehicle() || (u->isVehicle() && !((Vehicle*)u)->getGarrisonable()));
|
||||
bool selected = (find(selectedUnits.begin(), selectedUnits.end(), u) != selectedUnits.end());
|
||||
|
||||
if(garrisonable && !selected){
|
||||
selectedUnits.push_back(u);
|
||||
u->select();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getUnitsById(int id, int numUnits){
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace battleship{
|
||||
Player(int, int, int, vb01::Vector3, bool = true, int = -1, std::string = "");
|
||||
~Player();
|
||||
void update();
|
||||
void haltUnits();
|
||||
void issueOrder(Order::TYPE, vb01::Vector3, std::vector<Order::Target>, bool);
|
||||
void removeUnit(Unit*);
|
||||
void removeUnit(int);
|
||||
|
||||
@@ -493,7 +493,7 @@ namespace battleship{
|
||||
Map *map = Map::getSingleton();
|
||||
|
||||
if(alignToSurface){
|
||||
vector<RayCaster::CollisionResult> res = RayCaster::cast(Vector3(p.x, 100, p.z), -Vector3::VEC_J, map->getNodeParent()->getChildren(), 0, 20);
|
||||
vector<RayCaster::CollisionResult> res = map->raycastTerrain(Vector3(p.x, 100, p.z), -Vector3::VEC_J, true);
|
||||
|
||||
if(res.empty() || res[0].mesh->getNode() != map->getNodeParent()->getChild(0))
|
||||
model->lookAt(Vector3(dirVec.x, 0, dirVec.z).norm(), Vector3::VEC_J);
|
||||
@@ -514,8 +514,7 @@ namespace battleship{
|
||||
if(activeState){
|
||||
map->blockCells(this);
|
||||
|
||||
if(activeState->getPlayer())
|
||||
Map::Minimap::getSingleton()->updateImage();
|
||||
//if(activeState->getPlayer()) Map::Minimap::getSingleton()->updateImage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -49,7 +49,11 @@ namespace battleship{
|
||||
void Vehicle::startCurrentOrder(){
|
||||
Unit::startCurrentOrder();
|
||||
|
||||
if(orders[0].type == Order::TYPE::LAUNCH) return;
|
||||
switch(orders[0].type){
|
||||
case Order::TYPE::LAUNCH:
|
||||
case Order::TYPE::EJECT:
|
||||
return;
|
||||
}
|
||||
|
||||
removeAllPathpoints();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user