Skip to content

Commit

Permalink
Merge pull request #13 from RGreenlees/InProgress
Browse files Browse the repository at this point in the history
Merge for v1.1
  • Loading branch information
RGreenlees authored Aug 26, 2023
2 parents 24588df + a3820dd commit 750b6a5
Show file tree
Hide file tree
Showing 15 changed files with 463 additions and 68 deletions.
2 changes: 2 additions & 0 deletions evobot/src/NS_Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ const int kGestateBaseArmor = 150;
const int kSpitVelocity = 1500;
const int kShootCloudVelocity = 1100;
const int kAcidRocketVelocity = 2000;
const int kGrenadeForce = 800;
const int kBileBombVelocity = 650;

const float kBiteRange = 80.0f;
const float kBite2Range = 80.0f; // Lerk bite range
Expand Down
16 changes: 9 additions & 7 deletions evobot/src/bot_commander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3069,26 +3069,28 @@ void COMM_SetNextSupportAction(bot_t* CommanderBot, commander_action* Action)
{
edict_t* PrototypeLab = UTIL_GetNearestStructureOfTypeInLocation(STRUCTURE_MARINE_PROTOTYPELAB, UTIL_GetCommChairLocation(), UTIL_MetresToGoldSrcUnits(15.0f), true, false);

NSStructureType SpecialWeaponToDrop = (UTIL_GetNumWeaponsOfTypeInPlay(WEAPON_MARINE_GL) == 0) ? DEPLOYABLE_ITEM_MARINE_GRENADELAUNCHER : DEPLOYABLE_ITEM_MARINE_HMG;

bool bShouldDropHeavyArmour = false;
bool bShouldDropHMG = false;
bool bShouldDropWeapon = false;
bool bShouldDropWelder = false;

if (CommanderBot->resources > 100)
{
bShouldDropHeavyArmour = UTIL_GetItemCountOfTypeInArea(DEPLOYABLE_ITEM_MARINE_HEAVYARMOUR, PrototypeLab->v.origin, UTIL_MetresToGoldSrcUnits(5.0f)) < 3;
bShouldDropHMG = UTIL_GetItemCountOfTypeInArea(DEPLOYABLE_ITEM_MARINE_HMG, AdvArmoury->v.origin, UTIL_MetresToGoldSrcUnits(5.0f)) < 3;
bShouldDropWeapon = UTIL_GetItemCountOfTypeInArea(SpecialWeaponToDrop, AdvArmoury->v.origin, UTIL_MetresToGoldSrcUnits(5.0f)) < 3;
bShouldDropWelder = UTIL_GetItemCountOfTypeInArea(DEPLOYABLE_ITEM_MARINE_WELDER, AdvArmoury->v.origin, UTIL_MetresToGoldSrcUnits(5.0f)) < 3;
}
else
{
edict_t* MarineNeedingLoadout = UTIL_GetNearestMarineWithoutFullLoadout(AdvArmoury->v.origin, UTIL_MetresToGoldSrcUnits(10.0f));

int NumHeavyArmour = UTIL_GetItemCountOfTypeInArea(DEPLOYABLE_ITEM_MARINE_HEAVYARMOUR, PrototypeLab->v.origin, UTIL_MetresToGoldSrcUnits(5.0f));
int NumHMG = UTIL_GetItemCountOfTypeInArea(DEPLOYABLE_ITEM_MARINE_HMG, AdvArmoury->v.origin, UTIL_MetresToGoldSrcUnits(5.0f));
int NumWeapons = UTIL_GetItemCountOfTypeInArea(SpecialWeaponToDrop, AdvArmoury->v.origin, UTIL_MetresToGoldSrcUnits(5.0f));
int NumWelder = UTIL_GetItemCountOfTypeInArea(DEPLOYABLE_ITEM_MARINE_WELDER, AdvArmoury->v.origin, UTIL_MetresToGoldSrcUnits(5.0f));

bShouldDropHeavyArmour = (!FNullEnt(MarineNeedingLoadout) && !PlayerHasEquipment(MarineNeedingLoadout) && NumHeavyArmour == 0);
bShouldDropHMG = (!FNullEnt(MarineNeedingLoadout) && !PlayerHasSpecialWeapon(MarineNeedingLoadout) && NumHMG == 0);
bShouldDropWeapon = (!FNullEnt(MarineNeedingLoadout) && !PlayerHasSpecialWeapon(MarineNeedingLoadout) && NumWeapons == 0);
bShouldDropWelder = (!FNullEnt(MarineNeedingLoadout) && !PlayerHasWeapon(MarineNeedingLoadout, WEAPON_MARINE_WELDER) && NumWelder == 0);
}

Expand All @@ -3102,12 +3104,12 @@ void COMM_SetNextSupportAction(bot_t* CommanderBot, commander_action* Action)
return;
}

if (bShouldDropHMG)
if (bShouldDropWeapon)
{
if (Action->ActionType == ACTION_DEPLOY && Action->StructureToBuild == DEPLOYABLE_ITEM_MARINE_HMG) { return; }
if (Action->ActionType == ACTION_DEPLOY && Action->StructureToBuild == SpecialWeaponToDrop) { return; }

Action->ActionType = ACTION_DEPLOY;
Action->StructureToBuild = DEPLOYABLE_ITEM_MARINE_HMG;
Action->StructureToBuild = SpecialWeaponToDrop;
Action->BuildLocation = UTIL_GetRandomPointOnNavmeshInRadius(MARINE_REGULAR_NAV_PROFILE, AdvArmoury->v.origin, UTIL_MetresToGoldSrcUnits(5.0f));
return;
}
Expand Down
186 changes: 181 additions & 5 deletions evobot/src/bot_marine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,46 @@ void BotMarineSetPrimaryTask(bot_t* pBot, bot_task* Task)
case BOT_ROLE_ASSAULT:
MarineAssaultSetPrimaryTask(pBot, Task);
return;
case BOT_ROLE_BOMBARDIER:
MarineBombardierSetPrimaryTask(pBot, Task);
return;
default:
return;
}

}

void MarineBombardierSetPrimaryTask(bot_t* pBot, bot_task* Task)
{
// This is a bit of a hacky way of ensuring bot doesn't fall into a loop of head for hive -> spot offence chamber -> back up to kill it and lose sight -> head for hive
// A better option is to have the bot head for hive and target offence chambers that are along their path rather than base it on sight
if (Task->TaskType == TASK_ATTACK && GetStructureTypeFromEdict(Task->TaskTarget) == STRUCTURE_ALIEN_OFFENCECHAMBER) { return; }

edict_t* DangerTurret = BotGetNearestDangerTurret(pBot, UTIL_MetresToGoldSrcUnits(15.0f));

if (!FNullEnt(DangerTurret))
{
TASK_SetAttackTask(pBot, Task, DangerTurret, false);
return;
}

const hive_definition* SiegedHive = UTIL_GetNearestHiveUnderSiege(pBot->pEdict->v.origin);

if (SiegedHive)
{
TASK_SetAttackTask(pBot, Task, SiegedHive->edict, false);
return;
}

edict_t* NearestAlienRT = UTIL_GetNearestStructureOfTypeInLocation(STRUCTURE_ALIEN_RESTOWER, UTIL_GetCommChairLocation(), UTIL_MetresToGoldSrcUnits(500.0f), true, true);

if (!FNullEnt(NearestAlienRT))
{
TASK_SetAttackTask(pBot, Task, NearestAlienRT, false);
return;
}
}

void BotMarineSetCombatModePrimaryTask(bot_t* pBot, bot_task* Task)
{
switch (pBot->CurrentRole)
Expand Down Expand Up @@ -1011,6 +1045,12 @@ bool MarineCombatThink(bot_t* pBot)

if (pBot->CurrentEnemy < 0) { return false; }

if (GetBotMarinePrimaryWeapon(pBot) == WEAPON_MARINE_GL)
{
MarineBombardierCombatThink(pBot);
return true;
}

edict_t* CurrentEnemy = pBot->TrackedEnemies[pBot->CurrentEnemy].EnemyEdict;
enemy_status* TrackedEnemyRef = &pBot->TrackedEnemies[pBot->CurrentEnemy];

Expand Down Expand Up @@ -1042,7 +1082,10 @@ bool MarineCombatThink(bot_t* pBot)
else
{
MoveTo(pBot, Armoury->v.origin, MOVESTYLE_NORMAL);
BotReloadWeapons(pBot);
if (gpGlobals->time - TrackedEnemyRef->LastSeenTime > 5.0f)
{
BotReloadWeapons(pBot);
}
}
return true;
}
Expand Down Expand Up @@ -1129,7 +1172,10 @@ bool MarineCombatThink(bot_t* pBot)
if (LOSCheck == ATTACK_OUTOFRANGE)
{
MoveTo(pBot, TrackedEnemyRef->LastFloorPosition, MOVESTYLE_NORMAL);
BotReloadWeapons(pBot);
if (gpGlobals->time - TrackedEnemyRef->LastSeenTime > 5.0f)
{
BotReloadWeapons(pBot);
}
return true;
}

Expand Down Expand Up @@ -1217,13 +1263,144 @@ bool MarineCombatThink(bot_t* pBot)

MoveTo(pBot, RetreatLocation, MOVESTYLE_NORMAL);

BotReloadWeapons(pBot);
if (gpGlobals->time - TrackedEnemyRef->LastSeenTime > 5.0f)
{
BotReloadWeapons(pBot);
}
}


return true;
}

void MarineBombardierCombatThink(bot_t* pBot)
{
edict_t* pEdict = pBot->pEdict;

if (pBot->CurrentEnemy < 0) { return; }

edict_t* CurrentEnemy = pBot->TrackedEnemies[pBot->CurrentEnemy].EnemyEdict;
enemy_status* TrackedEnemyRef = &pBot->TrackedEnemies[pBot->CurrentEnemy];

if (!TrackedEnemyRef || FNullEnt(CurrentEnemy) || IsPlayerDead(CurrentEnemy)) { return; }

if (TrackedEnemyRef->bHasLOS)
{
NSWeapon BestWeapon = BotMarineChooseBestWeapon(pBot, CurrentEnemy);

BotShootTarget(pBot, BestWeapon, CurrentEnemy);

if (WeaponCanBeReloaded(BestWeapon) && BotGetCurrentWeaponClipAmmo(pBot) == 0)
{
BotReloadWeapons(pBot);
}

}
else
{
if (BotGetPrimaryWeaponClipAmmo(pBot) > 0 && gpGlobals->time - TrackedEnemyRef->LastSeenTime < 5.0f)
{
Vector GrenadeLoc = UTIL_GetGrenadeThrowTarget(pBot->pEdict, TrackedEnemyRef->LastSeenLocation, UTIL_MetresToGoldSrcUnits(5.0f), true);

if (GrenadeLoc != ZERO_VECTOR)
{
BotShootLocation(pBot, WEAPON_MARINE_GL, GrenadeLoc);
return;
}
}
else
{
BotLookAt(pBot, TrackedEnemyRef->LastSeenLocation);

if (gpGlobals->time - TrackedEnemyRef->LastSeenTime > 3.0f)
{
BotReloadWeapons(pBot);
}
}
}

bool bNeedHealing = (pBot->pEdict->v.health < 80.0f);

if (bNeedHealing)
{
edict_t* NearestHealthPack = UTIL_GetNearestItemOfType(DEPLOYABLE_ITEM_MARINE_HEALTHPACK, pBot->pEdict->v.origin, UTIL_MetresToGoldSrcUnits(10.0f));

if (!FNullEnt(NearestHealthPack))
{
float Dist = vDist2DSq(pBot->pEdict->v.origin, NearestHealthPack->v.origin);
float EnemyDist = vDist2DSq(CurrentEnemy->v.origin, NearestHealthPack->v.origin);

if (Dist < EnemyDist)
{
MoveTo(pBot, NearestHealthPack->v.origin, MOVESTYLE_NORMAL);
return;
}

}
}

bool bNeedAmmo = (BotGetPrimaryWeaponAmmoReserve(pBot) < BotGetPrimaryWeaponMaxClipSize(pBot));

if (bNeedAmmo)
{
edict_t* NearestAmmoPack = UTIL_GetNearestItemOfType(DEPLOYABLE_ITEM_MARINE_AMMO, pBot->pEdict->v.origin, UTIL_MetresToGoldSrcUnits(10.0f));

if (!FNullEnt(NearestAmmoPack))
{
float Dist = vDist2DSq(pBot->pEdict->v.origin, NearestAmmoPack->v.origin);
float EnemyDist = vDist2DSq(CurrentEnemy->v.origin, NearestAmmoPack->v.origin);

if (Dist < EnemyDist)
{
MoveTo(pBot, NearestAmmoPack->v.origin, MOVESTYLE_NORMAL);
return;
}
}
}

edict_t* CoverPlayer = UTIL_GetClosestPlayerOnTeamWithLOS(pBot->pEdict->v.origin, MARINE_TEAM, UTIL_MetresToGoldSrcUnits(10.0f), pBot->pEdict);

if (FNullEnt(CoverPlayer))
{
if (TrackedEnemyRef->bHasLOS)
{
MoveTo(pBot, UTIL_GetCommChairLocation(), MOVESTYLE_NORMAL);
}
else
{
BotGuardLocation(pBot, pBot->pEdict->v.origin);
}

return;
}

if (vDist2DSq(CoverPlayer->v.origin, CurrentEnemy->v.origin) < vDist2DSq(pBot->pEdict->v.origin, CurrentEnemy->v.origin))
{
if (vDist2DSq(pBot->pEdict->v.origin, CoverPlayer->v.origin) < sqrf(UTIL_MetresToGoldSrcUnits(3.0f)))
{
Vector MoveDir = UTIL_GetVectorNormal2D(pBot->pEdict->v.origin - CoverPlayer->v.origin);
pBot->desiredMovementDir = MoveDir;
}
else
{
BotGuardLocation(pBot, pBot->pEdict->v.origin);
BotLookAt(pBot, TrackedEnemyRef->LastSeenLocation);
}

}
else
{
Vector EscapeLocation = pBot->BotNavInfo.TargetDestination;

if (!EscapeLocation || vDist2DSq(EscapeLocation, TrackedEnemyRef->LastSeenLocation) <= vDist2DSq(CoverPlayer->v.origin, TrackedEnemyRef->LastSeenLocation))
{
EscapeLocation = UTIL_GetRandomPointOnNavmeshInRadius(MARINE_REGULAR_NAV_PROFILE, CoverPlayer->v.origin, UTIL_MetresToGoldSrcUnits(5.0f));
}

MoveTo(pBot, EscapeLocation, MOVESTYLE_HIDE);
}
}

void BotReceiveCommanderOrder(bot_t* pBot, AvHOrderType orderType, AvHUser3 TargetType, Vector destination)
{
UTIL_ClearBotTask(pBot, &pBot->CommanderTask);
Expand Down Expand Up @@ -1436,7 +1613,7 @@ void MarineHuntEnemy(bot_t* pBot, enemy_status* TrackedEnemy)
{
if (TimeSinceLastSighting < 5.0f && vDist3DSq(pBot->pEdict->v.origin, TrackedEnemy->LastSeenLocation) <= sqrf(UTIL_MetresToGoldSrcUnits(10.0f)))
{
Vector GrenadeThrowLocation = UTIL_GetGrenadeThrowTarget(pBot, TrackedEnemy->LastSeenLocation, UTIL_MetresToGoldSrcUnits(5.0f));
Vector GrenadeThrowLocation = UTIL_GetGrenadeThrowTarget(pBot->pEdict, TrackedEnemy->LastSeenLocation, UTIL_MetresToGoldSrcUnits(5.0f), false);

if (GrenadeThrowLocation != ZERO_VECTOR)
{
Expand Down Expand Up @@ -1495,7 +1672,6 @@ void MarineCombatModeCheckWantsAndNeeds(bot_t* pBot)
pBot->WantsAndNeedsTask.TaskTarget = NearestArmoury;
}


}

void MarineCheckWantsAndNeeds(bot_t* pBot)
Expand Down
2 changes: 2 additions & 0 deletions evobot/src/bot_marine.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ void MarineThink(bot_t* pBot);
void MarineCombatModeThink(bot_t* pBot);

bool MarineCombatThink(bot_t* pBot);
void MarineBombardierCombatThink(bot_t* pBot);
void MarineHuntEnemy(bot_t* pBot, enemy_status* TrackedEnemy);


Expand All @@ -30,6 +31,7 @@ void MarineSetCombatModeSecondaryTask(bot_t* pBot, bot_task* Task);
void MarineSweeperSetPrimaryTask(bot_t* pBot, bot_task* Task);
void MarineCapperSetPrimaryTask(bot_t* pBot, bot_task* Task);
void MarineAssaultSetPrimaryTask(bot_t* pBot, bot_task* Task);
void MarineBombardierSetPrimaryTask(bot_t* pBot, bot_task* Task);

void MarineSweeperSetCombatModePrimaryTask(bot_t* pBot, bot_task* Task);
void MarineAssaultSetCombatModePrimaryTask(bot_t* pBot, bot_task* Task);
Expand Down
36 changes: 34 additions & 2 deletions evobot/src/bot_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ float clampi(int input, int inMin, int inMax)

Vector GetPitchForProjectile(Vector LaunchPoint, Vector TargetPoint, const float ProjectileSpeed, const float Gravity)
{
const Vector FlightDelta = TargetPoint - LaunchPoint;
/*const Vector FlightDelta = TargetPoint - LaunchPoint;
const Vector DirXY = UTIL_GetVectorNormal2D(FlightDelta);
const float DeltaXY = vSize2D(FlightDelta);
Expand Down Expand Up @@ -439,10 +439,42 @@ Vector GetPitchForProjectile(Vector LaunchPoint, Vector TargetPoint, const float
// final answer!
Vector OutTossVelocity = (DirXY * MagXY) + (UP_VECTOR * MagZ * ZSign);
return OutTossVelocity;
return OutTossVelocity;*/

double start_x = LaunchPoint.x;
double start_y = LaunchPoint.y;
double start_z = LaunchPoint.z;
double target_x = TargetPoint.x;
double target_y = TargetPoint.y;
double target_z = TargetPoint.z;

double x = target_x - start_x;
double y = target_y - start_y;
double z = target_z - start_z;

double range = sqrt(x * x + y * y);

double discriminant = pow(ProjectileSpeed, 4) - Gravity * (Gravity * pow(range, 2) + 2 * z * pow(ProjectileSpeed, 2));

if (discriminant < 0)
{
return ZERO_VECTOR;
}

double launch_angle = atan((pow(ProjectileSpeed, 2) - sqrt(discriminant)) / (Gravity * range));

// Calculate the components of the unit vector
double unit_vector_x = cos(launch_angle) * cos(atan2(y, x));
double unit_vector_y = cos(launch_angle) * sin(atan2(y, x));
double unit_vector_z = sin(launch_angle);

Vector LaunchVector = Vector(unit_vector_x, unit_vector_y, unit_vector_z);
return LaunchVector;

}



void UTIL_AnglesToVector(const Vector angles, Vector* fwd, Vector* right, Vector* up)
{
g_engfuncs.pfnAngleVectors(angles, (float*)fwd, (float*)right, (float*)up);
Expand Down
2 changes: 1 addition & 1 deletion evobot/src/bot_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static const Vector FWD_VECTOR = Vector(0.0f, 1.0f, 0.0f); // Normalized "forwar
static const float MATH_PI = 3.141592654f;
static const float DEGREES_RADIANS_CONV = (MATH_PI / 180.0f);

static const float GOLDSRC_GRAVITY = 800.0f; // Default speed of gravity in GoldSrc units per second squared
static const float GOLDSRC_GRAVITY = 400.0f; // Default speed of gravity in GoldSrc units per second squared

// Defines a frustum plane
typedef struct _FRUSTUM_PLANE_T
Expand Down
Loading

0 comments on commit 750b6a5

Please sign in to comment.