Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
[sea_ai] ai_group configurability
Browse files Browse the repository at this point in the history
- individual ship position in group can be manipulated through event
- removed non-vanilla behavior (in any case it was broken)
  • Loading branch information
espkk committed Apr 8, 2022
1 parent 0a36c91 commit e6070f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
46 changes: 21 additions & 25 deletions src/libs/sea_ai/src/ai_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@
#include "shared/messages.h"

std::vector<AIGroup *> AIGroup::AIGroups;
float AIGroup::fDistanceBetweenGroupShips = 300.0f;
float AIGroup::fDistanceBetweenGroupLines = 250.0f;
float AIGroup::fDistanceBetweenGroupShips = 250.0f;

AIGroup::AIGroup(const char *pGroupName)
{
Assert(pGroupName);

bFirstExecute = true;
pACommander = nullptr;

iWarShipsNum = 0;
iTradeShipsNum = 0;

sGroupName = pGroupName;

dtCheckTask.Setup(FRAND(4.0f), 2.0f, 4.0f);
Expand All @@ -32,49 +29,48 @@ void AIGroup::AddShip(entid_t eidShip, ATTRIBUTES *pACharacter, ATTRIBUTES *pASh
AIShip *pShip = nullptr;
if (const auto *pAMode = pACharacter->FindAClass(pACharacter, "Ship.Mode"))
{
if (std::string("trade") == pAMode->GetThisAttr())
if (std::string("war") == pAMode->GetThisAttr())
{
pShip = new AIShipWar();
}
else if (std::string("trade") == pAMode->GetThisAttr())
{
pShip = new AIShipTrade();
iTradeShipsNum++;
}
else if (std::string("boat") == pAMode->GetThisAttr())
{
pShip = new AIShipBoat();
iTradeShipsNum++;
}
}
if (!pShip)
{
pShip = new AIShipWar();
}

CVECTOR vShipPos;

if (pShip == nullptr)
if (const auto event = GetCommanderACharacter()->GetAttribute("GroupShipPos_event"))
{
pShip = new AIShipWar();
iWarShipsNum++;

// war
const CVECTOR vTmpPos = ((iWarShipsNum - 1) * AIGroup::fDistanceBetweenGroupShips) *
CVECTOR(sinf(vInitGroupPos.y), 0.0f, cosf(vInitGroupPos.y));
vShipPos = CVECTOR(vInitGroupPos.x, vInitGroupPos.y, vInitGroupPos.z) - vTmpPos;
const auto result = core.Event(event, "lfffa", static_cast<uint32_t>(aGroupShips.size()), vInitGroupPos.x,
vInitGroupPos.y, vInitGroupPos.z, pACharacter);
result->Get(vShipPos.x, 0);
result->Get(vShipPos.y, 1);
result->Get(vShipPos.z, 2);
}
else
{
// trade
const CVECTOR vTmpPos = ((iTradeShipsNum - 1) * AIGroup::fDistanceBetweenGroupShips) *
CVECTOR(sinf(vInitGroupPos.y), 0.0f, cosf(vInitGroupPos.y));
vShipPos = CVECTOR(vInitGroupPos.x, vInitGroupPos.y, vInitGroupPos.z) - vTmpPos -
CVECTOR(0.0f, 0.0f, AIGroup::fDistanceBetweenGroupLines);
vShipPos = CVECTOR(vInitGroupPos.x, vInitGroupPos.y, vInitGroupPos.z) -
(aGroupShips.size() * fDistanceBetweenGroupShips) *
CVECTOR(sinf(vInitGroupPos.y), 0.0f, cosf(vInitGroupPos.y));
}

pShip->CreateShip(eidShip, pACharacter, pAShip, &vShipPos);
pShip->SetGroupName(GetName());

AIShip::AIShips.push_back(pShip); // add to global array
aGroupShips.push_back(pShip); // add to local group array

// pACharacter->Dump(pACharacter, 0);

Helper.AddCharacter(pACharacter, GetCommanderACharacter());

// pShip->CheckStartPosition();
}

bool AIGroup::isMainGroup()
Expand Down
1 change: 0 additions & 1 deletion src/libs/sea_ai/src/ai_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class AIGroup
std::string sGroupType;
CVECTOR vInitGroupPos, vMovePoint;
bool bFirstExecute;
uint32_t iWarShipsNum, iTradeShipsNum;

ATTRIBUTES *pACommander;

Expand Down

0 comments on commit e6070f9

Please sign in to comment.