-
Notifications
You must be signed in to change notification settings - Fork 0
/
Area.cpp
194 lines (157 loc) · 4.26 KB
/
Area.cpp
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**
* @file Area.cpp
* Provides the functionality for an area in a game.
*
* @brief Source file for Area functionality.
*
* @author Michael Abrams
* @author James Boocock
* @author Toby Herbert
* @author Tatai Nikora
* @version 0.3
*/
#include "Area.h"
std::string Area::get_area_name(){
return name;
}
bool Area::has_description(std::string desc_id) {
for(int desc = 0; desc < num_descriptions; desc++) {
if(!description[desc]->get_id().compare(desc_id)) {
return true;
}
}
return false;
}
std::string Area::get_status() {
return status;
}
bool Area::has_current_desc() {
return has_description(curr_desc_id);
}
int Area::get_num_items() {
return num_items;
}
std::string Area::get_description() {
for(int desc = 0; desc < num_descriptions; desc++) {
if(!description[desc]->get_id().compare(curr_desc_id)) {
return description[desc]->get_description();
}
}
return "";
}
void Area::remove_item(int index) {
items.erase(items.begin()+index);
num_items--;
}
void Area::remove_item(std::string item_id){
for(unsigned int i=0; i < items.size(); i++){
if(!items[i]->get_id().compare(item_id)){
items.erase(items.begin() + i);
num_items--;
}else if(items[i]->has_synonym(item_id)) {
items.erase(items.begin() + i);
num_items--;
}else{
items[i]->remove_item(item_id);
}
}
}
void Area::add_item(Item *new_item) {
items.push_back(new_item);
num_items++;
}
Item *Area::get_item(int index) {
return items[index];
}
std::string Area::get_id() {
return id;
}
bool Area::has_item(std::string item_to_find) {
for(unsigned int item_num = 0; item_num < items.size(); item_num++) {
if(items[item_num]->get_id().compare(item_to_find) == 0) {
return true;
}
else if(items[item_num]->has_synonym(item_to_find)) {
return items[item_num];
}
}
return false;
}
Item * Area::get_item(std::string item_id, unsigned int &index) {
for(unsigned int item_num = 0; item_num < items.size(); item_num++) {
if(items[item_num]->get_id().compare(item_id) == 0) {
index = item_num;
return items[item_num];
}
else if(items[item_num]->has_synonym(item_id)) {
index = item_num;
return items[item_num];
}else if(items[item_num]->has_container() && !items[item_num]->is_locked()){
Item* temp_item = items[item_num]->get_item(item_id);
if(temp_item != NULL){
return temp_item;
}
}
}
return NULL;
}
void Area::add_description(StateDescriptor *desc) {
description.push_back(desc);
num_descriptions++;
}
void Area::add_command(AreaCommand *command_name) {
commands.push_back(command_name);
num_commands++;
}
int Area::get_num_commands() {
return num_commands;
}
AreaCommand *Area::get_command(int index) {
return commands[index];
}
AreaCommand *Area::has_command(std::string command_name) {
for(unsigned int c_num = 0; c_num < commands.size(); c_num++) {
if(!commands[c_num]->get_name().compare(command_name)) {
return commands[c_num];
} else if(commands[c_num]->has_synonym(command_name)) {
return commands[c_num];
}
}
return NULL;
}
int Area::get_num_descriptions() {
return num_descriptions;
}
StateDescriptor *Area::get_descriptor(int index) {
return description[index];
}
Area::Area(const char *id, const char *desc_id, const char* status, const char* name) {
this->status = status;
this->id = id;
num_descriptions = 0;
num_items = 0;
num_commands = 0;
this->curr_desc_id = desc_id;
this->name = name;
if(!strcmp(name ,"none")){
this->name = id;
}
}
Area::~Area() {
for(unsigned int item_num = 0; item_num < items.size(); item_num++) {
delete items[item_num];
}
for(unsigned int desc_num = 0; desc_num < description.size(); desc_num++) {
delete description[desc_num];
}
for(unsigned int command_num = 0; command_num < commands.size(); command_num++) {
delete commands[command_num];
}
}
void Area::unlock(std::string area_command_id) {
for(unsigned int c_num = 0; c_num < commands.size(); c_num++) {
if(!commands[c_num]->get_name().compare(area_command_id)) {
commands[c_num]->unlock();
}
}
}