forked from dworkin/gurbalib
/
heart_beat.c
137 lines (116 loc) · 2.97 KB
/
heart_beat.c
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
static int heal_rate;
static int heal_amount;
static int heal_time;
int player_age;
#define YEAR 31536000
#define DAY 86400
#define MIN 60
int is_fighting(void);
void do_fight(void);
int is_alive();
int is_dead();
int add_stat(string statname, int amt);
int query_stat(string statname);
string query_age();
void set_heal_rate(int rate) {
heal_rate = rate;
}
int query_heal_rate(void) {
return (heal_rate);
}
void set_heal_step(int amt) {
heal_amount = amt;
}
int query_heal_step(void) {
return (heal_amount);
}
void create() {
EVENT_D->subscribe_event("heart_beat");
heal_time = 0;
heal_rate = 10;
heal_amount = 2;
if (!intp(player_age)) {
player_age = 0;
}
}
void event_heart_beat(void) {
object sp;
sp = this_player();
set_this_player(this_object());
if (this_object()->is_alive()) {
heal_time++;
if (heal_time > heal_rate) {
heal_time = 0;
if (this_object()->query_hp() < this_object()->query_max_hp())
this_object()->increase_hp(random(heal_amount) + 1);
if (this_object()->query_mana() < this_object()->query_max_mana())
this_object()->increase_mana(random(heal_amount) + 1);
if (this_object()->query_end() < this_object()->query_max_end())
this_object()->increase_end(random(2 * heal_amount) + 1);
}
}
/* Check here to see is we are in combat, if so, continue battle */
if (this_object()->is_fighting() > 0) {
this_object()->do_fight();
} else {
if (function_object("event_wander", this_object())) {
call_other(this_object(), "event_wander");
}
}
set_this_player(sp);
if (!this_object()->is_player()) { /* NPC routines */
if (this_object()->is_dead()) {
EVENT_D->unsubscribe_event("heart_beat");
this_object()->destruct();
}
} else { /* Player routines */
if (this_object()->query_idle() < 60) /* A player ages when not idle */
player_age += HEART_BEAT_INTERVAL;
}
}
string query_age() {
string ret;
int years, days, mins, secs;
secs = player_age;
ret = " ";
while (secs > YEAR) {
years += 1;
secs -= YEAR;
}
while (secs > DAY) {
days += 1;
secs -= DAY;
}
while (secs > MIN) {
mins += 1;
secs -= MIN;
}
if (years > 0) {
ret += years + " years ";
}
if (days > 0) {
ret += days + " days ";
}
if (mins > 0) {
ret += mins + " mins ";
}
if (secs > 0) {
ret += secs + " secs ";
}
return ret;
}
void die(void) {
object obj;
obj = clone_object("/domains/required/objects/corpse");
if (this_object()->is_player()) {
obj->set_name(this_object()->query_Name());
obj->move(this_object()->query_environment());
this_object()->move(VOID);
// XXX Need to figure out consiquences and how to get back to life...
// EVENT_D->unsubscribe_event("heart_beat");
} else {
obj->set_name("a " + this_object()->query_id());
obj->move(this_object()->query_environment());
this_object()->destruct();
}
}