Hi guys I am a little confused on using these two together, I am not allowed to use and special libraries to do this so I just have to use header files. I have to make a C++ class to for a NPC/Player for this game so I am just putting my C struct inside of the class and I will make C interface functions there will interface with the C++ functions to use the C functions. You may say this is stupid but the whole point of this HW is for me to interface C++ and C so its not supposed to make sense. My problem is I have a header file that describes the Monster struct and in my class I have a pointer to the Monster struct. When I try compiling the .cpp file using g++ it gives me an error that it doesn't know the type Monster that is described in the header file.
gameMap.h
#ifndef HEADER_H
#define HEADER_H
#ifdef __cplusplus
extern "C"{
#else
#endif
#include <ncurses.h>
#include "heap.h"
struct list{
int directions[1000];
int size;
};
typedef struct{
struct list directions;
int thePlayer;
int bigPeople;
int dragon;
int other;
unsigned int characteristics : 4; /*Intel,Telapath,Tunneling,Erratic*/
int alive;
int xloc;
int yloc;
int modelNumber;
unsigned int roundVal;
int speed;
int patrolMode;
int searchLocationX;
int searchLocationY;
}Monster;
typedef struct {
int topLeft[2];
int topright[2];
int bottomLeft[2];
int bottomRight[2];
}Room;
typedef struct{
int distance;
int xloc;
int yloc;
}distanceCell;
typedef struct {
char grid[21][80];
distanceCell distanceGrid[21][80];
distanceCell nonTunnelingDistanceGrid[21][80];
unsigned char hardness[21][80];
Monster *thePlayer;
Room rooms[100];
int numOfRooms;
int pcX;
int pcY;
}Map;
typedef struct corridor_path corridor_path_t;
int initMap(int numOfMonster);
void printGrid(void);
void printDistanceGrid(void);
void printDistanceGridPlus();
void playGame();
void initMonsterLib(Map *map, int numOfMax);
Monster* MonsterInit(Map *map,int x,int y,int isPlayer);
int moveUp(Monster *mon);
int moveDown(Monster *mon);
int moveRight(Monster *mon);
int moveLeft(Monster *mon);
int moveTopRight(Monster *mon);
int moveTopLeft(Monster *mon);
int moveBottomLeft(Monster *mon);
int moveBottomRight(Monster *mon);
int isIntelegent(Monster *mon);
int isTelapathic(Monster *mon);
int canTunnle(Monster *mon);
void reInitMap(int num_of_mon);
int isErratic(Monster *mon);
int hasMonster(int xl, int yl);
void deconstructor(Monster *m);
void performAction(Monster *mon);
int scanArea(Monster *mon);
int getPCX();
int getPCY();
int32_t compare_monster(const void *key,const void *with);
void analyzeDistances(void);
Room* pointContains(int y,int x);
int performPCMove(Monster *pci);
extern Monster* monsterArray[21][80];
extern Map *m;
extern int NUMBER_OF_MONSTERS;
//extern WINDOW *window;
extern binheap_t heap;
#ifdef __cpluspluc
}
#endif
#endif
#include <cstring>
#include <cstdlib>
#include "mons.h"
#include "gameMap.h"
/*Library Variables*/
int pcx;
int pcy;
Monster* monsterArray[21][80] = {{NULL}};
/*Functions to be called by C*/
int getPCX(){
return pcx;
}
int getPCY(){
return pcy;
}
int hasMonster(int yl, int xl){
if(yl>21 || 0>yl){
return 0;
}
if(xl>80 || 0>xl){
return 0;
}
if(!monsterArray[yl][xl]){
return 0;
}
return 1;
}
Monster::Monster(int x, int y,int isPlayer){
Monster *monster;
monster = malloc(sizeof(Monster));
if(isPlayer){
monster->thePlayer=1;
monster->speed=10;
monster->roundVal=10;
monster->xloc=x;
monster->yloc=y;
pcx = x;
pcy = y;
monster->alive=1;
}else{
initList();
monster->thePlayer=0;
monster->bigPeople=0;
monster->dragon=0;
monster->other=0;
monster->patrolMode=1;
monster->alive=1;
monster->characteristics = rand()%16;
monster->yloc=y;
monster->searchLocationY=y;
monster->searchLocationX=x;
monster->xloc=x;
int typeSwitch = rand()%3;
switch(typeSwitch){
case 0:
monster->bigPeople=1;
break;
case 1:
monster->dragon=1;
break;
case 2:
monster->other=1;
break;
}
if(!isPlayer){
int spee = (rand()%19)+1;
spee = 100 / spee;
if(spee<5){
spee=spee+5;
}
monster->roundVal=spee;
monster->speed= spee;
}
numOfMonsters++;
}
monsterArray[monster->yloc][monster->xloc]=monster;
this.monster = monster;
}
Monster::~Monster(){
free(monster);
}
Monster::moveUp(){
}
/*Private*/
void Monster::initList(){
this.directions.size=0;
}
void Monster::addToList(int num){
this.directions.directions[this.directions.size]=num;
this.directions.size++;
}
void Monster::reset(){
this.directions.size=0;
}
int Monster::removeFromList(){
int num = this.directions.directions[0];
int x;
for(x=1;x<this.directions.size;x++){
this.directions.directions[x-1]=this.directions.directions[x];
}
this.directions.size--;
return num;
}
mons.cpp
/*public*/
int Monster::moveUpC(){
return moveUp(this.monster);
}
int Monster::moveDownC(){
return moveDown(this.monster);
}
int Monster::moveRightC(){
return moveRight(this.monster);
}
int Monster::moveLeftC(){
return moveLeft(this.monster);
}
int Monster::moveTopRightC(){
return moveTopright(this.monster);
}
int Monster::moveTopLeftC(){
return moveTopLeft(this.monster);
}
int Monster::moveBottomLeftC(){
return moveBottomLeft(this.monster);
}
int Monster::moveBottomRightC(){
return moveBottomRight(this.monster);
}
int Monster::isIntelegent(){
int unsigned temp = this.characteristics;
return 1 & temp;
}
int Monster::isTelapathic(){
int unsigned temp = this.characteristics;
return 2 & temp;
}
int Monster::canTunnle(){
int unsigned temp = this.characteristics;
return 4 & temp;
}
int Monster::isErratic(){
int unsigned temp = this.characteristics;
return 8 & temp;
}
void Monster::performAction(){
performAction(this.monster);
}
void Monster::readDirectionsC(){
readDirections(this.monster);
}
void Monster::getDirectionsTunnelingC(){
getDirectionsTunneling(this.monster);
}
void Monster::getDirectionsC(){
getDirections(this.monster);
}
void Monster::performWanderC(){
performWander(this.monster);
}
void Monster::moveNearestNonTunnelingC(){
moveNearestNonTunneling(this.monster)
}
void Monster::moveNearestTunnelingC(){
moveNearestTunneling(this.monster);
}
int Monster::scanAreaC(){
return scanArea(this.monster);
}