Skip to content

Commit

Permalink
Made Lerk, Fade and Onos configurable
Browse files Browse the repository at this point in the history
* Lerk, fade and onos can be enabled/disabled via config now
  • Loading branch information
RGreenlees committed Aug 31, 2023
1 parent 807a954 commit edfabb1
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 37 deletions.
43 changes: 21 additions & 22 deletions evobot/src/bot_alien.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,6 @@ void AlienHarasserSetCombatModePrimaryTask(bot_t* pBot, bot_task* Task)

void AlienCapperSetPrimaryTask(bot_t* pBot, bot_task* Task)
{
bool bCappingIsUrgent = UTIL_GetNumPlacedStructuresOfType(STRUCTURE_ALIEN_RESTOWER) < 3;

int RequiredRes = kResourceTowerCost;

if (!IsPlayerGorge(pBot->pEdict))
Expand All @@ -471,14 +469,12 @@ void AlienCapperSetPrimaryTask(bot_t* pBot, bot_task* Task)
{
const resource_node* RandomResNode = nullptr;

if (!IsPlayerGorge(pBot->pEdict) || PlayerHasWeapon(pBot->pEdict, WEAPON_GORGE_BILEBOMB))
RandomResNode = UTIL_AlienFindUnclaimedResNodeFurthestFromLocation(pBot, UTIL_GetCommChairLocation(), !IsPlayerSkulk(pBot->pEdict));

if (!RandomResNode && (!IsPlayerGorge(pBot->pEdict) || PlayerHasWeapon(pBot->pEdict, WEAPON_GORGE_BILEBOMB)))
{
RandomResNode = UTIL_FindEligibleResNodeFurthestFromLocation(UTIL_GetCommChairLocation(), ALIEN_TEAM, !IsPlayerSkulk(pBot->pEdict));
}
else
{
RandomResNode = UTIL_AlienFindUnclaimedResNodeFurthestFromLocation(pBot, UTIL_GetCommChairLocation(), !IsPlayerSkulk(pBot->pEdict));
}

if (RandomResNode)
{
Expand All @@ -492,12 +488,10 @@ void AlienCapperSetPrimaryTask(bot_t* pBot, bot_task* Task)
// Don't have enough to cap right now, take out marine towers
if (!IsPlayerGorge(pBot->pEdict) || PlayerHasWeapon(pBot->pEdict, WEAPON_GORGE_BILEBOMB))
{
edict_t* EnemyResTower = UTIL_GetNearestStructureOfTypeInLocation(STRUCTURE_MARINE_RESTOWER, pBot->pEdict->v.origin, UTIL_MetresToGoldSrcUnits(200.0f), false, false);
edict_t* EnemyResTower = UTIL_GetFurthestStructureOfTypeFromLocation(STRUCTURE_MARINE_RESTOWER, UTIL_GetCommChairLocation(), !IsPlayerSkulk(pBot->pEdict));

if (!FNullEnt(EnemyResTower))
{
// Don't set a new attack or move task if we have one already
if (Task->TaskType == TASK_ATTACK && Task->TaskTarget == EnemyResTower) { return; }
TASK_SetAttackTask(pBot, Task, EnemyResTower, false);
return;
}
Expand Down Expand Up @@ -802,24 +796,29 @@ void AlienDestroyerSetPrimaryTask(bot_t* pBot, bot_task* Task)
if (pBot->resources >= kFadeEvolutionCost)
{
int NumOnos = GAME_GetNumPlayersOnTeamOfClass(pBot->pEdict->v.team, CLASS_ONOS);
int Evolution = IMPULSE_ALIEN_EVOLVE_FADE;
int Evolution = (CONFIG_IsFadeAllowed()) ? IMPULSE_ALIEN_EVOLVE_FADE : 0;

if (pBot->resources >= kOnosEvolutionCost && NumOnos < 2)
// Normally we only want 2 Onos at any one time, but if Fade isn't allowed and Onos is then we will skip that check and have more rhino boys
if (CONFIG_IsOnosAllowed() && pBot->resources >= kOnosEvolutionCost && (!CONFIG_IsFadeAllowed() || NumOnos < 2))
{
Evolution = IMPULSE_ALIEN_EVOLVE_ONOS;
}

const hive_definition* NearestHive = UTIL_GetNearestHiveOfStatus(pBot->pEdict->v.origin, HIVE_STATUS_BUILT);

if (NearestHive)
// Skip this bit if we aren't allowed to go fade, and aren't allowed or can't go onos
if (Evolution > 0)
{
TASK_SetEvolveTask(pBot, Task, NearestHive->edict, Evolution, true);
}
else
{
TASK_SetEvolveTask(pBot, Task, pBot->pEdict->v.origin, Evolution, true);
const hive_definition* NearestHive = UTIL_GetNearestHiveOfStatus(pBot->pEdict->v.origin, HIVE_STATUS_BUILT);

if (NearestHive)
{
TASK_SetEvolveTask(pBot, Task, NearestHive->edict, Evolution, true);
}
else
{
TASK_SetEvolveTask(pBot, Task, pBot->pEdict->v.origin, Evolution, true);
}
return;
}
return;
}
}

Expand Down Expand Up @@ -2173,7 +2172,7 @@ BotRole AlienGetBestBotRole(bot_t* pBot)
}
}

bool bCanGoLerk = ((gpGlobals->time - GAME_GetLastLerkSeenTime()) >= CONFIG_GetLerkCooldown());
bool bCanGoLerk = (CONFIG_IsLerkAllowed() && ((gpGlobals->time - GAME_GetLastLerkSeenTime()) >= CONFIG_GetLerkCooldown()));

// If we have enough resources, or nearly enough, and we don't have any lerks already on the team then prioritise this
// Also, if we're close to fade then save for that
Expand Down
82 changes: 67 additions & 15 deletions evobot/src/bot_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ CommanderMode eCommanderMode = COMMANDERMODE_ALWAYS;
int NSVersion = 33; // 32 for 3.2, 33 for 3.3 (including betas)
char BotPrefix[32] = "";

bool bLerkAllowed = true;
bool bFadeAllowed = true;
bool bOnosAllowed = true;

float MaxStuckTime = 0.0f;

HiveTechStatus ChamberSequence[3];
Expand Down Expand Up @@ -267,6 +271,33 @@ void ParseConfigFile(bool bOverride)
continue;
}

if (key.compare("AllowLerk") == 0)
{
if (isNumber(value.c_str()))
{
bLerkAllowed = atoi(value.c_str()) > 0;
}
continue;
}

if (key.compare("AllowFade") == 0)
{
if (isNumber(value.c_str()))
{
bFadeAllowed = atoi(value.c_str()) > 0;
}
continue;
}

if (key.compare("AllowOnos") == 0)
{
if (isNumber(value.c_str()))
{
bOnosAllowed = atoi(value.c_str()) > 0;
}
continue;
}

if (key.compare("MaxStuckTime") == 0)
{
if (isNumber(value.c_str()))
Expand Down Expand Up @@ -593,7 +624,7 @@ void CONFIG_RegenerateConfigFile()

fprintf(NewConfigFile, "### General bot settings ###\n\n");

fprintf(NewConfigFile, "# NS Version. The following options are valid:\n");
fprintf(NewConfigFile, "# IMPORTANT! This is the version of NS you're running. The following options are valid:\n");
fprintf(NewConfigFile, "# '32' - NS 3.2.X including vanilla 3.2\n");
fprintf(NewConfigFile, "# '33' - NS 3.3 and all betas\n");
fprintf(NewConfigFile, "nsversion=33\n\n");
Expand Down Expand Up @@ -630,24 +661,24 @@ void CONFIG_RegenerateConfigFile()

fprintf(NewConfigFile, "# Bot skill settings. You can define as many settings as you like and reference them by name\n");
fprintf(NewConfigFile, "# Format is BotSkillName = name, followed by one of the following:\n");
fprintf(NewConfigFile, "# ReactionTime = How quickly in seconds the bot will react to sighting enemies(Marine and Alien)\n");
fprintf(NewConfigFile, "# AimSkill = How accurately the bot can lock sights on you after seeing you(Marine and Alien)\n");
fprintf(NewConfigFile, "# MovementTracking = How accurately the bot can follow a moving target(Marine and Alien)\n");
fprintf(NewConfigFile, "# ViewSpeed = How fast the bot can swivel its view(Marine and Alien)\n");
fprintf(NewConfigFile, "# ReactionTime = How quickly in seconds the bot will react to sighting enemies\n");
fprintf(NewConfigFile, "# AimSkill = How accurately the bot can lock sights on you after seeing you (0.0 - 1.0)\n");
fprintf(NewConfigFile, "# MovementTracking = How accurately the bot can follow a moving target (0.0 - 1.0)\n");
fprintf(NewConfigFile, "# ViewSpeed = How fast the bot can swivel its view (0.1 - 2.0)\n");
fprintf(NewConfigFile, "# Reference the difficulties by name using the 'botskill' command (see Help.txt)\n\n");

fprintf(NewConfigFile, "BotSkillName=MyCustomSkill\n");
fprintf(NewConfigFile, "MarineReactionTime=0.3\n");
fprintf(NewConfigFile, "MarineAimSkill=0.3\n");
fprintf(NewConfigFile, "MarineMovementTracking=0.3\n");
fprintf(NewConfigFile, "MarineReactionTime=0.2\n");
fprintf(NewConfigFile, "MarineAimSkill=0.2\n");
fprintf(NewConfigFile, "MarineMovementTracking=0.2\n");
fprintf(NewConfigFile, "MarineViewSpeed=1.0\n");
fprintf(NewConfigFile, "AlienReactionTime=0.3\n");
fprintf(NewConfigFile, "AlienReactionTime=0.2\n");
fprintf(NewConfigFile, "AlienAimSkill=0.5\n");
fprintf(NewConfigFile, "AlienMovementTracking=0.5\n");
fprintf(NewConfigFile, "AlienViewSpeed=1.3\n\n");

fprintf(NewConfigFile, "# Default bot skill level for all bots created.Must be a valid skill defined above\n");
fprintf(NewConfigFile, "DefaultSkillLevel = MyCustomSkill\n\n\n\n");
fprintf(NewConfigFile, "# Default bot skill level for all bots created. Must be a valid skill defined above\n");
fprintf(NewConfigFile, "DefaultSkillLevel=MyCustomSkill\n\n\n\n");



Expand All @@ -665,18 +696,24 @@ void CONFIG_RegenerateConfigFile()


fprintf(NewConfigFile, "### Alien Settings ###\n\n");
fprintf(NewConfigFile, "# Preferred chamber sequence. Valid entries are 'defense', 'movement' and 'sensory'. Separate sequence with /\n");
fprintf(NewConfigFile, "# Preferred chamber sequence. Valid entries are 'defense', 'movement' and 'sensory'. Separate sequence with forward slash\n");
fprintf(NewConfigFile, "# You can also use ? for random, so if you want movement always first but then defense and sensory at random, use\n");
fprintf(NewConfigFile, "# ChamberSequence:movement/?/?\n");
fprintf(NewConfigFile, "# # Or if you want sensory always last, but movement and defence random, use\n");
fprintf(NewConfigFile, "# ChamberSequence=?/?/sensory\n");
fprintf(NewConfigFile, "ChamberSequence:defense/movement/sensory\n\n");


fprintf(NewConfigFile, "# Lerk cooldown in seconds.How long should bots wait after a lerk has died to replace them?");
fprintf(NewConfigFile, "# Lerks are fragile, so this prevents bots taking it in turns to go lerk every time one dies and burning through all their res.");
fprintf(NewConfigFile, "# Lerk cooldown in seconds. How long should bots wait after a lerk has died to replace them?\n");
fprintf(NewConfigFile, "# Lerks are fragile, so this prevents bots taking it in turns to go lerk every time one dies and burning through all their res.\n");
fprintf(NewConfigFile, "LerkCooldown=60\n\n");

fprintf(NewConfigFile, "# Enabled life forms. If you don't want the bots to evolve to certain life forms then you can disable them here.\n");
fprintf(NewConfigFile, "# 0 = Disabled, 1 = Enabled\n");
fprintf(NewConfigFile, "AllowLerk=1\n");
fprintf(NewConfigFile, "AllowFade=1\n");
fprintf(NewConfigFile, "AllowOnos=1\n");

fprintf(NewConfigFile, "\n");

fclose(NewConfigFile);

Expand Down Expand Up @@ -915,4 +952,19 @@ void CONFIG_SetGlobalBotSkillLevel(const char* NewSkillLevel)
}

GlobalSkillLevel = NewSkillLevel;
}

bool CONFIG_IsLerkAllowed()
{
return bLerkAllowed;
}

bool CONFIG_IsFadeAllowed()
{
return bFadeAllowed;
}

bool CONFIG_IsOnosAllowed()
{
return bOnosAllowed;
}
4 changes: 4 additions & 0 deletions evobot/src/bot_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ CommanderMode CONFIG_GetCommanderMode();
// Returns the current lerk cooldown (how long aliens wait before evolving another lerk after the last one died)
float CONFIG_GetLerkCooldown();

bool CONFIG_IsLerkAllowed();
bool CONFIG_IsFadeAllowed();
bool CONFIG_IsOnosAllowed();

// Returns the max time a bot is allowed to be stuck before suiciding (0 means forever)
float CONFIG_GetMaxStuckTime();

Expand Down

0 comments on commit edfabb1

Please sign in to comment.