[Add] Pilots can now have up to four hooks at any given time.

This commit is contained in:
Allanis 2013-11-16 20:13:31 +00:00
parent 2489949d30
commit ef19939647
2 changed files with 46 additions and 13 deletions

View File

@ -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_shootWeapon(Pilot* p, PilotOutfit* w, const unsigned int t);
static void pilot_update(Pilot* pilot, const double dt); static void pilot_update(Pilot* pilot, const double dt);
static void pilot_hyperspace(Pilot* pilot); static void pilot_hyperspace(Pilot* pilot);
static void pilot_runHook(Pilot* p, int hook_type);
void pilot_render(Pilot* pilot); void pilot_render(Pilot* pilot);
static void pilot_calcCargo(Pilot* pilot); static void pilot_calcCargo(Pilot* pilot);
void pilot_free(Pilot* p); void pilot_free(Pilot* p);
@ -435,8 +436,22 @@ void pilot_dead(Pilot* p) {
pilot_setFlag(p, PILOT_DEAD); pilot_setFlag(p, PILOT_DEAD);
/* Run hook if pilot has a death hook. */ /* Run hook if pilot has a death hook. */
if(p->hook_type == PILOT_HOOK_DEATH) pilot_runHook(p, PILOT_HOOK_DEATH);
hook_runID(p->hook); }
/**
* @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)) { if(!pilot_isFlag(pilot, PILOT_DISABLED)) {
pilot_setFlag(pilot, PILOT_DISABLED); /* Set as disabled. */ pilot_setFlag(pilot, PILOT_DISABLED); /* Set as disabled. */
/* Run hook. */ /* Run hook. */
if(pilot->hook_type == PILOT_HOOK_DISABLE) pilot_runHook(pilot, PILOT_HOOK_DISABLE);
hook_runID(pilot->hook);
} }
/* Come to a halt slowly. */ /* Come to a halt slowly. */
@ -694,8 +708,8 @@ static void pilot_hyperspace(Pilot* p) {
if(p == player) { if(p == player) {
player_brokeHyperspace(); player_brokeHyperspace();
} else { } else {
if(p->hook_type == PILOT_HOOK_JUMP) pilot_runHook(p, PILOT_HOOK_JUMP);
hook_runID(p->hook); pilot_setFlag(p, PILOT_DELETE); /* Set flag to delete pilot. */
} }
return; return;
} }
@ -1100,10 +1114,25 @@ int pilot_rmCargo(Pilot* pilot, Commodity* cargo, int quantity) {
return 0; /* Pilot didn't have it. */ 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) { void pilot_addHook(Pilot* pilot, int type, int hook) {
pilot->hook_type = type; int i;
pilot->hook = hook;
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, AI_Profile* ai, const double dir, const Vec2* pos,
const Vec2* vel, const int flags) { const Vec2* vel, const int flags) {
int i;
ShipOutfit* so; ShipOutfit* so;
if(flags & PILOT_PLAYER) /* Player is ID 0 */ 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); pilot_calcStats(pilot);
/* Hooks. */ /* Hooks. */
pilot->hook_type = PILOT_HOOK_NONE; for(i = 0; i < PILOT_HOOKS; i++) {
pilot->hook = 0; pilot->hook_type[i] = PILOT_HOOK_NONE;
pilot->hook[i] = 0;
}
/* Set flags and functions. */ /* Set flags and functions. */
if(flags & PILOT_PLAYER) { if(flags & PILOT_PLAYER) {

View File

@ -21,6 +21,7 @@
#define PILOT_DISABLED_ARMOUR 0.3 /**< Armour % that makes it disabled. */ #define PILOT_DISABLED_ARMOUR 0.3 /**< Armour % that makes it disabled. */
/* Hooks. */ /* Hooks. */
#define PILOT_HOOKS 4 /**< Max number of hooks a pilot can have. */
#define PILOT_HOOK_NONE 0 /**< No hook. */ #define PILOT_HOOK_NONE 0 /**< No hook. */
#define PILOT_HOOK_DEATH 1 /**< Pilot died. */ #define PILOT_HOOK_DEATH 1 /**< Pilot died. */
#define PILOT_HOOK_BOARD 2 /**< Pilot got boarded. */ #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. */ int lockons; /**< Stores how many seeking weapons are targetting pilot. */
/* Hook attached to the pilot. */ /* Hook attached to the pilot. */
int hook_type; /**< Type of the hook atached to the pilot. */ int hook_type[PILOT_HOOKS]; /**< Type of the hook atached to the pilot. */
int hook; /**< Hook id. */ int hook[PILOT_HOOKS]; /**< Hook id. */
/* AI. */ /* AI. */
AI_Profile* ai; /**< Ai personality profile. */ AI_Profile* ai; /**< Ai personality profile. */