diff --git a/src/pilot.c b/src/pilot.c index fb0452c..639cf20 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -58,6 +58,7 @@ extern int gui_load(const char* name); static void pilot_shootWeapon(Pilot* p, PilotOutfit* w, const unsigned int t); static void pilot_update(Pilot* pilot, const double dt); static void pilot_hyperspace(Pilot* pilot); +static void pilot_runHook(Pilot* p, int hook_type); void pilot_render(Pilot* pilot); static void pilot_calcCargo(Pilot* pilot); void pilot_free(Pilot* p); @@ -435,8 +436,22 @@ void pilot_dead(Pilot* p) { pilot_setFlag(p, PILOT_DEAD); /* Run hook if pilot has a death hook. */ - if(p->hook_type == PILOT_HOOK_DEATH) - hook_runID(p->hook); + pilot_runHook(p, PILOT_HOOK_DEATH); +} + +/** + * @fn static void pilot_runHook(Pilot* p, int hook_type) + * + * @brief Tries to run a pilot hook if she has it. + * @param p Pilot to run the hook. + * @param hook_type Type of hook to run. + */ +static void pilot_runHook(Pilot* p, int hook_type) { + int i; + for(i = 0; i < PILOT_HOOKS; i++) { + if(p->hook_type[i] == hook_type) + hook_runID(p->hook[i]); + } } /** @@ -627,8 +642,7 @@ static void pilot_update(Pilot* pilot, const double dt) { if(!pilot_isFlag(pilot, PILOT_DISABLED)) { pilot_setFlag(pilot, PILOT_DISABLED); /* Set as disabled. */ /* Run hook. */ - if(pilot->hook_type == PILOT_HOOK_DISABLE) - hook_runID(pilot->hook); + pilot_runHook(pilot, PILOT_HOOK_DISABLE); } /* Come to a halt slowly. */ @@ -694,8 +708,8 @@ static void pilot_hyperspace(Pilot* p) { if(p == player) { player_brokeHyperspace(); } else { - if(p->hook_type == PILOT_HOOK_JUMP) - hook_runID(p->hook); + pilot_runHook(p, PILOT_HOOK_JUMP); + pilot_setFlag(p, PILOT_DELETE); /* Set flag to delete pilot. */ } return; } @@ -1100,10 +1114,25 @@ int pilot_rmCargo(Pilot* pilot, Commodity* cargo, int quantity) { return 0; /* Pilot didn't have it. */ } -/* Add a hook to the pilot. */ +/** + * @fn void pilot_addHook(Pilot* pilot, int type, int hook) + * + * @brief Add a hook to the pilot. + * @param pilot Pilot to add the hook to. + * @param type Type of the hook to add. + * @param hook ID of the hook to add. + */ void pilot_addHook(Pilot* pilot, int type, int hook) { - pilot->hook_type = type; - pilot->hook = hook; + int i; + + for(i = 0; i < PILOT_HOOKS; i++) { + if(pilot->hook_type[i] == PILOT_HOOK_NONE) { + pilot->hook_type[i] = type; + pilot->hook[i] = hook; + return; + } + } + WARN("Pilot has maximum amount of hooks, cannot add another."); } /** @@ -1125,6 +1154,7 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction, AI_Profile* ai, const double dir, const Vec2* pos, const Vec2* vel, const int flags) { + int i; ShipOutfit* so; if(flags & PILOT_PLAYER) /* Player is ID 0 */ @@ -1190,8 +1220,10 @@ void pilot_init(Pilot* pilot, Ship* ship, char* name, int faction, pilot_calcStats(pilot); /* Hooks. */ - pilot->hook_type = PILOT_HOOK_NONE; - pilot->hook = 0; + for(i = 0; i < PILOT_HOOKS; i++) { + pilot->hook_type[i] = PILOT_HOOK_NONE; + pilot->hook[i] = 0; + } /* Set flags and functions. */ if(flags & PILOT_PLAYER) { diff --git a/src/pilot.h b/src/pilot.h index d2bf55e..89e47d6 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -21,6 +21,7 @@ #define PILOT_DISABLED_ARMOUR 0.3 /**< Armour % that makes it disabled. */ /* Hooks. */ +#define PILOT_HOOKS 4 /**< Max number of hooks a pilot can have. */ #define PILOT_HOOK_NONE 0 /**< No hook. */ #define PILOT_HOOK_DEATH 1 /**< Pilot died. */ #define PILOT_HOOK_BOARD 2 /**< Pilot got boarded. */ @@ -158,8 +159,8 @@ typedef struct Pilot_ { int lockons; /**< Stores how many seeking weapons are targetting pilot. */ /* Hook attached to the pilot. */ - int hook_type; /**< Type of the hook atached to the pilot. */ - int hook; /**< Hook id. */ + int hook_type[PILOT_HOOKS]; /**< Type of the hook atached to the pilot. */ + int hook[PILOT_HOOKS]; /**< Hook id. */ /* AI. */ AI_Profile* ai; /**< Ai personality profile. */