diff options
Diffstat (limited to 'src/entities.cpp')
-rw-r--r-- | src/entities.cpp | 103 |
1 files changed, 68 insertions, 35 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index 4e582c9..100eefb 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -10,6 +10,39 @@ extern Player *player; extern const char *itemName; +void getRandomName(Entity *e){ + int tempNum,max=0; + char buf,*bufs; + + rewind(names); + + bufs = new char[16]; //(char *)malloc(16); + + for(;!feof(names);max++){ + fgets(bufs,16,(FILE*)names); + } + + tempNum = rand() % max; + rewind(names); + + for(int i=0;i<tempNum;i++){ + fgets(bufs,16,(FILE*)names); + } + + switch(fgetc(names)){ + case 'm': e->gender = MALE; break; + case 'f': e->gender = FEMALE;break; + default : break; + } + + if((fgets(bufs,16,(FILE*)names)) != NULL){ + bufs[strlen(bufs)-1] = '\0'; + strcpy(e->name,bufs); + } + + delete[] bufs; +} + void Entity::spawn(float x, float y){ //spawns the entity you pass to it based off of coords and global entity settings loc.x = x; loc.y = y; @@ -33,8 +66,8 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o } } - name = new char[16]; //(char*)malloc(16); - getName(); + name = new char[16]; + getRandomName(this); } Player::Player(){ //sets all of the player specific traits on object creation @@ -48,6 +81,11 @@ Player::Player(){ //sets all of the player specific traits on object creation tex = new Texturec(3, "assets/player1.png", "assets/player.png", "assets/player2.png"); inv = new Inventory(PLAYER_INV_SIZE); } +Player::~Player(){ + delete inv; + delete tex; + delete[] name; +} NPC::NPC(){ //sets all of the NPC specific traits on object creation width = HLINE * 10; @@ -63,6 +101,15 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation tex = new Texturec(1,"assets/NPC.png"); inv = new Inventory(NPC_INV_SIZE); } +NPC::~NPC(){ + while(!aiFunc.empty()){ + aiFunc.pop_back(); + } + + delete inv; + delete tex; + delete[] name; +} Structures::Structures(){ //sets the structure type health = maxHealth = 1; @@ -74,6 +121,11 @@ Structures::Structures(){ //sets the structure type inWorld = NULL; } +Structures::~Structures(){ + delete inv; + delete tex; + delete[] name; +} Mob::Mob(int sub){ type = MOBT; @@ -99,6 +151,11 @@ Mob::Mob(int sub){ inv = new Inventory(NPC_INV_SIZE); } +Mob::~Mob(){ + delete inv; + delete tex; + delete[] name; +} Object::Object(ITEM_ID id, bool qo, const char *pd){ identifier = id; @@ -107,6 +164,7 @@ Object::Object(ITEM_ID id, bool qo, const char *pd){ pickupDialog = new char[strlen(pd)+1]; strcpy(pickupDialog,pd); + type = OBJECTT; alive = true; near = false; @@ -115,8 +173,15 @@ Object::Object(ITEM_ID id, bool qo, const char *pd){ maxHealth = health = 1; tex = new Texturec(1,getItemTexturePath(id)); -} +} +Object::~Object(){ + delete[] pickupDialog; + + delete inv; + delete tex; + delete[] name; +} void Entity::draw(void){ //draws the entities glPushMatrix(); @@ -208,38 +273,6 @@ NOPE: } } -void Entity::getName(){ - rewind(names); - char buf,*bufs = new char[16]; //(char *)malloc(16); - int tempNum,max = 0; - for(;!feof(names);max++){ - fgets(bufs,16,(FILE*)names); - } - tempNum = rand()%max; - rewind(names); - for(int i=0;i<tempNum;i++){ - fgets(bufs,16,(FILE*)names); - } - switch(fgetc(names)){ - case 'm': - gender = MALE; - //std::puts("Male"); - break; - case 'f': - gender = FEMALE; - //std::puts("Female"); - break; - default: - break; - } - if((fgets(bufs,16,(FILE*)names)) != NULL){ - //std::puts(bufs); - bufs[strlen(bufs)-1] = '\0'; - strcpy(name,bufs); - } - delete[] bufs; //free(bufs); -} - void Player::interact(){ //the function that will cause the player to search for things to interact with } |