diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 2efaf00ff..8ad152843 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -322,7 +322,6 @@ void CHARACTER::fire_weapon() projectile_startpos, direction, (int)(server_tickspeed()*tuning.gun_lifetime), - this, 1, 0, 0, -1, WEAPON_GUN); // pack the projectile and send it to the client directly @@ -358,7 +357,6 @@ void CHARACTER::fire_weapon() projectile_startpos, vec2(cosf(a), sinf(a))*speed, (int)(server_tickspeed()*tuning.shotgun_lifetime), - this, 1, 0, 0, -1, WEAPON_SHOTGUN); // pack the projectile and send it to the client directly @@ -382,7 +380,6 @@ void CHARACTER::fire_weapon() projectile_startpos, direction, (int)(server_tickspeed()*tuning.grenade_lifetime), - this, 1, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE); // pack the projectile and send it to the client directly @@ -401,7 +398,7 @@ void CHARACTER::fire_weapon() case WEAPON_RIFLE: { - new LASER(pos, direction, tuning.laser_reach, this); + new LASER(pos, direction, tuning.laser_reach, player->client_id); game.create_sound(pos, SOUND_RIFLE_FIRE); } break; diff --git a/src/game/server/entities/laser.cpp b/src/game/server/entities/laser.cpp index 8b512d824..20054ed4c 100644 --- a/src/game/server/entities/laser.cpp +++ b/src/game/server/entities/laser.cpp @@ -7,7 +7,7 @@ ////////////////////////////////////////////////// // laser ////////////////////////////////////////////////// -LASER::LASER(vec2 pos, vec2 direction, float start_energy, CHARACTER *owner) +LASER::LASER(vec2 pos, vec2 direction, float start_energy, int owner) : ENTITY(NETOBJTYPE_LASER) { this->pos = pos; @@ -24,14 +24,15 @@ LASER::LASER(vec2 pos, vec2 direction, float start_energy, CHARACTER *owner) bool LASER::hit_character(vec2 from, vec2 to) { vec2 at; - CHARACTER *hit = game.world.intersect_character(pos, to, 0.0f, at, owner); + CHARACTER *owner_char = game.get_player_char(owner); + CHARACTER *hit = game.world.intersect_character(pos, to, 0.0f, at, owner_char); if(!hit) return false; this->from = from; pos = at; energy = -1; - hit->take_damage(vec2(0,0), tuning.laser_damage, owner->player->client_id, WEAPON_RIFLE); + hit->take_damage(vec2(0,0), tuning.laser_damage, owner, WEAPON_RIFLE); return true; } diff --git a/src/game/server/entities/laser.hpp b/src/game/server/entities/laser.hpp index 4842b3f87..aa4c22843 100644 --- a/src/game/server/entities/laser.hpp +++ b/src/game/server/entities/laser.hpp @@ -14,14 +14,14 @@ class LASER : public ENTITY float energy; int bounces; int eval_tick; - CHARACTER *owner; + int owner; bool hit_character(vec2 from, vec2 to); void do_bounce(); public: - LASER(vec2 pos, vec2 direction, float start_energy, CHARACTER *owner); + LASER(vec2 pos, vec2 direction, float start_energy, int owner); virtual void reset(); virtual void tick(); diff --git a/src/game/server/entities/projectile.cpp b/src/game/server/entities/projectile.cpp index cd15ba10c..e0b4701ab 100644 --- a/src/game/server/entities/projectile.cpp +++ b/src/game/server/entities/projectile.cpp @@ -7,7 +7,7 @@ ////////////////////////////////////////////////// // projectile ////////////////////////////////////////////////// -PROJECTILE::PROJECTILE(int type, int owner, vec2 pos, vec2 dir, int span, ENTITY* powner, +PROJECTILE::PROJECTILE(int type, int owner, vec2 pos, vec2 dir, int span, int damage, int flags, float force, int sound_impact, int weapon) : ENTITY(NETOBJTYPE_PROJECTILE) { @@ -16,7 +16,6 @@ PROJECTILE::PROJECTILE(int type, int owner, vec2 pos, vec2 dir, int span, ENTITY this->direction = dir; this->lifespan = span; this->owner = owner; - this->powner = powner; this->flags = flags; this->force = force; this->damage = damage; @@ -68,8 +67,8 @@ void PROJECTILE::tick() int collide = col_intersect_line(prevpos, curpos, &curpos); //int collide = col_check_point((int)curpos.x, (int)curpos.y); - - CHARACTER *targetchr = game.world.intersect_character(prevpos, curpos, 6.0f, curpos, powner); + CHARACTER *ownerchar = game.get_player_char(owner); + CHARACTER *targetchr = game.world.intersect_character(prevpos, curpos, 6.0f, curpos, ownerchar); if(targetchr || collide || lifespan < 0) { if(lifespan >= 0 || weapon == WEAPON_GRENADE) diff --git a/src/game/server/entities/projectile.hpp b/src/game/server/entities/projectile.hpp index c1370af18..a5c3b88f6 100644 --- a/src/game/server/entities/projectile.hpp +++ b/src/game/server/entities/projectile.hpp @@ -12,7 +12,6 @@ public: }; vec2 direction; - ENTITY *powner; // this is nasty, could be removed when client quits int lifespan; int owner; int type; @@ -24,7 +23,7 @@ public: float force; int start_tick; - PROJECTILE(int type, int owner, vec2 pos, vec2 vel, int span, ENTITY* powner, + PROJECTILE(int type, int owner, vec2 pos, vec2 vel, int span, int damage, int flags, float force, int sound_impact, int weapon); vec2 get_pos(float time); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 76609fe6d..c4b956adb 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -26,6 +26,13 @@ void GAMECONTEXT::clear() } +class CHARACTER *GAMECONTEXT::get_player_char(int client_id) +{ + if(client_id < 0 || client_id >= MAX_CLIENTS || !players[client_id]) + return 0; + return players[client_id]->get_character(); +} + void GAMECONTEXT::create_damageind(vec2 p, float angle, int amount) { float a = 3 * 3.14159f / 2 + angle; diff --git a/src/game/server/gamecontext.hpp b/src/game/server/gamecontext.hpp index 106efd5f5..1c4571ebd 100644 --- a/src/game/server/gamecontext.hpp +++ b/src/game/server/gamecontext.hpp @@ -44,6 +44,9 @@ public: void tick(); void snap(int client_id); + // helper functions + class CHARACTER *get_player_char(int client_id); + // voting void start_vote(const char *desc, const char *command); void end_vote();