diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-11 14:42:25 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-11 14:42:25 +0000 |
commit | 041c6e3cb599d019d1e92d5087ec6726a5970902 (patch) | |
tree | 893e740d13cb564fce1b5512094a123e139049dd /src | |
parent | 851f567faff580834677d11b8fd45c6b344722a9 (diff) | |
download | mana-041c6e3cb599d019d1e92d5087ec6726a5970902.tar.gz mana-041c6e3cb599d019d1e92d5087ec6726a5970902.tar.bz2 mana-041c6e3cb599d019d1e92d5087ec6726a5970902.tar.xz mana-041c6e3cb599d019d1e92d5087ec6726a5970902.zip |
Switched NODE and PATH_NODE to use constructors.
Diffstat (limited to 'src')
-rw-r--r-- | src/astar.cpp | 8 | ||||
-rw-r--r-- | src/being.cpp | 62 | ||||
-rw-r--r-- | src/being.h | 48 | ||||
-rw-r--r-- | src/game.cpp | 12 |
4 files changed, 60 insertions, 70 deletions
diff --git a/src/astar.cpp b/src/astar.cpp index 5fff9687..00d3be4b 100644 --- a/src/astar.cpp +++ b/src/astar.cpp @@ -288,18 +288,20 @@ PATH_NODE *find_path(int pathfinderID, int s_x, int s_y, int e_x, int e_y) { PATH_NODE *ret = NULL, *temp = NULL; pathLocation = 1; - ret = create_path_node(s_x,s_y); + ret = new PATH_NODE(s_x, s_y); temp = ret; //alert(stringa,"","","","",0,0); while(pathLocation<pathLength) { sprintf(stringa,"%i %i",path_bank[pathLocation*2-2], path_bank[pathLocation*2-1]); //alert(stringa,"","","","",0,0); - temp->next = create_path_node(path_bank[pathLocation*2-2], path_bank[pathLocation*2-1]); + temp->next = new PATH_NODE( + path_bank[pathLocation * 2 - 2], + path_bank[pathLocation * 2 - 1]); if(temp->next==NULL)ok("Error", "Unable to create path node"); temp = temp->next; pathLocation++; } - if(temp!=NULL)temp->next = create_path_node(e_x, e_y); + if(temp!=NULL)temp->next = new PATH_NODE(e_x, e_y); else ok("Error", "Null reference"); return ret; diff --git a/src/being.cpp b/src/being.cpp index 921170aa..1344bfbf 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -22,14 +22,6 @@ */ #include <stdio.h> -#include <memory.h> -#ifndef MACOSX - #include <malloc.h> -#endif - -#ifdef LINUXPPC - #include <malloc.h> -#endif #include "astar.h" #include "being.h" @@ -39,12 +31,11 @@ NODE *head = NULL; // First node of the list unsigned int count = 0; // Number of beings in the list /** Create a path node */ -PATH_NODE *create_path_node(unsigned short x, unsigned short y) { - PATH_NODE *ret = (PATH_NODE *)malloc(sizeof(PATH_NODE)); - ret->x = x; - ret->y = y; - ret->next = NULL; - return ret; +PATH_NODE::PATH_NODE(unsigned short x, unsigned short y): + next(NULL) +{ + this->x = x; + this->y = y; } /** Return a* path */ @@ -58,27 +49,20 @@ NODE *get_head() { } /** Creates a empty node */ -NODE *create_node() { - NODE *node = (NODE *)malloc(sizeof(NODE)); - node->id = 0; - node->job = 0; - memset(node->coordinates, 0, 3); - node->next = NULL; - node->action = 0; - node->frame = 0; - node->path = NULL; - node->speech = NULL; - node->speech_time = 0; - node->speech_color = makecol(255,255,255); - node->tick_time = 0; - node->speed = 150; - node->emotion = 0; - node->emotion_time = 0; - node->text_x = node->text_y = 0; - node->hair_style = 1; - node->hair_color = 1; - node->weapon = 0; - return node; +NODE::NODE(): + id(0), job(0), + next(NULL), + action(0), frame(0), + path(NULL), + speech(NULL), speech_time(0), + tick_time(0), speed(150), + emotion(0), emotion_time(0), + text_x(0), text_y(0), + hair_style(1), hair_color(1), + weapon(0) +{ + memset(coordinates, 0, 3); + speech_color = makecol(255,255,255); } /** Returns number of beings in the list */ @@ -92,7 +76,7 @@ void empty() { NODE *next; while(node) { next = node->next; - free(node); + delete node; node = next; } count = 0; @@ -121,12 +105,12 @@ void remove_node(unsigned int id) { if(temp==id) { if(node_new==NULL) { head = node_old->next; - free(node_old); + delete node_old; count--; return; } else { node_new->next = node_old->next; - free(node_old); + delete node_old; count--; return; } @@ -222,7 +206,7 @@ void empty_path(NODE *node) { PATH_NODE *next; while(temp) { next = temp->next; - free(temp); + delete temp; temp = next; } node->path = NULL; diff --git a/src/being.h b/src/being.h index 5fc88021..78cffcc4 100644 --- a/src/being.h +++ b/src/being.h @@ -32,35 +32,39 @@ #define MONSTER_NODE 3 struct PATH_NODE { - unsigned short x, y; - PATH_NODE *next; + PATH_NODE(unsigned short x, unsigned short y); + + unsigned short x, y; + PATH_NODE *next; }; struct NODE { - unsigned int id; - short job; - char coordinates[3]; - NODE *next; - unsigned char type; - unsigned char action; - unsigned char frame; - PATH_NODE *path; - char *speech; - unsigned char speech_time; - int speech_color; - short tick_time; - short speed; - unsigned char emotion; - unsigned char emotion_time; - int text_x, text_y; // temp solution to fix speech position - short hair_style, hair_color; - short weapon; + NODE(); + + unsigned int id; + short job; + char coordinates[3]; + NODE *next; + unsigned char type; + unsigned char action; + unsigned char frame; + PATH_NODE *path; + char *speech; + unsigned char speech_time; + int speech_color; + short tick_time; + short speed; + unsigned char emotion; + unsigned char emotion_time; + int text_x, text_y; // temp solution to fix speech position + short hair_style, hair_color; + short weapon; }; void empty(); NODE *get_head(); -NODE *create_node(); -PATH_NODE *create_path_node(unsigned short x, unsigned short y); +//NODE *create_node(); +//PATH_NODE *create_path_node(unsigned short x, unsigned short y); void add_node(NODE *node); NODE *find_node(unsigned int id); void remove_node(unsigned int id); diff --git a/src/game.cpp b/src/game.cpp index a0e428ae..26c99f93 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -136,7 +136,7 @@ void do_init() { // Initialize beings empty(); - player_node = create_node(); + player_node = new NODE(); player_node->id = account_ID; player_node->type = ACTION_NODE; set_coordinates(player_node->coordinates, x, y, 0); @@ -409,7 +409,7 @@ void do_parse() { // Add new being / stop monster case 0x0078: if(find_node(RFIFOL(2))==NULL) { - node = create_node(); + node = new NODE(); node->id = RFIFOL(2); node->speed = RFIFOW(6); if(node->speed==0)node->speed = 150; // Else division by 0 when calculating frame @@ -450,7 +450,7 @@ void do_parse() { case 0x01d9: node = find_node(RFIFOL(2)); if(node==NULL) { - node = create_node(); + node = new NODE(); node->id = RFIFOL(2); node->job = RFIFOW(14); memcpy(node->coordinates, RFIFOP(46), 3); @@ -467,7 +467,7 @@ void do_parse() { //case 0x01da: node = find_node(RFIFOL(2)); if(node==NULL) { - node = create_node(); + node = new NODE(); node->action = STAND; set_coordinates(node->coordinates, get_src_x(RFIFOP(50)), get_src_y(RFIFOP(50)), 0); node->id = RFIFOL(2); @@ -502,7 +502,7 @@ void do_parse() { case 0x01da: node = find_node(RFIFOL(2)); if(node==NULL) { - node = create_node(); + node = new NODE(); node->id = RFIFOL(2); node->job = RFIFOW(14); set_coordinates(node->coordinates, get_src_x(RFIFOP(50)), get_src_y(RFIFOP(50)), 0); @@ -545,7 +545,7 @@ void do_parse() { append_filename(map_path, "./data/map/", RFIFOP(2), 480); if(load_map(map_path)) { empty(); - player_node = create_node(); + player_node = new NODE(); player_node->job = 0; player_node->action = STAND; player_node->frame = 0; |