[Add] Weapons save their faction and take that into account.

This commit is contained in:
Allanis 2013-07-06 16:35:42 +01:00
parent 71fdcffd07
commit 30b6dfed77

View File

@ -34,6 +34,7 @@ extern void ai_attacked(Pilot* attacked, const unsigned int attacker);
typedef struct Weapon_ { typedef struct Weapon_ {
Solid* solid; /* Actually has its own solid. :D */ Solid* solid; /* Actually has its own solid. :D */
unsigned int faction; /* Faction of pilot that shot the weapon. */
unsigned int parent; /* The pilot that just shot at you! */ unsigned int parent; /* The pilot that just shot at you! */
unsigned int target; /* Target to hit. Only used by seeking stuff. */ unsigned int target; /* Target to hit. Only used by seeking stuff. */
const Outfit* outfit; /* Related outfit that fired. */ const Outfit* outfit; /* Related outfit that fired. */
@ -279,8 +280,8 @@ static void weapon_update(Weapon* w, const double dt, WeaponLayer layer) {
return; return;
} }
/* Dumb weapons hit anything not of the same faction. */ /* Dumb weapons hit anything not of the same faction. */
else if(!weapon_isSmart(w) && if(!weapon_isSmart(w) &&
!areAllies(pilot_get(w->parent)->faction, pilot_stack[i]->faction) && !areAllies(w->faction, pilot_stack[i]->faction) &&
CollideSprite(gfx, wsx, wsy, &w->solid->pos, CollideSprite(gfx, wsx, wsy, &w->solid->pos,
pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos)) { pilot_stack[i]->ship->gfx_space, psx, psy, &pilot_stack[i]->solid->pos)) {
weapon_hit(w, pilot_stack[i], layer); weapon_hit(w, pilot_stack[i], layer);
@ -332,6 +333,7 @@ static Weapon* weapon_create(const Outfit* outfit, const double dir, const Vec2*
double mass = 1; /* Presumer lasers have a mass of 1. */ double mass = 1; /* Presumer lasers have a mass of 1. */
double rdir = dir; /* Real direction (accuracy). */ double rdir = dir; /* Real direction (accuracy). */
Weapon* w = MALLOC_L(Weapon); Weapon* w = MALLOC_L(Weapon);
w->faction = pilot_get(parent)->faction; /*Non-Changeable. */
w->parent = parent; /* Non-Changeable. */ w->parent = parent; /* Non-Changeable. */
w->target = target; /* Non-Changeable. */ w->target = target; /* Non-Changeable. */
w->outfit = outfit; /* Non-Changeable. */ w->outfit = outfit; /* Non-Changeable. */