diff --git a/src/escort.c b/src/escort.c index 56efba3..dda2d9f 100644 --- a/src/escort.c +++ b/src/escort.c @@ -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; } diff --git a/src/weapon.c b/src/weapon.c index fc5d150..a985708 100644 --- a/src/weapon.c +++ b/src/weapon.c @@ -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,22 +715,24 @@ 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; - /* Get the distance. */ - dist = vect_dist(pos, &pilot_target->solid->pos); + else { + /* Get the distance. */ + dist = vect_dist(pos, &pilot_target->solid->pos); - /* Time for shots to reach that distance. */ - t = dist / w->outfit->u.blt.speed; + /* Time for shots to reach that distance. */ + t = dist / w->outfit->u.blt.speed; - /* 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); + /* 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); - 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); + rdir = VANGLE(v); + } } else /* Fire straight. */ rdir = dir;