Hi, this is a very long post and im really sorry, but i dont know where else to turn
I have a main program that has a list of objects (each one a class NPC),
this is to represent a list of bots, using the STL <list>.
Im passing that list as a parametre to the NPC class constructor along with an int reference so the NPC knows which NPC in the list he is. The NPC's constructor looks like :
NPC(list<NPC> *NPClist, int ref);
First question is am i able to do the above? make class NPC accept as a construtor parametre a pointer to a list of NPC's from back in the main class?
The reason i need it like this is that NPC has two pointers to other classes as well (Environment and AI) which are 'newed' inside the NPC's constructor for each bot. These objects are inturn passed an NPC pointer of 'this' NPC so that they can refer back to its public functions to change conditions and movement for each tic. The Environment class will be sent the list of NPC's each tic (to refresh it and remove dead bots and update thier status etc) so the AI class can query where the player character and others are. The AI class contains a state machine with 4 states (patrol, chase etc) and calculation functions (finding waypoints, turning, firing etc) and sets the bool states and movement by calling back the NPC public set functions.
After the initial constuction, i was just planning to cycle through the NPC list in the main program each tic, call reCalc for each one and send it the updated list.
But i am getting errors like the following:
environment.h(21) : error C2629: unexpected 'class Environment ('
environment.h(21) : error C2238: unexpected token(s) preceding ';'
environment.h(27) : error C2061: syntax error : identifier 'list'
environment.h(38) : error C2143: syntax error : missing ';' before '<'
environment.h(38) : error C2501: 'list' : missing storage-class or type specifiers
environment.h(38) : error C2059: syntax error : '<'
environment.h(38) : error C2238: unexpected token(s) preceding ';'
environment.h(41) : error C2143: syntax error : missing ';' before '*'
environment.h(41) : error C2501: 'NPC' : missing storage-class or type specifiers
environment.h(41) : error C2501: 'body' : missing storage-class or type specifiers
ai.h(25) : error C2629: unexpected 'class AI ('
ai.h(25) : error C2238: unexpected token(s) preceding ';'
etc...
those two classes accept the 'this' parametre like so:
AI(NPC *parent);
Environment(NPC *parent);
I really dont know what i am doing wrong and my head cant really think at the moment, i would love some advice if anyone can help pleaseee.
The two pointers in the NPC header are:
Environment *Geometry;
AI *Brain;
and basically the code in the NPC implimentation file looks like this:
Code:
NPC::NPC(list<NPC> *NPClist, int ref) {
//If '0' it means this is the player, who is always the '0' element
if(ref == 0) {
this->is_Player = true;
this->Brain = NULL;
this->Geometry = NULL;
}
else
this->is_Player = false;
this->is_Hurt = false;
this->is_Still = false;
this->in_Combat = false;
this->is_Fleeing = false;
this->is_Firing = false;
this->is_Meelee = false;
this->is_Walking = true;
this->is_Running = false;
this->is_Dead = false;
this->in_Shoot_Range = false;
this->in_Meelee_Range = false;
this->has_Ammo = true;
this->Enemy_Spotted = false;
this->Player_Hit = false;
this->status = PATROL;
this->health = 100;
if(!is_Player) {
//Creating brain and environment
try {
this->Brain = new AI(this);
this->Geometry = new Environment(this);
}
catch(...) {cerr << "\nError, Could not new memory for NPC" << endl;}
//Request think cycle
reCalc(NPClist);
}
}
void NPC::reCalc(list<NPC> *NPClist) {
//Refresh the NPC surroundings knowledge
this->Geometry.refresh(NPClist);
//If this isnt the player, then think and move
if(!is_Player) {
Brain.Cycle();
set_Movement();
}
}
void NPC::set_Movement() {
//use updated x,y,z,yaw,pitch position stored in struct motion
//If not ok, recall brain cycle and try again
}
Thanks.