1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001-2003,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001-2003 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
… | |
… | |
33 | |
33 | |
34 | #include <../random_maps/random_map.h> |
34 | #include <../random_maps/random_map.h> |
35 | #include <../random_maps/rproto.h> |
35 | #include <../random_maps/rproto.h> |
36 | #include "path.h" |
36 | #include "path.h" |
37 | |
37 | |
38 | static char days[7][4] = { |
|
|
39 | "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" |
|
|
40 | }; |
|
|
41 | |
|
|
42 | void |
38 | void |
43 | version (object *op) |
39 | version (object *op) |
44 | { |
40 | { |
45 | new_draw_info_format (NDI_UNIQUE, 0, op, "This is Deliantra v%s", VERSION); |
41 | new_draw_info_format (NDI_UNIQUE, 0, op, "This is Deliantra v%s", VERSION); |
46 | } |
42 | } |
… | |
… | |
85 | |
81 | |
86 | if (contr && map != newmap && map) |
82 | if (contr && map != newmap && map) |
87 | if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr))) |
83 | if (INVOKE_MAP (LEAVE, map, ARG_PLAYER (contr))) |
88 | return; |
84 | return; |
89 | |
85 | |
90 | // remove, so stupid ob_locked does not trigger a failure |
86 | // remove, so stupid blocked does not trigger a failure |
91 | remove (); |
87 | remove (); |
92 | |
88 | |
93 | /* try to find a spot for the player */ |
89 | /* try to find a spot for the player */ |
94 | if (blocked (newmap, x, y)) |
90 | if (blocked (newmap, x, y)) |
95 | { /* First choice blocked */ |
91 | { /* First choice blocked */ |
… | |
… | |
100 | * Note that for the second and third calls, we could start at a position other |
96 | * Note that for the second and third calls, we could start at a position other |
101 | * than one, but then we could end up on the other side of walls and so forth. |
97 | * than one, but then we could end up on the other side of walls and so forth. |
102 | */ |
98 | */ |
103 | int i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE1 + 1); |
99 | int i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE1 + 1); |
104 | |
100 | |
105 | if (i == -1) |
101 | if (i < 0) |
106 | { |
102 | { |
107 | i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE2 + 1); |
103 | i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE2 + 1); |
108 | if (i == -1) |
104 | if (i < 0) |
109 | i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE); |
105 | i = find_free_spot (this, newmap, x, y, 1, SIZEOFFREE); |
110 | } |
106 | } |
111 | |
107 | |
112 | if (i != -1) |
108 | if (i >= 0) |
113 | { |
109 | { |
114 | x += freearr_x[i]; |
110 | x += freearr_x[i]; |
115 | y += freearr_y[i]; |
111 | y += freearr_y[i]; |
116 | } |
112 | } |
117 | else |
113 | else |
… | |
… | |
126 | |
122 | |
127 | if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (contr), ARG_INT (x), ARG_INT (y))) |
123 | if (INVOKE_MAP (ENTER, newmap, ARG_PLAYER (contr), ARG_INT (x), ARG_INT (y))) |
128 | return; |
124 | return; |
129 | } |
125 | } |
130 | |
126 | |
131 | this->x = x; |
127 | newmap->insert (this, x, y, 0, INS_NO_WALK_ON); |
132 | this->y = y; |
|
|
133 | map = newmap; |
|
|
134 | |
|
|
135 | insert_ob_in_map (this, map, 0, INS_NO_WALK_ON); |
|
|
136 | |
128 | |
137 | enemy = 0; |
129 | enemy = 0; |
138 | |
130 | |
139 | if (contr) |
131 | if (contr) |
140 | { |
132 | { |
… | |
… | |
151 | if (i < 0) |
143 | if (i < 0) |
152 | golem->drop_and_destroy (); |
144 | golem->drop_and_destroy (); |
153 | else |
145 | else |
154 | { |
146 | { |
155 | newmap->insert (golem, x + freearr_x[i], y + freearr_y[i]); |
147 | newmap->insert (golem, x + freearr_x[i], y + freearr_y[i]); |
156 | golem->direction = find_dir_2 (x - golem->x, y - golem->y); |
148 | golem->direction = find_dir_2 (golem->x - x, golem->y - y); |
157 | } |
149 | } |
158 | } |
150 | } |
159 | |
151 | |
160 | /* since the players map is already loaded, we don't need to worry |
152 | /* since the players map is already loaded, we don't need to worry |
161 | * about pending objects. |
153 | * about pending objects. |
… | |
… | |
191 | |
183 | |
192 | for_all_players (pl) |
184 | for_all_players (pl) |
193 | { |
185 | { |
194 | object *ob = pl->ob; |
186 | object *ob = pl->ob; |
195 | |
187 | |
|
|
188 | // process_objects destroys the speed_left value |
|
|
189 | pl->speed_left_save = ob->speed_left; |
|
|
190 | |
196 | if (expect_false (!ob || !pl->ns || !ob->active)) |
191 | if (expect_false (!ob || !pl->ns || !ob->active)) |
197 | continue; |
192 | continue; |
198 | |
193 | |
199 | do_some_living (ob); |
194 | do_some_living (ob); |
200 | } |
195 | } |
… | |
… | |
204 | process_players2 () |
199 | process_players2 () |
205 | { |
200 | { |
206 | /* Then check if any players should use weapon-speed instead of speed */ |
201 | /* Then check if any players should use weapon-speed instead of speed */ |
207 | for_all_players (pl) |
202 | for_all_players (pl) |
208 | { |
203 | { |
|
|
204 | // restore speed_left value saved by process_players1 |
|
|
205 | pl->ob->speed_left = pl->speed_left_save; |
|
|
206 | |
209 | pl->weapon_sp_left = min (pl->weapon_sp, pl->weapon_sp_left + pl->weapon_sp); |
207 | pl->weapon_sp_left = min (pl->weapon_sp, pl->weapon_sp_left + pl->weapon_sp); |
210 | pl->ob->speed_left = min (pl->ob->speed, pl->ob->speed_left + pl->ob->speed); |
208 | pl->ob->speed_left = min (pl->ob->speed, pl->ob->speed_left + pl->ob->speed); |
211 | } |
209 | } |
212 | } |
210 | } |
213 | |
211 | |
… | |
… | |
216 | { |
214 | { |
217 | process_players1 (); |
215 | process_players1 (); |
218 | |
216 | |
219 | for_all_actives (op) |
217 | for_all_actives (op) |
220 | { |
218 | { |
|
|
219 | // try to prefetch some stuff we expect to need |
|
|
220 | // obviously, it should be grouped into the same cacheline. |
|
|
221 | // preliminary results indicate that this gives halves the speed |
|
|
222 | // used for the inner loop |
|
|
223 | if (_i < actives.size ()) // HACK, rely on _i :/ |
|
|
224 | { |
|
|
225 | object *next = actives [_i + 1]; |
|
|
226 | |
|
|
227 | prefetch (&next->flag , 0, 1); |
|
|
228 | prefetch (&next->speed , 0, 1); |
|
|
229 | prefetch (&next->anim_speed, 0, 1); |
|
|
230 | prefetch (&next->contr , 0, 1); |
|
|
231 | } |
|
|
232 | |
221 | /* Now process op */ |
233 | /* Now process op */ |
222 | if (expect_false (QUERY_FLAG (op, FLAG_FREED))) |
234 | if (expect_false (op->flag [FLAG_FREED])) |
223 | { |
235 | { |
224 | LOG (llevError, "BUG: process_events(): Free object on list\n"); |
236 | LOG (llevError, "BUG: process_events(): Free object on list\n"); |
225 | op->set_speed (0); |
237 | op->set_speed (0); |
226 | continue; |
238 | continue; |
227 | } |
239 | } |
… | |
… | |
257 | { |
269 | { |
258 | --op->speed_left; |
270 | --op->speed_left; |
259 | process_object (op); |
271 | process_object (op); |
260 | } |
272 | } |
261 | |
273 | |
262 | if (expect_true (!op->contr)) |
274 | // this will destroy the speed_left value for players, but |
|
|
275 | // process_players1 and ..2 save/restore the real value, |
|
|
276 | // so we can avoid a costly test here. |
263 | op->speed_left = min (abs (op->speed), op->speed_left + abs (op->speed)); |
277 | op->speed_left = min (op->speed, op->speed_left + op->speed); |
264 | } |
278 | } |
265 | |
279 | |
266 | process_players2 (); |
280 | process_players2 (); |
267 | } |
281 | } |
268 | |
282 | |
… | |
… | |
353 | * |
367 | * |
354 | * I also think this code makes it easier to see how often we really are |
368 | * I also think this code makes it easier to see how often we really are |
355 | * doing the various things. |
369 | * doing the various things. |
356 | */ |
370 | */ |
357 | static void |
371 | static void |
358 | do_specials (void) |
372 | do_specials () |
359 | { |
373 | { |
360 | shstr::gc (); |
374 | shstr::gc (); |
361 | archetype::gc (); |
375 | archetype::gc (); |
362 | |
376 | |
363 | if (expect_false (!(pticks % TICKS_PER_HOUR))) |
377 | if (expect_false (!(pticks % TICKS_PER_HOUR))) |
… | |
… | |
390 | // then do some bookkeeping, should not really be here |
404 | // then do some bookkeeping, should not really be here |
391 | do_specials (); /* Routines called from time to time. */ |
405 | do_specials (); /* Routines called from time to time. */ |
392 | attachable::check_mortals (); |
406 | attachable::check_mortals (); |
393 | |
407 | |
394 | ++pticks; |
408 | ++pticks; |
|
|
409 | |
|
|
410 | if (object::object_count >= RESTART_COUNT) |
|
|
411 | cleanup ("running out of protocol ID values - need full restart"); |
395 | } |
412 | } |
396 | |
413 | |
397 | // normal main |
414 | // normal main |
398 | int |
415 | int |
399 | main (int argc, char **argv) |
416 | main (int argc, char **argv) |