void Improve_SeaAi(String groupe)
{
ref crgchar = Group_GetGroupCommander(groupe);
if(CheckAttribute(crgchar,"surrendered") || CharacterIsDead(crgchar)){return;}
float x, z;
int enemydist = 0;
int nextenemy = 0;
string sLocationGroup, sLocationLocator;
ref rIsland;
string sTst;
ref rGroup = Group_GetGroupByID(groupe);
ref PChar = GetMainCharacter();
//LogIt("Leadership : " + crgchar.skill.leadership + " ");
if(CheckAttribute(crgchar,"fantomtype"))
{
if(crgchar.fantomtype=="trade")
{
nextenemy = Find_nearest_inf_ship(crgchar);
if(nextenemy != -1) // && Characters[nextenemy].ship.type != SHIP_FORT_NAME )
{
if(Check_courageous_merchant(crgchar, &Characters[nextenemy]) || GetCharacterShipClass(crgchar) < 3)
{
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " a brave merchant and I'm defending!");
Group_UnlockTask(groupe);
Group_SetTaskAttack(groupe, GetGroupIDFromCharacter(GetCharacter(nextenemy)), false); // PB: Relations should already be hostile
Group_LockTask(groupe);
}
else
{
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " a merchant and I have a too close enemy, so I'm running away!");
Group_UnlockTask(groupe);
Group_SetTaskRunaway(groupe);
Group_LockTask(groupe);
if(Group_GetTask(groupe)==AITASK_MOVE)
{
rGroup.memo.x = rGroup.Task.Target.Pos.x;
rGroup.memo.z = rGroup.Task.Target.Pos.z;
}
else
{
if(Group_GetTask(groupe)!=AITASK_ATTACK)
{
rGroup.memo.x = crgchar.ship.Pos.x;
rGroup.memo.z = crgchar.ship.Pos.z;
}
}
}
}
else
{
if(Group_GetTask(groupe)==AITASK_RUNAWAY || Group_GetTask(groupe)==AITASK_ATTACK)
{
if(CheckAttribute(rGroup,"memo"))
{
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " a merchant! There's no more danger, so I can return to my initial route!");
x = stf(rGroup.memo.x);
z = stf(rGroup.memo.z);
Group_UnlockTask(groupe);
Group_SetTaskMove(groupe, x, z);
Group_LockTask(groupe);
DeleteAttribute(rGroup,"memo");
}
//else{TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " an anchoring merchant!");}
}
else
{
if(Group_GetTask(groupe)==AITASK_MOVE)
{
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " a merchant sailing to a destination!");
Group_UnlockTask(groupe);
Group_SetTaskMove(groupe, stf(rGroup.Task.Target.Pos.x), stf(rGroup.Task.Target.Pos.z));
Group_LockTask(groupe);
}
//else{TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " an anchoring merchant!");}
}
}
}
if(crgchar.fantomtype=="pirate" || crgchar.fantomtype=="war")
{
//nextenemy = FindClosestShipofRel(crgchar.index, &enemydist, RELATION_ENEMY);
nextenemy = Find_nearest_inf_ship(crgchar);
if(CheckAttribute(crgchar,"runaway"))
{
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " a " + crgchar.fantomtype + " and I'm running away!");
Group_UnlockTask(groupe);
Group_SetTaskRunaway(groupe);
Group_LockTask(groupe);
}
else
{
if(nextenemy != -1)
{
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " a " + crgchar.fantomtype + " and I'm attacking " + Characters[nextenemy].id + "!");
Group_UnlockTask(groupe);
Group_SetTaskAttack(groupe, GetGroupIDFromCharacter(GetCharacter(nextenemy)), false); // PB: Relations should already be hostile
Group_LockTask(groupe);
}
else
{
// find new Quest_ship locator to patrol
if(PChar.location!="")
{
sLocationGroup = "Quest_ships";
sLocationLocator = GetRandomQuestShipLocator(PChar.location); // PB
rIsland = GetIslandByID(PChar.location);
sTst = sLocationGroup + "." + sLocationLocator + ".x";
if (CheckAttribute(rIsland, sTst) || CheckAttribute(rGroup,"memo"))
{
if(CheckAttribute(rGroup,"memo"))
{
if(GetDistance2D(stf(crgchar.ship.Pos.x), stf(crgchar.ship.Pos.z), stf(rGroup.memo.x), stf(rGroup.memo.z)) <= 500)
{
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " a " + crgchar.fantomtype + " and I'm patroling to " + sLocationLocator + "!");
x = stf(rIsland.(sLocationGroup).(sLocationLocator).x);
z = stf(rIsland.(sLocationGroup).(sLocationLocator).z);
rGroup.memo.x = x;
rGroup.memo.z = z;
}
else
{
x = stf(rGroup.memo.x);
z = stf(rGroup.memo.z);
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " a " + crgchar.fantomtype + " and I'm " + GetDistance2D(stf(crgchar.ship.Pos.x), stf(crgchar.ship.Pos.z), stf(rGroup.memo.x), stf(rGroup.memo.z)) + " yards from my next patrol point!");
}
}
else
{
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " a " + crgchar.fantomtype + " and I'm patroling to " + sLocationLocator + "!");
x = stf(rIsland.(sLocationGroup).(sLocationLocator).x);
z = stf(rIsland.(sLocationGroup).(sLocationLocator).z);
rGroup.memo.x = x;
rGroup.memo.z = z;
}
}
else
{
if(rand(1)==0){x = 10000.0 * rand(10);}else{x = -10000.0 * rand(10);}
if(rand(1)==0){z = 10000.0 * rand(10);}else{z = -10000.0 * rand(10);}
if(CheckAttribute(rGroup,"memo")){DeleteAttribute(rGroup,"memo");}
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " a " + crgchar.fantomtype + " without target or I've lost my target!");
}
}
else
{
if(rand(1)==0){x = 10000.0 * rand(10);}else{x = -10000.0 * rand(10);}
if(rand(1)==0){z = 10000.0 * rand(10);}else{z = -10000.0 * rand(10);}
if(CheckAttribute(rGroup,"memo")){DeleteAttribute(rGroup,"memo");}
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " a " + crgchar.fantomtype + " without target or I've lost my target!");
}
Group_UnlockTask(groupe);
Group_SetTaskMove(groupe, x, z);
Group_LockTask(groupe);
}
}
}
}
else
{
if(CheckAttribute(crgchar,"runaway"))
{
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " and I'm running away!");
Group_UnlockTask(groupe);
Group_SetTaskRunaway(groupe);
Group_LockTask(groupe);
}
else
{
nextenemy = Find_nearest_inf_ship(crgchar);
if(nextenemy != -1)
{
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " and I'm attacking " + Characters[nextenemy].id + "!");
Group_UnlockTask(groupe);
Group_SetTaskAttack(groupe, GetGroupIDFromCharacter(GetCharacter(nextenemy)), false); // PB: Relations should already be hostile
Group_LockTask(groupe);
}
else
{
//TraceAndLog("I'm " + GetMyShipNameShow(crgchar) + " and I'm doing nothing...");
}
}
}
}