Original Post
Goal.h - This is the base class for storing NPCs' goals NPC.h TakeItem.h - This is a class that is a specific Goal for taking items off of the ground Another file... So in the last part is within a function I call from my main.cpp file. So basically the currGoal variable is a pointer so I can put any Goal I want there (like the TakeItem goal for instance) My question is do I need some sort of deep copy so currGoal can see all the pointers that are in the take variable? If so, I'm a bit confused about how to go about doing a deep copy. The inheritance is making it confusing for me. Thanks!
class Goal
{
private:
Character *doer;
Character *giver;
//TODO --- Item rewards[3];
//TODO --- NEED fulfilled;
public:
MORALITY morality; //good, evil, etc
public:
bool finished; //is it finished
virtual void Execute()=0;
...
class NPC : public Character
{
public:
Goal *currGoal;
};
class Goal;
class Move;
class TakeItem : public Goal
{
public:
Item *item;
Move move;
TakeItem() {
item=NULL;
setDoer(NULL);
finished=false;
}
void Execute ()
{
if (!move.finished)
{
move.Execute();
printf("%s moves to (%f,%f,%f)\n", getDoer()->getName(),getDoer()->x,getDoer()->y,getDoer()->z);
//if the npc just finished the move:
if (move.finished)
{
item->personCarrying=getDoer();
printf("\n%s takes item: <%s>\n\n",getDoer()->getName(), item->getName());
}
}
else
finished=true;
}
};
TakeItem take;
take.item=items[indexOfClosestItem];
take.setDoer(&NPCs);
NPCs.currGoal=&take