From 26e966c1dd6dafa17d5ec6a8cd1d2859f8391dfd Mon Sep 17 00:00:00 2001 From: Allanis Date: Sun, 1 Jun 2014 14:42:07 +0100 Subject: [PATCH] [Add] Added pilot_rmHostile. --- dat/ship.xml | 8 ++++---- src/comm.c | 1 + src/music.c | 5 ++++- src/pilot.c | 21 +++++++++++++-------- src/pilot.h | 1 + 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/dat/ship.xml b/dat/ship.xml index 6c42e7e..d7f23c7 100644 --- a/dat/ship.xml +++ b/dat/ship.xml @@ -30,13 +30,13 @@ 600000 - Ripper MK2 Lancelot Fighter Bay - Lancelot Fighter + Lancelot Fighter + Ripper MK2 Banshee Launcher Banshee Rocket - Headhunter Launcher - Headhunter + Headhunter Launcher + Headhunter 0 diff --git a/src/comm.c b/src/comm.c index c84bb6a..a4265e2 100644 --- a/src/comm.c +++ b/src/comm.c @@ -166,6 +166,7 @@ static void comm_bribe(unsigned int wid, char* unused) { /* Mark as bribed and don't allow bribing again. */ pilot_setFlag(comm_pilot, PILOT_BRIBED); + pilot_rmHostile(comm_pilot); L = comm_pilot->ai->L; lua_getglobal(L, "mem"); lua_pushnil(L); diff --git a/src/music.c b/src/music.c index ed34dec..045117a 100644 --- a/src/music.c +++ b/src/music.c @@ -98,7 +98,10 @@ static int music_runLua(char* situation) { if(music_disabled) return 0; /* Run the choose function in Lua. */ lua_getglobal(music_lua, "choose"); - lua_pushstring(music_lua, situation); + if(situation != NULL) + lua_pushstring(music_lua, situation); + else + lua_pushnil(music_lua); if(lua_pcall(music_lua, 1, 0, 0)) /* Error has occured. */ WARN("Error while choosing music: %s", (char*)lua_tostring(music_lua, -1)); diff --git a/src/pilot.c b/src/pilot.c index 26c5361..8797d00 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -228,6 +228,17 @@ void pilot_setHostile(Pilot* p) { } } +/** + * @brief Unmark a pilot as neutral to player. + * @param p Pilot to mark as neutral. + */ +void pilot_rmHostile(Pilot* p) { + if(pilot_isFlag(p, PILOT_HOSTILE)) { + player_enemies--; + pilot_rmFlag(p, PILOT_HOSTILE); + } +} + /* Get the amount of jumps the pilot has left. */ int pilot_getJumps(const Pilot* p) { return (int)(p->fuel) / HYPERSPACE_FUEL; @@ -833,10 +844,7 @@ static void pilot_update(Pilot* pilot, const double dt) { /* 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_rmHostile(pilot); pilot_setFlag(pilot, PILOT_DISABLED); /* Set as disabled. */ /* Run hook. */ @@ -1752,10 +1760,7 @@ void pilot_free(Pilot* p) { hook_rm(p->hook[i]); /* If hostile, must remove counter. */ - if(pilot_isFlag(p, PILOT_HOSTILE)) { - player_enemies--; - pilot_rmFlag(p, PILOT_HOSTILE); - } + pilot_rmHostile(p); /* Remove outfits. */ while(p->outfits != NULL) diff --git a/src/pilot.h b/src/pilot.h index 7df7c30..a19b1a5 100644 --- a/src/pilot.h +++ b/src/pilot.h @@ -236,6 +236,7 @@ int pilot_getJumps(const Pilot* p); /* Misc. */ void pilot_setHostile(Pilot* p); +void pilot_rmHostile(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,