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 (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001-2003 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2001-2003 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * 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 |
10 | * 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 |
11 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
12 | * option) any later version. |
12 | * |
13 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
17 | * |
18 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
21 | * <http://www.gnu.org/licenses/>. |
21 | * |
22 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
24 | */ |
24 | |
25 | |
25 | #include <global.h> |
26 | #include <global.h> |
26 | #include <object.h> |
27 | #include <object.h> |
… | |
… | |
104 | } |
105 | } |
105 | |
106 | |
106 | if (i >= 0) |
107 | if (i >= 0) |
107 | { |
108 | { |
108 | maptile *m = newmap; |
109 | maptile *m = newmap; |
109 | sint16 nx = x + freearr_x[i]; |
110 | sint16 nx = x + DIRX (i); |
110 | sint16 ny = y + freearr_y[i]; |
111 | sint16 ny = y + DIRY (i); |
111 | |
112 | |
112 | if (xy_normalise (m, nx, ny)) |
113 | if (xy_normalise (m, nx, ny)) |
113 | { |
114 | { |
114 | newmap = m; |
115 | newmap = m; |
115 | x = nx; |
116 | x = nx; |
… | |
… | |
151 | |
152 | |
152 | if (i < 0) |
153 | if (i < 0) |
153 | golem->drop_and_destroy (); |
154 | golem->drop_and_destroy (); |
154 | else |
155 | else |
155 | { |
156 | { |
156 | newmap->insert (golem, x + freearr_x[i], y + freearr_y[i]); |
157 | newmap->insert (golem, x + DIRX (i), y + DIRY (i)); |
157 | golem->direction = find_dir_2 (golem->x - x, golem->y - y); |
158 | golem->direction = find_dir_2 (golem->x - x, golem->y - y); |
158 | } |
159 | } |
159 | } |
160 | } |
160 | } |
161 | } |
161 | |
162 | |
… | |
… | |
186 | flag = 0; |
187 | flag = 0; |
187 | for_all_players (pl) |
188 | for_all_players (pl) |
188 | { |
189 | { |
189 | pl->refcnt_chk (); |
190 | pl->refcnt_chk (); |
190 | |
191 | |
191 | if (expect_false (!pl->ob || !pl->ns || !pl->ob->active)) |
192 | if (ecb_expect_false (!pl->ob || !pl->ns || !pl->ob->active)) |
192 | continue; |
193 | continue; |
193 | |
194 | |
194 | if (handle_newcs_player (pl->ob)) |
195 | if (handle_newcs_player (pl->ob)) |
195 | flag = 1; |
196 | flag = 1; |
196 | } |
197 | } |
… | |
… | |
201 | object *ob = pl->ob; |
202 | object *ob = pl->ob; |
202 | |
203 | |
203 | // process_objects destroys the speed_left value |
204 | // process_objects destroys the speed_left value |
204 | pl->speed_left_save = ob->speed_left; |
205 | pl->speed_left_save = ob->speed_left; |
205 | |
206 | |
206 | if (expect_false (!ob || !pl->ns || !ob->active)) |
207 | if (ecb_expect_false (!ob || !pl->ns || !ob->active)) |
207 | continue; |
208 | continue; |
208 | |
209 | |
209 | do_some_living (ob); |
210 | do_some_living (ob); |
210 | } |
211 | } |
211 | } |
212 | } |
… | |
… | |
237 | // used for the inner loop |
238 | // used for the inner loop |
238 | if (_i < actives.size ()) // HACK, rely on _i :/ |
239 | if (_i < actives.size ()) // HACK, rely on _i :/ |
239 | { |
240 | { |
240 | object *next = actives [_i + 1]; |
241 | object *next = actives [_i + 1]; |
241 | |
242 | |
242 | prefetch (&next->flag , 0, 1); |
243 | ecb_prefetch (&next->flag , 0, 1); |
243 | prefetch (&next->speed , 0, 1); |
244 | ecb_prefetch (&next->speed , 0, 1); |
244 | prefetch (&next->anim_speed, 0, 1); |
245 | ecb_prefetch (&next->anim_speed, 0, 1); |
245 | prefetch (&next->contr , 0, 1); |
246 | ecb_prefetch (&next->contr , 0, 1); |
246 | } |
247 | } |
247 | |
248 | |
248 | /* Now process op */ |
249 | /* Now process op */ |
249 | if (expect_false (op->flag [FLAG_FREED])) |
250 | if (ecb_expect_false (op->flag [FLAG_FREED])) |
250 | { |
251 | { |
251 | LOG (llevError, "BUG: process_events(): Free object on list (%s)\n", op->debug_desc ()); |
252 | LOG (llevError, "BUG: process_events(): Free object on list (%s)\n", op->debug_desc ()); |
252 | op->set_speed (0); |
253 | op->set_speed (0); |
253 | continue; |
254 | continue; |
254 | } |
255 | } |
255 | |
256 | |
256 | if (expect_false (!op->has_active_speed ())) |
257 | if (ecb_expect_false (!op->has_active_speed ())) |
257 | { |
258 | { |
258 | LOG (llevError, "BUG: process_events(): Object %s has no speed (%f), " |
259 | LOG (llevError, "BUG: process_events(): Object %s has no speed (%f), " |
259 | "but is on active list\n", op->debug_desc (), op->speed); |
260 | "but is on active list\n", op->debug_desc (), op->speed); |
260 | op->set_speed (0); |
261 | op->set_speed (0); |
261 | continue; |
262 | continue; |
262 | } |
263 | } |
263 | |
264 | |
264 | if (expect_false (op->flag [FLAG_REMOVED])) |
265 | if (ecb_expect_false (op->flag [FLAG_REMOVED])) |
265 | { |
266 | { |
266 | LOG (llevError, "BUG: process_events(): removed object is on active list: %s\n", |
267 | LOG (llevError, "BUG: process_events(): removed object is on active list: %s\n", |
267 | op->debug_desc ()); |
268 | op->debug_desc ()); |
268 | op->set_speed (0); |
269 | op->set_speed (0); |
269 | continue; |
270 | continue; |
… | |
… | |
278 | op->last_anim = 1; |
279 | op->last_anim = 1; |
279 | } |
280 | } |
280 | else |
281 | else |
281 | ++op->last_anim; |
282 | ++op->last_anim; |
282 | |
283 | |
283 | if (expect_false (op->speed_left > 0.f)) |
284 | if (ecb_expect_false (op->speed_left > 0.f)) |
284 | { |
285 | { |
285 | --op->speed_left; |
286 | --op->speed_left; |
286 | process_object (op); |
287 | process_object (op); |
287 | } |
288 | } |
288 | |
289 | |
… | |
… | |
387 | do_specials () |
388 | do_specials () |
388 | { |
389 | { |
389 | shstr::gc (); |
390 | shstr::gc (); |
390 | archetype::gc (); |
391 | archetype::gc (); |
391 | |
392 | |
392 | if (expect_false (!(server_tick % TICKS_PER_HOUR))) |
393 | if (ecb_expect_false (!(server_tick % TICKS_PER_HOUR))) |
393 | maptile::adjust_daylight (); |
394 | maptile::adjust_daylight (); |
394 | |
395 | |
395 | if (expect_false (!(server_tick % 2503))) |
396 | if (ecb_expect_false (!(server_tick % 2503))) |
396 | fix_weight (); /* Hack to fix weightproblems caused by bugs */ |
397 | fix_weight (); /* Hack to fix weightproblems caused by bugs */ |
397 | |
398 | |
398 | if (expect_false (!(server_tick % 5003))) |
399 | if (ecb_expect_false (!(server_tick % 5003))) |
399 | write_book_archive (); |
400 | write_book_archive (); |
400 | |
401 | |
401 | if (expect_false (!(server_tick % 5009))) |
402 | if (ecb_expect_false (!(server_tick % 5009))) |
402 | clean_friendly_list (); |
403 | clean_friendly_list (); |
403 | |
404 | |
404 | if (expect_false (!(server_tick % 5011))) |
405 | if (ecb_expect_false (!(server_tick % 5011))) |
405 | obsolete_parties (); |
406 | obsolete_parties (); |
406 | |
407 | |
407 | if (expect_false (!(server_tick % 12503))) |
408 | if (ecb_expect_false (!(server_tick % 12503))) |
408 | fix_luck (); |
409 | fix_luck (); |
409 | } |
410 | } |
410 | |
411 | |
411 | void |
412 | void |
412 | one_tick () |
413 | one_tick () |
… | |
… | |
431 | { |
432 | { |
432 | settings.argc = argc; |
433 | settings.argc = argc; |
433 | settings.argv = argv; |
434 | settings.argv = argv; |
434 | |
435 | |
435 | rndm.seed (time (0)); |
436 | rndm.seed (time (0)); |
436 | g_thread_init (0); // for the slice allocator only |
|
|
437 | |
437 | |
438 | // temporary(?) testing hack |
438 | // temporary(?) testing hack |
439 | if (argc >= 2 && !strcmp (argv [1], "--noise")) |
439 | if (argc >= 2 && !strcmp (argv [1], "--noise")) |
440 | { |
440 | { |
441 | void noise_test (); |
441 | void noise_test (); |