[Fix] Removed more possible seg faults.

This commit is contained in:
Allanis 2014-03-07 23:35:52 +00:00
parent 108d4f1c72
commit d358bff1e4
2 changed files with 23 additions and 16 deletions

View File

@ -142,11 +142,16 @@ static int escort_command(Pilot* parent, int cmd, int param) {
*/ */
int escorts_attack(Pilot* parent) { int escorts_attack(Pilot* parent) {
int ret; int ret;
Pilot* t;
ret = 1; ret = 1;
if(parent->target != parent->id) if(parent->target != parent->id)
ret = escort_command(parent, ESCORT_ATTACK, parent->target); ret = escort_command(parent, ESCORT_ATTACK, parent->target);
if((ret == 0) && (parent == player)) if((ret == 0) && (parent == player)) {
player_message("Escorts: Attacking %s.", pilot_get(parent->target)->name); t = pilot_get(parent->target);
if(t != NULL)
player_message("Escorts: Attacking %s.", t->name);
}
return ret; return ret;
} }

View File

@ -605,7 +605,7 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) {
if((player != NULL) && (w->parent == player->id) && if((player != NULL) && (w->parent == player->id) &&
((player->target == p->id) || (RNGF() > 0.33))) { /* 33% chance. */ ((player->target == p->id) || (RNGF() > 0.33))) { /* 33% chance. */
parent = pilot_get(w->parent); parent = pilot_get(w->parent);
if((parent->faction == FACTION_PLAYER) && if((parent != NULL) && (parent->faction == FACTION_PLAYER) &&
(!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */ (!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */
faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */ faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */
} }
@ -648,7 +648,7 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer,
if((player != NULL) && (w->parent == player->id) && if((player != NULL) && (w->parent == player->id) &&
((player->target == p->id) || (RNGF() < 0.30*dt))) { /* 30% chance per second. */ ((player->target == p->id) || (RNGF() < 0.30*dt))) { /* 30% chance per second. */
parent = pilot_get(w->parent); parent = pilot_get(w->parent);
if((parent->faction == FACTION_PLAYER) && if((parent != NULL) && (parent->faction == FACTION_PLAYER) &&
(!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */ (!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */
faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */ faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */
} }
@ -715,22 +715,24 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
case OUTFIT_TYPE_TURRET_BOLT: case OUTFIT_TYPE_TURRET_BOLT:
if((outfit->type == OUTFIT_TYPE_TURRET_BEAM) && (w->parent != w->target)) { if((outfit->type == OUTFIT_TYPE_TURRET_BEAM) && (w->parent != w->target)) {
pilot_target = pilot_get(w->target); pilot_target = pilot_get(w->target);
if(pilot_target == NULL)
rdir = dir;
/* Get the distance. */ else {
dist = vect_dist(pos, &pilot_target->solid->pos); /* Get the distance. */
dist = vect_dist(pos, &pilot_target->solid->pos);
/* Time for shots to reach that distance. */ /* Time for shots to reach that distance. */
t = dist / w->outfit->u.blt.speed; t = dist / w->outfit->u.blt.speed;
/* Position is calculated on where it should be. */ /* Position is calculated on where it should be. */
x = (pilot_target->solid->pos.x + pilot_target->solid->vel.x*t) x = (pilot_target->solid->pos.x + pilot_target->solid->vel.x*t)
- (pos->x + vel->x*t); - (pos->x + vel->x*t);
y = (pilot_target->solid->pos.y + pilot_target->solid->vel.y*t)
- (pos->y + vel->y*t);
y = (pilot_target->solid->pos.y + pilot_target->solid->vel.y*t) rdir = VANGLE(v);
- (pos->y + vel->y*t); }
vect_cset(&v, x, y);
rdir = VANGLE(v);
} else /* Fire straight. */ } else /* Fire straight. */
rdir = dir; rdir = dir;