-
Notifications
You must be signed in to change notification settings - Fork 0
/
zone.cpp
52 lines (46 loc) · 980 Bytes
/
zone.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
#include "entities.h"
using namespace std;
class Zone {
public:
int pop,mpop;
Entity** ents;
int empty();
int full();
int nsEnt(Entity* e); // I[ns]ert [Ent]ity
int rmEnt(Entity* e); // [r]e[m]ove [Ent]ity
int tick();
};
int Zone::empty() {
return mpop-pop;
}
int Zone::full() {
return mpop<=pop;
}
int Zone::nsEnt(Entity* e) {
if(full()) {
fprintf(stderr,"zone: full, cannot insert entity\n");
return -1;
}
int i=0;
while(i<mpop&&ents[i]!=0) i++;
ents[i] = e;
return 0;
}
int Zone::rmEnt(Entity* e) {
if(empty()) {
fprintf(stderr,"zone: empty, cannot remove entity\n");
return -1;
}
int i=0;
while(i<mpop&&ents[i]!=e) i++;
if(i==mpop) {
fprintf(stderr,"zone: cannot remove entity not in zone\n");
return -1;
}
ents[i] = 0;
return 0;
}
int tick() {
// Put stuff here to call tick() on all the Entities in the zone
return 0;
}