diff --git a/source/src/bot/ac_bot.cpp b/source/src/bot/ac_bot.cpp index f3886e2d..f76bf35a 100644 --- a/source/src/bot/ac_bot.cpp +++ b/source/src/bot/ac_bot.cpp @@ -73,97 +73,7 @@ void CACBot::Spawn() void CACBot::CheckItemPickup() { - if(editmode) return; - loopv(ents) - { - entity &e = ents[i]; - if(e.type==NOTUSED) continue; - - if (!e.spawned) continue; - if (sents.inrange(i) && (!sents[i].spawned)) continue; - - if(OUTBORD(e.x, e.y)) continue; - vec v(e.x, e.y, S(e.x, e.y)->floor+m_pMyEnt->eyeheight); - - if(v.dist(m_pMyEnt->o)<2.5) - { - PickUp(i); - } - } -} - -void CACBot::PickUp(int n) -{ - int np = 1; - loopv(players) if(players[i]) np++; - np = np<3 ? 4 : (np>4 ? 2 : 3); // spawn times are dependent on number of players - int ammo = np*2; - switch(ents[n].type) - { - case I_AMMO: AddItem(n, m_pMyEnt->ammo[m_pMyEnt->primary], ammo, m_pMyEnt->primary); break; - case I_CLIPS: AddItem(n, m_pMyEnt->ammo[GUN_PISTOL], ammo, GUN_PISTOL); break; - case I_GRENADE: AddItem(n, m_pMyEnt->ammo[GUN_GRENADE], ammo, 6); break; - case I_HEALTH: AddItem(n, m_pMyEnt->health, ammo, 7); break; - case I_ARMOUR: AddItem(n, m_pMyEnt->armour, ammo, 8); break; - -/* case I_HELMET: - // (100h/100g only absorbs 166 damage) - if(m_pMyEnt->armourtype==A_YELLOW && m_pMyEnt->armour>66) break; - AddItem(n, m_pMyEnt->armour, 20); - break; - - case I_ARMOUR: - AddItem(n, m_pMyEnt->armour, 20); - break; - - case OBJ_ITEM: - AddItem(n, m_pMyEnt->quadmillis, 60); - break;*/ - -/* case TRIGGER: - ents[n].spawned = false; - triggertime = lastmillis; - trigger(ents[n].attr1, ents[n].attr2, false); // needs to go over server for multiplayer - - // HACK: Reset ent goal if bot was looking for this ent - if (m_pTargetEnt == &ents[n]) - { - m_pTargetEnt = NULL; - m_vGoal = g_vecZero; - ResetWaypointVars(); - m_iCheckEntsDelay = lastmillis + RandomLong(5000, 10000); - } - - BotManager.PickNextTrigger(); - break;*/ - }; -}; - -void CACBot::AddItem(int i, int &v, int spawnsec, int t) -{ - if((i>=sents.length()) || (!sents[i].spawned)) - return; - -//fixmebot - if(v>=itemstats[t].max) // don't pick up if not needed - return; - - itemstat &is = itemstats[t]; - ents[i].spawned = false; - v += is.add; - if(v>is.max) v = is.max; - playsound(is.sound, &m_pMyEnt->o); - sents[i].spawned = false; - sents[i].spawnsecs = spawnsec; - - // HACK: Reset ent goal if bot was looking for for this ent - if (m_pTargetEnt == &ents[i]) - { - m_pTargetEnt = NULL; - m_vGoal = g_vecZero; - ResetWaypointVars(); - m_iCheckEntsDelay = lastmillis + RandomLong(5000, 10000); - }; + checkitems(m_pMyEnt); } // AC Bot class end diff --git a/source/src/bot/ac_bot.h b/source/src/bot/ac_bot.h index cbf83421..858874f5 100644 --- a/source/src/bot/ac_bot.h +++ b/source/src/bot/ac_bot.h @@ -24,8 +24,6 @@ public: friend class CWaypointClass; virtual void CheckItemPickup(void); - virtual void PickUp(int n); - virtual void AddItem(int i, int &v, int spawnsec, int t); // AI Functions virtual bool ChoosePreferredWeapon(void); diff --git a/source/src/bot/ac_bot_ai.cpp b/source/src/bot/ac_bot_ai.cpp index 7ce0a016..57ace81b 100644 --- a/source/src/bot/ac_bot_ai.cpp +++ b/source/src/bot/ac_bot_ai.cpp @@ -127,7 +127,7 @@ entity *CACBot::SearchForEnts(bool bUseWPs, float flRange, float flMaxHeight) bool bInteresting = false; short sAmmo = 0, sMaxAmmo = 0; - //fixmebot + switch(e.type) { case I_CLIPS: @@ -140,10 +140,10 @@ entity *CACBot::SearchForEnts(bool bUseWPs, float flRange, float flMaxHeight) bInteresting = (m_pMyEnt->ammo[m_pMyEnt->primary]ammo[m_pMyEnt->primary]; break; - case I_GRENADE: + case I_GRENADE: sMaxAmmo = itemstats[GUN_GRENADE].max; - bInteresting = (m_pMyEnt->ammo[GUN_GRENADE]ammo[GUN_GRENADE]; + bInteresting = (m_pMyEnt->mag[GUN_GRENADE]mag[GUN_GRENADE]; break; case I_HEALTH: sMaxAmmo = itemstats[7].max; //FIXME diff --git a/source/src/bot/bot.h b/source/src/bot/bot.h index 312049f4..956f0b9d 100644 --- a/source/src/bot/bot.h +++ b/source/src/bot/bot.h @@ -231,8 +231,6 @@ public: float ChangeAngle(float speed, float ideal, float current); bool SelectGun(int Gun); virtual void CheckItemPickup(void) = 0; - virtual void PickUp(int n) = 0; - virtual void AddItem(int i, int &v, int spawnsec, int t) = 0; void SendBotInfo(void); float GetDistance(const vec &o); float GetDistance(const vec &v1, const vec &v2); diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 6d6dcc75..c81db655 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -278,7 +278,7 @@ void updateworld(int curtime, int lastmillis) // main game update loop else if(!intermission) { moveplayer(player1, 20, true); - checkitems(); + checkitems(player1); }; c2sinfo(player1); // do this last, to reduce the effective frame lag }; diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 31a17c72..6876ae45 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -59,7 +59,7 @@ void renderentities() if(e.type!=CARROT) { if(!e.spawned) continue; - if(e.typeI_AKIMBO) continue; + if(!isitem(e.type)) continue; renderent(e, entmdlnames[e.type-I_CLIPS], (float)(1+sinf(lastmillis/100.0f+e.x+e.y)/20), lastmillis/10.0f); } else switch(e.attr2) @@ -100,13 +100,13 @@ void baseammo(int gun, playerent *d) { d->ammo[gun] = itemstats[gun].add*2; }; // these two functions are called when the server acknowledges that you really // picked up the item (in multiplayer someone may grab it before you). -void equipitem(int i, int &v, int t) +void equipitem(playerent *d, int i, int &v, int t) { itemstat &is = itemstats[t]; ents[i].spawned = false; v += is.add; if(v>is.max) v = is.max; - playsoundc(is.sound); + playsound(is.sound, &d->o); }; void realpickup(int n, playerent *d) @@ -114,40 +114,40 @@ void realpickup(int n, playerent *d) switch(ents[n].type) { case I_CLIPS: - equipitem(n, d->ammo[1], 1); + equipitem(d, n, d->ammo[1], 1); break; case I_AMMO: - equipitem(n, d->ammo[d->primary], d->primary); + equipitem(d, n, d->ammo[d->primary], d->primary); break; case I_GRENADE: - equipitem(n, d->mag[6], 6); + equipitem(d, n, d->mag[6], 6); player1->thrownademillis = 0; break; case I_HEALTH: - equipitem(n, d->health, 7); + equipitem(d, n, d->health, 7); break; case I_ARMOUR: - equipitem(n, d->armour, 8); - //d->hasarmour = true; + equipitem(d, n, d->armour, 8); break; case I_AKIMBO: d->akimbomillis = lastmillis+30000; d->mag[GUN_PISTOL] = 16; - equipitem(n, d->ammo[1], 9); - weaponswitch(GUN_PISTOL); + equipitem(d, n, d->ammo[1], 9); + if(d==player1) weaponswitch(GUN_PISTOL); break; }; }; // these functions are called when the client touches the item -void additem(int i, int &v, int spawnsec, int t) +void additem(playerent *d, int i, int &v, int spawnsec, int t) { - if(vtype==ENT_PLAYER) addmsg(SV_ITEMPICKUP, "rii", i, spawnsec); + else if(d->type==ENT_BOT && serverpickup(i, spawnsec, -1)) realpickup(i, d); + ents[i].spawned = false; + }; }; void pickup(int n, playerent *d) @@ -159,20 +159,20 @@ void pickup(int n, playerent *d) switch(ents[n].type) { case I_CLIPS: - additem(n, d->ammo[1], ammo, 1); + additem(d, n, d->ammo[1], ammo, 1); break; case I_AMMO: - additem(n, d->ammo[d->primary], ammo, d->primary); + additem(d, n, d->ammo[d->primary], ammo, d->primary); break; - case I_GRENADE: additem(n, d->mag[6], ammo, 6); break; - case I_HEALTH: additem(n, d->health, np*5, 7); break; + case I_GRENADE: additem(d, n, d->mag[6], ammo, 6); break; + case I_HEALTH: additem(d, n, d->health, np*5, 7); break; case I_ARMOUR: - additem(n, d->armour, 20, 8); + additem(d, n, d->armour, 20, 8); break; case I_AKIMBO: - additem(n, d->akimbo, 60, 9); + additem(d, n, d->akimbo, 60, 9); break; case CARROT: @@ -182,17 +182,16 @@ void pickup(int n, playerent *d) break; case LADDER: - { d->onladder = true; break; - }; // EDIT: AH case CTF_FLAG: { + if(d->type!=ENT_PLAYER) break; int team = ents[n].attr2; flaginfo &f = flaginfos[team]; - bool isownflag = team == rb_team_int(player1->team); + bool isownflag = team == rb_team_int(d->team); if(f.state == CTFF_STOLEN) break; else if(isownflag && f.state == CTFF_DROPPED) { @@ -203,20 +202,20 @@ void pickup(int n, playerent *d) { addmsg(SV_FLAGPICKUP, "ri", team); ents[n].spawned = false; - f.actor = player1; // do this although we don't know if we picked the flag to avoid getting it after a possible respawn + f.actor = d; // do this although we don't know if we picked the flag to avoid getting it after a possible respawn f.state = CTFF_STOLEN; f.pick_ack = false; } - else if(isownflag && f.state == CTFF_INBASE && flaginfos[rb_opposite(team)].state == CTFF_STOLEN && flaginfos[rb_opposite(team)].actor == player1) addmsg(SV_FLAGSCORE, "ri", rb_opposite(team)); + else if(isownflag && f.state == CTFF_INBASE && flaginfos[rb_opposite(team)].state == CTFF_STOLEN && flaginfos[rb_opposite(team)].actor == d) addmsg(SV_FLAGSCORE, "ri", rb_opposite(team)); break; }; }; }; -void checkitems() +void checkitems(playerent *d) { if(editmode) return; - player1->onladder = false; + d->onladder = false; loopv(ents) { entity &e = ents[i]; @@ -224,23 +223,23 @@ void checkitems() if(e.type==LADDER) { if(OUTBORD(e.x, e.y)) continue; - vec v(e.x, e.y, player1->o.z); - float dist1 = player1->o.dist(v); - float dist2 = player1->o.z - (S(e.x, e.y)->floor+player1->eyeheight); - if(dist1<1.5f && dist2o.z); + float dist1 = d->o.dist(v); + float dist2 = d->o.z - (S(e.x, e.y)->floor+d->eyeheight); + if(dist1<1.5f && dist2floor+player1->eyeheight); - if(player1->o.dist(v)<2.5f) pickup(i, player1); + vec v(e.x, e.y, S(e.x, e.y)->floor+d->eyeheight); + if(d->o.dist(v)<2.5f) pickup(i, d); }; }; void putitems(ucharbuf &p) // puts items in network stream and also spawns them locally { - loopv(ents) if((ents[i].type>=I_CLIPS && ents[i].type<=I_AKIMBO) || ents[i].type==CARROT) + loopv(ents) if(isitem(ents[i].type) || ents[i].type==CARROT) { if(m_noitemsnade && ents[i].type!=I_GRENADE) continue; else if(m_pistol && ents[i].type==I_AMMO) continue; @@ -250,7 +249,7 @@ void putitems(ucharbuf &p) // puts items in network stream and also s }; void resetspawns() -{ +{ loopv(ents) ents[i].spawned = false; if(m_noitemsnade || m_pistol) loopv(ents) diff --git a/source/src/entity.h b/source/src/entity.h index c9b44032..8acae65c 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -12,6 +12,8 @@ enum // static entity types MAXENTTYPES }; +#define isitem(i) (i >= I_CLIPS && i <= I_AKIMBO) + struct persistent_entity // map entity { short x, y, z; // cube aligned position diff --git a/source/src/physics.cpp b/source/src/physics.cpp index 4ca79647..ab8472b5 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -218,10 +218,13 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) { if(pl->onladder) { - if(pl->type==ENT_PLAYER || pl->type==ENT_BOT) + const float climbspeed = 1.0f; + + if(pl->type==ENT_BOT) pl->vel.z = climbspeed; // bots climb upwards only + else if(pl->type==ENT_PLAYER) { - if(((playerent *)pl)->k_up) pl->vel.z = 1.0f; - else if(((playerent *)pl)->k_down) pl->vel.z = -1.0f; + if(((playerent *)pl)->k_up) pl->vel.z = climbspeed; + else if(((playerent *)pl)->k_down) pl->vel.z = -climbspeed; }; pl->timeinair = 0; } diff --git a/source/src/protos.h b/source/src/protos.h index 3224ceec..2003139a 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -266,9 +266,9 @@ extern void serverms(int mode, int numplayers, int minremain, char *smapname, in extern void servermsinit(const char *master, char *sdesc, bool listen); extern void sendmaps(int n, string mapname, int mapsize, uchar *mapdata); extern ENetPacket *recvmap(int n); +extern bool serverpickup(uint i, int sec, int sender); // weapon -//extern void selectgun(int a = -1, int b = -1, int c =-1); extern void shoot(playerent *d, vec &to); extern void shootv(int gun, vec &from, vec &to, playerent *d = 0, bool local = false, int nademillis=0); extern void createrays(vec &from, vec &to); @@ -299,7 +299,7 @@ extern void renderentities(); extern void resetspawns(); extern void setspawn(int i, bool on); extern void baseammo(int gun, playerent *d); -extern void checkitems(); +extern void checkitems(playerent *d); extern void equip(playerent *d); extern bool intersect(entity *e, vec &from, vec &to, vec *end=NULL); diff --git a/source/src/server.cpp b/source/src/server.cpp index 0068bcb6..946abf28 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -337,18 +337,19 @@ void disconnect_client(int n, int reason = -1) void resetitems() { sents.setsize(0); notgotitems = true; }; -void pickup(uint i, int sec, int sender) // server side item pickup, acknowledge first client that gets it +bool serverpickup(uint i, int sec, int sender) // server side item pickup, acknowledge first client that gets it { - if(i>=(uint)sents.length()) return; + if(i>=(uint)sents.length()) return false; if(sents[i].spawned) { sents[i].spawned = false; sents[i].spawnsecs = sec; - sendf(sender, 1, "rii", SV_ITEMACC, i); + if(sender>=0) sendf(sender, 1, "rii", SV_ITEMACC, i); + return true; }; + return false; }; -// EDIT: AH struct configset { string mapname; @@ -660,7 +661,7 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 case SV_ITEMPICKUP: { int n = getint(p); - pickup(n, getint(p), sender); + serverpickup(n, getint(p), sender); QUEUE_MSG; break; };