From 4e64a229180f467b897944179bca453e33a577ff Mon Sep 17 00:00:00 2001 From: Edgar Simo Date: Thu, 17 Mar 2011 21:11:12 +0100 Subject: [PATCH] * Fixed issue in AI where player would lose it's memory. --- src/ai.c | 14 ++++++++------ src/pilot.c | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/ai.c b/src/ai.c index 430d589ed5..245371c806 100644 --- a/src/ai.c +++ b/src/ai.c @@ -544,11 +544,13 @@ void ai_destroy( Pilot* p ) L = p->ai->L; /* Get rid of pilot's memory. */ - lua_getglobal(L, AI_MEM); /* t */ - lua_pushnumber(L, p->id); /* t, id */ - lua_pushnil(L); /* t, id, nil */ - lua_settable(L,-3); /* t */ - lua_pop(L,1); /* */ + if (!pilot_isPlayer(p)) { /* Player is an exception as more than one ship shares pilot id. */ + lua_getglobal(L, AI_MEM); /* t */ + lua_pushnumber(L, p->id); /* t, id */ + lua_pushnil(L); /* t, id, nil */ + lua_settable(L,-3); /* t */ + lua_pop(L,1); /* */ + } /* Clear the tasks. */ ai_cleartasks( p ); @@ -839,7 +841,7 @@ void ai_attacked( Pilot* attacked, const unsigned int attacker ) if (pilot_isFlag( attacked, PILOT_MANUAL_CONTROL )) return; - /* Must have an AI profile. */ + /* Must have an AI profile and not be player. */ if (attacked->ai == NULL) return; diff --git a/src/pilot.c b/src/pilot.c index c8dd0dc71b..0fa383ef94 100644 --- a/src/pilot.c +++ b/src/pilot.c @@ -2006,15 +2006,15 @@ void pilot_free( Pilot* p ) pilot_cargoRmRaw( p, p->commodities[0].commodity, p->commodities[0].quantity, 1 ); + /* Clean up data. */ + if (p->ai != NULL) + ai_destroy(p); /* Must be destroyed first if applicable. */ + /* Free name and title. */ if (p->name != NULL) free(p->name); if (p->title != NULL) free(p->title); - - /* Clean up data. */ - if (p->ai != NULL) - ai_destroy(p); /* Must be destroyed first if applicable. */ /* Case if pilot is the player. */ if (player.p==p) player.p = NULL;