[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 ret;
Pilot* t;
ret = 1;
if(parent->target != parent->id)
ret = escort_command(parent, ESCORT_ATTACK, parent->target);
if((ret == 0) && (parent == player))
player_message("Escorts: Attacking %s.", pilot_get(parent->target)->name);
if((ret == 0) && (parent == player)) {
t = pilot_get(parent->target);
if(t != NULL)
player_message("Escorts: Attacking %s.", t->name);
}
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) &&
((player->target == p->id) || (RNGF() > 0.33))) { /* 33% chance. */
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. */
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) &&
((player->target == p->id) || (RNGF() < 0.30*dt))) { /* 30% chance per second. */
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. */
faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */
}
@ -715,7 +715,10 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
case OUTFIT_TYPE_TURRET_BOLT:
if((outfit->type == OUTFIT_TYPE_TURRET_BEAM) && (w->parent != w->target)) {
pilot_target = pilot_get(w->target);
if(pilot_target == NULL)
rdir = dir;
else {
/* Get the distance. */
dist = vect_dist(pos, &pilot_target->solid->pos);
@ -725,12 +728,11 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
/* Position is calculated on where it should be. */
x = (pilot_target->solid->pos.x + pilot_target->solid->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);
vect_cset(&v, x, y);
rdir = VANGLE(v);
}
} else /* Fire straight. */
rdir = dir;