Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float (entity targ) botrange;
- vector (vector src, vector trg, float invMvel) leadtarget =
- {
- local vector tg;
- local vector lead;
- lead = ((self.enemy.velocity * invMvel) * vlen ((trg - src)));
- tg = (trg + lead);
- if ((self.weapon == IT_ROCKET_LAUNCHER))
- {
- if ((self.skil > FL_SWIM))
- {
- traceline (src, tg, TRUE, self);
- if ((trace_fraction != TRUE))
- {
- tg = (tg - (lead * 0.5));
- traceline (src, tg, TRUE, self);
- if ((trace_fraction != TRUE))
- {
- tg = (tg - (lead * 0.5));
- }
- }
- }
- }
- return (tg);
- };
- vector (vector trg) adjustgrenade =
- {
- local vector tg;
- local vector tgxy;
- local vector selfxy;
- local vector lead;
- local float xypct;
- tg = trg;
- tgxy = tg;
- tgxy_z = FALSE;
- selfxy = self.origin;
- selfxy_z = FALSE;
- xypct = (vlen ((tgxy - selfxy)) * INVGRENADELEVELDIST);
- if ((xypct > TRUE))
- {
- if ((xypct < 12))
- {
- tg_z = (tg_z + (GRENADEMAXHEIGHT * (xypct - TRUE)));
- }
- }
- else
- {
- tg_z = (tg_z - (GRENADEMAXHEIGHT * (TRUE - xypct)));
- }
- return (tg);
- };
- vector () botaim =
- {
- local vector dir;
- local vector tg;
- local vector lead;
- local vector src;
- local float sk;
- local float rnd;
- if (REBOUND)
- {
- tg = REBOUNDSPOT;
- }
- else
- {
- src = self.origin;
- if ((self.weapon & ((IT_ROCKET_LAUNCHER + IT_SUPER_NAILGUN) + IT_NAILGUN)))
- {
- src = (src + '0 0 16');
- }
- tg = self.enemy.origin;
- traceline (src, tg, TRUE, self);
- if ((trace_fraction != TRUE))
- {
- tg = (tg + self.enemy.view_ofs);
- }
- if ((self.skil > TRUE))
- {
- if ((self.weapon & IT_ROCKET_LAUNCHER))
- {
- tg = leadtarget (src, tg, 0.001);
- if ((self.origin_z >= self.enemy.origin_z))
- {
- rnd = ((random () * 3.5) + TRUE);
- if ((self.skil > rnd))
- {
- tg_z = ((tg_z + self.enemy.mins_z) + FL_SWIM);
- traceline (src, tg, TRUE, self);
- if ((trace_fraction != TRUE))
- {
- tg_z = ((tg_z - self.enemy.mins_z) - MOVETYPE_WALK);
- }
- }
- }
- }
- else
- {
- if ((self.weapon & IT_GRENADE_LAUNCHER))
- {
- tg = leadtarget (src, tg, 0.00167);
- }
- else
- {
- if (((self.weapon & IT_SUPER_NAILGUN) || (self.weapon & IT_NAILGUN)))
- {
- rnd = (random () * 0.0016);
- tg = leadtarget (src, tg, rnd);
- }
- }
- }
- }
- }
- if ((self.weapon == IT_GRENADE_LAUNCHER))
- {
- tg = adjustgrenade (tg);
- }
- sk = self.skil;
- if ((self.weapon == IT_LIGHTNING))
- {
- if ((sk > 2.5))
- {
- sk = 2.5;
- }
- }
- if ((sk < MOVETYPE_WALK))
- {
- lead = (self.enemy.origin - self.enemy.oldorigin);
- lead = (((lead * (MOVETYPE_WALK - sk)) * 3.5) * (random () - 0.5));
- tg = (tg + lead);
- }
- dir = normalize ((tg - self.origin));
- if ((sk < MOVETYPE_WALK))
- {
- dir = (dir + (((MOVETYPE_WALK - sk) * crandom ()) * '0.06 0 0'));
- dir = (dir + (((MOVETYPE_WALK - sk) * crandom ()) * '0 0.06 0'));
- }
- dir = normalize (dir);
- return (dir);
- };
- float () CheckBotAttack =
- {
- local vector spot1;
- local vector spot2;
- local entity targ;
- targ = self.enemy;
- if ((time < self.attack_finished))
- {
- return (FALSE);
- }
- spot1 = (self.origin + self.view_ofs);
- spot2 = (targ.origin + targ.view_ofs);
- traceline (spot1, spot2, FALSE, self);
- if ((trace_ent != targ))
- {
- return (FALSE);
- }
- if ((trace_inopen && trace_inwater))
- {
- spot2 = targ.origin;
- traceline (spot1, spot2, FALSE, self);
- if ((trace_inopen && trace_inwater))
- {
- return (FALSE);
- }
- }
- self.attack_state = AS_MELEE;
- return (TRUE);
- };
- float () W_BestBotWeapon =
- {
- local float it;
- local float rng;
- local float wlevel;
- it = self.items;
- rng = botrange (self.enemy);
- if ((rng != RANGE_MELEE))
- {
- if (((self.ammo_rockets >= TRUE) && (it & IT_ROCKET_LAUNCHER)))
- {
- return (IT_ROCKET_LAUNCHER);
- }
- }
- if (((self.ammo_cells >= TRUE) && (it & IT_LIGHTNING)))
- {
- if (((rng == RANGE_MELEE) || (rng == RANGE_NEAR)))
- {
- wlevel = CheckWaterLevel ();
- if ((wlevel < FL_SWIM))
- {
- return (IT_LIGHTNING);
- }
- if ((self.items & IT_INVULNERABILITY))
- {
- return (IT_LIGHTNING);
- }
- }
- }
- if (((self.ammo_nails >= FL_SWIM) && (it & IT_SUPER_NAILGUN)))
- {
- return (IT_SUPER_NAILGUN);
- }
- if ((rng == RANGE_NEAR))
- {
- if (((self.ammo_rockets >= TRUE) && (it & IT_GRENADE_LAUNCHER)))
- {
- if ((self.enemy.origin_z < (self.origin_z + 175)))
- {
- return (IT_GRENADE_LAUNCHER);
- }
- }
- }
- if (((rng == RANGE_NEAR) || (rng == RANGE_MELEE)))
- {
- if (((self.ammo_shells >= FL_SWIM) && (it & IT_SUPER_SHOTGUN)))
- {
- return (IT_SUPER_SHOTGUN);
- }
- }
- if (((self.ammo_nails >= TRUE) && (it & IT_NAILGUN)))
- {
- return (IT_NAILGUN);
- }
- if (((self.ammo_shells >= TRUE) && (it & IT_SHOTGUN)))
- {
- return (IT_SHOTGUN);
- }
- return (IT_AXE);
- };
- float () W_BestHeldWeapon =
- {
- local float it;
- local float wlevel;
- it = self.items;
- if (((self.ammo_rockets >= TRUE) && (it & IT_ROCKET_LAUNCHER)))
- {
- return (IT_ROCKET_LAUNCHER);
- }
- if (((self.ammo_cells >= TRUE) && (it & IT_LIGHTNING)))
- {
- wlevel = CheckWaterLevel ();
- if ((wlevel < FL_SWIM))
- {
- return (IT_LIGHTNING);
- }
- if ((self.items & IT_INVULNERABILITY))
- {
- return (IT_LIGHTNING);
- }
- }
- if (((self.ammo_nails >= FL_SWIM) && (it & IT_SUPER_NAILGUN)))
- {
- return (IT_SUPER_NAILGUN);
- }
- if (((self.ammo_rockets >= TRUE) && (it & IT_GRENADE_LAUNCHER)))
- {
- if ((self.enemy.origin_z < (self.origin_z + 175)))
- {
- return (IT_GRENADE_LAUNCHER);
- }
- }
- if (((self.ammo_shells >= FL_SWIM) && (it & IT_SUPER_SHOTGUN)))
- {
- return (IT_SUPER_SHOTGUN);
- }
- if (((self.ammo_nails >= TRUE) && (it & IT_NAILGUN)))
- {
- return (IT_NAILGUN);
- }
- if (((self.ammo_shells >= TRUE) && (it & IT_SHOTGUN)))
- {
- return (IT_SHOTGUN);
- }
- return (IT_AXE);
- };
- void () bot_axe1;
- void () bot_axeb1;
- void () bot_axec1;
- void () bot_axed1;
- void () bot_shot1;
- void () bot_nail1;
- void () bot_light1;
- void () bot_rocket1;
- void () W_BotAttack =
- {
- local float r;
- local float addt;
- if (!W_CheckNoAmmo ())
- {
- return;
- }
- if ((time < self.attack_finished))
- {
- return;
- }
- addt = FALSE;
- if ((self.skil < MOVETYPE_WALK))
- {
- addt = (((MOVETYPE_WALK - self.skil) * random ()) * 0.35);
- }
- if ((self.skil < TRUE))
- {
- addt = (addt + (random () * 0.3));
- }
- makevectors (self.v_angle);
- self.show_hostile = (time + TRUE);
- if ((self.weapon == IT_AXE))
- {
- sound (self, CHAN_WEAPON, "weapons/ax1.wav", TRUE, ATTN_NORM);
- r = random ();
- if ((r < 0.25))
- {
- bot_axe1 ();
- }
- else
- {
- if ((r < 0.5))
- {
- bot_axeb1 ();
- }
- else
- {
- if ((r < 0.75))
- {
- bot_axec1 ();
- }
- else
- {
- bot_axed1 ();
- }
- }
- }
- self.attack_finished = ((time + 0.5) + addt);
- }
- else
- {
- if ((self.weapon == IT_SHOTGUN))
- {
- bot_shot1 ();
- W_FireShotgun ();
- self.attack_finished = ((time + 0.5) + addt);
- }
- else
- {
- if ((self.weapon == IT_SUPER_SHOTGUN))
- {
- bot_shot1 ();
- W_FireSuperShotgun ();
- self.attack_finished = ((time + 0.7) + addt);
- }
- else
- {
- if ((self.weapon == IT_NAILGUN))
- {
- self.think = bot_nail1;
- }
- else
- {
- if ((self.weapon == IT_SUPER_NAILGUN))
- {
- self.think = bot_nail1;
- }
- else
- {
- if ((self.weapon == IT_GRENADE_LAUNCHER))
- {
- bot_rocket1 ();
- W_FireGrenade ();
- self.attack_finished = ((time + 0.6) + addt);
- }
- else
- {
- if ((self.weapon == IT_ROCKET_LAUNCHER))
- {
- bot_rocket1 ();
- W_FireRocket ();
- self.attack_finished = ((time + 0.8) + addt);
- }
- else
- {
- if ((self.weapon == IT_LIGHTNING))
- {
- self.think = bot_light1;
- self.attack_finished = (time + 0.1);
- sound (self, CHAN_AUTO, "weapons/lstart.wav", TRUE, ATTN_NORM);
- }
- }
- }
- }
- }
- }
- }
- }
- };
- void () bot_rebound1;
- float () CheckReboundAttack =
- {
- local vector spot1;
- local vector spot2;
- local vector dir;
- local float dist;
- local float mel;
- if ((self.skil < TRUE))
- {
- return (FALSE);
- }
- if ((self.attack_finished > time))
- {
- return (FALSE);
- }
- if (!(self.items & (IT_ROCKET_LAUNCHER + IT_GRENADE_LAUNCHER)))
- {
- return (FALSE);
- }
- if ((self.ammo_rockets < MOVETYPE_WALK))
- {
- return (FALSE);
- }
- spot1 = self.origin;
- spot2 = self.goalentity.origin;
- traceline (spot1, spot2, FALSE, self);
- if ((trace_fraction < TRUE))
- {
- return (FALSE);
- }
- dir = normalize ((self.goalentity.origin - self.origin));
- spot2 = (spot2 + (200 * dir));
- traceline (spot1, spot2, TRUE, self);
- if ((trace_fraction == TRUE))
- {
- if ((self.origin_z < self.goalentity.origin_z))
- {
- return (FALSE);
- }
- spot2 = self.goalentity.origin;
- spot2_z = (dropline (spot2) + MOVETYPE_WALK);
- traceline (spot1, spot2, TRUE, self);
- if ((trace_fraction != TRUE))
- {
- return (FALSE);
- }
- }
- else
- {
- spot2 = (self.goalentity.origin + ((200 * dir) * trace_fraction));
- }
- dist = vlen ((self.enemy.origin - spot2));
- mel = 200;
- if ((self.items & IT_QUAD))
- {
- mel = (FL_SWIM * mel);
- }
- if ((dist > mel))
- {
- return (FALSE);
- }
- dist = vlen ((self.origin - spot2));
- mel = ((280 - (self.health * 0.5)) - (self.armorvalue * self.armortype));
- if ((self.items & IT_QUAD))
- {
- mel = (FL_SWIM * mel);
- }
- if ((dist < mel))
- {
- return (FALSE);
- }
- REBOUNDSPOT = spot2;
- REBOUND = TRUE;
- self.ideal_yaw = vectoyaw ((spot2 - self.origin));
- ChangeYaw ();
- bot_rebound1 ();
- if ((self.items & IT_ROCKET_LAUNCHER))
- {
- W_FireRocket ();
- }
- else
- {
- REBOUNDSPOT = (spot2 + (random () * '12 12 12'));
- W_FireGrenade ();
- }
- self.attack_finished = (time + TRUE);
- if ((self.skil < FL_SWIM))
- {
- self.attack_finished = (time + 1.5);
- }
- REBOUND = FALSE;
- };
- void (entity e) clearCache;
- float () CheckWaterLevel =
- {
- local float pnt;
- if ((self.waterlevel < TRUE))
- {
- return (FALSE);
- }
- pnt = pointcontents ((self.origin + self.view_ofs));
- if ((pnt != CONTENT_EMPTY))
- {
- return (MOVETYPE_WALK);
- }
- pnt = pointcontents (self.origin);
- if ((pnt != CONTENT_EMPTY))
- {
- return (FL_SWIM);
- }
- return (TRUE);
- };
- void () BotWaterMove =
- {
- local float wlevel;
- local float wtype;
- local float pnt;
- local vector bt;
- wlevel = CheckWaterLevel ();
- if ((self.health < FALSE))
- {
- return;
- }
- if ((wlevel != MOVETYPE_WALK))
- {
- if ((self.air_finished < time))
- {
- sound (self, CHAN_VOICE, "player/gasp2.wav", TRUE, ATTN_NORM);
- }
- else
- {
- if ((self.air_finished < (time + MOVETYPE_FLYMISSILE)))
- {
- sound (self, CHAN_VOICE, "player/gasp1.wav", TRUE, ATTN_NORM);
- }
- }
- self.air_finished = (time + KINDA_WANT);
- self.dmg = FL_SWIM;
- }
- else
- {
- if ((self.air_finished < time))
- {
- if ((self.pain_finished < time))
- {
- self.dmg = (self.dmg + FL_SWIM);
- if ((self.dmg > 15))
- {
- self.dmg = MOVETYPE_BOUNCE;
- }
- T_Damage (self, world, world, self.dmg);
- self.pain_finished = (time + TRUE);
- }
- }
- }
- wtype = self.watertype;
- if ((wlevel < TRUE))
- {
- bt = ((self.absmin + self.absmax) * 0.5);
- bt_z = (self.absmin_z + TRUE);
- pnt = pointcontents (bt);
- if ((pnt != CONTENT_EMPTY))
- {
- wlevel = TRUE;
- wtype = pnt;
- }
- }
- if ((self.waterlevel < TRUE))
- {
- if ((self.flags & FL_INWATER))
- {
- sound (self, CHAN_BODY, "misc/outwater.wav", TRUE, ATTN_NORM);
- self.flags = (self.flags - FL_INWATER);
- }
- if ((self.flags & FL_SWIM))
- {
- self.flags = (self.flags - FL_SWIM);
- }
- if ((wlevel < TRUE))
- {
- return;
- }
- }
- if ((wtype == CONTENT_LAVA))
- {
- if ((self.dmgtime < time))
- {
- if ((self.radsuit_finished > time))
- {
- self.dmgtime = (time + TRUE);
- }
- else
- {
- self.dmgtime = (time + 0.2);
- }
- T_Damage (self, world, world, (MOVETYPE_BOUNCE * wlevel));
- }
- }
- else
- {
- if ((wtype == CONTENT_SLIME))
- {
- if (((self.dmgtime < time) && (self.radsuit_finished < time)))
- {
- self.dmgtime = (time + TRUE);
- T_Damage (self, world, world, (MOVETYPE_STEP * wlevel));
- }
- }
- }
- if ((self.waterlevel < TRUE))
- {
- return;
- }
- if (!(self.flags & FL_INWATER))
- {
- if ((self.watertype == CONTENT_LAVA))
- {
- sound (self, CHAN_BODY, "player/inlava.wav", TRUE, ATTN_NORM);
- }
- if ((self.watertype == CONTENT_WATER))
- {
- sound (self, CHAN_BODY, "player/inh2o.wav", TRUE, ATTN_NORM);
- }
- if ((self.watertype == CONTENT_SLIME))
- {
- sound (self, CHAN_BODY, "player/slimbrn2.wav", TRUE, ATTN_NORM);
- }
- self.flags = (self.flags + FL_INWATER);
- if (!(self.flags & FL_SWIM))
- {
- self.flags = (self.flags + FL_SWIM);
- }
- self.dmgtime = FALSE;
- }
- };
- void () BotCheckPowerups =
- {
- if ((self.health <= FALSE))
- {
- return;
- }
- if (self.invisible_finished)
- {
- if ((self.invisible_sound < time))
- {
- sound (self, CHAN_AUTO, "items/inv3.wav", 0.5, ATTN_IDLE);
- self.invisible_sound = (time + ((random () * MOVETYPE_WALK) + TRUE));
- }
- if ((self.invisible_finished < (time + MOVETYPE_WALK)))
- {
- if ((self.invisible_time == TRUE))
- {
- sound (self, CHAN_AUTO, "items/inv2.wav", TRUE, ATTN_NORM);
- self.invisible_time = (time + TRUE);
- }
- if ((self.invisible_time < time))
- {
- self.invisible_time = (time + TRUE);
- }
- }
- if ((self.invisible_finished < time))
- {
- self.items = (self.items - IT_INVISIBILITY);
- self.invisible_finished = FALSE;
- self.invisible_time = FALSE;
- }
- self.frame = FALSE;
- self.modelindex = modelindex_eyes;
- }
- else
- {
- self.modelindex = modelindex_player;
- }
- if (self.invincible_finished)
- {
- if ((self.invincible_finished < (time + MOVETYPE_WALK)))
- {
- if ((self.invincible_time == TRUE))
- {
- sound (self, CHAN_AUTO, "items/protect2.wav", TRUE, ATTN_NORM);
- self.invincible_time = (time + TRUE);
- }
- if ((self.invincible_time < time))
- {
- self.invincible_time = (time + TRUE);
- }
- }
- if ((self.invincible_finished < time))
- {
- self.items = (self.items - IT_INVULNERABILITY);
- self.invincible_time = FALSE;
- self.invincible_finished = FALSE;
- }
- if ((self.invincible_finished > time))
- {
- self.effects = (self.effects | EF_DIMLIGHT);
- }
- else
- {
- self.effects = (self.effects - (self.effects & EF_DIMLIGHT));
- }
- }
- if (self.super_damage_finished)
- {
- if ((self.super_damage_finished < (time + MOVETYPE_WALK)))
- {
- if ((self.super_time == TRUE))
- {
- sound (self, CHAN_AUTO, "items/damage2.wav", TRUE, ATTN_NORM);
- self.super_time = (time + TRUE);
- }
- if ((self.super_time < time))
- {
- self.super_time = (time + TRUE);
- }
- }
- if ((self.super_damage_finished < time))
- {
- self.items = (self.items - IT_QUAD);
- self.super_damage_finished = FALSE;
- self.super_time = FALSE;
- }
- if ((self.super_damage_finished > time))
- {
- self.effects = (self.effects | EF_DIMLIGHT);
- }
- else
- {
- self.effects = (self.effects - (self.effects & EF_DIMLIGHT));
- }
- }
- if (self.radsuit_finished)
- {
- self.air_finished = (time + 12);
- if ((self.radsuit_finished < (time + MOVETYPE_WALK)))
- {
- if ((self.rad_time == TRUE))
- {
- sound (self, CHAN_AUTO, "items/suit2.wav", TRUE, ATTN_NORM);
- self.rad_time = (time + TRUE);
- }
- if ((self.rad_time < time))
- {
- self.rad_time = (time + TRUE);
- }
- }
- if ((self.radsuit_finished < time))
- {
- self.items = (self.items - IT_SUIT);
- self.rad_time = FALSE;
- self.radsuit_finished = FALSE;
- }
- }
- };
- void () BotDead;
- void () BotPostThink =
- {
- local float fraglimit;
- if (self.pather)
- {
- if (CheckDropPath ())
- {
- DropBotPath ();
- }
- }
- self.movetarget.flags = self.flags;
- setorigin (self.movetarget, self.origin);
- if ((self.deadflag != DEAD_NO))
- {
- dprint ("Bot should be dead!\n");
- GibPlayer ();
- BotDead ();
- return;
- }
- BotCheckPowerups ();
- BotWaterMove ();
- fraglimit = cvar ("fraglimit");
- if ((fraglimit && (self.frags >= fraglimit)))
- {
- NextLevel ();
- self.button0 = TRUE;
- self.think = IntermissionThink;
- self.nextthink = (time + MOVETYPE_FLY);
- return;
- }
- };
- void () AddAnotherBot;
- void () initBotLevel =
- {
- local float num;
- local float offset;
- local float i;
- local entity e;
- local string tmp;
- NOISEQUEUE = noisetarget ();
- num = ((serverflags & BOTS) / FL_INWATER);
- serverflags = ((serverflags - (serverflags & BOTS)) - INITLEVEL);
- NUMBOTS = FALSE;
- NUMPATHS = FALSE;
- NUMPATHERS = FALSE;
- offset = TRUE;
- while ((num > FALSE))
- {
- num = (num - TRUE);
- if (((NUMBOTS < MOVETYPE_FLY) && !(serverflags & DEDICATED)))
- {
- skill = ((0.1 * (parm10 & (offset * SVC_FINALE))) / offset);
- }
- offset = (offset * FL_MONSTER);
- AddAnotherBot ();
- }
- if ((serverflags & TEAMFLAG))
- {
- if (!teamplay)
- {
- serverflags = (serverflags - TEAMFLAG);
- serverflags = (serverflags - (serverflags & TEAMBOTS));
- return;
- }
- }
- else
- {
- if (teamplay)
- {
- serverflags = (serverflags + TEAMFLAG);
- serverflags = (serverflags - (serverflags & TEAMBOTS));
- return;
- }
- }
- if (!teamplay)
- {
- return;
- }
- num = ((serverflags & TEAMBOTS) / FL_ITEM);
- if ((num == FALSE))
- {
- return;
- }
- e = find (world, classname, "player");
- while (e)
- {
- i = FALSE;
- offset = TRUE;
- while ((i < num))
- {
- i = (i + TRUE);
- if (((i < MOVETYPE_TOSS) && !(serverflags & DEDICATED)))
- {
- skill = ((0.1 * (parm11 & (offset * SVC_FINALE))) / offset);
- }
- offset = (offset * FL_MONSTER);
- addTeamBots (e, TRUE);
- }
- e = find (e, classname, "player");
- }
- if ((serverflags & DEDICATED))
- {
- serverflags = (serverflags - DEDICATED);
- }
- };
- void () setBotGravity =
- {
- local float newmax;
- local float vel;
- local float sk;
- local string tmp;
- GRAVITY = (cvar ("sv_gravity") * 0.1);
- dprint ("Gravity accel is ");
- tmp = ftos (GRAVITY);
- dprint (tmp);
- dprint ("\n");
- newmax = FALSE;
- vel = 270;
- MAXJUMP = CONTENT_EMPTY;
- while ((newmax > MAXJUMP))
- {
- vel = (vel - GRAVITY);
- MAXJUMP = newmax;
- newmax = (newmax + (vel * 0.1));
- }
- MAXJUMP = (MAXJUMP - TRUE);
- dprint ("Max jump height is ");
- tmp = ftos (MAXJUMP);
- dprint (tmp);
- dprint ("\n");
- LEVELJUMPTIME = FALSE;
- vel = 270;
- newmax = FALSE;
- while ((newmax > CONTENT_EMPTY))
- {
- LEVELJUMPTIME = (LEVELJUMPTIME + 0.1);
- vel = (vel - GRAVITY);
- newmax = (newmax + (vel * 0.1));
- }
- LEVELJUMPTIME = (LEVELJUMPTIME - (newmax / vel));
- dprint ("Level jump time is ");
- tmp = ftos (LEVELJUMPTIME);
- dprint (tmp);
- dprint ("\n");
- newmax = FALSE;
- vel = 200;
- GRENADEMAXHEIGHT = CONTENT_EMPTY;
- while ((newmax > GRENADEMAXHEIGHT))
- {
- vel = (vel - GRAVITY);
- GRENADEMAXHEIGHT = newmax;
- newmax = (newmax + (vel * 0.1));
- }
- dprint ("Max grenade height is ");
- tmp = ftos (GRENADEMAXHEIGHT);
- dprint (tmp);
- dprint ("\n");
- INVGRENADELEVELDIST = (((0.1 * FL_SWIM) * (200 - GRAVITY)) / GRAVITY);
- INVGRENADELEVELDIST = (TRUE / (INVGRENADELEVELDIST * SEARCH_RADIUS));
- dprint ("inverse grenade level distance is ");
- tmp = ftos (INVGRENADELEVELDIST);
- dprint (tmp);
- dprint ("\n");
- BOTSPEED = (cvar ("sv_maxspeed") / MOVETYPE_BOUNCE);
- };
- void () PutBotInServer;
- float () numplayers;
- float (entity e) totalscore;
- void () respawnBot =
- {
- local string m;
- local float n;
- local float o;
- local entity e;
- CopyToBodyQue (self);
- if (!teamplay)
- {
- if ((serverflags & TEAMBOTS))
- {
- n = (NUMBOTS + numplayers ());
- o = ((serverflags & TEAMBOTS) / FL_ITEM);
- if (((o < n) || (self.team != 99)))
- {
- self.nextthink = (time + TRUE);
- if ((self.team == 99))
- {
- NUMBOTS = (NUMBOTS - TRUE);
- }
- remove (self.movetarget);
- remove (self.goalentity);
- self.think = SUB_Remove;
- if (self.pather)
- {
- NUMPATHERS = (NUMPATHERS - TRUE);
- }
- if ((self.team != 99))
- {
- m = ": I'm going to find a team server.\n";
- }
- else
- {
- if ((totalscore (self) < FALSE))
- {
- m = ": I'm tired of getting fragged. I'm off\n";
- }
- else
- {
- if ((totalscore (self) > MUST_HAVE))
- {
- m = ": I'm going to find some real competition\n";
- }
- else
- {
- m = ": This server's too crowded. I'm off\n";
- }
- }
- }
- bprint (self.teamname);
- bprint (self.netname);
- bprint (m);
- bprint (self.teamname);
- bprint (self.netname);
- bprint (" left the game with ");
- m = ftos (self.frags);
- bprint (m);
- bprint (" frags\n");
- return;
- }
- }
- }
- else
- {
- if ((self.team != 99))
- {
- e = find (world, classname, "player");
- while (e)
- {
- if ((e.team == self.team))
- {
- PutBotInServer ();
- return;
- }
- e = find (e, classname, "player");
- }
- bprint (self.teamname);
- bprint (self.netname);
- bprint (": Going off to join my team\n");
- bprint (self.teamname);
- bprint (self.netname);
- bprint (" left the game with ");
- m = ftos (self.frags);
- bprint (m);
- bprint (" frags\n");
- return;
- }
- else
- {
- if ((SKINSMODE == FL_SWIM))
- {
- skinChange (self, 15);
- }
- }
- }
- PutBotInServer ();
- };
- void () bot_pain;
- void () BotDie;
- void () bot_stand1;
- void () bot_walk;
- void () bot_run;
- void () bot_start;
- void () dmbot_melee;
- entity () botmovetarget;
- void () PutBotInServer =
- {
- local entity spwn;
- local vector spot;
- local string tmp;
- local float aimvar;
- self.classname = "dmbot";
- self.health = MUST_HAVE;
- self.takedamage = DAMAGE_AIM;
- self.solid = SOLID_SLIDEBOX;
- self.movetype = MOVETYPE_STEP;
- self.show_hostile = FALSE;
- self.max_health = MUST_HAVE;
- self.air_finished = (time + SVC_INTERMISSION);
- self.dmg = TRUE;
- self.super_damage_finished = FALSE;
- self.radsuit_finished = FALSE;
- self.invisible_finished = FALSE;
- self.invincible_finished = FALSE;
- self.effects = FALSE;
- self.invincible_time = FALSE;
- self.yaw_speed = (45 + (25 * self.skil));
- self.lefty = STRAFE_DIR;
- if ((self.goalentity == world))
- {
- self.goalentity = botmovetarget ();
- }
- self.goalentity.goalentity = world;
- SetNewParms ();
- DecodeLevelParms ();
- W_SetCurrentAmmo ();
- self.search_time = time;
- self.attack_finished = time;
- self.th_pain = bot_pain;
- self.th_die = BotDie;
- self.th_stand = bot_stand1;
- self.th_walk = bot_walk;
- self.th_run = bot_run;
- self.th_melee = dmbot_melee;
- self.th_cache = cacheenemy;
- self.think = bot_start;
- self.nextthink = (time + 0.1);
- self.enemy = world;
- self.pathtype = NEVERTARGET;
- self.deadflag = DEAD_NO;
- self.pausetime = FALSE;
- spwn = SelectSpawnPoint ();
- spot = (spwn.origin + '0 0 1');
- self.origin = spot;
- setorigin (self, spot);
- self.angles = spwn.angles;
- self.fixangle = TRUE;
- setmodel (self, "progs/eyes.mdl");
- modelindex_eyes = self.modelindex;
- setmodel (self, "progs/player.mdl");
- modelindex_player = self.modelindex;
- setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
- if ((self.movetarget == world))
- {
- NewCarriedPath ();
- }
- else
- {
- setorigin (self.movetarget, self.origin);
- }
- self.movetarget.movetarget = world;
- clearCache (self);
- if (self.pather)
- {
- NUMPATHERS = (NUMPATHERS - TRUE);
- self.pather = FALSE;
- }
- if ((NUMPATHERS < MAXPATHERS))
- {
- self.pather = TRUE;
- NUMPATHERS = (NUMPATHERS + TRUE);
- }
- self.view_ofs = '0 0 22';
- makevectors (self.angles);
- spawn_tfog ((self.origin + (v_forward * KINDA_WANT)));
- spawn_tdeath (self.origin, self);
- if ((BOTSPEED < FL_MONSTER))
- {
- dprint ("Feeling kind of slow today (SV_MAXSPEED = ");
- tmp = ftos ((BOTSPEED * MOVETYPE_BOUNCE));
- dprint (tmp);
- dprint ("\n");
- }
- aimvar = cvar ("sv_aim");
- if ((aimvar != 0.93))
- {
- dprint ("Seems like sv_aim isn't 0.93\n");
- }
- };
- void () SpawnNewBot =
- {
- local string tmp;
- PutBotInServer ();
- bprint (self.teamname);
- bprint (self.netname);
- tmp = ftos (self.skil);
- bprint (" (skill ");
- bprint (tmp);
- bprint (") entered the game.\n");
- };
- entity () AddBot =
- {
- local entity newbot;
- local entity oldself;
- local string mycolor;
- local float plycolor;
- newbot = spawn ();
- oldself = self;
- self = newbot;
- self.think = SpawnNewBot;
- self.nextthink = (time + (12 * random ()));
- self.skil = skill;
- if ((self.skil < FALSE))
- {
- self.skil = FALSE;
- }
- else
- {
- if ((self.skil > MOVETYPE_WALK))
- {
- self.skil = MOVETYPE_WALK;
- }
- }
- initscore ();
- self = oldself;
- return (newbot);
- };
- float () numplayers =
- {
- local entity e;
- local float n;
- n = FALSE;
- e = find (world, classname, "player");
- while (e)
- {
- n = (n + TRUE);
- e = find (e, classname, "player");
- }
- return (n);
- };
- void () AddAnotherBot =
- {
- local entity newbot;
- local entity tmp;
- local float n;
- local string st;
- self.impulse = FALSE;
- if (!teamplay)
- {
- if ((serverflags & TEAMBOTS))
- {
- n = (NUMBOTS + numplayers ());
- if (((serverflags & TEAMBOTS) < n))
- {
- dprint ("Can't add bot - exceeds bound\n");
- return;
- }
- }
- }
- newbot = AddBot ();
- newbot.colormap = FALSE;
- if (teamplay)
- {
- skinChange (newbot, 15);
- }
- else
- {
- if ((SKINSMODE == TRUE))
- {
- skinChange (newbot, NUMBOTS);
- }
- else
- {
- if ((SKINSMODE == FL_SWIM))
- {
- st = ftos (((newbot.skil & MOVETYPE_WALK) + TRUE));
- dprint (st);
- dprint ("= skil skin\n");
- skinChange (newbot, ((newbot.skil & MOVETYPE_WALK) + TRUE));
- }
- }
- }
- newbot.team = 99;
- if (NAMEBOTS)
- {
- newbot.teamname = self.netname;
- }
- else
- {
- if ((newbot.skil < TRUE))
- {
- newbot.teamname = "Reaper0Bot";
- }
- else
- {
- if ((newbot.skil < FL_SWIM))
- {
- newbot.teamname = "Reaper1Bot";
- }
- else
- {
- if ((newbot.skil < MOVETYPE_WALK))
- {
- newbot.teamname = "Reaper2Bot";
- }
- else
- {
- newbot.teamname = "Reaper3Bot";
- }
- }
- }
- }
- NUMBOTS = (NUMBOTS + TRUE);
- if ((NUMBOTS == TRUE))
- {
- newbot.nextthink = (time + 0.1);
- }
- if ((NUMBOTS < FL_INWATER))
- {
- serverflags = ((serverflags - (serverflags & BOTS)) + (FL_INWATER * NUMBOTS));
- }
- if ((NUMBOTS == TRUE))
- {
- newbot.netname = "1";
- }
- else
- {
- if ((NUMBOTS == FL_SWIM))
- {
- newbot.netname = "2";
- }
- else
- {
- if ((NUMBOTS == MOVETYPE_WALK))
- {
- newbot.netname = "3";
- }
- else
- {
- if ((NUMBOTS == MOVETYPE_STEP))
- {
- newbot.netname = "4";
- }
- else
- {
- if ((NUMBOTS == MOVETYPE_FLY))
- {
- newbot.netname = "5";
- }
- else
- {
- if ((NUMBOTS == MOVETYPE_TOSS))
- {
- newbot.netname = "6";
- }
- else
- {
- if ((NUMBOTS == MOVETYPE_PUSH))
- {
- newbot.netname = "7";
- }
- else
- {
- if ((NUMBOTS == FL_CLIENT))
- {
- newbot.netname = "8";
- }
- else
- {
- if ((NUMBOTS == MOVETYPE_FLYMISSILE))
- {
- newbot.netname = "9";
- }
- else
- {
- if ((NUMBOTS == MOVETYPE_BOUNCE))
- {
- newbot.netname = "10";
- }
- else
- {
- if ((NUMBOTS == MOVETYPE_BOUNCEMISSILE))
- {
- newbot.netname = "11";
- }
- else
- {
- if ((NUMBOTS == 12))
- {
- newbot.netname = "12";
- }
- else
- {
- if ((NUMBOTS == 13))
- {
- newbot.netname = "13";
- }
- else
- {
- if ((NUMBOTS == 14))
- {
- newbot.netname = "14";
- }
- else
- {
- if ((NUMBOTS == 15))
- {
- newbot.netname = "15";
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- };
- void (entity ply, float n) addTeamBots =
- {
- local entity newbot;
- local entity tmp;
- local float i;
- i = n;
- while ((i > FALSE))
- {
- newbot = AddBot ();
- newbot.colormap = ply.colormap;
- newbot.team = ply.team;
- newbot.teamname = ply.netname;
- skinChange (newbot, ply.skin);
- if ((newbot.skil < TRUE))
- {
- newbot.netname = "0Bot";
- }
- else
- {
- if ((newbot.skil < FL_SWIM))
- {
- newbot.netname = "1Bot";
- }
- else
- {
- if ((newbot.skil < MOVETYPE_WALK))
- {
- newbot.netname = "2Bot";
- }
- else
- {
- newbot.netname = "3Bot";
- }
- }
- }
- i = (i - TRUE);
- }
- };
- void (entity ply, float n) removeTeamBots =
- {
- local float i;
- local entity e;
- i = n;
- e = find (world, classname, "dmbot");
- while ((i > FALSE))
- {
- while (((e != world) && (e.team != ply.team)))
- {
- e = find (e, classname, "dmbot");
- }
- if (!e)
- {
- return;
- }
- if (e.pather)
- {
- NUMPATHERS = (NUMPATHERS - TRUE);
- }
- remove (e.movetarget);
- remove (e.goalentity);
- remove (e);
- i = (i - TRUE);
- }
- };
- void () removeAllBots =
- {
- local entity e;
- e = find (world, classname, "dmbot");
- while (e)
- {
- if (!e)
- {
- return;
- }
- if (e.pather)
- {
- NUMPATHERS = (NUMPATHERS - TRUE);
- }
- remove (e.movetarget);
- remove (e.goalentity);
- remove (e);
- e = find (e, classname, "dmbot");
- }
- NUMBOTS = FALSE;
- dprint ("All bots removed.\n");
- };
- void (float n) SetMaxBots =
- {
- local float t;
- local string tmp;
- self.impulse = FALSE;
- if ((serverflags & TEAMFLAG))
- {
- dprint ("Entering bounded deathmatch mode\n");
- serverflags = ((serverflags - TEAMFLAG) - (serverflags & TEAMBOTS));
- }
- dprint ("Max bots + players set to ");
- tmp = ftos (n);
- dprint (tmp);
- dprint ("\n");
- serverflags = ((serverflags - (serverflags & TEAMBOTS)) + (n * FL_ITEM));
- t = numplayers ();
- while (((NUMBOTS + t) < n))
- {
- AddAnotherBot ();
- }
- };
- void (float n) SetTeamBots =
- {
- local float t;
- local entity e;
- local string tmp;
- self.impulse = FALSE;
- if (!(serverflags & TEAMFLAG))
- {
- dprint ("Entering bot team mode\n");
- serverflags = ((serverflags + TEAMFLAG) - (serverflags & TEAMBOTS));
- }
- dprint ("Bots per player team set to ");
- tmp = ftos (n);
- dprint (tmp);
- dprint ("\n");
- t = ((serverflags & TEAMBOTS) / FL_ITEM);
- serverflags = ((serverflags - (serverflags & TEAMBOTS)) + (n * FL_ITEM));
- if ((t < n))
- {
- e = find (world, classname, "player");
- t = (n - t);
- while (e)
- {
- addTeamBots (e, t);
- e = find (e, classname, "player");
- }
- return;
- }
- if ((t > n))
- {
- e = find (world, classname, "player");
- while (e)
- {
- t = (t - n);
- removeTeamBots (e, t);
- e = find (e, classname, "player");
- }
- return;
- }
- };
- void () UpdateTeamColors =
- {
- local entity e;
- e = find (world, classname, "dmbot");
- while (e)
- {
- if ((e.colormap == self.colormap))
- {
- e.team = self.team;
- }
- e = find (e, classname, "dmbot");
- }
- };
- void () t_botmovetarget;
- entity (entity chaser, entity en) BestChaseRoute;
- entity () botmovetarget =
- {
- local entity targ;
- targ = spawn ();
- targ.classname = "BotTarget";
- targ.solid = SOLID_TRIGGER;
- targ.movetarget = world;
- targ.touch = t_botmovetarget;
- setsize (targ, '-4 -4 0', '4 4 8');
- return (targ);
- };
- void () t_botmovetarget =
- {
- local vector in;
- local entity tmp;
- local entity pth;
- local float rnd;
- if ((other.goalentity != self))
- {
- return;
- }
- if ((self.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_touch! 1\n");
- }
- if ((self.goalentity.classname != "player"))
- {
- if (VERBOSEBOT)
- {
- dprint (other.teamname);
- dprint (other.netname);
- dprint (" got to ");
- dprint (self.goalentity.classname);
- dprint ("\n");
- }
- other.lefty = (other.lefty - (other.lefty & LOCAL_TIME));
- if ((self.goalentity.classname == "door"))
- {
- if ((self.goalentity.use == fd_secret_use))
- {
- return;
- }
- }
- if ((self.goalentity.classname == "train"))
- {
- if (!(other.lefty & ONTRAIN))
- {
- other.lefty = (other.lefty | ONTRAIN);
- other.search_time = (time + TRUE);
- }
- return;
- }
- if ((self.goalentity.classname != "func_button"))
- {
- if ((other.lefty & GETGOODY))
- {
- other.goody_time = time;
- }
- else
- {
- other.search_time = time;
- }
- return;
- }
- tmp = self;
- self = self.goalentity;
- button_touch ();
- self = tmp;
- clearCache (other);
- other.search_time = (time + MOVETYPE_WALK);
- other.nextthink = (time + 0.3);
- return;
- }
- if (VERBOSEBOT)
- {
- dprint (other.teamname);
- dprint (other.netname);
- dprint ("tracking ");
- dprint (self.goalentity.teamname);
- dprint (self.goalentity.netname);
- dprint ("\n");
- }
- pth = BestChaseRoute (other, self.goalentity);
- rnd = ((2000 + (random () * 1000)) + (other.skil * SEARCH_RADIUS));
- rnd = (rnd - vlen ((other.origin - pth.origin)));
- if ((rnd < pth.enemylen))
- {
- other.search_time = (time - TRUE);
- return;
- }
- random ();
- rnd = (random () * (other.skil + TRUE));
- if ((rnd < 0.1))
- {
- other.search_time = (time - TRUE);
- return;
- }
- if ((self.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_touch! 2\n");
- }
- setorigin (self, pth.origin);
- other.search_time = (time + MOVETYPE_STEP);
- };
- void () bot_toucheditem =
- {
- if ((other.goalentity.goalentity == self))
- {
- if (VERBOSEBOT)
- {
- dprint (other.teamname);
- dprint (other.netname);
- dprint (" got to ");
- dprint (self.classname);
- dprint ("\n");
- }
- other.lefty = (other.lefty - (other.lefty & LOCAL_TIME));
- other.search_time = (time - TRUE);
- }
- };
- void (entity bot) bot_triggered =
- {
- local vector org;
- local entity Botgoal;
- Botgoal = bot.goalentity;
- if ((Botgoal.goalentity != self))
- {
- return;
- }
- Botgoal.goalentity = find (world, targetname, self.target);
- if ((Botgoal.goalentity.classname == "light"))
- {
- bot.search_time = time;
- return;
- }
- if (Botgoal.goalentity)
- {
- bot.search_time = (time + MOVETYPE_WALK);
- org = ((Botgoal.goalentity.absmax + Botgoal.goalentity.absmin) * 0.5);
- org_z = (Botgoal.goalentity.absmin_z + TRUE);
- if ((Botgoal.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_touch! 3\n");
- }
- setorigin (Botgoal, org);
- Botgoal.goalentity.lastbot = bot;
- Botgoal.goalentity.lasttime = time;
- if (VERBOSEBOT)
- {
- dprint ("now Bot will go after the triggered ");
- dprint (Botgoal.goalentity.classname);
- dprint ("\n");
- }
- }
- };
- void () aibot_setupchase;
- void () bot_touched =
- {
- local entity tmp;
- tmp = self;
- self = other.goalentity;
- if ((self.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_touch! 4\n");
- }
- if ((self.goalentity == tmp))
- {
- t_botmovetarget ();
- }
- else
- {
- if ((self.goalentity.classname == "door"))
- {
- if ((tmp.classname == "door"))
- {
- t_botmovetarget ();
- }
- }
- }
- self = tmp;
- };
- void () enemy_touched =
- {
- local entity tmp;
- local vector org;
- if (VERBOSEBOT)
- {
- dprint (other.enemy.teamname);
- dprint (other.enemy.netname);
- dprint (" chasing ");
- dprint (other.teamname);
- dprint (other.netname);
- dprint (" through ");
- dprint (self.classname);
- dprint ("!\n");
- }
- org = ((self.absmax + self.absmin) * 0.5);
- org_z = (self.absmin_z + TRUE);
- if ((self.classname == "door"))
- {
- org = other.origin;
- }
- tmp = self;
- self = other.enemy;
- if ((self.enemy != other))
- {
- self = tmp;
- return;
- }
- if ((tmp.classname == "trigger_push"))
- {
- endEnemy ();
- self.search_time = (time + MOVETYPE_STEP);
- if ((self.goalentity.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_touch! 5\n");
- }
- setorigin (self.goalentity, org);
- self = tmp;
- return;
- }
- if ((self.goalentity.classname != "BotTarget"))
- {
- objerror ("ERROR - bad bot target!\n");
- }
- setorigin (self.goalentity, org);
- self.goalentity.goalentity = self.enemy;
- self.search_time = (time + MOVETYPE_STEP);
- if ((self.lefty & GETGOODY))
- {
- self.lefty = (self.lefty - GETGOODY);
- }
- aibot_setupchase ();
- self = tmp;
- };
- void () halfwalkmove =
- {
- walkmove (self.strafeyaw, self.strafedist);
- self.think = self.strafethink;
- self.nextthink = (time + 0.05);
- };
- float (float s_yaw, float s_dist) botwalkmove =
- {
- local float halfdist;
- self.oldorigin = self.origin;
- if ((self.skil > FL_SWIM))
- {
- halfdist = (0.55 * s_dist);
- }
- else
- {
- halfdist = (0.5 * s_dist);
- }
- if (!walkmove (s_yaw, halfdist))
- {
- return (FALSE);
- }
- self.strafethink = self.think;
- self.strafeyaw = s_yaw;
- self.strafedist = halfdist;
- self.think = halfwalkmove;
- self.nextthink = (time + 0.05);
- return (TRUE);
- };
- float (float dist) teleptest =
- {
- local vector start;
- local vector up;
- up = self.origin;
- start = self.origin;
- if ((dist < FALSE))
- {
- up_z = ((self.absmin_z + dist) - TRUE);
- }
- else
- {
- up_z = ((self.absmax_z + dist) + TRUE);
- }
- traceline (start, up, FALSE, self);
- if ((trace_fraction < TRUE))
- {
- return (FALSE);
- }
- start_x = (start_x + FL_INWATER);
- start_y = (start_y + FL_INWATER);
- up_x = (up_x + FL_INWATER);
- up_y = (up_y + FL_INWATER);
- traceline (start, up, FALSE, self);
- if ((trace_fraction < TRUE))
- {
- return (FALSE);
- }
- start_x = (start_x - FL_MONSTER);
- up_x = (up_x - FL_MONSTER);
- traceline (start, up, FALSE, self);
- if ((trace_fraction < TRUE))
- {
- return (FALSE);
- }
- start_y = (start_y - FL_MONSTER);
- up_y = (up_y - FL_MONSTER);
- traceline (start, up, FALSE, self);
- if ((trace_fraction < TRUE))
- {
- return (FALSE);
- }
- start_x = (start_x + FL_MONSTER);
- up_x = (up_x + FL_MONSTER);
- traceline (start, up, FALSE, self);
- if ((trace_fraction < TRUE))
- {
- return (FALSE);
- }
- start = self.origin;
- start_z = up_z;
- up = start;
- start_x = (start_x + FL_INWATER);
- up_x = (up_x - FL_INWATER);
- traceline (start, up, FALSE, self);
- if ((trace_fraction < TRUE))
- {
- return (FALSE);
- }
- start = self.origin;
- start_z = up_z;
- up = start;
- start_y = (start_y + FL_INWATER);
- up_y = (up_y - FL_INWATER);
- traceline (start, up, FALSE, self);
- if ((trace_fraction < TRUE))
- {
- return (FALSE);
- }
- return (TRUE);
- };
- float (float dist) waterupz =
- {
- local vector start;
- local vector up;
- if (!teleptest (dist))
- {
- return (FALSE);
- }
- up = self.origin;
- up_z = (up_z + dist);
- setorigin (self, up);
- return (TRUE);
- };
- float (float dist) waterdownz =
- {
- local vector up;
- local vector start;
- if (!teleptest ((CONTENT_EMPTY * dist)))
- {
- return (FALSE);
- }
- up = self.origin;
- up_z = (up_z - dist);
- setorigin (self, up);
- return (TRUE);
- };
- float (vector jmpv) Botjump =
- {
- if ((self.flags & FL_ONGROUND))
- {
- self.flags = (self.flags - FL_ONGROUND);
- }
- self.velocity = jmpv;
- return (TRUE);
- };
- float (vector jmpv) Botwaterjump =
- {
- if ((self.flags & FL_ONGROUND))
- {
- self.flags = (self.flags - FL_ONGROUND);
- }
- if (!waterupz (45))
- {
- return (FALSE);
- }
- jmpv_z = 200;
- self.velocity = jmpv;
- if ((self.flags & FL_SWIM))
- {
- self.flags = (self.flags - FL_SWIM);
- }
- if ((self.flags & FL_INWATER))
- {
- self.flags = (self.flags - FL_INWATER);
- }
- self.teleport_time = (time + 0.7);
- return (TRUE);
- };
- float (entity targ) Swimto;
- float (vector spot) CheckLavaOrLow =
- {
- local float lnd;
- local float boost;
- local vector spot2;
- lnd = pointcontents (spot);
- if (((lnd == CONTENT_LAVA) || (lnd == CONTENT_SLIME)))
- {
- return (TRUE);
- }
- spot2 = spot;
- spot2_z = (spot_z + FL_CLIENT);
- lnd = pointcontents (spot2);
- if (((lnd == CONTENT_LAVA) || (lnd == CONTENT_SLIME)))
- {
- return (TRUE);
- }
- if ((lnd != CONTENT_WATER))
- {
- boost = (MAXJUMP + TRUE);
- if ((self.goalentity.goalentity.classname == "func_button"))
- {
- boost = ((boost + self.maxs_z) - TRUE);
- }
- if (((spot_z + boost) < self.goalentity.origin_z))
- {
- return (TRUE);
- }
- }
- else
- {
- traceline (spot2, self.goalentity.absmin, TRUE, self);
- if (trace_inopen)
- {
- if (((spot_z + 45) > self.goalentity.origin_z))
- {
- return (FALSE);
- }
- return (TRUE);
- }
- if ((trace_fraction == TRUE))
- {
- return (FALSE);
- }
- return (TRUE);
- }
- return (FALSE);
- };
- float (vector middle) checkLanding =
- {
- local float goodcnt;
- local vector spot;
- local vector center;
- center = middle;
- spot = middle;
- spot_x = (spot_x + MOVETYPE_TOSS);
- if ((pointcontents (spot) == CONTENT_SOLID))
- {
- center_x = (center_x - MOVETYPE_TOSS);
- }
- spot_x = (spot_x - 12);
- if ((pointcontents (spot) == CONTENT_SOLID))
- {
- center_x = (center_x + MOVETYPE_TOSS);
- }
- spot = middle;
- spot_y = (spot_y + MOVETYPE_TOSS);
- if ((pointcontents (spot) == CONTENT_SOLID))
- {
- center_y = (center_y - MOVETYPE_TOSS);
- }
- spot_y = (spot_y - 12);
- if ((pointcontents (spot) == CONTENT_SOLID))
- {
- center_y = (center_y + MOVETYPE_TOSS);
- }
- spot = center;
- spot_z = dropline (spot);
- goodcnt = MOVETYPE_FLY;
- if (CheckLavaOrLow (spot))
- {
- return (FALSE);
- }
- spot = center;
- spot_x = (spot_x + MOVETYPE_TOSS);
- spot_z = dropline (spot);
- if (CheckLavaOrLow (spot))
- {
- goodcnt = (goodcnt - TRUE);
- }
- spot = center;
- spot_x = (spot_x - MOVETYPE_TOSS);
- spot_z = dropline (spot);
- if (CheckLavaOrLow (spot))
- {
- goodcnt = (goodcnt - TRUE);
- }
- spot = center;
- spot_y = (spot_y + MOVETYPE_TOSS);
- spot_z = dropline (spot);
- if (CheckLavaOrLow (spot))
- {
- goodcnt = (goodcnt - TRUE);
- }
- spot = center;
- spot_y = (spot_y - MOVETYPE_TOSS);
- spot_z = dropline (spot);
- if (CheckLavaOrLow (spot))
- {
- goodcnt = (goodcnt - TRUE);
- }
- if ((goodcnt > MOVETYPE_WALK))
- {
- return (TRUE);
- }
- return (FALSE);
- };
- float (float dist) JumpUpToPush =
- {
- local float len;
- local vector botxy;
- local vector goalxy;
- local vector xydir;
- local vector jumpv;
- botxy = self.origin;
- botxy_z = FALSE;
- goalxy = self.goalentity.origin;
- goalxy_z = FALSE;
- xydir = normalize ((goalxy - botxy));
- len = vlen ((goalxy - botxy));
- if ((len < 25))
- {
- jumpv = (xydir * KINDA_WANT);
- jumpv_z = 270;
- Botjump (jumpv);
- return (TRUE);
- }
- if ((len < 80))
- {
- jumpv = (xydir * (len / LEVELJUMPTIME));
- jumpv_z = 270;
- Botjump (jumpv);
- return (TRUE);
- }
- return (FALSE);
- };
- float (float vz, float dist, float imagine) Bot_tryjump =
- {
- local float timetofloor;
- local float tvel;
- local float dis;
- local float diffz;
- local float diffxy;
- local float NOTLAND;
- local float lnd;
- local float len;
- local float depth;
- local float wlevel;
- local float velz;
- local float ht;
- local float frac;
- local vector botxy;
- local vector goalxy;
- local vector xydir;
- local vector top;
- local vector bottom;
- local vector jumpv;
- local vector newtop;
- local vector newbottom;
- local vector back;
- local vector front;
- local vector dir;
- local vector start;
- local string tmp;
- local entity botTarget;
- if (!(self.flags & (FL_ONGROUND + FL_SWIM)))
- {
- return (FALSE);
- }
- wlevel = CheckWaterLevel ();
- if ((wlevel > FL_SWIM))
- {
- return (FALSE);
- }
- if (!FacingIdeal ())
- {
- ChangeYaw ();
- if (!FacingIdeal ())
- {
- ChangeYaw ();
- if (!FacingIdeal ())
- {
- ChangeYaw ();
- }
- }
- }
- makevectors (self.angles);
- start = (self.origin + (FL_INWATER * v_forward));
- botTarget = self.goalentity;
- velz = vz;
- if ((wlevel >= TRUE))
- {
- if ((velz > 200))
- {
- velz = 200;
- }
- }
- if ((wlevel == FL_SWIM))
- {
- if ((botTarget.origin_z < self.origin_z))
- {
- return (FALSE);
- }
- start_z = (start_z + 45);
- }
- botxy = self.origin;
- botxy_z = FALSE;
- diffz = ((start_z - botTarget.origin_z) + TRUE);
- if ((diffz < (CONTENT_EMPTY * MAXJUMP)))
- {
- if ((botTarget.goalentity.classname != "trigger_push"))
- {
- return (FALSE);
- }
- else
- {
- if ((diffz < FALSE))
- {
- if (JumpUpToPush (dist))
- {
- return (TRUE);
- }
- }
- }
- }
- dis = dist;
- goalxy = botTarget.origin;
- if ((botTarget.goalentity.classname == "train"))
- {
- goalxy = (goalxy + (LEVELJUMPTIME * botTarget.goalentity.velocity));
- }
- lnd = pointcontents (goalxy);
- if (((lnd == CONTENT_LAVA) || (lnd == CONTENT_SLIME)))
- {
- return (FALSE);
- }
- goalxy_z = FALSE;
- xydir = normalize ((goalxy - botxy));
- diffxy = vlen ((goalxy - botxy));
- if ((wlevel == FL_SWIM))
- {
- if ((diffxy > (MOVETYPE_WALK * BOTSPEED)))
- {
- diffxy = (MOVETYPE_WALK * BOTSPEED);
- }
- }
- bottom = (start + self.view_ofs);
- top = (bottom + (xydir * dis));
- top_z = (top_z + (0.1 * (velz - GRAVITY)));
- traceline (bottom, top, TRUE, self);
- if ((trace_fraction != TRUE))
- {
- if ((velz > (GRAVITY + 180)))
- {
- return (Bot_tryjump ((velz - GRAVITY), dist, imagine));
- }
- else
- {
- return (FALSE);
- }
- }
- bottom = (start - (FL_INWATER * v_forward));
- bottom_z = (bottom_z + self.mins_z);
- top = (bottom + ((xydir * dis) * FL_SWIM));
- top_z = ((top_z + (0.2 * (velz - GRAVITY))) - (0.1 * GRAVITY));
- traceline (bottom, top, TRUE, self);
- if ((trace_fraction != TRUE))
- {
- if ((diffxy > (1.9 * BOTSPEED)))
- {
- diffxy = (1.9 * BOTSPEED);
- }
- top = (bottom + (xydir * dis));
- top_z = ((top_z + (0.2 * (velz - GRAVITY))) - (0.1 * GRAVITY));
- traceline (bottom, top, TRUE, self);
- if ((trace_fraction != TRUE))
- {
- if ((diffxy > (0.9 * BOTSPEED)))
- {
- diffxy = (0.9 * BOTSPEED);
- }
- velz = 290;
- }
- }
- timetofloor = FALSE;
- tvel = velz;
- if ((diffz < FALSE))
- {
- timetofloor = 0.3;
- }
- else
- {
- while ((diffz > FALSE))
- {
- timetofloor = (timetofloor + 0.1);
- tvel = (tvel - GRAVITY);
- diffz = (diffz + (tvel * 0.1));
- }
- timetofloor = (timetofloor - (diffz / tvel));
- }
- if ((diffxy < ((dis * MOVETYPE_BOUNCE) * timetofloor)))
- {
- jumpv = (xydir * (diffxy / timetofloor));
- }
- else
- {
- jumpv = (xydir * (MOVETYPE_BOUNCE * dis));
- if (imagine)
- {
- return (FALSE);
- }
- }
- tvel = velz;
- bottom = start;
- bottom_z = (bottom_z + self.mins_z);
- ht = (self.view_ofs_z - self.mins_z);
- NOTLAND = TRUE;
- while (NOTLAND)
- {
- tvel = (tvel - GRAVITY);
- newbottom = (bottom + (jumpv * 0.1));
- newbottom_z = (newbottom_z + (tvel * 0.1));
- traceline (bottom, newbottom, TRUE, self);
- frac = trace_fraction;
- if ((trace_fraction == TRUE))
- {
- newtop = newbottom;
- top = bottom;
- top_z = (top_z + ht);
- newtop_z = (newtop_z + ht);
- traceline (top, newtop, TRUE, self);
- if ((trace_fraction == TRUE))
- {
- traceline (newbottom, newtop, TRUE, self);
- }
- if ((trace_fraction == TRUE))
- {
- top = (top + (FL_INWATER * v_right));
- newtop = (newtop + (FL_INWATER * v_right));
- traceline (top, newtop, TRUE, self);
- }
- if ((trace_fraction == TRUE))
- {
- top = (top - (FL_MONSTER * v_right));
- newtop = (newtop - (FL_MONSTER * v_right));
- traceline (top, newtop, TRUE, self);
- }
- if ((trace_fraction != TRUE))
- {
- frac = 0.1;
- }
- }
- if ((trace_fraction != TRUE))
- {
- dir = normalize ((newbottom - bottom));
- len = vlen ((newbottom - bottom));
- newbottom = (bottom + ((dir * len) * frac));
- newbottom_z = (newbottom_z + KINDA_WANT);
- if (!checkLanding ((newbottom - (FL_INWATER * v_forward))))
- {
- return (FALSE);
- }
- NOTLAND = FALSE;
- }
- if (NOTLAND)
- {
- if (CheckLavaOrLow (newbottom))
- {
- return (FALSE);
- }
- }
- lnd = pointcontents (newbottom);
- if ((lnd == CONTENT_WATER))
- {
- NOTLAND = FALSE;
- }
- bottom = newbottom;
- }
- jumpv_z = velz;
- if (imagine)
- {
- if ((wlevel == FL_SWIM))
- {
- return (teleptest (45));
- }
- return (TRUE);
- }
- if ((wlevel == FL_SWIM))
- {
- return (Botwaterjump (jumpv));
- }
- if ((newbottom_z < (self.absmin_z - MAXJUMP)))
- {
- clearCache (self);
- }
- return (Botjump (jumpv));
- };
- float (float dist) waterupdown =
- {
- local float wlevel;
- local float dis;
- local float rnd;
- local float zbottom;
- dis = KINDA_WANT;
- wlevel = CheckWaterLevel ();
- if ((wlevel < FL_SWIM))
- {
- return (FALSE);
- }
- if ((self.absmin_z > self.goalentity.origin_z))
- {
- if ((dis > KINDA_WANT))
- {
- dis = KINDA_WANT;
- }
- if (waterdownz (dis))
- {
- return (TRUE);
- }
- if (waterdownz ((dis * 0.5)))
- {
- return (TRUE);
- }
- if (waterdownz ((dis * 0.2)))
- {
- return (TRUE);
- }
- }
- if ((wlevel == MOVETYPE_WALK))
- {
- if ((self.absmin_z < self.goalentity.origin_z))
- {
- dis = (self.goalentity.origin_z - self.absmin_z);
- if ((dis > KINDA_WANT))
- {
- dis = KINDA_WANT;
- }
- if (waterupz (dis))
- {
- return (TRUE);
- }
- if (waterupz ((dis * 0.5)))
- {
- return (TRUE);
- }
- if (waterupz ((dis * 0.2)))
- {
- return (TRUE);
- }
- }
- }
- return (FALSE);
- };
- void (float dist) strafemove =
- {
- local float ofs;
- local float rnd;
- if ((self.flags & FL_SWIM))
- {
- if (waterupdown (dist))
- {
- return;
- }
- }
- ofs = 90;
- rnd = random ();
- if (self.enemy)
- {
- self.strafeonly = MOVETYPE_FLY;
- if ((self.lefty & STRAFE_DIR))
- {
- ofs = (CONTENT_EMPTY * ofs);
- }
- }
- else
- {
- if ((rnd < 0.5))
- {
- ofs = (CONTENT_EMPTY * ofs);
- }
- }
- if (walkmove ((self.ideal_yaw + ofs), dist))
- {
- return;
- }
- if (self.enemy)
- {
- return;
- }
- ofs = (CONTENT_EMPTY * ofs);
- if (walkmove ((self.ideal_yaw + ofs), dist))
- {
- return;
- }
- if ((self.flags & (FL_INWATER + FL_ONGROUND)))
- {
- self.search_time = (self.search_time - 0.3);
- }
- };
- void (float dist, float wlevel) BotUnderwaterMove =
- {
- local float rng;
- local float oldrng;
- local float rnd;
- rnd = random ();
- if ((rnd < 0.75))
- {
- oldrng = vlen ((self.origin - self.goalentity.origin));
- movetogoal (dist);
- rng = vlen ((self.origin - self.goalentity.origin));
- if ((oldrng > rng))
- {
- return;
- }
- if ((wlevel == FL_SWIM))
- {
- if (Bot_tryjump (200, dist, FALSE))
- {
- return;
- }
- }
- }
- strafemove (dist);
- };
- float (float dist) trysidestep =
- {
- local vector dir;
- local vector start;
- dir = (self.goalentity.origin - self.origin);
- dir_z = FALSE;
- dir = normalize (dir);
- start = self.origin;
- start_z = (self.origin_z + (self.view_ofs_z * 0.5));
- traceline (start, (start + (BOTSPEED * dir)), FALSE, self);
- if ((trace_fraction != TRUE))
- {
- strafemove ((dist * 0.6));
- return (TRUE);
- }
- makevectors (self.angles);
- start = (start + (v_right * 15));
- traceline (start, (start + (BOTSPEED * dir)), FALSE, self);
- if ((trace_fraction != TRUE))
- {
- if (walkmove ((self.ideal_yaw - 90), (dist * 0.6)))
- {
- return (TRUE);
- }
- }
- start = (start - (v_right * SVC_INTERMISSION));
- traceline (start, (start + (BOTSPEED * dir)), FALSE, self);
- if ((trace_fraction != TRUE))
- {
- if (walkmove ((self.ideal_yaw + 90), (dist * 0.6)))
- {
- return (TRUE);
- }
- }
- return (FALSE);
- };
- float (float dist) testmove =
- {
- local float rng;
- local float oldrng;
- oldrng = vlen ((self.origin - self.goalentity.origin));
- movetogoal (dist);
- rng = vlen ((self.origin - self.goalentity.origin));
- if ((rng < oldrng))
- {
- return (TRUE);
- }
- return (FALSE);
- };
- void (float dist) BotmovetoWindTunnel =
- {
- if (testmove (dist))
- {
- return;
- }
- if (trysidestep (dist))
- {
- return;
- }
- if (Bot_tryjump (270, dist, FALSE))
- {
- return;
- }
- strafemove ((dist * 0.5));
- return;
- };
- void (float dist) BotmovetoVisiblegoal =
- {
- if (walkmove (self.ideal_yaw, FL_CLIENT))
- {
- botwalkmove (self.ideal_yaw, (dist - FL_CLIENT));
- return;
- }
- if (walkmove ((self.ideal_yaw + 45), FL_CLIENT))
- {
- movetogoal ((dist - FL_CLIENT));
- return;
- }
- if (walkmove ((self.ideal_yaw - 45), FL_CLIENT))
- {
- movetogoal ((dist - FL_CLIENT));
- return;
- }
- if (trysidestep (dist))
- {
- return;
- }
- if (Bot_tryjump (270, dist, FALSE))
- {
- return;
- }
- strafemove ((dist * 0.5));
- return;
- };
- void (float dist) Botmovetogoal =
- {
- local entity Botgoal;
- local float wlevel;
- self.oldorigin = self.origin;
- Botgoal = self.goalentity;
- self.ideal_yaw = vectoyaw ((Botgoal.origin - self.origin));
- ChangeYaw ();
- if ((self.flags & FL_INWATER))
- {
- wlevel = CheckWaterLevel ();
- if ((wlevel > TRUE))
- {
- BotUnderwaterMove ((dist * 0.8), wlevel);
- return;
- }
- }
- if ((Botgoal.goalentity.classname == "trigger_push"))
- {
- BotmovetoWindTunnel (dist);
- return;
- }
- if (Spotvisible (Botgoal))
- {
- BotmovetoVisiblegoal (dist);
- return;
- }
- if (testmove (dist))
- {
- return;
- }
- strafemove ((dist * 0.8));
- return;
- };
- entity () noisetarget =
- {
- local entity targ;
- targ = spawn ();
- targ.classname = "NoiseTarget";
- targ.solid = SOLID_NOT;
- setsize (targ, '-8 -8 -8', '8 8 8');
- return (targ);
- };
- void () removenoise =
- {
- NOISEQUEUE.goalentity = world;
- NOISEQUEUE.movetarget = world;
- };
- void (entity noisemaker, entity noiseobject) signalnoise =
- {
- if ((noisemaker.classname != "player"))
- {
- return;
- }
- if (!NOISEQUEUE)
- {
- return;
- }
- NOISEQUEUE.goalentity = noisemaker;
- NOISEQUEUE.movetarget = noiseobject;
- NOISEQUEUE.think = removenoise;
- NOISEQUEUE.nextthink = (time + TRUE);
- };
- float (entity e) hearnoise =
- {
- local float rnd;
- if ((self.skil < TRUE))
- {
- return (FALSE);
- }
- if ((self.skil < FL_SWIM))
- {
- rnd = (random () + 0.9);
- if ((self.skil < rnd))
- {
- return (FALSE);
- }
- }
- if ((NOISEQUEUE.goalentity == e))
- {
- dprint (self.teamname);
- dprint (self.classname);
- dprint (" heard ");
- dprint (NOISEQUEUE.goalentity.netname);
- if ((NOISEQUEUE.movetarget.classname == "player"))
- {
- dprint (" shoot\n");
- }
- else
- {
- dprint (" trigger ");
- dprint (NOISEQUEUE.movetarget.classname);
- dprint ("\n");
- }
- return (TRUE);
- }
- return (FALSE);
- };
- float (entity e) heardistantnoise =
- {
- return (FALSE);
- };
- float (entity targ) botrange =
- {
- local vector spot1;
- local vector spot2;
- local float mel;
- local float r;
- spot1 = (self.origin + self.view_ofs);
- spot2 = (targ.origin + targ.view_ofs);
- r = vlen ((spot1 - spot2));
- mel = ((180 - (self.health * 0.5)) - (self.armorvalue * self.armortype));
- if ((self.items & IT_QUAD))
- {
- mel = (FL_SWIM * mel);
- }
- if ((teamplay == TRUE))
- {
- mel = 60;
- }
- if ((r < mel))
- {
- return (RANGE_MELEE);
- }
- else
- {
- if ((r < SEARCH_RADIUS))
- {
- return (RANGE_NEAR);
- }
- else
- {
- if ((r < 1000))
- {
- return (RANGE_MID);
- }
- }
- }
- return (RANGE_FAR);
- };
- float (entity targ) infrontofbot =
- {
- local vector vec;
- local vector xydir;
- local float fov;
- local float dot;
- local float lnd;
- if ((self.skil == MOVETYPE_WALK))
- {
- return (TRUE);
- }
- lnd = pointcontents ((self.origin + self.view_ofs));
- if ((lnd != CONTENT_WATER))
- {
- if ((self.skil < FL_SWIM))
- {
- xydir = (targ.origin - self.origin);
- xydir_z = FALSE;
- dot = vlen (xydir);
- fov = ((targ.origin_z - self.origin_z) * (FL_SWIM - (0.75 * self.skil)));
- if ((fov < FALSE))
- {
- fov = (-0.8 * fov);
- }
- if (((fov > 150) && (dot < fov)))
- {
- return (FALSE);
- }
- }
- }
- makevectors (self.angles);
- vec = normalize ((targ.origin - self.origin));
- dot = (vec * v_forward);
- fov = (0.7 - (self.skil * 0.28));
- if ((dot > fov))
- {
- return (TRUE);
- }
- if ((lnd == CONTENT_WATER))
- {
- if ((dot > FALSE))
- {
- return (TRUE);
- }
- }
- return (FALSE);
- };
- float (entity targ) Swimto =
- {
- local vector spot1;
- local vector spot2;
- local float lnd;
- spot1 = (self.origin + self.view_ofs);
- spot2 = targ.absmin;
- lnd = pointcontents (spot2);
- if ((lnd != CONTENT_WATER))
- {
- if ((spot2_z > (spot1_z + MAXJUMP)))
- {
- return (FALSE);
- }
- }
- traceline (spot1, spot2, TRUE, self);
- if ((trace_fraction == TRUE))
- {
- return (TRUE);
- }
- if ((trace_ent == targ))
- {
- return (TRUE);
- }
- return (FALSE);
- };
- float (entity targ) Spotvisible =
- {
- local vector spot1;
- local vector spot2;
- local string t1;
- spot1 = (self.origin + self.view_ofs);
- spot2 = ((targ.absmin + targ.absmax) * 0.5);
- traceline (spot1, spot2, TRUE, self);
- if ((trace_fraction == TRUE))
- {
- return (TRUE);
- }
- if ((trace_ent == targ))
- {
- return (TRUE);
- }
- return (FALSE);
- };
- float (entity targ) enemyvisible =
- {
- local vector spot1;
- local vector spot2;
- if (visible (targ))
- {
- return (TRUE);
- }
- spot1 = (self.origin + self.view_ofs);
- spot2 = targ.origin;
- traceline (spot1, spot2, TRUE, self);
- if ((trace_inopen && trace_inwater))
- {
- return (FALSE);
- }
- if ((trace_fraction == TRUE))
- {
- return (TRUE);
- }
- return (FALSE);
- };
- float (entity targ) Platvisible =
- {
- local vector spot1;
- local vector spot2;
- local string t1;
- spot1 = (self.origin + self.view_ofs);
- spot2 = ((targ.absmin + targ.absmax) * 0.5);
- spot2_z = (targ.absmax_z + MOVETYPE_WALK);
- traceline (spot1, spot2, TRUE, self);
- if ((trace_fraction == TRUE))
- {
- return (TRUE);
- }
- if ((trace_ent == targ))
- {
- return (TRUE);
- }
- return (FALSE);
- };
- float (vector spot) dropline =
- {
- local float drop;
- local vector spot2;
- local string tmp;
- spot2 = spot;
- spot2_z = (spot2_z - 500);
- traceline (spot, spot2, TRUE, self);
- drop = (spot_z - (trace_fraction * 500));
- return (drop);
- };
- float (entity a, entity b, float bmaxjump) BotWalkable =
- {
- local vector spot1;
- local vector dir;
- local vector borg;
- local float tests;
- local float okpath;
- local float flr;
- local float goalheight;
- if ((b.pathtype != DROPPED))
- {
- borg = ((b.absmin + b.absmax) * 0.5);
- borg_z = (b.absmin_z + TRUE);
- }
- else
- {
- borg = b.origin;
- }
- spot1 = a.origin;
- dir = normalize ((borg - a.origin));
- dir = (((dir * LEVELJUMPTIME) * BOTSPEED) * 6.5);
- tests = vlen ((borg - a.origin));
- tests = (tests / ((LEVELJUMPTIME * BOTSPEED) * 6.5));
- if ((b.pathtype == DROPPED))
- {
- goalheight = (borg_z + self.mins_z);
- }
- else
- {
- goalheight = borg_z;
- }
- while ((tests > TRUE))
- {
- okpath = TRUE;
- spot1 = (spot1 + dir);
- tests = (tests - TRUE);
- flr = dropline (spot1);
- if (((flr + bmaxjump) < goalheight))
- {
- spot1 = (spot1 - (dir * 0.5));
- flr = dropline (spot1);
- if (((flr + bmaxjump) < goalheight))
- {
- okpath = FALSE;
- }
- spot1 = (spot1 + dir);
- tests = (tests - 0.5);
- flr = dropline (spot1);
- if (((flr + bmaxjump) < goalheight))
- {
- if (!okpath)
- {
- return (FALSE);
- }
- spot1 = (spot1 + (dir * 0.5));
- tests = (tests - 0.5);
- flr = dropline (spot1);
- if (((flr + bmaxjump) < goalheight))
- {
- return (FALSE);
- }
- }
- }
- }
- return (TRUE);
- };
- float (entity a, entity b) IsUpstream;
- float (entity a, entity b, float truereach) Reachable =
- {
- local vector spot1;
- local vector spot2;
- local vector borg;
- local float lnd;
- local float vel;
- local float diffz;
- local float diffxy;
- local float rng;
- local float maxzd;
- local float bmaxjump;
- local float brad;
- local string tmp;
- if (truereach)
- {
- bmaxjump = MAXJUMP;
- }
- else
- {
- bmaxjump = (0.6 * MAXJUMP);
- }
- if ((b.pathtype != DROPPED))
- {
- borg = ((b.absmin + b.absmax) * 0.5);
- borg_z = (b.absmin_z + TRUE);
- }
- else
- {
- if ((a.pathtype == DROPPED))
- {
- if (IsUpstream (a, b))
- {
- return (TRUE);
- }
- }
- borg = b.origin;
- }
- spot1 = a.origin;
- spot2 = borg;
- if ((b.pathtype != DROPPED))
- {
- spot2_z = ((b.absmin_z + b.absmax_z) * 0.5);
- }
- rng = vlen ((spot2 - spot1));
- if (truereach)
- {
- if ((rng > SEARCH_RADIUS))
- {
- return (FALSE);
- }
- }
- else
- {
- if ((rng > (SEARCH_RADIUS - (FL_SWIM * BOTSPEED))))
- {
- return (FALSE);
- }
- }
- lnd = pointcontents (a.origin);
- if ((lnd != CONTENT_WATER))
- {
- spot1_z = ((dropline (spot1) + self.view_ofs_z) - self.mins_z);
- }
- traceline (spot1, spot2, TRUE, a);
- spot2 = borg;
- if ((lnd == CONTENT_WATER))
- {
- if (!trace_inopen)
- {
- if ((trace_fraction == TRUE))
- {
- return (TRUE);
- }
- if (truereach)
- {
- return (TRUE);
- }
- }
- if (truereach)
- {
- maxzd = 45;
- lnd = pointcontents ((a.origin + self.view_ofs));
- if ((lnd == CONTENT_WATER))
- {
- maxzd = (maxzd + self.view_ofs_z);
- }
- if ((spot2_z < (a.origin_z + maxzd)))
- {
- if ((trace_fraction == TRUE))
- {
- return (TRUE);
- }
- spot1_z = spot2_z;
- traceline (spot1, spot2, TRUE, a);
- if ((trace_fraction == TRUE))
- {
- return (TRUE);
- }
- }
- }
- }
- if ((trace_fraction != TRUE))
- {
- return (FALSE);
- }
- spot1 = a.origin;
- if ((spot2_z > (spot1_z + bmaxjump)))
- {
- return (FALSE);
- }
- spot1 = a.origin;
- spot1_z = FALSE;
- spot2 = borg;
- spot2_z = FALSE;
- diffxy = vlen ((spot2 - spot1));
- diffxy = (diffxy - ((LEVELJUMPTIME * BOTSPEED) * MOVETYPE_BOUNCE));
- if ((diffxy < FALSE))
- {
- return (TRUE);
- }
- vel = FALSE;
- diffz = (a.origin_z - borg_z);
- while ((diffz > FALSE))
- {
- diffxy = (diffxy - BOTSPEED);
- vel = (vel - GRAVITY);
- diffz = (diffz + (0.1 * vel));
- }
- if ((diffxy < FALSE))
- {
- return (TRUE);
- }
- return (BotWalkable (a, b, bmaxjump));
- };
- void (entity a, entity b) BotReachable =
- {
- return (Reachable (a, b, FALSE));
- };
- void (entity b) TrueReachable =
- {
- return (Reachable (self, b, TRUE));
- };
- void (float dist) ai_botrun;
- void () bot_chase;
- void () bot_trigger1;
- void () aibot_chooseGoal;
- float () BotFindTarget;
- void () shoottarget =
- {
- local vector dir;
- local entity botTarget;
- botTarget = self.goalentity;
- bot_trigger1 ();
- sound (self, CHAN_WEAPON, "weapons/guncock.wav", TRUE, ATTN_NORM);
- dir = ((botTarget.goalentity.absmin + botTarget.goalentity.absmax) * 0.5);
- dir = normalize ((dir - self.origin));
- FireBullets (MOVETYPE_TOSS, dir, '0.04 0.04 0');
- self.attack_finished = (time + 0.5);
- self.enemy = world;
- if ((botTarget.goalentity.classname == "door"))
- {
- self.search_time = (time + FL_CLIENT);
- }
- };
- void (float dist) ai_botseek =
- {
- local entity botTarget;
- local vector dir;
- local float rng;
- local float oldrng;
- if (self.enemy)
- {
- aibot_setupchase ();
- }
- if (BotFindTarget ())
- {
- self.lefty = (self.lefty | FAR_SEEK);
- return;
- }
- botTarget = self.goalentity;
- if ((time < self.search_time))
- {
- if ((botTarget.goalentity.classname == "train"))
- {
- dir = ((botTarget.goalentity.absmin + botTarget.goalentity.absmax) * 0.5);
- dir_z = (botTarget.goalentity.absmax_z + TRUE);
- setorigin (botTarget, dir);
- }
- if ((botTarget.goalentity.solid != SOLID_NOT))
- {
- oldrng = vlen ((botTarget.origin - self.origin));
- Botmovetogoal (dist);
- rng = vlen ((botTarget.origin - self.origin));
- if ((rng >= oldrng))
- {
- self.search_time = (self.search_time - 0.4);
- if ((botTarget.goalentity == botTarget))
- {
- }
- }
- return;
- }
- }
- aibot_chooseGoal ();
- if ((botTarget.goalentity.takedamage == DAMAGE_YES))
- {
- shoottarget ();
- }
- Botmovetogoal (dist);
- };
- float (entity e) thingweight =
- {
- local float weight;
- local float OK_HIGH;
- local float recent;
- local float waittime;
- weight = DONT_WANT;
- OK_HIGH = FALSE;
- if ((self.flags & FL_SWIM))
- {
- OK_HIGH = Swimto (e);
- }
- if ((e.lastbot == self))
- {
- recent = (e.lasttime > (time - FL_CLIENT));
- if (!recent)
- {
- waittime = (time - (LOOPTIME * random ()));
- recent = (e.lasttime > waittime);
- }
- if (recent)
- {
- return (DONT_WANT);
- }
- }
- if (e.th_weight)
- {
- weight = e.th_weight (e);
- }
- else
- {
- e.pathtype = NEVERTARGET;
- }
- if ((weight > DONT_WANT))
- {
- if (!OK_HIGH)
- {
- if ((e.absmin_z > (self.origin_z + MAXJUMP)))
- {
- weight = DONT_WANT;
- }
- }
- }
- return (weight);
- };
- float (entity e) trigweight =
- {
- local float weight;
- weight = DONT_WANT;
- if ((e.lastbot == self))
- {
- if ((e.lasttime > (time - FL_CLIENT)))
- {
- return (DONT_WANT);
- }
- }
- if (e.th_weight)
- {
- weight = e.th_weight (e);
- }
- else
- {
- e.pathtype = NEVERTARGET;
- }
- return (weight);
- };
- float (entity e) itemweight =
- {
- local float weight;
- local float OK_HIGH;
- weight = DONT_WANT;
- OK_HIGH = FALSE;
- if ((self.flags & FL_SWIM))
- {
- OK_HIGH = Swimto (e);
- }
- if ((e.lastbot == self))
- {
- if ((e.lasttime > (time - MOVETYPE_FLY)))
- {
- return (DONT_WANT);
- }
- }
- if (e.th_weight)
- {
- weight = e.th_weight (e);
- }
- else
- {
- e.pathtype = NEVERTARGET;
- }
- if ((weight > DONT_WANT))
- {
- if (!OK_HIGH)
- {
- if ((e.absmin_z > (self.origin_z + MAXJUMP)))
- {
- weight = DONT_WANT;
- }
- }
- }
- if ((weight > DONT_WANT))
- {
- if (!TrueReachable (e))
- {
- weight = DONT_WANT;
- }
- }
- return (weight);
- };
- vector (float n) chooseRoamTarget =
- {
- local float len;
- local float r;
- local float d;
- local float m;
- local float lnd;
- local vector dir;
- local vector below;
- local vector bestorg;
- bestorg = self.origin;
- d = random ();
- if ((d < 0.8))
- {
- r = random ();
- m = TRUE;
- if ((r < 0.5))
- {
- m = CONTENT_EMPTY;
- }
- bestorg_x = (bestorg_x + (m * ((700 * random ()) + 50)));
- }
- if ((d > 0.2))
- {
- r = random ();
- m = TRUE;
- if ((r < 0.5))
- {
- m = CONTENT_EMPTY;
- }
- bestorg_y = (bestorg_y + (m * ((700 * random ()) + 50)));
- }
- bestorg_z = (((bestorg_z + ((MOVETYPE_WALK * MAXJUMP) * random ())) - (FL_SWIM * MAXJUMP)) - TRUE);
- traceline (self.origin, bestorg, TRUE, self);
- dir = normalize ((bestorg - self.origin));
- len = vlen ((bestorg - self.origin));
- bestorg = (self.origin + (dir * ((len * trace_fraction) - KINDA_WANT)));
- below = bestorg;
- below_z = (dropline (below) + TRUE);
- lnd = pointcontents (below);
- if ((lnd != CONTENT_EMPTY))
- {
- if ((lnd != CONTENT_WATER))
- {
- if ((n < MOVETYPE_PUSH))
- {
- return (chooseRoamTarget ((n + TRUE)));
- }
- }
- }
- below = (bestorg - (SVC_INTERMISSION * dir));
- below_z = (dropline (below) + TRUE);
- lnd = pointcontents (below);
- if ((lnd != CONTENT_EMPTY))
- {
- if ((lnd != CONTENT_WATER))
- {
- if ((n < MOVETYPE_PUSH))
- {
- return (chooseRoamTarget ((n + TRUE)));
- }
- }
- }
- r = (n + (random () * MOVETYPE_WALK));
- if (((bestorg_z > self.origin_z) || (r > MOVETYPE_FLY)))
- {
- bestorg_z = (below_z - self.mins_z);
- }
- len = vlen ((bestorg - self.origin));
- if ((len < KINDA_WANT))
- {
- if ((n < MOVETYPE_PUSH))
- {
- return (chooseRoamTarget ((n + TRUE)));
- }
- }
- return (bestorg);
- };
- float (entity e) cacheweight =
- {
- local float weight;
- local float tw;
- local float dis;
- local float it;
- weight = FALSE;
- if ((e.lastbot == self))
- {
- if ((e.lasttime > (time - FL_SWIM)))
- {
- return (weight);
- }
- }
- dis = vlen ((self.origin - e.origin));
- it = self.items;
- e.pendingcache = world;
- e.pendinglen = FALSE;
- if (e.rocketcache)
- {
- if (((e.rocketcache.solid == SOLID_TRIGGER) || (e.rocketcache.nextthink < (time + MOVETYPE_STEP))))
- {
- if (((self.rocketcache != e.rocketcache) || (self.rocketlen > e.rocketlen)))
- {
- weight = ((1000000 - e.rocketlen) - (FL_SWIM * dis));
- if ((it & IT_ROCKET_LAUNCHER))
- {
- weight = (weight * 0.5);
- }
- e.pendingcache = e.rocketcache;
- e.pendinglen = e.rocketlen;
- }
- }
- }
- if (e.lightningcache)
- {
- if (((e.lightningcache.solid == SOLID_TRIGGER) || (e.lightningcache.nextthink < (time + MOVETYPE_STEP))))
- {
- if (((self.lightningcache != e.lightningcache) || (self.lightninglen > e.lightninglen)))
- {
- tw = ((1000000 - e.lightninglen) - (FL_SWIM * dis));
- if ((it & IT_LIGHTNING))
- {
- tw = (tw * 0.5);
- }
- if ((tw > weight))
- {
- weight = tw;
- e.pendingcache = e.lightningcache;
- e.pendinglen = e.lightninglen;
- }
- }
- }
- }
- if ((self.armorvalue < 101))
- {
- if (e.armorcache)
- {
- if (((e.armorcache.solid == SOLID_TRIGGER) || (e.armorcache.nextthink < (time + MOVETYPE_STEP))))
- {
- if (((self.armorcache != e.armorcache) || (self.armorlen > e.armorlen)))
- {
- tw = ((1000000 - e.armorlen) - (FL_SWIM * dis));
- if ((tw > weight))
- {
- weight = tw;
- e.pendingcache = e.armorcache;
- e.pendinglen = e.armorlen;
- }
- }
- }
- }
- }
- if (e.nailcache)
- {
- if (((e.nailcache.solid == SOLID_TRIGGER) || (e.nailcache.nextthink < (time + FL_SWIM))))
- {
- if (((self.nailcache != e.nailcache) || (self.naillen > e.naillen)))
- {
- tw = ((1000000 - e.naillen) - (FL_SWIM * dis));
- if ((it & IT_SUPER_NAILGUN))
- {
- tw = (tw * 0.5);
- }
- if ((tw > (weight + 2500)))
- {
- weight = tw;
- e.pendingcache = e.nailcache;
- e.pendinglen = e.naillen;
- }
- }
- }
- }
- if (e.grenadecache)
- {
- if (((e.grenadecache.solid == SOLID_TRIGGER) || (e.grenadecache.nextthink < (time + FL_SWIM))))
- {
- if (((self.grenadecache != e.grenadecache) || (self.grenadelen > e.grenadelen)))
- {
- tw = ((1000000 - e.grenadelen) - (FL_SWIM * dis));
- if ((it & IT_GRENADE_LAUNCHER))
- {
- tw = (tw * 0.5);
- }
- if ((tw > (weight + 2500)))
- {
- weight = tw;
- e.pendingcache = e.grenadecache;
- e.pendinglen = e.grenadelen;
- }
- }
- }
- }
- if (e.powerupcache)
- {
- if ((e.powerupcache.solid == SOLID_TRIGGER))
- {
- if (((self.powerupcache != e.powerupcache) || (self.poweruplen > e.poweruplen)))
- {
- tw = ((1000000 - e.poweruplen) - (FL_SWIM * dis));
- if ((tw > weight))
- {
- weight = tw;
- e.pendingcache = e.powerupcache;
- e.pendinglen = e.poweruplen;
- }
- }
- }
- }
- return (weight);
- };
- float (entity e) pathweight =
- {
- local float OK_HIGH;
- local float weight;
- local vector org;
- weight = DONT_WANT;
- if (TrueReachable (e))
- {
- weight = cacheweight (e);
- if ((weight > FALSE))
- {
- return (weight);
- }
- weight = vlen ((self.origin - org));
- weight = ((50 * SEARCH_RADIUS) - weight);
- if ((e.lastbot == self))
- {
- if ((e.lasttime > (time - MOVETYPE_TOSS)))
- {
- weight = DONT_WANT;
- }
- else
- {
- if ((e.lasttime > (time - LOOPTIME)))
- {
- weight = ((weight - (FL_SWIM * SEARCH_RADIUS)) - (((45 * SEARCH_RADIUS) * ((LOOPTIME + e.lasttime) - time)) / LOOPTIME));
- }
- }
- }
- else
- {
- if (teamplay)
- {
- if ((e.lastbot.team == self.team))
- {
- if ((e.lasttime > (time - 1.2)))
- {
- weight = DONT_WANT;
- }
- else
- {
- if ((e.lasttime > (time - FL_SWIM)))
- {
- weight = (weight - SEARCH_RADIUS);
- }
- }
- }
- }
- }
- }
- return (weight);
- };
- void () goForAir =
- {
- local vector bestorg;
- local entity botTarget;
- if (VERBOSEBOT)
- {
- dprint (self.teamname);
- dprint (self.netname);
- dprint (" needs air!\n");
- }
- bestorg = self.origin;
- bestorg_z = (bestorg_z + 800);
- traceline (self.origin, bestorg, TRUE, self);
- if (!trace_inopen)
- {
- bestorg = chooseRoamTarget (TRUE);
- bestorg_z = (bestorg_z + 200);
- }
- botTarget = self.goalentity;
- botTarget.goalentity = botTarget;
- if ((self.goalentity.classname != "BotTarget"))
- {
- objerror ("bad bot target in botgoal! 1\n");
- }
- setorigin (botTarget, bestorg);
- };
- void (entity item) ageCache =
- {
- if (self.rocketcache)
- {
- self.rocketlen = (self.rocketlen + TRUE);
- }
- if (self.lightningcache)
- {
- self.lightninglen = (self.lightninglen + TRUE);
- }
- if (self.armorcache)
- {
- self.armorlen = (self.armorlen + TRUE);
- }
- if (self.powerupcache)
- {
- self.poweruplen = (self.poweruplen + TRUE);
- }
- if (self.nailcache)
- {
- self.naillen = (self.naillen + TRUE);
- }
- if (self.grenadecache)
- {
- self.grenadelen = (self.grenadelen + TRUE);
- }
- if ((item.solid == SOLID_TRIGGER))
- {
- if ((self.rocketcache == item))
- {
- self.rocketlen = TRUE;
- }
- else
- {
- if ((self.lightningcache == item))
- {
- self.lightninglen = TRUE;
- }
- else
- {
- if ((self.armorcache == item))
- {
- self.armorlen = TRUE;
- }
- else
- {
- if ((self.powerupcache == item))
- {
- self.poweruplen = TRUE;
- }
- else
- {
- if ((self.nailcache == item))
- {
- self.naillen = TRUE;
- }
- else
- {
- if ((self.grenadecache == item))
- {
- self.grenadelen = TRUE;
- }
- }
- }
- }
- }
- }
- }
- };
- void () resetCache =
- {
- self.pendingcache = world;
- self.pendinglen = FALSE;
- if (self.rocketcache)
- {
- if ((self.rocketcache.solid == SOLID_NOT))
- {
- self.rocketcache = world;
- self.rocketlen = FALSE;
- }
- }
- if (self.lightningcache)
- {
- if ((self.lightningcache.solid == SOLID_NOT))
- {
- self.lightningcache = world;
- self.lightninglen = FALSE;
- }
- }
- if (self.armorcache)
- {
- if ((self.armorcache.solid == SOLID_NOT))
- {
- self.armorcache = world;
- self.armorlen = FALSE;
- }
- }
- if (self.powerupcache)
- {
- if ((self.powerupcache.solid == SOLID_NOT))
- {
- self.powerupcache = world;
- self.poweruplen = FALSE;
- }
- }
- if (self.nailcache)
- {
- if ((self.nailcache.solid == SOLID_NOT))
- {
- self.nailcache = world;
- self.naillen = FALSE;
- }
- }
- if (self.grenadecache)
- {
- if ((self.grenadecache.solid == SOLID_NOT))
- {
- self.grenadecache = world;
- self.grenadelen = FALSE;
- }
- }
- };
- void () updateBotCache =
- {
- if (self.pendingcache.th_update)
- {
- self.pendingcache.th_update ();
- }
- else
- {
- dprint ("Error - no think update for ");
- dprint (self.pendingcache.classname);
- dprint ("\n");
- }
- self.pendingcache = world;
- self.pendinglen = FALSE;
- };
- void () aibot_chooseGoal =
- {
- local vector org;
- local vector bestorg;
- local float best;
- local float weight;
- local float d1;
- local float d2;
- local float OK_NOTVIS;
- local entity e;
- local entity current;
- local entity botTarget;
- local string tmp;
- botTarget = self.goalentity;
- if ((self.lefty & FAR_SEEK))
- {
- self.lefty = ((self.lefty - (self.lefty & LOCAL_TIME)) - FAR_SEEK);
- }
- if ((self.lefty & ONTRAIN))
- {
- self.lefty = (self.lefty - ONTRAIN);
- }
- self.lefty = (self.lefty + TRUE);
- current = botTarget.goalentity;
- self.search_time = (time + MOVETYPE_STEP);
- best = DONT_WANT;
- OK_NOTVIS = FALSE;
- if ((self.air_finished < (time + MOVETYPE_FLYMISSILE)))
- {
- goForAir ();
- return;
- }
- if (((self.lefty & LOCAL_TIME) < MOVETYPE_FLY))
- {
- e = findradius (self.origin, SEARCH_RADIUS);
- while (e)
- {
- weight = DONT_WANT;
- if ((e == current))
- {
- weight = DONT_WANT;
- }
- else
- {
- if (e.pathtype)
- {
- weight = DONT_WANT;
- }
- else
- {
- if ((e.solid == SOLID_NOT))
- {
- weight = DONT_WANT;
- }
- else
- {
- if ((e.solid == SOLID_TRIGGER))
- {
- if (e.istrigger)
- {
- weight = trigweight (e);
- }
- else
- {
- weight = itemweight (e);
- }
- }
- else
- {
- weight = thingweight (e);
- }
- }
- }
- }
- if ((weight > (KINDA_WANT - MOVETYPE_FLY)))
- {
- if ((weight < (WANT + FL_SWIM)))
- {
- if (((e.absmin_z + MAXJUMP) < self.absmin_z))
- {
- weight = (KINDA_WANT - MOVETYPE_FLY);
- }
- }
- }
- if ((weight > DONT_WANT))
- {
- org = ((e.absmin + e.absmax) * 0.5);
- org_z = (e.absmin_z + TRUE);
- if ((((e.classname == "plat") || (e.classname == "func_plat")) || (e.classname == "train")))
- {
- org_z = (e.absmax_z + TRUE);
- }
- if ((weight == best))
- {
- d1 = vlen ((self.origin - bestorg));
- d2 = vlen ((self.origin - org));
- weight = ((weight + (random () * MOVETYPE_FLY)) - FL_SWIM);
- if ((d1 < d2))
- {
- weight = (weight - TRUE);
- }
- if ((weight > best))
- {
- weight = best;
- best = (best - TRUE);
- }
- }
- if ((weight > best))
- {
- botTarget.goalentity = e;
- best = weight;
- bestorg = org;
- }
- }
- e = e.chain;
- }
- }
- resetCache ();
- if ((best < (KINDA_WANT - MOVETYPE_WALK)))
- {
- if ((best > DONT_WANT))
- {
- best = (1000000 - 900);
- }
- e = findradius (self.origin, SEARCH_RADIUS);
- best = DONT_WANT;
- while (e)
- {
- if (((e.pathtype == DROPPED) || (e.pathtype == TELEPORT)))
- {
- if ((e == current))
- {
- weight = DONT_WANT;
- }
- else
- {
- weight = pathweight (e);
- }
- if ((weight > best))
- {
- best = weight;
- botTarget.goalentity = e;
- self.pendingcache = e.pendingcache;
- self.pendinglen = e.pendinglen;
- bestorg = e.origin;
- if (!bestorg)
- {
- bestorg = ((e.absmin + e.absmax) * 0.5);
- bestorg_z = (e.absmin_z + TRUE);
- }
- self.lefty = (self.lefty | FAR_SEEK);
- }
- }
- e = e.chain;
- }
- }
- if ((best > DONT_WANT))
- {
- if (self.pendingcache)
- {
- updateBotCache ();
- }
- else
- {
- if ((botTarget.goalentity.classname != "BotPath"))
- {
- ageCache (botTarget.goalentity);
- }
- }
- }
- if ((best <= DONT_WANT))
- {
- botTarget.goalentity = botTarget;
- bestorg = chooseRoamTarget (FALSE);
- self.lefty = (self.lefty | FAR_SEEK);
- self.search_time = (time + FL_SWIM);
- }
- if (VERBOSEBOT)
- {
- dprint (self.teamname);
- dprint (self.netname);
- dprint (" going after ");
- dprint (botTarget.goalentity.classname);
- dprint ("\n");
- }
- if (botTarget.goalentity)
- {
- if ((botTarget.goalentity != botTarget))
- {
- botTarget.goalentity.lastbot = self;
- botTarget.goalentity.lasttime = time;
- }
- }
- if ((botTarget.goalentity.classname == "func_button"))
- {
- bestorg = ((bestorg - botTarget.goalentity.pos2) - (FL_MONSTER * normalize (botTarget.goalentity.pos2)));
- }
- if ((botTarget.classname != "BotTarget"))
- {
- objerror ("bad bot target in botgoal! 2\n");
- }
- setorigin (botTarget, bestorg);
- };
- float (entity e) RunAwayWeight =
- {
- local float weight;
- if (!TrueReachable (e))
- {
- return (FALSE);
- }
- traceline ((self.enemy.origin + self.enemy.view_ofs), e.origin, TRUE, self.enemy);
- if ((trace_fraction != TRUE))
- {
- weight = WANT;
- }
- if ((trace_inopen && trace_inwater))
- {
- weight = (WANT - MOVETYPE_FLY);
- }
- weight = (weight + (0.1 * vlen ((self.enemy.origin - e.origin))));
- weight = (weight + (KINDA_WANT * random ()));
- return (weight);
- };
- void (entity en) RouteToEnemy;
- entity (entity chaser, entity en) BestChaseRoute =
- {
- local entity e;
- local entity p;
- local entity tmp;
- local float weight;
- local float best;
- local string ts;
- RouteToEnemy (en);
- e = findradius (chaser.origin, SEARCH_RADIUS);
- best = 1000000;
- p = en;
- tmp = self;
- self = chaser;
- while (e)
- {
- if (((e.pathtype == DROPPED) || (e.pathtype == TELEPORT)))
- {
- weight = 1000000;
- if ((e.enemycache == en))
- {
- if (TrueReachable (e))
- {
- weight = (e.enemylen + (vlen ((self.origin - e.origin)) * 0.5));
- }
- }
- if ((weight < best))
- {
- best = weight;
- p = e;
- }
- }
- e = e.chain;
- }
- self = tmp;
- return (p);
- };
- void () endEnemy =
- {
- local entity olden;
- olden = self.enemy;
- if ((self.lefty & GETGOODY))
- {
- self.lefty = (self.lefty - GETGOODY);
- }
- if ((self.lefty & MULTIENEMY))
- {
- self.lefty = (self.lefty - MULTIENEMY);
- }
- self.enemy = world;
- self.think = self.th_walk;
- self.nextthink = (time + 0.1);
- self.search_time = (time - TRUE);
- self.enemyrun = FALSE;
- self.goalentity.goalentity = self.goalentity;
- if ((olden.classname == "player"))
- {
- if ((olden.enemy == self))
- {
- olden.enemy = world;
- }
- }
- };
- void () CallForHelp =
- {
- local entity e;
- local entity p;
- local entity tmp;
- local float d;
- HELPING = TRUE;
- e = find (world, classname, "dmbot");
- while (e)
- {
- if ((e != self))
- {
- if ((e.team == self.team))
- {
- if ((e.enemy == world))
- {
- if ((e.health > 80))
- {
- if ((e.items & ((((IT_ROCKET_LAUNCHER + IT_LIGHTNING) + IT_SUPER_NAILGUN) + IT_SUPER_SHOTGUN) + IT_GRENADE_LAUNCHER)))
- {
- p = BestChaseRoute (e, self.enemy);
- traceline (e.origin, self.enemy.origin, TRUE, e);
- if (((trace_fraction == TRUE) || (p.enemycache == self.enemy)))
- {
- if (VERBOSEBOT)
- {
- dprint (e.teamname);
- dprint (e.netname);
- dprint (" coming to help!\n");
- }
- e.enemy = self.enemy;
- tmp = self;
- self = e;
- BotFoundTarget ();
- if ((self.goalentity.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_ai! 1\n");
- }
- setorigin (self.goalentity, p.origin);
- self = tmp;
- }
- }
- }
- }
- }
- }
- e = find (e, classname, "dmbot");
- }
- HELPING = FALSE;
- };
- float () RunAway =
- {
- local float weap;
- if ((self.items & IT_INVULNERABILITY))
- {
- return (FALSE);
- }
- if ((self.enemy.items & IT_INVULNERABILITY))
- {
- return (TRUE);
- }
- if ((self.enemy.health < WANT))
- {
- return (FALSE);
- }
- weap = W_BestHeldWeapon ();
- if ((weap & (IT_ROCKET_LAUNCHER + IT_LIGHTNING)))
- {
- return (FALSE);
- }
- if ((self.items & IT_QUAD))
- {
- if (((self.health + (self.armorvalue * self.armortype)) > 50))
- {
- return (FALSE);
- }
- }
- if ((self.health < 45))
- {
- return (TRUE);
- }
- if ((weap & ((IT_SHOTGUN + IT_AXE) + IT_NAILGUN)))
- {
- if ((self.enemy.items & IT_QUAD))
- {
- return (TRUE);
- }
- if ((self.enemy.weapon & ((IT_ROCKET_LAUNCHER + IT_LIGHTNING) + IT_SUPER_NAILGUN)))
- {
- return (TRUE);
- }
- }
- if ((self.lefty & MULTIENEMY))
- {
- if ((self.health < 70))
- {
- return (TRUE);
- }
- }
- return (FALSE);
- };
- void () BotHuntTarget =
- {
- if (VERBOSEBOT)
- {
- dprint (self.teamname);
- dprint (self.netname);
- dprint (": Go kick ");
- dprint (self.enemy.teamname);
- dprint (self.enemy.netname);
- dprint ("'s ass!\n");
- }
- self.enemyrun = FALSE;
- self.strafetime = FALSE;
- if ((self.lefty & ONTRAIN))
- {
- self.lefty = (self.lefty - ONTRAIN);
- }
- self.goalentity.goalentity = self.enemy;
- if ((self.enemy.enemy == world))
- {
- self.enemy.enemy = self;
- }
- if ((self.goalentity.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_ai! 2\n");
- }
- setorigin (self.goalentity, self.enemy.origin);
- self.think = self.th_run;
- self.strafeonly = FALSE;
- self.ideal_yaw = vectoyaw ((self.enemy.origin - self.origin));
- self.lefty = ((self.lefty - (self.lefty & LOCAL_TIME)) + MOVETYPE_TOSS);
- self.nextthink = (time + 0.1);
- self.attack_finished = ((time + 0.7) - (0.2 * self.skil));
- self.search_time = (time + MOVETYPE_PUSH);
- clearCache (self);
- if (teamplay)
- {
- if (!HELPING)
- {
- CallForHelp ();
- }
- }
- };
- float () BotFoundTarget =
- {
- if ((self.enemy == world))
- {
- return (FALSE);
- }
- if (teamplay)
- {
- if ((self.enemy.team == self.team))
- {
- self.enemy = world;
- return (FALSE);
- }
- }
- if ((self.deadflag != DEAD_NO))
- {
- self.enemy = world;
- return (FALSE);
- }
- if ((self.enemy.deadflag != DEAD_NO))
- {
- self.enemy = world;
- return (FALSE);
- }
- if (((self.enemy.classname != "player") && (self.enemy.classname != "dmbot")))
- {
- self.enemy = world;
- return (FALSE);
- }
- if ((self.enemy == self))
- {
- self.enemy = world;
- return (FALSE);
- }
- BotHuntTarget ();
- return (TRUE);
- };
- void (entity en2) secondEnemy =
- {
- if ((self.enemy.classname != "player"))
- {
- if ((en2.classname == "player"))
- {
- endEnemy ();
- self.enemy = en2;
- BotFoundTarget ();
- return;
- }
- }
- if (!enemyvisible (self.enemy))
- {
- endEnemy ();
- self.enemy = en2;
- BotFoundTarget ();
- }
- if ((en2.weapon & (IT_LIGHTNING + IT_ROCKET_LAUNCHER)))
- {
- if (!(self.enemy.weapon & (IT_LIGHTNING + IT_ROCKET_LAUNCHER)))
- {
- endEnemy ();
- self.enemy = en2;
- BotFoundTarget ();
- }
- }
- };
- float () BotfindBot =
- {
- local float n;
- local entity bots;
- if (!self.lastbot)
- {
- self.lastbot = find (world, classname, "dmbot");
- }
- n = MOVETYPE_STEP;
- while ((n > FALSE))
- {
- n = (n - TRUE);
- bots = self.lastbot;
- if ((!teamplay || (self.team != bots.team)))
- {
- if ((bots != self))
- {
- if ((bots != self.enemy))
- {
- if (visible (bots))
- {
- if ((bots.health > FALSE))
- {
- self.enemy = bots;
- return (BotFoundTarget ());
- }
- }
- }
- }
- }
- self.lastbot = find (bots, classname, "dmbot");
- if (!self.lastbot)
- {
- self.lastbot = find (world, classname, "dmbot");
- }
- }
- return (FALSE);
- };
- float () BotFindTarget =
- {
- local entity client;
- local float len;
- local float bw;
- client = checkclient ();
- if (!client)
- {
- return (BotfindBot ());
- }
- if ((client.classname == "peeper"))
- {
- return (BotfindBot ());
- }
- if ((client == self.enemy))
- {
- return (FALSE);
- }
- if (teamplay)
- {
- if ((self.team == client.team))
- {
- return (BotfindBot ());
- }
- }
- if ((client.flags & FL_NOTARGET))
- {
- return (BotfindBot ());
- }
- if (!enemyvisible (client))
- {
- return (BotfindBot ());
- }
- if (!infrontofbot (client))
- {
- if (!hearnoise (client))
- {
- return (BotfindBot ());
- }
- }
- if (((self.origin_z > (client.origin_z + 120)) || ((self.origin_z + 120) < client.origin_z)))
- {
- self.enemy = client;
- if (RunAway ())
- {
- self.enemy = world;
- return (BotfindBot ());
- }
- }
- if ((client.items & IT_INVISIBILITY))
- {
- return (BotfindBot ());
- }
- if ((self.skil < TRUE))
- {
- len = (random () * MUST_HAVE);
- if ((len > 25))
- {
- return (FALSE);
- }
- }
- self.enemy = client;
- return (BotFoundTarget ());
- };
- void () ai_botstand =
- {
- if (BotFindTarget ())
- {
- return;
- }
- };
- void () ai_botturn =
- {
- if (BotFindTarget ())
- {
- return;
- }
- ChangeYaw ();
- };
- void () aibot_run_melee =
- {
- self.ideal_yaw = vectoyaw ((self.enemy.origin - self.origin));
- ChangeYaw ();
- if (FacingIdeal ())
- {
- self.attack_state = AS_STRAIGHT;
- self.th_melee ();
- }
- };
- void (float dist, float turn) aibot_run_slide =
- {
- local float ofs;
- local float rdir;
- local float rng;
- local float rnd;
- local float dis;
- local float trn;
- local float weap;
- trn = turn;
- self.ideal_yaw = vectoyaw ((self.enemy.origin - self.origin));
- ChangeYaw ();
- ofs = 90;
- dis = dist;
- self.strafeonly = (self.strafeonly - TRUE);
- if ((self.strafeonly > FALSE))
- {
- trn = NOTURN;
- }
- rdir = (random () * MOVETYPE_WALK);
- rng = botrange (self.enemy);
- if ((rng == RANGE_NEAR))
- {
- rdir = (rdir + 0.8);
- }
- else
- {
- if ((rng == RANGE_MELEE))
- {
- rdir = (rdir + 1.2);
- rnd = random ();
- weap = W_BestHeldWeapon ();
- if ((weap == IT_ROCKET_LAUNCHER))
- {
- rnd = FALSE;
- }
- else
- {
- if ((weap == IT_GRENADE_LAUNCHER))
- {
- rnd = FALSE;
- }
- else
- {
- if ((self.enemyrun > MOVETYPE_STEP))
- {
- rnd = TRUE;
- }
- else
- {
- if ((weap == IT_AXE))
- {
- rnd = TRUE;
- }
- else
- {
- if ((self.enemy.weapon == IT_ROCKET_LAUNCHER))
- {
- rnd = TRUE;
- }
- }
- }
- }
- }
- if ((rnd < 0.3))
- {
- if (botwalkmove ((self.ideal_yaw + 180), dis))
- {
- return;
- }
- }
- }
- else
- {
- if ((rng == RANGE_MID))
- {
- weap = W_BestHeldWeapon ();
- if ((weap == IT_LIGHTNING))
- {
- rdir = (rdir - MOVETYPE_WALK);
- }
- else
- {
- rdir = (rdir - TRUE);
- }
- }
- else
- {
- if ((rng == RANGE_FAR))
- {
- rdir = (rdir - 2.5);
- }
- }
- }
- }
- if ((self.weapon == IT_AXE))
- {
- rdir = FALSE;
- }
- else
- {
- if ((self.weapon == IT_ROCKET_LAUNCHER))
- {
- rdir = (rdir + 1.5);
- }
- else
- {
- if ((self.weapon == IT_GRENADE_LAUNCHER))
- {
- rdir = (rdir + 1.5);
- }
- }
- }
- if ((self.enemy.weapon == IT_ROCKET_LAUNCHER))
- {
- rdir = (rdir + 1.5);
- }
- else
- {
- if ((self.enemy.weapon == IT_LIGHTNING))
- {
- rdir = (rdir + 1.5);
- }
- }
- if ((self.enemyrun > FL_CLIENT))
- {
- rdir = (rdir - FL_SWIM);
- }
- else
- {
- if ((self.origin_z > (self.enemy.origin_z + 130)))
- {
- rdir = ((rdir + 1.1) + random ());
- if ((rdir >= 1.5))
- {
- trn = NOTURN;
- }
- if ((self.weapon == IT_AXE))
- {
- trn = turn;
- rdir = FALSE;
- }
- }
- }
- if ((rdir < 1.5))
- {
- if ((trn == CANTURN))
- {
- Botmovetogoal (dis);
- return;
- }
- if (botwalkmove (self.ideal_yaw, dis))
- {
- return;
- }
- ofs = 90;
- }
- else
- {
- if ((rdir < 2.4))
- {
- ofs = 45;
- }
- }
- if ((self.skil == FALSE))
- {
- return;
- }
- self.strafetime = (self.strafetime + 0.1);
- if ((self.skil < FL_SWIM))
- {
- if ((self.skil < TRUE))
- {
- dis = (0.7 * dis);
- }
- if ((self.strafetime == 0.1))
- {
- rnd = (random () * MOVETYPE_STEP);
- if ((self.skil >= TRUE))
- {
- rnd = ((rnd - self.skil) + 0.5);
- }
- if ((rnd > self.skil))
- {
- self.strafetime = FALSE;
- return;
- }
- }
- }
- if ((self.strafetime > 0.4))
- {
- rnd = (random () * FL_SWIM);
- if ((rnd > 1.87))
- {
- if ((self.lefty & STRAFE_DIR))
- {
- self.lefty = (self.lefty - STRAFE_DIR);
- }
- else
- {
- self.lefty = (self.lefty + STRAFE_DIR);
- }
- self.strafetime = FALSE;
- return;
- }
- }
- if ((self.lefty & STRAFE_DIR))
- {
- ofs = (CONTENT_EMPTY * ofs);
- }
- if (botwalkmove ((self.ideal_yaw + ofs), dis))
- {
- return;
- }
- self.strafetime = FALSE;
- if ((self.lefty & STRAFE_DIR))
- {
- self.lefty = (self.lefty - STRAFE_DIR);
- }
- else
- {
- self.lefty = (self.lefty + STRAFE_DIR);
- }
- if (((ofs == 90) || (ofs == -90)))
- {
- rnd = random ();
- if ((rnd < 0.05))
- {
- if ((trn == CANTURN))
- {
- Botmovetogoal (dis);
- return;
- }
- }
- if ((rnd < 0.5))
- {
- walkmove ((self.ideal_yaw + 180), (dis * 0.5));
- }
- return;
- }
- botwalkmove (self.ideal_yaw, dis);
- };
- void (float dist) ai_botgetGoody;
- void (float dist) ai_botcharge =
- {
- local float rng;
- local float oldrng;
- if ((self.lefty & GETGOODY))
- {
- ai_botgetGoody (dist);
- return;
- }
- if (enemyvisible (self.enemy))
- {
- rng = vlen ((self.enemy.origin - self.origin));
- oldrng = vlen ((self.goalentity.origin - self.origin));
- if ((self.goalentity.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_ai! 3\n");
- }
- setorigin (self.goalentity, self.enemy.origin);
- if ((self.enemyrun > FALSE))
- {
- self.enemyrun = (self.enemyrun - TRUE);
- }
- if ((rng > (oldrng + MOVETYPE_BOUNCE)))
- {
- self.enemyrun = (self.enemyrun + FL_SWIM);
- }
- }
- aibot_run_slide (dist, NOTURN);
- };
- void (float dist) ai_botnailcharge =
- {
- local float rnd;
- if (!enemyvisible (self.enemy))
- {
- self.think = self.th_run;
- }
- if (!FacingIdeal ())
- {
- self.think = self.th_run;
- }
- if ((self.enemy.deadflag != DEAD_NO))
- {
- endEnemy ();
- return;
- }
- ai_botcharge (dist);
- };
- float (float minweight) aibot_checkforGoodies;
- void (float dist) ai_botrun =
- {
- local vector delta;
- local float axis;
- local float rng;
- local float oldrng;
- local float direct;
- local float ang_rint;
- local float ang_floor;
- local float ang_ceil;
- if ((self.enemy.deadflag != DEAD_NO))
- {
- endEnemy ();
- return;
- }
- if (!self.enemy)
- {
- endEnemy ();
- return;
- }
- if ((self.lefty & GETGOODY))
- {
- ai_botgetGoody (dist);
- return;
- }
- enemy_vis = enemyvisible (self.enemy);
- if ((enemy_vis || Spotvisible (self.enemy)))
- {
- rng = vlen ((self.enemy.origin - self.origin));
- oldrng = vlen ((self.goalentity.origin - self.origin));
- if ((self.enemyrun > FALSE))
- {
- self.enemyrun = (self.enemyrun - TRUE);
- }
- if ((rng > (oldrng + MOVETYPE_BOUNCE)))
- {
- self.enemyrun = (self.enemyrun + FL_SWIM);
- }
- if ((self.goalentity.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_ai! 4\n");
- }
- setorigin (self.goalentity, self.enemy.origin);
- self.search_time = (time + MOVETYPE_PUSH);
- }
- if ((self.search_time < time))
- {
- endEnemy ();
- BotFindTarget ();
- return;
- }
- if (((self.lefty & LOCAL_TIME) > MOVETYPE_FLY))
- {
- self.lefty = (self.lefty - (self.lefty & LOCAL_TIME));
- self.lastseenpos = self.goalentity.origin;
- if (aibot_checkforGoodies (DONT_WANT))
- {
- ai_botgetGoody (dist);
- return;
- }
- }
- self.lefty = (self.lefty + TRUE);
- if (RunAway ())
- {
- self.lefty = (self.lefty - (self.lefty & LOCAL_TIME));
- self.lastseenpos = self.goalentity.origin;
- if (aibot_checkforGoodies (DONT_WANT))
- {
- ai_botgetGoody (dist);
- return;
- }
- }
- enemy_infront = infrontofbot (self.enemy);
- enemy_yaw = vectoyaw ((self.enemy.origin - self.origin));
- if (!enemy_vis)
- {
- aibot_setupchase ();
- Botmovetogoal (dist);
- return;
- }
- if ((self.attack_state == AS_MELEE))
- {
- aibot_run_melee ();
- }
- CheckBotAttack ();
- aibot_run_slide (dist, CANTURN);
- return;
- };
- void () aibot_setupchase =
- {
- local entity pth;
- self.think = bot_chase;
- if (TrueReachable (self.goalentity))
- {
- return;
- }
- if (RunAway ())
- {
- self.lefty = (self.lefty - (self.lefty & LOCAL_TIME));
- aibot_checkforGoodies ((WANT - TRUE));
- self.lastseenpos = self.goalentity.origin;
- return;
- }
- pth = BestChaseRoute (self, self.enemy);
- if ((self.goalentity.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_ai! 1\n");
- }
- if ((pth != self.enemy))
- {
- setorigin (self.goalentity, pth.origin);
- }
- self.search_time = (time + MOVETYPE_TOSS);
- };
- void (float dist) aibot_chase =
- {
- local entity olden;
- local float weap;
- local float rnd;
- if ((self.enemy.deadflag != DEAD_NO))
- {
- endEnemy ();
- return;
- }
- if ((self.lefty & GETGOODY))
- {
- ai_botgetGoody (dist);
- return;
- }
- enemy_vis = enemyvisible (self.enemy);
- rnd = random ();
- if ((rnd < 0.9))
- {
- enemy_vis = enemy_vis;
- }
- if (enemy_vis)
- {
- if ((self.goalentity.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_ai! 1\n");
- }
- setorigin (self.goalentity, self.enemy.origin);
- self.search_time = (time + MOVETYPE_FLY);
- self.think = self.th_run;
- Botmovetogoal (dist);
- return;
- }
- if (RunAway ())
- {
- if ((self.search_time < time))
- {
- endEnemy ();
- return;
- }
- self.lefty = (self.lefty - (self.lefty & LOCAL_TIME));
- if (aibot_checkforGoodies ((WANT - TRUE)))
- {
- ai_botgetGoody (dist);
- self.lastseenpos = self.goalentity.origin;
- return;
- }
- }
- if ((self.enemy.items & IT_INVISIBILITY))
- {
- if ((self.skil < MOVETYPE_WALK))
- {
- endEnemy ();
- return;
- }
- }
- if (((self.lefty & LOCAL_TIME) > MOVETYPE_FLY))
- {
- self.lastseenpos = self.goalentity.origin;
- self.lefty = (self.lefty - (self.lefty & LOCAL_TIME));
- if (aibot_checkforGoodies ((MUST_HAVE - MOVETYPE_WALK)))
- {
- ai_botgetGoody (dist);
- return;
- }
- }
- self.lefty = (self.lefty + TRUE);
- olden = self.enemy;
- if (BotFindTarget ())
- {
- if ((olden.enemy == self))
- {
- olden.enemy = world;
- }
- return;
- }
- if ((self.search_time < time))
- {
- endEnemy ();
- return;
- }
- if (CheckReboundAttack ())
- {
- return;
- }
- Botmovetogoal (dist);
- };
- float (float minweight) aibot_checkforGoodies =
- {
- local entity e;
- local entity botTarget;
- local float AFRAID;
- local float steps;
- local float best;
- local float weight;
- local float goody_yaw;
- local float lnd;
- local float weap;
- local float minimum;
- local vector spot;
- if ((self.air_finished < (time + MOVETYPE_FLYMISSILE)))
- {
- goForAir ();
- self.lefty = (self.lefty | GETGOODY);
- self.goody_time = (time + MOVETYPE_WALK);
- return (TRUE);
- }
- AFRAID = RunAway ();
- botTarget = self.goalentity;
- e = findradius (self.origin, SEARCH_RADIUS);
- best = DONT_WANT;
- while (e)
- {
- weight = DONT_WANT;
- if ((e.origin_z > (self.origin_z + (0.7 * MAXJUMP))))
- {
- weight = DONT_WANT;
- }
- else
- {
- if (((e.pathtype == DROPPED) || (e.pathtype == TELEPORT)))
- {
- weight = DONT_WANT;
- if (AFRAID)
- {
- weight = RunAwayWeight (e);
- }
- }
- else
- {
- if ((e.pathtype != REGULARTARGET))
- {
- weight = DONT_WANT;
- }
- else
- {
- if ((e.solid != SOLID_TRIGGER))
- {
- weight = DONT_WANT;
- }
- else
- {
- if (!e.istrigger)
- {
- weight = itemweight (e);
- if ((weight < MUST_HAVE))
- {
- if ((((e.origin_z < self.enemy.absmin_z) && (e.origin_z < self.absmin_z)) && !AFRAID))
- {
- weight = DONT_WANT;
- }
- }
- }
- }
- }
- }
- }
- if ((weight > best))
- {
- botTarget.goalentity = e;
- best = weight;
- }
- e = e.chain;
- }
- minimum = minweight;
- if ((self.skil < TRUE))
- {
- if ((minimum < (WANT + FL_SWIM)))
- {
- minimum = (WANT + FL_SWIM);
- }
- }
- if ((best > DONT_WANT))
- {
- if (((best > minimum) || AFRAID))
- {
- if ((botTarget.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_ai! 6\n");
- }
- setorigin (botTarget, botTarget.goalentity.origin);
- self.lefty = (self.lefty | GETGOODY);
- self.goody_time = (time + MOVETYPE_WALK);
- return (TRUE);
- }
- }
- botTarget.goalentity = self.enemy;
- return (FALSE);
- };
- void (float dist) ai_endgetGoody =
- {
- if ((self.lefty & GETGOODY))
- {
- self.lefty = (self.lefty - GETGOODY);
- }
- if ((self.goalentity.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_ai! 7\n");
- }
- setorigin (self.goalentity, self.lastseenpos);
- self.goalentity.goalentity = self.enemy;
- if (enemyvisible (self.enemy))
- {
- self.lastseenpos = self.enemy.origin;
- if ((self.attack_finished < time))
- {
- if ((self.attack_state == AS_MELEE))
- {
- aibot_run_melee ();
- }
- CheckBotAttack ();
- }
- }
- Botmovetogoal (dist);
- };
- void (float dist) ai_botgetGoody =
- {
- local float goody_yaw;
- local float dis;
- local float weap;
- self.search_time = (self.search_time + 0.1);
- if ((time > self.goody_time))
- {
- ai_endgetGoody (dist);
- return;
- }
- if ((self.goalentity.goalentity.solid == SOLID_NOT))
- {
- ai_endgetGoody (dist);
- return;
- }
- if (!Spotvisible (self.goalentity.goalentity))
- {
- if ((self.air_finished > MOVETYPE_FLYMISSILE))
- {
- ai_endgetGoody (dist);
- return;
- }
- }
- goody_yaw = vectoyaw ((self.goalentity.origin - self.origin));
- if (enemyvisible (self.enemy))
- {
- self.lastseenpos = self.enemy.origin;
- weap = W_BestBotWeapon ();
- if ((((self.enemy.items & IT_INVULNERABILITY) || (self.skil < TRUE)) || (weap == IT_AXE)))
- {
- self.ideal_yaw = goody_yaw;
- ChangeYaw ();
- }
- else
- {
- if ((self.attack_finished < time))
- {
- self.ideal_yaw = vectoyaw ((self.enemy.origin - self.origin));
- ChangeYaw ();
- if ((self.attack_state == AS_MELEE))
- {
- aibot_run_melee ();
- }
- CheckBotAttack ();
- }
- }
- }
- if ((self.air_finished < MOVETYPE_TOSS))
- {
- waterupz (SVC_TEMPENTITY);
- return;
- }
- if ((self.flags & FL_SWIM))
- {
- if (waterupdown (dist))
- {
- return;
- }
- }
- dis = vlen ((self.origin - self.goalentity.origin));
- if ((dis > dist))
- {
- dis = dist;
- }
- else
- {
- if ((self.goalentity.goalentity.pathtype == DROPPED))
- {
- ai_endgetGoody (dist);
- return;
- }
- }
- if (botwalkmove (goody_yaw, dis))
- {
- return;
- }
- if (Bot_tryjump (270, dist, FALSE))
- {
- return;
- }
- if ((self.lefty & GETGOODY))
- {
- self.lefty = (self.lefty - GETGOODY);
- }
- if ((self.goalentity.classname != "BotTarget"))
- {
- objerror ("bad bot target in bot_ai! 8\n");
- }
- setorigin (self.goalentity, self.lastseenpos);
- self.goalentity.goalentity = self.enemy;
- };
- void () bot_start = [ 12, bot_walk ]
- {
- local string tmp;
- BotPostThink ();
- droptofloor ();
- self.nextthink = ((time + 0.2) + (0.2 * random ()));
- if ((self.skil < MOVETYPE_WALK))
- {
- self.nextthink = (self.nextthink + (0.1 * (MOVETYPE_WALK - self.skil)));
- }
- };
- void () bot_stand1 = [ 12, bot_walk ]
- {
- ai_botstand ();
- BotPostThink ();
- };
- void () bot_walk = [ 6, bot_walk ]
- {
- self.weaponframe = FALSE;
- if ((self.weapon == IT_AXE))
- {
- if ((self.walkframe == MOVETYPE_TOSS))
- {
- self.walkframe = FALSE;
- }
- self.frame = (FALSE + self.walkframe);
- }
- else
- {
- if ((self.walkframe == MOVETYPE_TOSS))
- {
- self.walkframe = FALSE;
- }
- self.frame = (self.frame + self.walkframe);
- }
- self.walkframe = (self.walkframe + TRUE);
- ai_botseek (BOTSPEED);
- BotPostThink ();
- };
- void () bot_run = [ 6, bot_run ]
- {
- self.weaponframe = FALSE;
- if ((self.weapon == IT_AXE))
- {
- if ((self.walkframe == MOVETYPE_TOSS))
- {
- self.walkframe = FALSE;
- }
- self.frame = (FALSE + self.walkframe);
- }
- else
- {
- if ((self.walkframe == MOVETYPE_TOSS))
- {
- self.walkframe = FALSE;
- }
- self.frame = (self.frame + self.walkframe);
- }
- self.walkframe = (self.walkframe + TRUE);
- ai_botrun (BOTSPEED);
- BotPostThink ();
- };
- void () bot_chase = [ 6, bot_chase ]
- {
- self.weaponframe = FALSE;
- if ((self.weapon == IT_AXE))
- {
- if ((self.walkframe == MOVETYPE_TOSS))
- {
- self.walkframe = FALSE;
- }
- self.frame = (FALSE + self.walkframe);
- }
- else
- {
- if ((self.walkframe == MOVETYPE_TOSS))
- {
- self.walkframe = FALSE;
- }
- self.frame = (self.frame + self.walkframe);
- }
- self.walkframe = (self.walkframe + TRUE);
- aibot_chase (BOTSPEED);
- BotPostThink ();
- };
- void () bot_shot1 = [ 113, bot_shot2 ]
- {
- self.weaponframe = TRUE;
- self.effects = (self.effects | EF_MUZZLEFLASH);
- };
- void () bot_shot2 = [ 114, bot_shot3 ]
- {
- self.weaponframe = FL_SWIM;
- if ((self.skil > 0.9))
- {
- ai_botcharge (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_shot3 = [ 115, bot_shot4 ]
- {
- self.weaponframe = MOVETYPE_WALK;
- if ((self.skil > FALSE))
- {
- ai_botcharge (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_shot4 = [ 116, bot_shot5 ]
- {
- self.weaponframe = MOVETYPE_STEP;
- if ((self.skil > FALSE))
- {
- ai_botcharge (BOTSPEED);
- }
- else
- {
- ai_botcharge ((BOTSPEED * 0.5));
- }
- BotPostThink ();
- };
- void () bot_shot5 = [ 117, bot_shot6 ]
- {
- self.weaponframe = MOVETYPE_FLY;
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_shot6 = [ 118, bot_run ]
- {
- self.weaponframe = MOVETYPE_TOSS;
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_trigger1 = [ 113, bot_trigger2 ]
- {
- self.weaponframe = TRUE;
- self.effects = (self.effects | EF_MUZZLEFLASH);
- };
- void () bot_trigger2 = [ 114, bot_trigger3 ]
- {
- self.weaponframe = FL_SWIM;
- ai_botseek (BOTSPEED);
- BotPostThink ();
- };
- void () bot_trigger3 = [ 115, bot_trigger4 ]
- {
- self.weaponframe = MOVETYPE_WALK;
- ai_botseek (BOTSPEED);
- BotPostThink ();
- };
- void () bot_trigger4 = [ 116, bot_trigger5 ]
- {
- self.weaponframe = MOVETYPE_STEP;
- ai_botseek (BOTSPEED);
- BotPostThink ();
- };
- void () bot_trigger5 = [ 117, bot_trigger6 ]
- {
- self.weaponframe = MOVETYPE_FLY;
- ai_botseek (BOTSPEED);
- BotPostThink ();
- };
- void () bot_trigger6 = [ 118, bot_walk ]
- {
- self.weaponframe = MOVETYPE_TOSS;
- ai_botseek (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axe1 = [ 119, bot_axe2 ]
- {
- self.weaponframe = TRUE;
- };
- void () bot_axe2 = [ 120, bot_axe3 ]
- {
- self.weaponframe = FL_SWIM;
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axe3 = [ 121, bot_axe4 ]
- {
- self.weaponframe = MOVETYPE_WALK;
- W_FireAxe ();
- BotPostThink ();
- };
- void () bot_axe4 = [ 122, bot_run ]
- {
- self.weaponframe = MOVETYPE_STEP;
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axeb1 = [ 125, bot_axeb2 ]
- {
- self.weaponframe = MOVETYPE_FLY;
- };
- void () bot_axeb2 = [ 126, bot_axeb3 ]
- {
- self.weaponframe = MOVETYPE_TOSS;
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axeb3 = [ 127, bot_axeb4 ]
- {
- self.weaponframe = MOVETYPE_PUSH;
- W_FireAxe ();
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axeb4 = [ 128, bot_run ]
- {
- self.weaponframe = FL_CLIENT;
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axec1 = [ 131, bot_axec2 ]
- {
- self.weaponframe = TRUE;
- };
- void () bot_axec2 = [ 132, bot_axec3 ]
- {
- self.weaponframe = FL_SWIM;
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axec3 = [ 133, bot_axec4 ]
- {
- self.weaponframe = MOVETYPE_WALK;
- W_FireAxe ();
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axec4 = [ 134, bot_run ]
- {
- self.weaponframe = MOVETYPE_STEP;
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axed1 = [ 137, bot_axed2 ]
- {
- self.weaponframe = MOVETYPE_FLY;
- };
- void () bot_axed2 = [ 138, bot_axed3 ]
- {
- self.weaponframe = MOVETYPE_TOSS;
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axed3 = [ 139, bot_axed4 ]
- {
- self.weaponframe = MOVETYPE_PUSH;
- W_FireAxe ();
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axed4 = [ 140, bot_run ]
- {
- self.weaponframe = FL_CLIENT;
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () dmbot_melee =
- {
- self.weapon = W_BestBotWeapon ();
- W_BotAttack ();
- };
- void () bot_nail1 = [ 103, bot_nail2 ]
- {
- self.effects = (self.effects | EF_MUZZLEFLASH);
- self.weaponframe = (self.weaponframe + TRUE);
- if ((self.weaponframe == MOVETYPE_FLYMISSILE))
- {
- self.weaponframe = TRUE;
- }
- SuperDamageSound ();
- W_FireSpikes (MOVETYPE_STEP);
- ai_botnailcharge (BOTSPEED);
- self.attack_finished = (time + 0.2);
- BotPostThink ();
- };
- void () bot_nail2 = [ 104, bot_nail1 ]
- {
- self.effects = (self.effects | EF_MUZZLEFLASH);
- self.weaponframe = (self.weaponframe + TRUE);
- if ((self.weaponframe == MOVETYPE_FLYMISSILE))
- {
- self.weaponframe = TRUE;
- }
- SuperDamageSound ();
- W_FireSpikes (CONTENT_SLIME);
- ai_botnailcharge (BOTSPEED);
- self.attack_finished = (time + 0.2);
- BotPostThink ();
- };
- void () bot_light1 = [ 105, bot_light2 ]
- {
- self.effects = (self.effects | EF_MUZZLEFLASH);
- self.weaponframe = (self.weaponframe + TRUE);
- if ((self.weaponframe == MOVETYPE_FLY))
- {
- self.weaponframe = TRUE;
- }
- SuperDamageSound ();
- W_FireLightning ();
- ai_botnailcharge (BOTSPEED);
- self.attack_finished = (time + 0.2);
- BotPostThink ();
- };
- void () bot_light2 = [ 106, bot_light1 ]
- {
- self.effects = (self.effects | EF_MUZZLEFLASH);
- self.weaponframe = (self.weaponframe + TRUE);
- if ((self.weaponframe == MOVETYPE_FLY))
- {
- self.weaponframe = TRUE;
- }
- SuperDamageSound ();
- W_FireLightning ();
- ai_botnailcharge (BOTSPEED);
- self.attack_finished = (time + 0.2);
- BotPostThink ();
- };
- void () bot_rocket1 = [ 107, bot_rocket2 ]
- {
- self.weaponframe = TRUE;
- self.effects = (self.effects | EF_MUZZLEFLASH);
- BotPostThink ();
- };
- void () bot_rocket2 = [ 108, bot_rocket3 ]
- {
- self.weaponframe = FL_SWIM;
- if ((self.skil > FL_SWIM))
- {
- ai_botcharge (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_rocket3 = [ 109, bot_rocket4 ]
- {
- self.weaponframe = MOVETYPE_WALK;
- if ((self.skil > TRUE))
- {
- ai_botcharge (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_rocket4 = [ 110, bot_rocket5 ]
- {
- self.weaponframe = MOVETYPE_STEP;
- if ((self.skil > TRUE))
- {
- ai_botcharge (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_rocket5 = [ 111, bot_rocket6 ]
- {
- self.weaponframe = MOVETYPE_FLY;
- if ((self.skil > FALSE))
- {
- ai_botcharge (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_rocket6 = [ 112, bot_run ]
- {
- self.weaponframe = MOVETYPE_TOSS;
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_rebound1 = [ 107, bot_rebound2 ]
- {
- self.weaponframe = TRUE;
- self.effects = (self.effects | EF_MUZZLEFLASH);
- BotPostThink ();
- };
- void () bot_rebound2 = [ 108, bot_rebound3 ]
- {
- self.weaponframe = FL_SWIM;
- BotPostThink ();
- };
- void () bot_rebound3 = [ 109, bot_rebound4 ]
- {
- self.weaponframe = MOVETYPE_WALK;
- BotPostThink ();
- };
- void () bot_rebound4 = [ 110, bot_rebound5 ]
- {
- self.weaponframe = MOVETYPE_STEP;
- aibot_chase (BOTSPEED);
- BotPostThink ();
- };
- void () bot_rebound5 = [ 111, bot_rebound6 ]
- {
- self.weaponframe = MOVETYPE_FLY;
- aibot_chase (BOTSPEED);
- BotPostThink ();
- };
- void () bot_rebound6 = [ 112, bot_chase ]
- {
- self.weaponframe = MOVETYPE_TOSS;
- aibot_chase (BOTSPEED);
- BotPostThink ();
- };
- void () bot_pain1 = [ 35, bot_pain2 ]
- {
- PainSound ();
- self.weaponframe = FALSE;
- };
- void () bot_pain2 = [ 36, bot_pain3 ]
- {
- local float r;
- r = ((MOVETYPE_STEP * random ()) + self.skil);
- if ((r > FL_SWIM))
- {
- ai_botrun (BOTSPEED);
- }
- else
- {
- ai_botcharge (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_pain3 = [ 37, bot_pain4 ]
- {
- if ((self.skil >= TRUE))
- {
- ai_botrun (BOTSPEED);
- }
- else
- {
- ai_botcharge (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_pain4 = [ 38, bot_pain5 ]
- {
- if ((self.skil > FALSE))
- {
- ai_botrun (BOTSPEED);
- }
- else
- {
- ai_botcharge (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_pain5 = [ 39, bot_pain6 ]
- {
- if ((self.skil > FL_SWIM))
- {
- ai_botrun (BOTSPEED);
- }
- else
- {
- ai_botcharge (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_pain6 = [ 40, bot_run ]
- {
- ai_botrun (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axpain1 = [ 29, bot_axpain2 ]
- {
- PainSound ();
- self.weaponframe = FALSE;
- BotPostThink ();
- };
- void () bot_axpain2 = [ 30, bot_axpain3 ]
- {
- local float r;
- r = ((MOVETYPE_STEP * random ()) + self.skil);
- if ((r > FL_SWIM))
- {
- ai_botrun (BOTSPEED);
- }
- else
- {
- ai_botcharge (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_axpain3 = [ 31, bot_axpain4 ]
- {
- if ((self.skil >= TRUE))
- {
- ai_botrun (BOTSPEED);
- }
- BotPostThink ();
- };
- void () bot_axpain4 = [ 32, bot_axpain5 ]
- {
- ai_botcharge (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axpain5 = [ 33, bot_axpain6 ]
- {
- ai_botrun (BOTSPEED);
- BotPostThink ();
- };
- void () bot_axpain6 = [ 34, bot_run ]
- {
- ai_botrun (BOTSPEED);
- BotPostThink ();
- };
- void () bot_pain =
- {
- if (self.weaponframe)
- {
- return;
- }
- if ((self.invisible_finished > time))
- {
- return;
- }
- if ((self.weapon == IT_AXE))
- {
- bot_axpain1 ();
- }
- else
- {
- bot_pain1 ();
- }
- };
- void () bot_diea1;
- void () bot_dieb1;
- void () bot_diec1;
- void () bot_died1;
- void () bot_diee1;
- void () bot_die_ax1;
- void () BotDead =
- {
- self.nextthink = ((time + 0.3) + ((random () * (NUMBOTS + MOVETYPE_WALK)) * 0.1));
- if (teamplay)
- {
- self.nextthink = (self.nextthink + random ());
- }
- if (TELEFRAGFLAG)
- {
- self.nextthink = (self.nextthink + (MOVETYPE_FLY * random ()));
- TELEFRAGFLAG = FALSE;
- }
- self.think = respawnBot;
- self.deadflag = DEAD_DEAD;
- };
- void () BotDie =
- {
- local float i;
- if ((self.deadflag != DEAD_NO))
- {
- return;
- }
- self.items = (self.items - (self.items & IT_INVISIBILITY));
- self.invisible_finished = FALSE;
- self.invincible_finished = FALSE;
- self.super_damage_finished = FALSE;
- self.radsuit_finished = FALSE;
- self.modelindex = modelindex_player;
- DropBackpack ();
- self.weaponmodel = "";
- self.view_ofs = '0 0 -8';
- self.deadflag = DEAD_DYING;
- self.solid = SOLID_NOT;
- self.flags = (self.flags - (self.flags & FL_ONGROUND));
- self.movetype = MOVETYPE_TOSS;
- if ((self.velocity_z < MOVETYPE_BOUNCE))
- {
- self.velocity_z = (self.velocity_z + (random () * 300));
- }
- if ((self.health < -40))
- {
- GibPlayer ();
- BotDead ();
- return;
- }
- DeathSound ();
- self.angles_x = FALSE;
- self.angles_z = FALSE;
- if ((self.weapon == IT_AXE))
- {
- bot_die_ax1 ();
- return;
- }
- i = cvar ("temp1");
- if (!i)
- {
- i = (TRUE + floor ((random () * MOVETYPE_TOSS)));
- }
- if ((i == TRUE))
- {
- bot_diea1 ();
- }
- else
- {
- if ((i == FL_SWIM))
- {
- bot_dieb1 ();
- }
- else
- {
- if ((i == MOVETYPE_WALK))
- {
- bot_diec1 ();
- }
- else
- {
- if ((i == MOVETYPE_STEP))
- {
- bot_died1 ();
- }
- else
- {
- bot_diee1 ();
- }
- }
- }
- }
- };
- void () bot_diea1 = [ 50, bot_diea2 ]
- {
- };
- void () bot_diea2 = [ 51, bot_diea3 ]
- {
- };
- void () bot_diea3 = [ 52, bot_diea4 ]
- {
- };
- void () bot_diea4 = [ 53, bot_diea5 ]
- {
- };
- void () bot_diea5 = [ 54, bot_diea6 ]
- {
- };
- void () bot_diea6 = [ 55, bot_diea7 ]
- {
- };
- void () bot_diea7 = [ 56, bot_diea8 ]
- {
- };
- void () bot_diea8 = [ 57, bot_diea9 ]
- {
- };
- void () bot_diea9 = [ 58, bot_diea10 ]
- {
- };
- void () bot_diea10 = [ 59, bot_diea11 ]
- {
- };
- void () bot_diea11 = [ 60, bot_diea11 ]
- {
- BotDead ();
- };
- void () bot_dieb1 = [ 61, bot_dieb2 ]
- {
- };
- void () bot_dieb2 = [ 62, bot_dieb3 ]
- {
- };
- void () bot_dieb3 = [ 63, bot_dieb4 ]
- {
- };
- void () bot_dieb4 = [ 64, bot_dieb5 ]
- {
- };
- void () bot_dieb5 = [ 65, bot_dieb6 ]
- {
- };
- void () bot_dieb6 = [ 66, bot_dieb7 ]
- {
- };
- void () bot_dieb7 = [ 67, bot_dieb8 ]
- {
- };
- void () bot_dieb8 = [ 68, bot_dieb9 ]
- {
- };
- void () bot_dieb9 = [ 69, bot_dieb9 ]
- {
- BotDead ();
- };
- void () bot_diec1 = [ 70, bot_diec2 ]
- {
- };
- void () bot_diec2 = [ 71, bot_diec3 ]
- {
- };
- void () bot_diec3 = [ 72, bot_diec4 ]
- {
- };
- void () bot_diec4 = [ 73, bot_diec5 ]
- {
- };
- void () bot_diec5 = [ 74, bot_diec6 ]
- {
- };
- void () bot_diec6 = [ 75, bot_diec7 ]
- {
- };
- void () bot_diec7 = [ 76, bot_diec8 ]
- {
- };
- void () bot_diec8 = [ 77, bot_diec9 ]
- {
- };
- void () bot_diec9 = [ 78, bot_diec10 ]
- {
- };
- void () bot_diec10 = [ 79, bot_diec11 ]
- {
- };
- void () bot_diec11 = [ 80, bot_diec12 ]
- {
- };
- void () bot_diec12 = [ 81, bot_diec13 ]
- {
- };
- void () bot_diec13 = [ 82, bot_diec14 ]
- {
- };
- void () bot_diec14 = [ 83, bot_diec15 ]
- {
- };
- void () bot_diec15 = [ 84, bot_diec15 ]
- {
- BotDead ();
- };
- void () bot_died1 = [ 85, bot_died2 ]
- {
- };
- void () bot_died2 = [ 86, bot_died3 ]
- {
- };
- void () bot_died3 = [ 87, bot_died4 ]
- {
- };
- void () bot_died4 = [ 88, bot_died5 ]
- {
- };
- void () bot_died5 = [ 89, bot_died6 ]
- {
- };
- void () bot_died6 = [ 90, bot_died7 ]
- {
- };
- void () bot_died7 = [ 91, bot_died8 ]
- {
- };
- void () bot_died8 = [ 92, bot_died9 ]
- {
- };
- void () bot_died9 = [ 93, bot_died9 ]
- {
- BotDead ();
- };
- void () bot_diee1 = [ 94, bot_diee2 ]
- {
- };
- void () bot_diee2 = [ 95, bot_diee3 ]
- {
- };
- void () bot_diee3 = [ 96, bot_diee4 ]
- {
- };
- void () bot_diee4 = [ 97, bot_diee5 ]
- {
- };
- void () bot_diee5 = [ 98, bot_diee6 ]
- {
- };
- void () bot_diee6 = [ 99, bot_diee7 ]
- {
- };
- void () bot_diee7 = [ 100, bot_diee8 ]
- {
- };
- void () bot_diee8 = [ 101, bot_diee9 ]
- {
- };
- void () bot_diee9 = [ 102, bot_diee9 ]
- {
- BotDead ();
- };
- void () bot_die_ax1 = [ 41, bot_die_ax2 ]
- {
- };
- void () bot_die_ax2 = [ 42, bot_die_ax3 ]
- {
- };
- void () bot_die_ax3 = [ 43, bot_die_ax4 ]
- {
- };
- void () bot_die_ax4 = [ 44, bot_die_ax5 ]
- {
- };
- void () bot_die_ax5 = [ 45, bot_die_ax6 ]
- {
- };
- void () bot_die_ax6 = [ 46, bot_die_ax7 ]
- {
- };
- void () bot_die_ax7 = [ 47, bot_die_ax8 ]
- {
- };
- void () bot_die_ax8 = [ 48, bot_die_ax9 ]
- {
- };
- void () bot_die_ax9 = [ 49, bot_die_ax9 ]
- {
- BotDead ();
- };
- void () t_botpath =
- {
- if ((other.classname != "dmbot"))
- {
- return;
- }
- if ((other.movetarget == self))
- {
- return;
- }
- bot_toucheditem ();
- addTarget (other.movetarget.movetarget, self);
- other.movetarget.movetarget = self;
- };
- entity () botpath =
- {
- local entity targ;
- targ = spawn ();
- targ.classname = "BotPath";
- targ.solid = SOLID_TRIGGER;
- targ.movetarget = world;
- targ.touch = t_botpath;
- setsize (targ, '-4 -4 -4', '4 4 4');
- return (targ);
- };
- float (entity a, entity b) IsUpstream =
- {
- if ((b.movetarget == a))
- {
- return (TRUE);
- }
- if ((b.movetarget2 == a))
- {
- return (TRUE);
- }
- if ((b.movetarget3 == a))
- {
- return (TRUE);
- }
- if ((b.movetarget4 == a))
- {
- return (TRUE);
- }
- if ((b.movetarget5 == a))
- {
- return (TRUE);
- }
- if ((b.movetarget6 == a))
- {
- return (TRUE);
- }
- return (FALSE);
- };
- void (entity node, entity targ, float len, entity item) cacheRouteTarget;
- void (entity a, entity b, float recurse) updateRouteCache =
- {
- RECURSEDEPTH = recurse;
- if ((b.rocketlen > FALSE))
- {
- cacheRouteTarget (b, a, b.rocketlen, b.rocketcache);
- }
- if ((b.lightninglen > FALSE))
- {
- cacheRouteTarget (b, a, b.lightninglen, b.lightningcache);
- }
- if ((b.armorlen > FALSE))
- {
- cacheRouteTarget (b, a, b.armorlen, b.armorcache);
- }
- if ((b.poweruplen > FALSE))
- {
- cacheRouteTarget (b, a, b.poweruplen, b.powerupcache);
- }
- if ((b.naillen > FALSE))
- {
- cacheRouteTarget (b, a, b.naillen, b.nailcache);
- }
- if ((b.grenadelen > FALSE))
- {
- cacheRouteTarget (b, a, b.grenadelen, b.grenadecache);
- }
- };
- void (entity a, entity b) addTarget =
- {
- if ((a == b))
- {
- return;
- }
- if ((b.movetarget == a))
- {
- return;
- }
- if (!a)
- {
- return;
- }
- else
- {
- if ((b.movetarget2 == a))
- {
- updateRouteCache (a, b, FL_INWATER);
- return;
- }
- else
- {
- if ((b.movetarget3 == a))
- {
- updateRouteCache (a, b, FL_INWATER);
- return;
- }
- else
- {
- if ((b.movetarget4 == a))
- {
- updateRouteCache (a, b, FL_INWATER);
- return;
- }
- else
- {
- if ((b.movetarget5 == a))
- {
- updateRouteCache (a, b, FL_INWATER);
- return;
- }
- else
- {
- if ((b.movetarget6 == a))
- {
- updateRouteCache (a, b, FL_INWATER);
- return;
- }
- }
- }
- }
- }
- }
- if (!b.movetarget)
- {
- b.movetarget = a;
- }
- else
- {
- if (!b.movetarget2)
- {
- b.movetarget2 = a;
- }
- else
- {
- if (!b.movetarget3)
- {
- b.movetarget3 = a;
- }
- else
- {
- if (!b.movetarget4)
- {
- b.movetarget4 = a;
- }
- else
- {
- if (!b.movetarget5)
- {
- b.movetarget5 = a;
- }
- else
- {
- if (!b.movetarget6)
- {
- b.movetarget6 = a;
- }
- }
- }
- }
- }
- }
- updateRouteCache (a, b, MOVETYPE_BOUNCE);
- };
- float () FindAPath;
- float () FindAltPath =
- {
- local entity e;
- local entity carriedPath;
- local entity bestPath;
- local float dropPath;
- local float bestrng;
- local float rng;
- if ((self.lefty & NODROP))
- {
- self.lefty = (self.lefty - NODROP);
- return (FindAPath ());
- }
- e = findradius (self.origin, SEARCH_RADIUS);
- bestrng = 1000;
- dropPath = TRUE;
- carriedPath = self.movetarget;
- bestPath = carriedPath.movetarget;
- while (e)
- {
- if ((e.pathtype == DROPPED))
- {
- rng = vlen ((e.origin - self.origin));
- if ((rng < bestrng))
- {
- if (BotReachable (e, self))
- {
- if (BotReachable (carriedPath.movetarget, e))
- {
- addTarget (carriedPath.movetarget, e);
- bestPath = e;
- bestrng = rng;
- dropPath = FALSE;
- }
- }
- }
- }
- e = e.chain;
- }
- carriedPath.movetarget = bestPath;
- return (dropPath);
- };
- float () FindAPath =
- {
- local float dropPath;
- local float bestrng;
- local float rng;
- local entity e;
- local entity carriedPath;
- local entity bestPath;
- carriedPath = self.movetarget;
- dropPath = TRUE;
- e = findradius (self.origin, SEARCH_RADIUS);
- bestrng = 1000;
- bestPath = carriedPath.movetarget;
- while (e)
- {
- if ((e.pathtype == DROPPED))
- {
- rng = vlen ((e.origin - self.origin));
- if ((rng < bestrng))
- {
- if (BotReachable (e, self))
- {
- addTarget (carriedPath.movetarget, e);
- bestPath = e;
- bestrng = rng;
- dropPath = FALSE;
- }
- }
- }
- e = e.chain;
- }
- carriedPath.movetarget = bestPath;
- return (dropPath);
- };
- float () CheckDropPath =
- {
- local entity carriedPath;
- local entity upstreamPath;
- local float rng;
- local float lnd;
- local float OK_HIGH;
- local string tmp;
- if ((NUMPATHS > 160))
- {
- return (FALSE);
- }
- carriedPath = self.movetarget;
- upstreamPath = carriedPath.movetarget;
- lnd = pointcontents (carriedPath.origin);
- if ((lnd == CONTENT_EMPTY))
- {
- rng = dropline (carriedPath.origin);
- if ((rng < (carriedPath.origin_z - SVC_FOUNDSECRET)))
- {
- if (!(carriedPath.flags & (FL_ONGROUND + FL_INWATER)))
- {
- return (FALSE);
- }
- }
- lnd = pointcontents (((carriedPath.origin + self.mins) + '0 0 1'));
- if ((lnd != CONTENT_EMPTY))
- {
- if ((lnd != CONTENT_WATER))
- {
- self.lefty = (self.lefty | NODROP);
- return (FALSE);
- }
- }
- }
- else
- {
- if ((lnd != CONTENT_WATER))
- {
- self.lefty = (self.lefty | NODROP);
- return (FALSE);
- }
- }
- if (((trace_ent.classname == "plat") || (trace_ent.classname == "train")))
- {
- if (trace_ent.think)
- {
- self.lefty = (self.lefty | NODROP);
- return (FALSE);
- }
- }
- if ((self.teleport_time > time))
- {
- self.lefty = (self.lefty | NODROP);
- if ((self.teleport_time > (time + 0.5)))
- {
- return (FALSE);
- }
- if ((self.lefty & NODROP))
- {
- self.lefty = (self.lefty - NODROP);
- }
- return (FindAPath ());
- }
- if (!upstreamPath)
- {
- return (FindAPath ());
- }
- if (!BotReachable (upstreamPath, self))
- {
- if ((upstreamPath.origin_z > (self.origin_z + MAXJUMP)))
- {
- return (FindAPath ());
- }
- return (FindAltPath ());
- }
- return (FALSE);
- };
- void () NewCarriedPath =
- {
- self.movetarget = botpath ();
- self.movetarget.pathtype = CARRIED;
- setorigin (self.movetarget, self.origin);
- };
- void () DropBotPath =
- {
- local string tmp;
- local entity oldpath;
- local float drop;
- oldpath = self.movetarget;
- if (oldpath.movetarget)
- {
- if ((oldpath.origin_z > ((oldpath.movetarget.origin_z + (MAXJUMP * 0.6)) - TRUE)))
- {
- drop = (((oldpath.movetarget.origin_z - oldpath.origin_z) + (MAXJUMP * 0.6)) - TRUE);
- if ((drop < (self.mins_z + FL_SWIM)))
- {
- drop = (self.mins_z + FL_SWIM);
- }
- oldpath.origin_z = (oldpath.origin_z + drop);
- }
- }
- NewCarriedPath ();
- oldpath.pathtype = DROPPED;
- self.movetarget.movetarget = oldpath;
- NUMPATHS = (NUMPATHS + TRUE);
- };
- void (entity node, float len, entity item) cacheRouteMsg;
- void (entity node, entity targ, float len, entity item) cacheRouteTarget =
- {
- local float rng;
- rng = vlen ((node.origin - targ.origin));
- if ((targ.pathtype == TELEPORT))
- {
- rng = 250;
- }
- rng = ((rng + len) + KINDA_WANT);
- RECURSEDEPTH = (RECURSEDEPTH + FL_SWIM);
- if ((RECURSEDEPTH < 24))
- {
- cacheRouteMsg (targ, rng, item);
- }
- else
- {
- node.endpoint = TRUE;
- }
- RECURSEDEPTH = (RECURSEDEPTH - FL_SWIM);
- };
- void (entity node, entity targ, float len, entity item) cacheRoute =
- {
- RECURSEDEPTH = TRUE;
- cacheRouteTarget (node, targ, len, item);
- if ((other.classname == "dmbot"))
- {
- if ((other.rocketcache == item))
- {
- clearCache (other);
- }
- else
- {
- if ((other.lightningcache == item))
- {
- clearCache (other);
- }
- else
- {
- if ((other.armorcache == item))
- {
- clearCache (other);
- }
- else
- {
- if ((other.powerupcache == item))
- {
- clearCache (other);
- }
- else
- {
- if ((other.nailcache == item))
- {
- clearCache (other);
- }
- else
- {
- if ((other.grenadecache == item))
- {
- clearCache (other);
- }
- }
- }
- }
- }
- }
- }
- };
- void (entity node, float len, entity item) cacheRouteMsg =
- {
- if (item.th_cache)
- {
- if (!item.th_cache (node, len, item))
- {
- return;
- }
- }
- else
- {
- return;
- }
- if (node.movetarget)
- {
- cacheRouteTarget (node, node.movetarget, len, item);
- }
- if (node.movetarget2)
- {
- cacheRouteTarget (node, node.movetarget2, len, item);
- }
- if (node.movetarget3)
- {
- cacheRouteTarget (node, node.movetarget3, len, item);
- }
- if (node.movetarget4)
- {
- cacheRouteTarget (node, node.movetarget4, len, item);
- }
- if (node.movetarget5)
- {
- cacheRouteTarget (node, node.movetarget5, len, item);
- }
- if (node.movetarget6)
- {
- cacheRouteTarget (node, node.movetarget6, len, item);
- }
- };
- void (entity e) clearCache =
- {
- e.rocketcache = world;
- e.lightningcache = world;
- e.armorcache = world;
- e.nailcache = world;
- e.grenadecache = world;
- e.powerupcache = world;
- e.rocketlen = FALSE;
- e.lightninglen = FALSE;
- e.armorlen = FALSE;
- e.naillen = FALSE;
- e.grenadelen = FALSE;
- e.poweruplen = FALSE;
- e.endpoint = FALSE;
- };
- void (entity en) RouteToEnemy =
- {
- local entity e;
- RECURSEDEPTH = FL_CLIENT;
- e = find (world, classname, "BotPath");
- while (e)
- {
- e.enemycache = world;
- e.endpoint = FALSE;
- e = find (e, classname, "BotPath");
- }
- if (en.movetarget)
- {
- if (en.movetarget.movetarget)
- {
- cacheRouteTarget (en.movetarget, en.movetarget.movetarget, FALSE, en);
- e = find (world, classname, "BotPath");
- while (e)
- {
- if (e.endpoint)
- {
- if ((e.enemycache == en))
- {
- RECURSEDEPTH = FL_CLIENT;
- if (e.movetarget)
- {
- cacheRouteTarget (e, e.movetarget, e.enemylen, en);
- }
- if (e.movetarget2)
- {
- cacheRouteTarget (e, e.movetarget2, e.enemylen, en);
- }
- if (e.movetarget3)
- {
- cacheRouteTarget (e, e.movetarget3, e.enemylen, en);
- }
- if (e.movetarget4)
- {
- cacheRouteTarget (e, e.movetarget4, e.enemylen, en);
- }
- if (e.movetarget5)
- {
- cacheRouteTarget (e, e.movetarget5, e.enemylen, en);
- }
- if (e.movetarget6)
- {
- cacheRouteTarget (e, e.movetarget6, e.enemylen, en);
- }
- }
- }
- e = find (e, classname, "BotPath");
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement