no message
git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@360 e016b1c5-ed68-44aa-a2f7-31cac88cffde
This commit is contained in:
@@ -27,12 +27,11 @@ void CACBot::Spawn()
|
||||
m_pMyEnt->eyeheight = 4.25f;
|
||||
m_pMyEnt->aboveeye = 0.7f;
|
||||
m_pMyEnt->radius = 1.1f;
|
||||
m_pMyEnt->primary = m_pMyEnt->nextprimary = rnd(3)+GUN_PISTOL;
|
||||
m_pMyEnt->primary = m_pMyEnt->nextprimary = 2 + rnd(4);
|
||||
|
||||
spawnplayer(m_pMyEnt);
|
||||
|
||||
m_pMyEnt->targetyaw = m_pMyEnt->yaw = m_pMyEnt->targetpitch = m_pMyEnt->pitch = 0.0f;
|
||||
m_pMyEnt->primary = m_pMyEnt->nextprimary = GUN_ASSAULT;
|
||||
radd(this->m_pMyEnt);
|
||||
m_pMyEnt->move = 0;
|
||||
m_pMyEnt->enemy = NULL;
|
||||
@@ -96,9 +95,6 @@ void CACBot::Spawn()
|
||||
SelectGun(GUN_SG);
|
||||
}*/
|
||||
|
||||
m_pMyEnt->ammo[GUN_KNIFE] = 1;
|
||||
m_pMyEnt->ammo[GUN_PISTOL] = 5;
|
||||
m_pMyEnt->mag[GUN_PISTOL] = 5;
|
||||
SelectGun(m_pMyEnt->primary);
|
||||
|
||||
m_eCurrentBotState = STATE_NORMAL;
|
||||
@@ -250,9 +246,11 @@ void CACBot::PickUp(int n)
|
||||
int ammo = np*2;
|
||||
switch(ents[n].type)
|
||||
{
|
||||
case I_CLIPS: AddItem(n, m_pMyEnt->ammo[GUN_PISTOL], ammo); break;
|
||||
case I_AMMO: AddItem(n, m_pMyEnt->ammo[m_pMyEnt->primary], ammo); break;
|
||||
case I_GRENADE: AddItem(n, m_pMyEnt->ammo[GUN_GRENADE], ammo); break;
|
||||
case I_AMMO: AddItem(n, m_pMyEnt->ammo[m_pMyEnt->primary], ammo, m_pMyEnt->primary); break;
|
||||
case I_CLIPS: AddItem(n, m_pMyEnt->ammo[GUN_PISTOL], ammo, GUN_PISTOL); break;
|
||||
case I_GRENADE: AddItem(n, m_pMyEnt->ammo[GUN_GRENADE], ammo, 6); break;
|
||||
case I_HEALTH: AddItem(n, m_pMyEnt->health, ammo, 7); break;
|
||||
case I_ARMOUR: AddItem(n, m_pMyEnt->armour, ammo, 8); break;
|
||||
|
||||
/* case I_HELMET:
|
||||
// (100h/100g only absorbs 166 damage)
|
||||
@@ -287,16 +285,16 @@ void CACBot::PickUp(int n)
|
||||
};
|
||||
};
|
||||
|
||||
void CACBot::AddItem(int i, int &v, int spawnsec)
|
||||
void CACBot::AddItem(int i, int &v, int spawnsec, int t)
|
||||
{
|
||||
if((i>=sents.length()) || (!sents[i].spawned))
|
||||
return;
|
||||
|
||||
//fixmebot
|
||||
if(v>=itemstats[ents[i].type].max) // don't pick up if not needed
|
||||
if(v>=itemstats[t].max) // don't pick up if not needed
|
||||
return;
|
||||
|
||||
itemstat &is = itemstats[ents[i].type];
|
||||
itemstat &is = itemstats[t];
|
||||
ents[i].spawned = false;
|
||||
v += is.add;
|
||||
if(v>is.max) v = is.max;
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
virtual void CheckItemPickup(void);
|
||||
virtual void PickUp(int n);
|
||||
virtual void AddItem(int i, int &v, int spawnsec);
|
||||
virtual void AddItem(int i, int &v, int spawnsec, int t);
|
||||
|
||||
// AI Functions
|
||||
virtual bool ChoosePreferredWeapon(void);
|
||||
|
||||
@@ -20,17 +20,17 @@ extern vector<dynent*> monsters;
|
||||
weaponinfo_s WeaponInfoTable[MAX_WEAPONS] =
|
||||
{
|
||||
// KNIFE
|
||||
{ TYPE_MELEE, 0.0f, 3.5f, 0.0f, 5.0f, 1 },
|
||||
{ TYPE_MELEE, 0.0f, 2.0f, 0.0f, 3.5f, 1 },
|
||||
// PISTOL
|
||||
{ TYPE_NORMAL, 0.0f, 12.0f, 0.0f, 50.0f, 6 },
|
||||
{ TYPE_NORMAL, 0.0f, 20.0f, 0.0f, 50.0f, 6 },
|
||||
// SHOTGUN
|
||||
{ TYPE_SHOTGUN, 0.0f, 20.0f, 0.0f, 70.0f, 4 },
|
||||
{ TYPE_SHOTGUN, 0.0f, 15.0f, 0.0f, 40.0f, 3 },
|
||||
// SUBGUN
|
||||
{ TYPE_AUTO, 0.0f, 25.0f, 0.0f, 100.0f, 15 },
|
||||
{ TYPE_AUTO, 0.0f, 25.0f, 0.0f, 60.0f, 10 },
|
||||
// SNIPER
|
||||
{ TYPE_SNIPER, 15.0f, 25.0f, 0.0f, 100.0f, 3 },
|
||||
{ TYPE_SNIPER, 30.0f, 50.0f, 20.0f, 200.0f, 3 },
|
||||
// ASSAULT
|
||||
{ TYPE_AUTO, 0.0f, 25.0f, 0.0f, 100.0f, 10 },
|
||||
{ TYPE_AUTO, 40.0f, 80.0f, 0.0f, 150.0f, 6 },
|
||||
// GRENADE
|
||||
{ TYPE_GRENADE, 30.0f, 25.0f, 0.0f, 50.0f, 1 }
|
||||
};
|
||||
@@ -39,76 +39,58 @@ weaponinfo_s WeaponInfoTable[MAX_WEAPONS] =
|
||||
|
||||
bool CACBot::ChoosePreferredWeapon()
|
||||
{
|
||||
printf("chose weapon\n");
|
||||
TMultiChoice<int> WeaponChoices;
|
||||
short bestWeapon = m_pMyEnt->gunselect;
|
||||
short bestWeaponScore = 0;
|
||||
|
||||
short sWeaponScore;
|
||||
float flDist = GetDistance(m_pMyEnt->enemy->o);
|
||||
|
||||
if ((m_iChangeWeaponDelay > lastmillis) && (m_pMyEnt->ammo[m_pMyEnt->gunselect]))
|
||||
|
||||
if (m_iChangeWeaponDelay < lastmillis && m_pMyEnt->mag[m_pMyEnt->gunselect])
|
||||
{
|
||||
if ((WeaponInfoTable[m_pMyEnt->gunselect].eWeaponType != TYPE_MELEE) || (flDist <= 3.5f))
|
||||
if ((WeaponInfoTable[m_pMyEnt->gunselect].eWeaponType != TYPE_MELEE) || (flDist <= WeaponInfoTable[GUN_KNIFE].flMaxFireDistance))
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Choose a weapon
|
||||
for(int i=0;i<MAX_WEAPONS;i++)
|
||||
{
|
||||
// If no ammo for this weapon, skip it
|
||||
if (m_pMyEnt->ammo[i] == 0) continue;
|
||||
if (!m_pMyEnt->mag[i] && !m_pMyEnt->ammo[i]) continue;
|
||||
|
||||
sWeaponScore = 5; // Minimal score for a weapon
|
||||
|
||||
if ((flDist >= WeaponInfoTable[i].flMinDesiredDistance) &&
|
||||
|
||||
// use the advantage of the melee weapon
|
||||
if((flDist >= WeaponInfoTable[i].flMinDesiredDistance) &&
|
||||
(flDist <= WeaponInfoTable[i].flMaxDesiredDistance))
|
||||
{
|
||||
// In desired range for this weapon
|
||||
sWeaponScore += 5; // Increase score much
|
||||
}
|
||||
else if ((flDist < WeaponInfoTable[i].flMinFireDistance) ||
|
||||
(flDist > WeaponInfoTable[i].flMaxFireDistance))
|
||||
continue; // Wrong distance for this weapon
|
||||
|
||||
// The ideal distance would be between the Min and Max desired distance.
|
||||
// Score on the difference of the avarage of the Min and Max desired distance.
|
||||
float flAvarage = (WeaponInfoTable[i].flMinDesiredDistance +
|
||||
WeaponInfoTable[i].flMaxDesiredDistance) / 2.0f;
|
||||
float flIdealDiff = fabs(flDist - flAvarage);
|
||||
|
||||
if (flIdealDiff < 0.5f) // Close to ideal distance
|
||||
sWeaponScore += 4;
|
||||
else if (flIdealDiff <= 1.0f)
|
||||
sWeaponScore += 2;
|
||||
|
||||
// Now rate the weapon on available ammo...
|
||||
if (WeaponInfoTable[i].sMinDesiredAmmo > 0)
|
||||
{
|
||||
// Calculate how much percent of the min desired ammo the bot has
|
||||
float flDesiredPercent = (float(m_pMyEnt->mag[i]) /
|
||||
float(WeaponInfoTable[i].sMinDesiredAmmo)) *
|
||||
100.0f;
|
||||
|
||||
if(flDesiredPercent >= 175.0f)
|
||||
sWeaponScore += 4;
|
||||
else if(flDesiredPercent >= 100.0f)
|
||||
sWeaponScore += 3;
|
||||
}
|
||||
|
||||
WeaponChoices.Insert(i, sWeaponScore);
|
||||
}
|
||||
{
|
||||
if(WeaponInfoTable[i].eWeaponType == TYPE_MELEE) sWeaponScore += 5;
|
||||
}
|
||||
|
||||
if ((flDist > WeaponInfoTable[i].flMinFireDistance) && // inside the range, continue to evaluate
|
||||
(flDist < WeaponInfoTable[i].flMaxFireDistance))
|
||||
{
|
||||
if(m_pMyEnt->mag[i]) sWeaponScore += 5;
|
||||
if(i > 1) sWeaponScore += 4; // prefer primary guns
|
||||
}
|
||||
|
||||
if(sWeaponScore > bestWeaponScore)
|
||||
{
|
||||
bestWeaponScore = sWeaponScore;
|
||||
bestWeapon = i;
|
||||
}
|
||||
}
|
||||
|
||||
int WeaponSelect;
|
||||
if (WeaponChoices.GetSelection(WeaponSelect))
|
||||
{
|
||||
m_iChangeWeaponDelay = lastmillis + RandomLong(2000, 8000);
|
||||
if(SelectGun(WeaponSelect))
|
||||
{
|
||||
if(m_pMyEnt->mag[WeaponSelect]==0) reload(m_pMyEnt); // fixme, more intelligent reload
|
||||
printf("gun selected %i\n", WeaponSelect);
|
||||
return true;
|
||||
}
|
||||
m_iChangeWeaponDelay = lastmillis + 8000; //RandomLong(2000, 8000);
|
||||
m_bShootAtFeet = false;
|
||||
SelectGun(bestWeapon);
|
||||
if(!m_pMyEnt->mag[bestWeapon])
|
||||
{
|
||||
reload(m_pMyEnt);
|
||||
m_iShootDelay = lastmillis + reloadtime(bestWeapon) + 10;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
void CACBot::Reload(int Gun)
|
||||
@@ -166,8 +148,18 @@ entity *CACBot::SearchForEnts(bool bUseWPs, float flRange, float flMaxHeight)
|
||||
bInteresting = (m_pMyEnt->ammo[GUN_GRENADE]<sMaxAmmo);
|
||||
sAmmo = m_pMyEnt->ammo[GUN_GRENADE];
|
||||
break;
|
||||
case I_HEALTH:
|
||||
sMaxAmmo = itemstats[7].max; //FIXME
|
||||
bInteresting = (m_pMyEnt->health < sMaxAmmo);
|
||||
sAmmo = m_pMyEnt->health;
|
||||
break;
|
||||
case I_ARMOUR:
|
||||
sMaxAmmo = itemstats[8].max; // FIXME
|
||||
bInteresting = (m_pMyEnt->armour < sMaxAmmo);
|
||||
sAmmo = m_pMyEnt->armour;
|
||||
break;
|
||||
};
|
||||
|
||||
|
||||
if (!bInteresting)
|
||||
continue; // Not an interesting item, skip
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ void CBot::Think()
|
||||
m_pMyEnt->move = 0;
|
||||
moveplayer(m_pMyEnt, 1, false);
|
||||
}
|
||||
else if (!m_arena)
|
||||
else if (!m_arena && lastmillis-m_pMyEnt->lastaction>5000)
|
||||
Spawn();
|
||||
|
||||
SendBotInfo();
|
||||
@@ -373,14 +373,10 @@ float CBot::GetDistance(entity *e)
|
||||
|
||||
bool CBot::SelectGun(int Gun)
|
||||
{
|
||||
if (m_pMyEnt->ammo[Gun])
|
||||
{
|
||||
//temporary doc out argh
|
||||
/* if (m_pMyEnt->gunselect != Gun) botplaysound(S_WEAPLOAD, m_pMyEnt); */
|
||||
m_pMyEnt->gunselect = Gun;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
if(m_pMyEnt->reloading) return false;
|
||||
if (m_pMyEnt->gunselect != Gun) botplaysound(S_GUNCHANGE, m_pMyEnt);
|
||||
m_pMyEnt->gunselect = Gun;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBot::IsVisible(entity *e, bool CheckPlayers)
|
||||
|
||||
@@ -239,7 +239,7 @@ public:
|
||||
bool SelectGun(int Gun);
|
||||
virtual void CheckItemPickup(void) = 0;
|
||||
virtual void PickUp(int n) = 0;
|
||||
virtual void AddItem(int i, int &v, int spawnsec) = 0;
|
||||
virtual void AddItem(int i, int &v, int spawnsec, int t) = 0;
|
||||
virtual void BotPain(int damage, dynent *d) = 0;
|
||||
void SendBotInfo(void);
|
||||
float GetDistance(const vec &o);
|
||||
@@ -254,6 +254,7 @@ public:
|
||||
|
||||
// AI Functions
|
||||
bool FindEnemy(void);
|
||||
void CheckReload(void);
|
||||
void ShootEnemy(void);
|
||||
bool CheckHunt(void);
|
||||
bool HuntEnemy(void);
|
||||
|
||||
@@ -865,8 +865,7 @@ bool CBot::HuntEnemy(void)
|
||||
|
||||
void CBot::ShootEnemy()
|
||||
{
|
||||
if (!m_pMyEnt->enemy)
|
||||
return;
|
||||
if(!m_pMyEnt->enemy) return;
|
||||
|
||||
m_iSawEnemyTime = lastmillis;
|
||||
|
||||
@@ -878,7 +877,7 @@ void CBot::ShootEnemy()
|
||||
if (m_iShootDelay < lastmillis)
|
||||
//if ((lastmillis-m_pMyEnt->lastaction) >= m_pMyEnt->gunwait)
|
||||
{
|
||||
if (m_pMyEnt->ammo[m_pMyEnt->gunselect])
|
||||
if (m_pMyEnt->mag[m_pMyEnt->gunselect])
|
||||
{
|
||||
// If the bot is using a sniper only shoot if crosshair is near the enemy
|
||||
if (WeaponInfoTable[m_pMyEnt->gunselect].eWeaponType == TYPE_SNIPER)
|
||||
@@ -1016,6 +1015,14 @@ int CBot::GetShootDelay()
|
||||
return max(m_pMyEnt->gunwait, int(RandomFloat(flMinShootDelay, flMaxShootDelay) * 1000.0f));
|
||||
}
|
||||
|
||||
void CBot::CheckReload() // reload gun if no enemies are around
|
||||
{
|
||||
if(m_pMyEnt->enemy) return;
|
||||
SelectGun(m_pMyEnt->primary);
|
||||
reload(m_pMyEnt);
|
||||
return;
|
||||
}
|
||||
|
||||
void CBot::MainAI()
|
||||
{
|
||||
// Default bots will run forward
|
||||
@@ -1056,22 +1063,26 @@ void CBot::MainAI()
|
||||
}
|
||||
else if (CheckHunt() && HuntEnemy())
|
||||
{
|
||||
CheckReload();
|
||||
AddDebugText("Hunting to %s", m_pHuntTarget->name);
|
||||
m_eCurrentBotState = STATE_HUNT;
|
||||
}
|
||||
// Heading to an interesting entity(ammo, armour etc)
|
||||
else if (CheckItems())
|
||||
{
|
||||
CheckReload();
|
||||
AddDebugText("has ent");
|
||||
m_eCurrentBotState = STATE_ENT;
|
||||
}
|
||||
else if (m_classicsp && DoSPStuff()) // Home to goal, find/follow friends etc.
|
||||
{
|
||||
|
||||
AddDebugText("SP stuff");
|
||||
m_eCurrentBotState = STATE_SP;
|
||||
}
|
||||
else // Normal navigation
|
||||
{
|
||||
CheckReload();
|
||||
if (m_eCurrentBotState != STATE_NORMAL)
|
||||
{
|
||||
m_vGoal = g_vecZero;
|
||||
|
||||
@@ -1082,12 +1082,6 @@ node_s *CWaypointClass::GetNearestWaypoint(vec v_src, float flRange)
|
||||
|
||||
while(pNode)
|
||||
{
|
||||
if (pNode->Entry->iFlags & W_FL_FLOOD)
|
||||
{
|
||||
pNode = pNode->next;
|
||||
continue;
|
||||
}
|
||||
|
||||
flDist = GetDistance(v_src, pNode->Entry->v_origin);
|
||||
if ((flDist < flNearestDist) && (flDist <= flRange))
|
||||
{
|
||||
@@ -1921,6 +1915,13 @@ void wpload(void)
|
||||
|
||||
COMMAND(wpload, ARG_NONE);
|
||||
|
||||
void wpclear(void)
|
||||
{
|
||||
WaypointClass.Clear();
|
||||
}
|
||||
|
||||
COMMAND(wpclear, ARG_NONE);
|
||||
|
||||
void autowp(int on)
|
||||
{
|
||||
WaypointClass.SetWaypointsVisible(true);
|
||||
@@ -2046,12 +2047,12 @@ void setwpyaw(void)
|
||||
COMMAND(setwpyaw, ARG_NONE);
|
||||
|
||||
#ifdef WP_FLOOD
|
||||
void startflood(void)
|
||||
void wpflood(void)
|
||||
{
|
||||
WaypointClass.StartFlood();
|
||||
}
|
||||
|
||||
COMMAND(startflood, ARG_NONE);
|
||||
COMMAND(wpflood, ARG_NONE);
|
||||
#endif
|
||||
|
||||
#ifdef VANILLA_CUBE
|
||||
|
||||
@@ -315,6 +315,8 @@ char *CBotManager::GetBotTeam()
|
||||
return szOutput;
|
||||
}
|
||||
|
||||
extern void renderplayer(dynent *d);
|
||||
|
||||
void CBotManager::RenderBots()
|
||||
{
|
||||
static bool drawblue;
|
||||
@@ -323,8 +325,9 @@ void CBotManager::RenderBots()
|
||||
{
|
||||
if (bots[i] && (bots[i] != m_pBotToView))
|
||||
{
|
||||
drawblue = (m_sp || isteam(player1->team, bots[i]->team));
|
||||
renderclient(bots[i], drawblue, "playermodels/counterterrorist", 1.6f);
|
||||
/*drawblue = (m_sp || isteam(player1->team, bots[i]->team));
|
||||
renderclient(bots[i], drawblue, "playermodels/counterterrorist", 1.6f);*/
|
||||
renderplayer(bots[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -916,7 +919,7 @@ dynent *CBotManager::CreateBot(const char *team, const char *skill, const char *
|
||||
{
|
||||
dynent *m = newdynent();
|
||||
if (!m) return NULL;
|
||||
|
||||
loopi(NUMGUNS) m->ammo[i] = m->mag[i] = 0;
|
||||
// Create new bot class, dependand on the current mod
|
||||
#if defined VANILLA_CUBE
|
||||
m->pBot = new CCubeBot;
|
||||
|
||||
Reference in New Issue
Block a user