1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
#include <iostream>
#include <limits>
using namespace std;
typedef class Room_Data;
typedef class Char_Data;
// adds obj to dll
template <typename T1, typename T2>
void LINK(T1& link, T2& first, T2& last)
{
if (!first) first = link;
else last->next_content = link;
link->next_content = NULL;
link->prev_content = last;
last = link;
}
// removes obj from dll
template <typename T1, typename T2>
void UNLINK(T1& link, T2& first, T2& last)
{
if (!link->prev_content)
first = link->next_content;
else
link->prev_content->next_content = link->next_content;
if (!link->next_content)
last = link->prev_content;
else
link->next_content->prev_content = link->prev_content;
}
class Obj_Data
{
public:
Obj_Data * next;
Obj_Data * prev;
Obj_Data * next_content; //dll iterators for rooms and charact inv
Obj_Data * prev_content; //" "
Char_Data * carried_by;
Room_Data * in_room;
char * name;
}*pObj;
class Room_Data
{
public:
Room_Data() { first_content = NULL; last_content = NULL;}
~Room_Data() {};
Obj_Data * first_content; //objects inroom
Obj_Data * last_content; //" "
int vnum;
};
class Char_Data
{
public:
Char_Data() { first_carry = NULL; last_carry = NULL;}
~Char_Data() {};
Obj_Data * first_carry;
Obj_Data * last_carry;
char * name;
};
// adds object to room dll
void move_obj(Room_Data *pRoom, char * name)
{
pObj = new Obj_Data;
pObj->name = name;
LINK(pObj, pRoom->first_content, pRoom->last_content); //adds object to room
pObj->in_room = pRoom;
pObj->carried_by = NULL;
return;
}
// adds obj to characters dll
void add_obj(Char_Data *ch, char * name)
{
pObj = new Obj_Data;
pObj->name = name;
LINK(pObj, ch->first_carry, ch->last_carry); //adds object to char inv
pObj->carried_by = ch;
pObj->in_room = NULL;
return;
}
int main()
{
Room_Data *pRoom;
pRoom = new Room_Data;
pRoom->vnum = 2400;
Char_Data *ch;
ch = new Char_Data;
ch->name = "Jim";
add_obj(ch, "pouch");
add_obj(ch, "box");
add_obj(ch, "sword");
move_obj(pRoom, "pipe");
cout << "Press ENTER to quit." << flush;
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
return 0;
}
|