Skip to content

Commit

Permalink
* Fixed issue in AI where player would lose it's memory.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbens committed Mar 17, 2011
1 parent fe45388 commit 4e64a22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 8 additions & 6 deletions src/ai.c
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions src/pilot.c
Expand Up @@ -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;
Expand Down

0 comments on commit 4e64a22

Please sign in to comment.