[Add] Have player keep track of hostiles it has in the system.
This commit is contained in:
parent
dd2249344b
commit
27780b01ba
2
src/ai.c
2
src/ai.c
@ -1519,7 +1519,7 @@ static int ai_hostile(lua_State* L) {
|
||||
LLUA_MIN_ARGS(1);
|
||||
|
||||
if(lua_isnumber(L,1) && ((unsigned int)lua_tonumber(L,1) == PLAYER_ID))
|
||||
pilot_setFlag(cur_pilot, PILOT_HOSTILE);
|
||||
pilot_setHostile(cur_pilot);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
24
src/pilot.c
24
src/pilot.c
@ -45,6 +45,7 @@ static int pilot_mstack = 0; /** Memory allocated for pilot_stack. */
|
||||
extern Pilot* player;
|
||||
extern double player_crating; /**< Players combat rating. */
|
||||
extern void player_abortAutonav(char* reason);
|
||||
extern int player_enemies;
|
||||
|
||||
/* Stack of fleets. */
|
||||
static Fleet* fleet_stack = NULL; /** Fleet stack. */
|
||||
@ -216,6 +217,17 @@ double pilot_face(Pilot* p, const double dir) {
|
||||
return diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Mark a pilot as hostile to player.
|
||||
* @param p Pilot to mark as hostile.
|
||||
*/
|
||||
void pilot_setHostile(Pilot* p) {
|
||||
if(!pilot_isFlag(p, PILOT_HOSTILE)) {
|
||||
player_enemies++;
|
||||
pilot_setFlag(p, PILOT_HOSTILE);
|
||||
}
|
||||
}
|
||||
|
||||
/* Get the amount of jumps the pilot has left. */
|
||||
int pilot_getJumps(const Pilot* p) {
|
||||
return (int)(p->fuel) / HYPERSPACE_FUEL;
|
||||
@ -820,6 +832,12 @@ static void pilot_update(Pilot* pilot, const double dt) {
|
||||
(pilot->armour < PILOT_DISABLED_ARMOUR*pilot->armour_max)) { /* Disabled. */
|
||||
/* First time pilot is disabled. */
|
||||
if(!pilot_isFlag(pilot, PILOT_DISABLED)) {
|
||||
/* If hostile, must remove counter. */
|
||||
if(pilot_isFlag(pilot, PILOT_HOSTILE)) {
|
||||
player_enemies--;
|
||||
pilot_rmFlag(pilot, PILOT_HOSTILE);
|
||||
}
|
||||
|
||||
pilot_setFlag(pilot, PILOT_DISABLED); /* Set as disabled. */
|
||||
/* Run hook. */
|
||||
pilot_runHook(pilot, PILOT_HOOK_DISABLE);
|
||||
@ -1733,6 +1751,12 @@ void pilot_free(Pilot* p) {
|
||||
if(p->hook_type[i] != PILOT_HOOK_NONE)
|
||||
hook_rm(p->hook[i]);
|
||||
|
||||
/* If hostile, must remove counter. */
|
||||
if(pilot_isFlag(p, PILOT_HOSTILE)) {
|
||||
player_enemies--;
|
||||
pilot_rmFlag(p, PILOT_HOSTILE);
|
||||
}
|
||||
|
||||
/* Remove outfits. */
|
||||
while(p->outfits != NULL)
|
||||
pilot_rmOutfit(p, p->outfits[0].outfit, p->outfits[0].quantity);
|
||||
|
@ -235,6 +235,7 @@ Fleet* fleet_get(const char* name);
|
||||
int pilot_getJumps(const Pilot* p);
|
||||
|
||||
/* Misc. */
|
||||
void pilot_setHostile(Pilot* p);
|
||||
void pilot_shoot(Pilot* p, const int secondary);
|
||||
void pilot_shootStop(Pilot* p, const int secondary);
|
||||
void pilot_hit(Pilot* p, const Solid* w, const unsigned int shooter,
|
||||
|
12
src/player.c
12
src/player.c
@ -59,13 +59,15 @@
|
||||
/* Player stuff. */
|
||||
Pilot* player = NULL; /**< The player. */
|
||||
static Ship* player_ship = NULL; /**< Temp ship to hold when naming it. */
|
||||
static double player_px; /**< Temp X position. */
|
||||
static double player_py; /**< Temp Y position. */
|
||||
static double player_vx; /**< Temp X velocity. */
|
||||
static double player_vy; /**< Temp Y velocity. */
|
||||
static double player_dir; /**< Temp direction. */
|
||||
static double player_px = 0.; /**< Temp X position. */
|
||||
static double player_py = 0.; /**< Temp Y position. */
|
||||
static double player_vx = 0.; /**< Temp X velocity. */
|
||||
static double player_vy = 0.; /**< Temp Y velocity. */
|
||||
static double player_dir = 0.; /**< Temp direction. */
|
||||
static int player_credits = 0; /**< Temp hack on create. */
|
||||
static char* player_mission = NULL; /**< More hack. */
|
||||
int player_enemies = 0;; /**< Number of enemies player has in system. */
|
||||
|
||||
|
||||
/* Licenses. */
|
||||
static char** player_licenses = NULL; /**< Licenses player has. */
|
||||
|
@ -26,6 +26,7 @@ extern Pilot* player; /**< The player. */
|
||||
extern char* player_name; /**< Player's name. */
|
||||
extern unsigned int player_flags; /**< Player's flags. */
|
||||
extern double player_crating; /**< Player's combat rating. */
|
||||
extern int player_enemies; /**< Amount of enemies player has. */
|
||||
|
||||
/* Enums. */
|
||||
|
||||
|
@ -628,6 +628,9 @@ void space_init(const char* sysname) {
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Reset player enemies. */
|
||||
player_enemies = 0;
|
||||
|
||||
/* Set up fleets -> pilots. */
|
||||
for(i = 0; i < cur_system->nfleets; i++)
|
||||
if(RNG(0,100) <= (cur_system->fleets[i].chance/2)) /* Fleet check (50% chance). */
|
||||
|
@ -637,7 +637,7 @@ static void weapon_hit(Weapon* w, Pilot* p, WeaponLayer layer, Vec2* pos) {
|
||||
(!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.5))) { /* 50% chance. */
|
||||
faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */
|
||||
}
|
||||
pilot_setFlag(p, PILOT_HOSTILE);
|
||||
pilot_setHostile(p);
|
||||
pilot_rmFlag(p, PILOT_BRIBED);
|
||||
}
|
||||
ai_attacked(p, w->parent);
|
||||
@ -684,8 +684,8 @@ static void weapon_hitBeam(Weapon* w, Pilot* p, WeaponLayer layer,
|
||||
(!pilot_isFlag(p, PILOT_HOSTILE) || (RNGF() < 0.50*dt))) { /* 50% chance. */
|
||||
faction_modPlayer(p->faction, -1.); /* Slowly lower faction. */
|
||||
}
|
||||
pilot_setHostile(p);
|
||||
pilot_rmFlag(p, PILOT_BRIBED);
|
||||
pilot_setFlag(p, PILOT_HOSTILE);
|
||||
}
|
||||
ai_attacked(p, w->parent);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user