From 80bc1b24bcf6862a7fbd3223a3d6988ce4e389e0 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 1 Dec 2015 07:29:25 -0500 Subject: memory fixes --- src/entities.cpp | 69 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) (limited to 'src/entities.cpp') diff --git a/src/entities.cpp b/src/entities.cpp index 4e582c9..f9723cf 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;igender = 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 @@ -208,38 +241,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