[Fix] Fixed major bugs in flag usage and also weapon_hit stuff.

This commit is contained in:
Allanis 2014-01-23 23:05:05 +00:00
parent 84b20c9bd3
commit eee760f411
5 changed files with 41 additions and 30 deletions

View File

@ -35,9 +35,9 @@
#define PILOT_HOOK_JUMP 4 /**< Pilot jumped. */ #define PILOT_HOOK_JUMP 4 /**< Pilot jumped. */
/* Flags. */ /* Flags. */
#define pilot_isFlag(p,f) (p->flags & (f)) /**< Check if flag f is set on pilot p. */ #define pilot_isFlag(p,f) (p->flags & (f)) /**< Check if flag f is set on pilot p. */
#define pilot_setFlag(p,f) (p->flags |= (f)) /**< Set flag f on pilot p. */ #define pilot_setFlag(p,f) (p->flags |= (f)) /**< Set flag f on pilot p. */
#define pilot_rmFlag(p,f) (p->flags ^= (f)) /**< Remove flag f on pilot p. */ #define pilot_rmFlag(p,f) ((p)->flags &= ~(f)) /**< Remove flag f on pilot p. */
/* Creation. */ /* Creation. */
#define PILOT_PLAYER (1<<0) /**< Pilot is a player. */ #define PILOT_PLAYER (1<<0) /**< Pilot is a player. */
#define PILOT_ESCORT (1<<1) /**< Pilot is an escort. */ #define PILOT_ESCORT (1<<1) /**< Pilot is an escort. */
@ -54,11 +54,12 @@
#define PILOT_HYP_BEGIN (1<<16) /**< Pilot is starting engines. */ #define PILOT_HYP_BEGIN (1<<16) /**< Pilot is starting engines. */
#define PILOT_HYPERSPACE (1<<17) /**< Pilot is in hyperspace. */ #define PILOT_HYPERSPACE (1<<17) /**< Pilot is in hyperspace. */
#define PILOT_BOARDED (1<<18) /**< Pilot has been boarded already! */ #define PILOT_BOARDED (1<<18) /**< Pilot has been boarded already! */
#define PILOT_DISABLED (1<<19) /**< Pilot is disabled. */ #define PILOT_BRIBED (1<<19) /**< Pilot has been bribed already. */
#define PILOT_DEAD (1<<20) /**< Pilot is on it's death bed. */ #define PILOT_DISABLED (1<<16) /**< Pilot is disabled. */
#define PILOT_DEATH_SOUND (1<<21) /**< Pilot just did death explosion. */ #define PILOT_DEAD (1<<27) /**< Pilot is on it's death bed. */
#define PILOT_EXPLODED (1<<22) /**< Pilot did final death explosion. */ #define PILOT_DEATH_SOUND (1<<28) /**< Pilot just did death explosion. */
#define PILOT_DELETE (1<<25) /**< Pilot will get delete asap. */ #define PILOT_EXPLODED (1<<29) /**< Pilot did final death explosion. */
#define PILOT_DELETE (1<<30) /**< Pilot will get delete asap. */
/* Just makes life simpler. */ /* Just makes life simpler. */
#define pilot_isPlayer(p) ((p)->flags & PILOT_PLAYER) /**< Check if pilot is a player. */ #define pilot_isPlayer(p) ((p)->flags & PILOT_PLAYER) /**< Check if pilot is a player. */

View File

@ -811,6 +811,7 @@ void player_render(void) {
else { else {
/* There is still a pilot target. */ /* There is still a pilot target. */
if(pilot_isDisabled(p)) c = &cInert; if(pilot_isDisabled(p)) c = &cInert;
else if(pilot_isFlag(p, PILOT_BRIBED)) c = &cNeutral;
else if(pilot_isFlag(p, PILOT_HOSTILE)) c = &cHostile; else if(pilot_isFlag(p, PILOT_HOSTILE)) c = &cHostile;
else c = faction_getColour(p->faction); else c = faction_getColour(p->faction);
@ -1164,18 +1165,19 @@ static void gui_renderPilot(const Pilot* p) {
} }
glBegin(GL_QUADS); glBegin(GL_QUADS);
/* Colours. */ /* Colours. */
if(p->id == player->target) col = &cRadar_targ; if(p->id == player->target) col = &cRadar_targ;
else if(pilot_isDisabled(p)) col = &cInert; else if(pilot_isDisabled(p)) col = &cInert;
else if(pilot_isFlag(p, PILOT_HOSTILE)) col = &cHostile; else if(pilot_isFlag(p, PILOT_BRIBED)) col = &cNeutral;
else col = faction_getColour(p->faction); else if(pilot_isFlag(p, PILOT_HOSTILE)) col = &cHostile;
COLOUR(*col); else col = faction_getColour(p->faction);
COLOUR(*col);
/* Image. */ /* Image. */
glVertex2d(MAX(x-sx, -w), MIN(y+sy, h)); /* Top left. */ glVertex2d(MAX(x-sx, -w), MIN(y+sy, h)); /* Top left. */
glVertex2d(MIN(x+sx, w), MIN(y+sy, h)); /* Top right. */ glVertex2d(MIN(x+sx, w), MIN(y+sy, h)); /* Top right. */
glVertex2d(MIN(x+sx, w), MAX(y-sy, -h)); /* Bottom right. */ glVertex2d(MIN(x+sx, w), MAX(y-sy, -h)); /* Bottom right. */
glVertex2d(MAX(x-sx, -w), MAX(y-sy, -h)); /* Bottom left. */ glVertex2d(MAX(x-sx, -w), MAX(y-sy, -h)); /* Bottom left. */
glEnd(); glEnd();
} }
@ -1954,7 +1956,12 @@ void player_targetHostile(void) {
tp = PLAYER_ID; tp = PLAYER_ID;
d = 0; d = 0;
for(i = 0; i < pilot_nstack; i++) for(i = 0; i < pilot_nstack; i++) {
/* Don't get if bribed. */
if(pilot_isFlag(pilot_stack[i], PILOT_BRIBED))
continue;
/* Normbal unbribed. */
if(pilot_isFlag(pilot_stack[i], PILOT_HOSTILE) || if(pilot_isFlag(pilot_stack[i], PILOT_HOSTILE) ||
areEnemies(FACTION_PLAYER, pilot_stack[i]->faction)) { areEnemies(FACTION_PLAYER, pilot_stack[i]->faction)) {
td = vect_dist(&pilot_stack[i]->solid->pos, &player->solid->pos); td = vect_dist(&pilot_stack[i]->solid->pos, &player->solid->pos);
@ -1963,6 +1970,7 @@ void player_targetHostile(void) {
tp = pilot_stack[i]->id; tp = pilot_stack[i]->id;
} }
} }
}
if((tp != PLAYER_ID) && (tp != player->target)) if((tp != PLAYER_ID) && (tp != player->target))
player_playSound(snd_target, 1); player_playSound(snd_target, 1);

View File

@ -17,9 +17,9 @@
#define PLAYER_AUTONAV (1<<17) /**< Player has autonaviagation on. */ #define PLAYER_AUTONAV (1<<17) /**< Player has autonaviagation on. */
/* Flag functions. */ /* Flag functions. */
#define player_isFlag(f) (player_flags & f) /**< Check for a player flag. */ #define player_isFlag(f) (player_flags & (f)) /**< Check for a player flag. */
#define player_setFlag(f) if(!player_isFlag(f)) (player_flags |= f) /**< Set a player flag. */ #define player_setFlag(f) (player_flags |= (f)) /**< Set a player flag. */
#define player_rmFlag(f) if(player_isFlag(f)) (player_flags ^= f) /**< Remove a player flag. */ #define player_rmFlag(f) (player_flags &= ~(f)) /**< Remove a player flag. */
/* The player. */ /* The player. */
extern Pilot* player; /**< The player. */ extern Pilot* player; /**< The player. */

View File

@ -82,9 +82,9 @@ typedef struct Planet_ {
/* Star system flags. */ /* Star system flags. */
#define SYSTEM_KNOWN (1<<0) /**< System is known. */ #define SYSTEM_KNOWN (1<<0) /**< System is known. */
#define SYSTEM_MARKED (1<<1) /**< System is marked by a mission. */ #define SYSTEM_MARKED (1<<1) /**< System is marked by a mission. */
#define sys_isFlag(s,f) ((s)->flags & (f)) /**< Check system flag. */ #define sys_isFlag(s,f) ((s)->flags & (f)) /**< Check system flag. */
#define sys_setFlag(s,f) if(!sys_isFlag(s,f)) (s)->flags |= (f) /**< Set a system flag. */ #define sys_setFlag(s,f) ((s)->flags |= (f)) /**< Set a system flag. */
#define sys_rmFlag(s,f) if(sys_isFlag(s,f)) (s)->flags ^= (f) /**< Remove a system flag. */ #define sys_rmFlag(s,f) ((s)->flags &= ~(f)) /**< Remove a system flag. */
#define sys_isKnown(s) sys_isFlag(s, SYSTEM_KNOWN) /**< Check if system is known. */ #define sys_isKnown(s) sys_isFlag(s, SYSTEM_KNOWN) /**< Check if system is known. */
#define sys_isMarked(s) sys_isFlag(s, SYSTEM_MARKED) /**< Check if system is marked. */ #define sys_isMarked(s) sys_isFlag(s, SYSTEM_MARKED) /**< Check if system is marked. */

View File

@ -597,14 +597,15 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) {
/* Someone should let the ai know it's been attacked. */ /* Someone should let the ai know it's been attacked. */
if(!pilot_isPlayer(p)) { if(!pilot_isPlayer(p)) {
if((player != NULL) && if((player != NULL) && (w->parent == player->id) &&
((player->target == p->id) || (RNGF() > 0.33))) { /* 33% chance. */ ((player->target == p->id) || (RNGF() > 0.33))) { /* 33% chance. */
parent = pilot_get(w->parent); parent = pilot_get(w->parent);
if((parent->faction == FACTION_PLAYER) && if((parent->faction == FACTION_PLAYER) &&
(!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */ (!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */
faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */ faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */
pilot_setFlag(p, PILOT_HOSTILE);
} }
pilot_setFlag(p, PILOT_HOSTILE);
pilot_rmFlag(p, PILOT_BRIBED);
ai_attacked(p, w->parent); ai_attacked(p, w->parent);
} }
spfx_add(outfit_spfx(w->outfit), pos->x, pos->y, spfx_add(outfit_spfx(w->outfit), pos->x, pos->y,
@ -639,14 +640,15 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer,
/* Inform the ai it has been attacked, useless if player. */ /* Inform the ai it has been attacked, useless if player. */
if(!pilot_isPlayer(p)) { if(!pilot_isPlayer(p)) {
if((player != NULL) && if((player != NULL) && (w->parent == player->id) &&
((player->target == p->id) || (RNGF() < 0.30*dt))) { /* 30% chance per second. */ ((player->target == p->id) || (RNGF() < 0.30*dt))) { /* 30% chance per second. */
parent = pilot_get(w->parent); parent = pilot_get(w->parent);
if((parent->faction == FACTION_PLAYER) && if((parent->faction == FACTION_PLAYER) &&
(!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */ (!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */
faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */ faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */
pilot_setFlag(p, PILOT_HOSTILE);
} }
pilot_rmFlag(p, PILOT_BRIBED);
pilot_setFlag(p, PILOT_HOSTILE);
ai_attacked(p, w->parent); ai_attacked(p, w->parent);
} }
if(w->lockon == -1.) { /* Code to signal create explosions. */ if(w->lockon == -1.) { /* Code to signal create explosions. */