fixed incorrect handling of projectiel and laser owner

This commit is contained in:
Magnus Auvinen 2008-10-20 23:00:46 +00:00
parent 9f7a6a04b0
commit ac1aeab149
7 changed files with 21 additions and 15 deletions

View file

@ -322,7 +322,6 @@ void CHARACTER::fire_weapon()
projectile_startpos, projectile_startpos,
direction, direction,
(int)(server_tickspeed()*tuning.gun_lifetime), (int)(server_tickspeed()*tuning.gun_lifetime),
this,
1, 0, 0, -1, WEAPON_GUN); 1, 0, 0, -1, WEAPON_GUN);
// pack the projectile and send it to the client directly // pack the projectile and send it to the client directly
@ -358,7 +357,6 @@ void CHARACTER::fire_weapon()
projectile_startpos, projectile_startpos,
vec2(cosf(a), sinf(a))*speed, vec2(cosf(a), sinf(a))*speed,
(int)(server_tickspeed()*tuning.shotgun_lifetime), (int)(server_tickspeed()*tuning.shotgun_lifetime),
this,
1, 0, 0, -1, WEAPON_SHOTGUN); 1, 0, 0, -1, WEAPON_SHOTGUN);
// pack the projectile and send it to the client directly // pack the projectile and send it to the client directly
@ -382,7 +380,6 @@ void CHARACTER::fire_weapon()
projectile_startpos, projectile_startpos,
direction, direction,
(int)(server_tickspeed()*tuning.grenade_lifetime), (int)(server_tickspeed()*tuning.grenade_lifetime),
this,
1, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE); 1, PROJECTILE::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE);
// pack the projectile and send it to the client directly // pack the projectile and send it to the client directly
@ -401,7 +398,7 @@ void CHARACTER::fire_weapon()
case WEAPON_RIFLE: 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); game.create_sound(pos, SOUND_RIFLE_FIRE);
} break; } break;

View file

@ -7,7 +7,7 @@
////////////////////////////////////////////////// //////////////////////////////////////////////////
// laser // 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) : ENTITY(NETOBJTYPE_LASER)
{ {
this->pos = pos; 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) bool LASER::hit_character(vec2 from, vec2 to)
{ {
vec2 at; 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) if(!hit)
return false; return false;
this->from = from; this->from = from;
pos = at; pos = at;
energy = -1; 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; return true;
} }

View file

@ -14,14 +14,14 @@ class LASER : public ENTITY
float energy; float energy;
int bounces; int bounces;
int eval_tick; int eval_tick;
CHARACTER *owner; int owner;
bool hit_character(vec2 from, vec2 to); bool hit_character(vec2 from, vec2 to);
void do_bounce(); void do_bounce();
public: 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 reset();
virtual void tick(); virtual void tick();

View file

@ -7,7 +7,7 @@
////////////////////////////////////////////////// //////////////////////////////////////////////////
// projectile // 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) int damage, int flags, float force, int sound_impact, int weapon)
: ENTITY(NETOBJTYPE_PROJECTILE) : ENTITY(NETOBJTYPE_PROJECTILE)
{ {
@ -16,7 +16,6 @@ PROJECTILE::PROJECTILE(int type, int owner, vec2 pos, vec2 dir, int span, ENTITY
this->direction = dir; this->direction = dir;
this->lifespan = span; this->lifespan = span;
this->owner = owner; this->owner = owner;
this->powner = powner;
this->flags = flags; this->flags = flags;
this->force = force; this->force = force;
this->damage = damage; this->damage = damage;
@ -68,8 +67,8 @@ void PROJECTILE::tick()
int collide = col_intersect_line(prevpos, curpos, &curpos); int collide = col_intersect_line(prevpos, curpos, &curpos);
//int collide = col_check_point((int)curpos.x, (int)curpos.y); //int collide = col_check_point((int)curpos.x, (int)curpos.y);
CHARACTER *ownerchar = game.get_player_char(owner);
CHARACTER *targetchr = game.world.intersect_character(prevpos, curpos, 6.0f, curpos, powner); CHARACTER *targetchr = game.world.intersect_character(prevpos, curpos, 6.0f, curpos, ownerchar);
if(targetchr || collide || lifespan < 0) if(targetchr || collide || lifespan < 0)
{ {
if(lifespan >= 0 || weapon == WEAPON_GRENADE) if(lifespan >= 0 || weapon == WEAPON_GRENADE)

View file

@ -12,7 +12,6 @@ public:
}; };
vec2 direction; vec2 direction;
ENTITY *powner; // this is nasty, could be removed when client quits
int lifespan; int lifespan;
int owner; int owner;
int type; int type;
@ -24,7 +23,7 @@ public:
float force; float force;
int start_tick; 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); int damage, int flags, float force, int sound_impact, int weapon);
vec2 get_pos(float time); vec2 get_pos(float time);

View file

@ -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) void GAMECONTEXT::create_damageind(vec2 p, float angle, int amount)
{ {
float a = 3 * 3.14159f / 2 + angle; float a = 3 * 3.14159f / 2 + angle;

View file

@ -44,6 +44,9 @@ public:
void tick(); void tick();
void snap(int client_id); void snap(int client_id);
// helper functions
class CHARACTER *get_player_char(int client_id);
// voting // voting
void start_vote(const char *desc, const char *command); void start_vote(const char *desc, const char *command);
void end_vote(); void end_vote();