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,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 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. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | * 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 |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
|
|
24 | |
|
|
25 | //+GPL |
|
|
26 | |
|
|
27 | #include <algorithm> |
|
|
28 | #include <functional> |
24 | |
29 | |
25 | #include <global.h> |
30 | #include <global.h> |
26 | #include <sproto.h> |
31 | #include <sproto.h> |
27 | #include <sounds.h> |
32 | #include <sounds.h> |
28 | #include <living.h> |
33 | #include <living.h> |
29 | #include <object.h> |
34 | #include <object.h> |
30 | #include <spells.h> |
35 | #include <spells.h> |
31 | #include <skills.h> |
36 | #include <skills.h> |
32 | |
37 | |
33 | #include <algorithm> |
|
|
34 | #include <functional> |
|
|
35 | |
|
|
36 | playervec players; |
38 | playervec players; |
37 | |
39 | |
38 | /* This loads the first map an puts the player on it. */ |
40 | /* This loads the first map an puts the player on it. */ |
39 | static void |
41 | static void |
40 | set_first_map (object *op) |
42 | set_first_map (object *op) |
… | |
… | |
52 | |
54 | |
53 | players.insert (this); |
55 | players.insert (this); |
54 | ob->remove (); |
56 | ob->remove (); |
55 | ob->map = 0; |
57 | ob->map = 0; |
56 | ob->activate_recursive (); |
58 | ob->activate_recursive (); |
57 | CLEAR_FLAG (ob, FLAG_FRIENDLY); |
59 | ob->clr_flag (FLAG_FRIENDLY); |
58 | add_friendly_object (ob); |
60 | add_friendly_object (ob); |
59 | } |
61 | } |
60 | |
62 | |
61 | void |
63 | void |
62 | player::deactivate () |
64 | player::deactivate () |
… | |
… | |
74 | ob->remove (); |
76 | ob->remove (); |
75 | ob->enemy = 0; // sometimes keeps an extra refcount on itself |
77 | ob->enemy = 0; // sometimes keeps an extra refcount on itself |
76 | ob->map = 0; |
78 | ob->map = 0; |
77 | party = 0; |
79 | party = 0; |
78 | |
80 | |
79 | combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this |
|
|
80 | |
|
|
81 | players.erase (this); |
81 | players.erase (this); |
82 | } |
82 | } |
83 | |
83 | |
84 | // connect the player with a specific client |
84 | // connect the player with a specific client |
85 | // also changes, rationalises, and fixes some incorrect settings |
85 | // also changes, rationalises, and fixes some incorrect settings |
… | |
… | |
105 | ob->race = ob->arch->race; |
105 | ob->race = ob->arch->race; |
106 | |
106 | |
107 | ob->update_weight (); |
107 | ob->update_weight (); |
108 | link_skills (); |
108 | link_skills (); |
109 | |
109 | |
110 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
|
|
111 | |
|
|
112 | assign (title, ob->arch->object::name); |
110 | assign (title, ob->arch->object::name); |
113 | |
111 | |
114 | /* if it's a dragon player, set the correct title here */ |
112 | /* if it's a dragon player, set the correct title here */ |
115 | if (is_dragon_pl (ob)) |
113 | if (ob->is_dragon ()) |
116 | { |
114 | { |
117 | object *tmp, *abil = 0, *skin = 0; |
115 | object *tmp, *abil = 0, *skin = 0; |
118 | |
116 | |
119 | for (tmp = ob->inv; tmp; tmp = tmp->below) |
117 | for (tmp = ob->inv; tmp; tmp = tmp->below) |
120 | if (tmp->type == FORCE) |
118 | if (tmp->type == FORCE) |
… | |
… | |
128 | |
126 | |
129 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
127 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
130 | |
128 | |
131 | esrv_new_player (this); |
129 | esrv_new_player (this); |
132 | |
130 | |
|
|
131 | ob->flag [FLAG_READY_WEAPON] = false; |
|
|
132 | ob->flag [FLAG_READY_SKILL] = false; |
|
|
133 | ob->flag [FLAG_READY_RANGE] = false; |
|
|
134 | ob->flag [FLAG_READY_BOW] = false; |
|
|
135 | |
133 | ob->update_stats (); |
136 | ob->update_stats (); |
134 | |
137 | |
135 | ns->floorbox_update (); |
138 | ns->floorbox_update (); |
136 | esrv_send_inventory (ob, ob); |
139 | esrv_send_inventory (ob, ob); |
137 | esrv_add_spells (this, 0); |
140 | esrv_add_spells (this, 0); |
… | |
… | |
161 | ns->reset_stats (); |
164 | ns->reset_stats (); |
162 | ns->pl = 0; |
165 | ns->pl = 0; |
163 | ns = 0; |
166 | ns = 0; |
164 | } |
167 | } |
165 | |
168 | |
166 | observe = ob; |
169 | // this is important for the player scheduler to get the correct refcount |
|
|
170 | // when ns = 0 |
|
|
171 | observe = viewpoint = ob; |
167 | |
172 | |
168 | deactivate (); |
173 | deactivate (); |
169 | } |
174 | } |
|
|
175 | |
|
|
176 | //-GPL |
170 | |
177 | |
171 | // the need for this function can be explained |
178 | // the need for this function can be explained |
172 | // by load_object not returning the object |
179 | // by load_object not returning the object |
173 | void |
180 | void |
174 | player::set_object (object *op) |
181 | player::set_object (object *op) |
175 | { |
182 | { |
176 | ob = observe = op; |
183 | ob = observe = viewpoint = op; |
177 | ob->contr = this; /* this aren't yet in archetype */ |
184 | ob->contr = this; /* this aren't yet in archetype */ |
178 | |
185 | |
179 | ob->speed = 1.0f; |
186 | ob->speed = 1.0f; // object still inactive, keep it that way |
180 | ob->speed_left = 0.5f; |
187 | ob->speed_left = 0.5f; |
181 | |
188 | |
182 | ob->direction = 5; /* So player faces south */ |
189 | ob->direction = 5; /* So player faces south */ |
183 | |
|
|
184 | ob->flag [FLAG_READY_WEAPON] = false; |
|
|
185 | ob->flag [FLAG_READY_SKILL] = false; |
|
|
186 | ob->flag [FLAG_READY_BOW] = false; |
|
|
187 | |
|
|
188 | for (object *op = ob->inv; op; op = op->below) |
|
|
189 | if (op->flag [FLAG_APPLIED]) |
|
|
190 | switch (op->type) |
|
|
191 | { |
|
|
192 | case SKILL: |
|
|
193 | ob->flag [FLAG_APPLIED] = false; |
|
|
194 | break; |
|
|
195 | |
|
|
196 | case WAND: |
|
|
197 | case ROD: |
|
|
198 | case HORN: |
|
|
199 | case BOW: |
|
|
200 | ranged_ob = op; |
|
|
201 | break; |
|
|
202 | |
|
|
203 | case WEAPON: |
|
|
204 | combat_ob = op; |
|
|
205 | break; |
|
|
206 | } |
|
|
207 | |
|
|
208 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
|
|
209 | ob->deactivate (); // change_weapon activates, fix this better |
|
|
210 | } |
190 | } |
211 | |
191 | |
212 | void |
192 | void |
213 | player::set_observe (object *op) |
193 | player::set_observe (object *op) |
214 | { |
194 | { |
215 | observe = op ? op : ob; |
195 | observe = viewpoint = op ? op : ob; |
216 | do_los = 1; |
196 | do_los = 1; |
217 | } |
197 | } |
|
|
198 | |
|
|
199 | void |
|
|
200 | player::set_viewpoint (object *op) |
|
|
201 | { |
|
|
202 | viewpoint = op ? op : (object *)observe; |
|
|
203 | do_los = 1; |
|
|
204 | } |
|
|
205 | |
|
|
206 | //+GPL |
218 | |
207 | |
219 | player::player () |
208 | player::player () |
220 | { |
209 | { |
221 | /* There are some elements we want initialised to non zero value - |
210 | /* There are some elements we want initialised to non zero value - |
222 | * we deal with that below this point. |
211 | * we deal with that below this point. |
… | |
… | |
245 | |
234 | |
246 | attachable::do_destroy (); |
235 | attachable::do_destroy (); |
247 | |
236 | |
248 | if (ob) |
237 | if (ob) |
249 | { |
238 | { |
250 | ob->destroy_inv (false); |
239 | ob->contr = 0; |
251 | ob->destroy (); |
240 | ob->destroy (); |
252 | } |
241 | } |
253 | |
242 | |
254 | ob = observe = 0; |
243 | ob = observe = viewpoint = 0; |
255 | } |
244 | } |
256 | |
245 | |
257 | player::~player () |
246 | player::~player () |
258 | { |
247 | { |
259 | /* Clear item stack */ |
248 | /* Clear item stack */ |
260 | free (stack_items); |
249 | free (stack_items); |
|
|
250 | } |
|
|
251 | |
|
|
252 | /* |
|
|
253 | * get_player_archetype() return next player archetype from archetype |
|
|
254 | * list. Not very efficient routine, but used only creating new players. |
|
|
255 | * Note: there MUST be at least one player archetype! |
|
|
256 | */ |
|
|
257 | static archetype * |
|
|
258 | get_player_archetype (archetype *at) |
|
|
259 | { |
|
|
260 | // archetypes could have been reloaded |
|
|
261 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
262 | |
|
|
263 | if (!nat) |
|
|
264 | return at; |
|
|
265 | |
|
|
266 | archvec::iterator i = archetypes.find (nat); |
|
|
267 | |
|
|
268 | for (;;) |
|
|
269 | { |
|
|
270 | if (++i == archetypes.end ()) |
|
|
271 | i = archetypes.begin (); |
|
|
272 | else if (*i == at) |
|
|
273 | cleanup ("not a single player archetype found"); |
|
|
274 | |
|
|
275 | if ((*i)->type == PLAYER) |
|
|
276 | return *i; |
|
|
277 | } |
261 | } |
278 | } |
262 | |
279 | |
263 | /* Tries to add player on the connection passed in ns. |
280 | /* Tries to add player on the connection passed in ns. |
264 | * All we can really get in this is some settings like host and display |
281 | * All we can really get in this is some settings like host and display |
265 | * mode. |
282 | * mode. |
… | |
… | |
267 | player * |
284 | player * |
268 | player::create () |
285 | player::create () |
269 | { |
286 | { |
270 | player *pl = new player; |
287 | player *pl = new player; |
271 | |
288 | |
272 | pl->set_object (arch_to_object (get_player_archetype (0))); |
289 | pl->set_object (get_player_archetype (0)->instance ()); |
273 | |
290 | |
274 | pl->ob->roll_stats (); |
291 | pl->ob->roll_stats (); |
275 | pl->ob->stats.wc = 2; |
292 | pl->ob->stats.wc = 2; |
276 | pl->ob->run_away = 25; /* Then we panick... */ |
293 | pl->ob->run_away = 25; /* Then we panick... */ |
277 | |
294 | |
278 | set_first_map (pl->ob); |
295 | set_first_map (pl->ob); |
279 | |
296 | |
280 | return pl; |
297 | return pl; |
281 | } |
|
|
282 | |
|
|
283 | /* |
|
|
284 | * get_player_archetype() return next player archetype from archetype |
|
|
285 | * list. Not very efficient routine, but used only creating new players. |
|
|
286 | * Note: there MUST be at least one player archetype! |
|
|
287 | */ |
|
|
288 | archetype * |
|
|
289 | get_player_archetype (archetype *at) |
|
|
290 | { |
|
|
291 | // archetypes could have been reloaded |
|
|
292 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
293 | |
|
|
294 | if (!nat) |
|
|
295 | return at; |
|
|
296 | |
|
|
297 | archvec::iterator i = archetypes.find (nat); |
|
|
298 | |
|
|
299 | for (;;) |
|
|
300 | { |
|
|
301 | if (++i == archetypes.end ()) |
|
|
302 | i = archetypes.begin (); |
|
|
303 | else if (*i == at) |
|
|
304 | cleanup ("not a single player archetype found"); |
|
|
305 | |
|
|
306 | if ((*i)->type == PLAYER) |
|
|
307 | return *i; |
|
|
308 | } |
|
|
309 | } |
298 | } |
310 | |
299 | |
311 | object * |
300 | object * |
312 | get_nearest_player (object *mon) |
301 | get_nearest_player (object *mon) |
313 | { |
302 | { |
… | |
… | |
341 | #endif |
330 | #endif |
342 | return op; |
331 | return op; |
343 | } |
332 | } |
344 | |
333 | |
345 | /* I believe this can safely go to 2, 3 is questionable, 4 will likely |
334 | /* I believe this can safely go to 2, 3 is questionable, 4 will likely |
346 | * result in a monster paths backtracking. It basically determines how large a |
335 | * result in a monster paths backtracking. It basically determines how large a |
347 | * detour a monster will take from the direction path when looking |
336 | * detour a monster will take from the direction path when looking |
348 | * for a path to the player. The values are in the amount of direction |
337 | * for a path to the player. The values are in the amount of direction |
349 | * the deviation is |
338 | * the deviation is |
350 | */ |
339 | */ |
351 | #define DETOUR_AMOUNT 2 |
340 | #define DETOUR_AMOUNT 2 |
… | |
… | |
387 | */ |
376 | */ |
388 | int |
377 | int |
389 | path_to_player (object *mon, object *pl, unsigned mindiff) |
378 | path_to_player (object *mon, object *pl, unsigned mindiff) |
390 | { |
379 | { |
391 | rv_vector rv; |
380 | rv_vector rv; |
392 | sint16 x, y; |
|
|
393 | int lastx, lasty, dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES, mflags, blocked; |
381 | int dir, i, diff, firstdir = 0, lastdir, max = MAX_SPACES; |
394 | maptile *m, *lastmap; |
|
|
395 | |
382 | |
396 | get_rangevector (mon, pl, &rv, 0); |
383 | get_rangevector (mon, pl, &rv, 0); |
397 | |
384 | |
398 | if (rv.distance < mindiff) |
385 | if (rv.distance < mindiff) |
399 | return 0; |
386 | return 0; |
400 | |
387 | |
401 | x = mon->x; |
388 | mapxy pos (mon); |
402 | y = mon->y; |
|
|
403 | m = mon->map; |
|
|
404 | dir = rv.direction; |
389 | dir = rv.direction; |
405 | lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ |
390 | lastdir = firstdir = rv.direction; /* perhaps we stand next to pl, init firstdir too */ |
406 | diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); |
391 | diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); |
407 | |
392 | |
408 | /* If we can't solve it within the search distance, return now. */ |
393 | /* If we can't solve it within the search distance, return now. */ |
409 | if (diff > max) |
394 | if (diff > max) |
410 | return 0; |
395 | return 0; |
411 | |
396 | |
412 | while (diff > 1 && max > 0) |
397 | while (diff > 1 && max > 0) |
413 | { |
398 | { |
414 | lastx = x; |
399 | mapxy lastpos = pos; |
415 | lasty = y; |
|
|
416 | lastmap = m; |
|
|
417 | x = lastx + freearr_x[dir]; |
|
|
418 | y = lasty + freearr_y[dir]; |
|
|
419 | |
400 | |
420 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
401 | pos.move (dir); |
421 | blocked = (mflags & P_OUT_OF_MAP) ? MOVE_ALL : GET_MAP_MOVE_BLOCK (m, x, y); |
|
|
422 | |
402 | |
423 | /* Space is blocked - try changing direction a little */ |
403 | /* Space is blocked - try changing direction a little */ |
424 | if ((mflags & P_OUT_OF_MAP) || ((OB_TYPE_MOVE_BLOCK (mon, blocked) || (mflags & P_BLOCKSVIEW)) |
404 | if (!pos.normalise () |
425 | && (m == mon->map && blocked_link (mon, m, x, y)))) |
405 | || (((pos->flags () & P_BLOCKSVIEW) || OB_TYPE_MOVE_BLOCK (mon, pos->move_block)) |
|
|
406 | && blocked_link (mon, pos.m, pos.x, pos.y))) |
426 | { |
407 | { |
427 | /* recalculate direction from last good location. Possible |
408 | /* recalculate direction from last good location. Possible |
428 | * we were not traversing ideal location before. |
409 | * we were not traversing ideal location before. |
429 | */ |
410 | */ |
430 | get_rangevector_from_mapcoord (lastmap, lastx, lasty, pl, &rv, 0); |
411 | get_rangevector_from_mapcoord (lastpos.m, lastpos.x, lastpos.y, pl, &rv, 0); |
431 | if (rv.direction != dir) |
412 | if (rv.direction != dir) |
432 | { |
413 | { |
433 | /* OK - says direction should be different - lets reset the |
414 | /* OK - says direction should be different - lets reset the |
434 | * the values so it will try again. |
415 | * the values so it will try again. |
435 | */ |
416 | */ |
436 | x = lastx; |
|
|
437 | y = lasty; |
|
|
438 | m = lastmap; |
417 | pos = lastpos; |
439 | dir = firstdir = rv.direction; |
418 | dir = firstdir = rv.direction; |
440 | } |
419 | } |
441 | else |
420 | else |
442 | { |
421 | { |
443 | /* direct path is blocked - try taking a side step to |
422 | /* direct path is blocked - try taking a side step to |
444 | * either the left or right. |
423 | * either the left or right. |
445 | * Note increase the values in the loop below to be |
424 | * Note increase the values in the loop below to be |
446 | * more than -1/1 respectively will mean the monster takes |
425 | * more than -1/1 respectively will mean the monster takes |
447 | * bigger detour. Have to be careful about these values getting |
426 | * bigger detour. Have to be careful about these values getting |
448 | * too big (3 or maybe 4 or higher) as the monster may just try |
427 | * too big (3 or maybe 4 or higher) as the monster may just try |
449 | * stepping back and forth |
428 | * stepping back and forth |
450 | */ |
429 | */ |
451 | for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++) |
430 | for (i = -DETOUR_AMOUNT; i <= DETOUR_AMOUNT; i++) |
452 | { |
431 | { |
453 | if (i == 0) |
432 | if (i == 0) |
454 | continue; /* already did this, so skip it */ |
433 | continue; /* already did this, so skip it */ |
|
|
434 | |
455 | /* Use lastdir here - otherwise, |
435 | /* Use lastdir here - otherwise, |
456 | * since the direction that the creature should move in |
436 | * since the direction that the creature should move in |
457 | * may change, you could get infinite loops. |
437 | * may change, you could get infinite loops. |
458 | * ie, player is northwest, but monster can only |
438 | * ie, player is northwest, but monster can only |
459 | * move west, so it does that. It goes some distance, |
439 | * move west, so it does that. It goes some distance, |
… | |
… | |
461 | * can't do that, but now finds it can move east, and |
441 | * can't do that, but now finds it can move east, and |
462 | * gets back to its original point. lastdir contains |
442 | * gets back to its original point. lastdir contains |
463 | * the last direction the creature has successfully |
443 | * the last direction the creature has successfully |
464 | * moved. |
444 | * moved. |
465 | */ |
445 | */ |
466 | |
|
|
467 | x = lastx + freearr_x[absdir (lastdir + i)]; |
|
|
468 | y = lasty + freearr_y[absdir (lastdir + i)]; |
|
|
469 | m = lastmap; |
446 | pos = lastpos; |
470 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
447 | pos.move (absdir (lastdir + i)); |
471 | if (mflags & P_OUT_OF_MAP) |
448 | |
|
|
449 | if (!pos.normalise ()) |
472 | continue; |
450 | continue; |
473 | blocked = GET_MAP_MOVE_BLOCK (m, x, y); |
451 | |
474 | if (OB_TYPE_MOVE_BLOCK (mon, blocked)) |
452 | mapspace &ms = *pos; |
|
|
453 | |
|
|
454 | if (ms.flags () & P_BLOCKSVIEW) |
475 | continue; |
455 | continue; |
476 | if (mflags & P_BLOCKSVIEW) |
456 | |
|
|
457 | if (OB_TYPE_MOVE_BLOCK (mon, ms.move_block)) |
477 | continue; |
458 | continue; |
478 | |
459 | |
479 | if (m == mon->map && blocked_link (mon, m, x, y)) |
460 | if (blocked_link (mon, pos.m, pos.x, pos.y)) |
480 | break; |
461 | break; |
481 | } |
462 | } |
|
|
463 | |
482 | /* go through entire loop without finding a valid |
464 | /* go through entire loop without finding a valid |
483 | * sidestep to take - thus, no valid path. |
465 | * sidestep to take - thus, no valid path. |
484 | */ |
466 | */ |
485 | if (i == (DETOUR_AMOUNT + 1)) |
467 | if (i == DETOUR_AMOUNT + 1) |
486 | return 0; |
468 | return 0; |
|
|
469 | |
487 | diff--; |
470 | diff--; |
488 | lastdir = dir; |
471 | lastdir = dir; |
489 | max--; |
472 | max--; |
490 | if (!firstdir) |
473 | if (!firstdir) |
491 | firstdir = dir + i; |
474 | firstdir = dir + i; |
… | |
… | |
495 | { |
478 | { |
496 | /* we moved towards creature, so diff is less */ |
479 | /* we moved towards creature, so diff is less */ |
497 | diff--; |
480 | diff--; |
498 | max--; |
481 | max--; |
499 | lastdir = dir; |
482 | lastdir = dir; |
|
|
483 | |
500 | if (!firstdir) |
484 | if (!firstdir) |
501 | firstdir = dir; |
485 | firstdir = dir; |
502 | } |
486 | } |
503 | |
487 | |
504 | if (diff <= 1) |
488 | if (diff <= 1) |
505 | { |
489 | { |
506 | /* Recalculate diff (distance) because we may not have actually |
490 | /* Recalculate diff (distance) because we may not have actually |
507 | * headed toward player for entire distance. |
491 | * headed toward player for entire distance. |
508 | */ |
492 | */ |
509 | get_rangevector_from_mapcoord (m, x, y, pl, &rv, 0); |
493 | get_rangevector_from_mapcoord (pos.m, pos.x, pos.y, pl, &rv, 0); |
510 | diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); |
494 | diff = ::max (abs (rv.distance_x), abs (rv.distance_y)); |
511 | } |
495 | } |
512 | |
496 | |
513 | if (diff > max) |
497 | if (diff > max) |
514 | return 0; |
498 | return 0; |
… | |
… | |
530 | for (object *next, *op = pl->inv; op; op = next) |
514 | for (object *next, *op = pl->inv; op; op = next) |
531 | { |
515 | { |
532 | next = op->below; |
516 | next = op->below; |
533 | |
517 | |
534 | /* Forces get applied per default, unless they have the |
518 | /* Forces get applied per default, unless they have the |
535 | * flag "neutral" set. Sorry but I can't think of a better way |
519 | * flag "neutral" set. Sorry but I can't think of a better way |
536 | */ |
520 | */ |
537 | if (op->type == FORCE && !QUERY_FLAG (op, FLAG_NEUTRAL)) |
521 | if (op->type == FORCE && !op->flag [FLAG_NEUTRAL]) |
538 | SET_FLAG (op, FLAG_APPLIED); |
522 | op->set_flag (FLAG_APPLIED); |
539 | |
523 | |
540 | /* we never give weapons/armour if these cannot be used |
524 | /* we never give weapons/armour if these cannot be used |
541 | * by this player due to race restrictions |
525 | * by this player due to race restrictions |
542 | */ |
526 | */ |
543 | if (pl->type == PLAYER) |
527 | if (pl->type == PLAYER) |
544 | { |
528 | { |
545 | if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) |
529 | if ((!pl->flag [FLAG_USE_ARMOUR] |
546 | && |
530 | && |
547 | (op->type == ARMOUR || op->type == BOOTS |
531 | (op->type == ARMOUR || op->type == BOOTS |
548 | || op->type == CLOAK || op->type == HELMET |
532 | || op->type == CLOAK || op->type == HELMET |
549 | || op->type == SHIELD || op->type == GLOVES |
533 | || op->type == SHIELD || op->type == GLOVES |
550 | || op->type == BRACERS || op->type == GIRDLE)) |
534 | || op->type == BRACERS || op->type == GIRDLE)) |
551 | || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) |
535 | || (!pl->flag [FLAG_USE_WEAPON] && op->type == WEAPON)) |
552 | { |
536 | { |
553 | op->destroy (); |
537 | op->destroy (); |
554 | continue; |
538 | continue; |
555 | } |
539 | } |
556 | } |
540 | } |
557 | |
541 | |
558 | /* Here we remove duplicated skills (as duplicated spell objects have |
542 | /* Here we remove duplicated skills (as duplicated spell objects have |
559 | * _very_ confusing effects for players), which could for instance be |
543 | * _very_ confusing effects for players), which could for instance be |
560 | * generated by bad treasurelists. - elmex |
544 | * generated by multiple treasurelists specifying the same skills. |
561 | */ |
545 | */ |
562 | if (op->type == SKILL) |
546 | if (op->type == SKILL) |
563 | { |
547 | { |
564 | for (object *tmp = op->below; tmp; tmp = tmp->below) |
548 | for (object *tmp = op->below; tmp; tmp = tmp->below) |
565 | if (tmp->type == op->type && tmp->name == op->name) |
549 | if (tmp->type == op->type && tmp->name == op->name) |
566 | { |
550 | { |
567 | op->destroy (); |
551 | op->destroy (); |
568 | LOG (llevError, |
|
|
569 | "give_initial_items: Removing duplicate skill %s\n", &tmp->name); |
|
|
570 | break; |
552 | break; |
571 | } |
553 | } |
572 | |
554 | |
573 | if (op->nrof > 1) |
555 | if (op->nrof > 1) |
574 | op->nrof = 1; |
556 | op->nrof = 1; |
575 | } |
557 | } |
576 | |
558 | |
577 | if (op->type == SPELLBOOK && op->inv) |
559 | if (op->type == SPELLBOOK && op->inv) |
578 | CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); |
560 | op->inv->clr_flag (FLAG_STARTEQUIP); |
579 | |
561 | |
580 | /* Give starting characters identified, uncursed, and undamned |
562 | /* Give starting characters identified, uncursed, and undamned |
581 | * items. Just don't identify gold or silver, or it won't be |
563 | * items. Just don't identify gold or silver, or it won't be |
582 | * merged properly. |
564 | * merged properly. |
583 | */ |
565 | */ |
584 | if (need_identify (op)) |
566 | if (op->need_identify ()) |
585 | { |
567 | { |
586 | SET_FLAG (op, FLAG_IDENTIFIED); |
568 | op->set_flag (FLAG_IDENTIFIED); |
587 | CLEAR_FLAG (op, FLAG_CURSED); |
569 | op->clr_flag (FLAG_CURSED); |
588 | CLEAR_FLAG (op, FLAG_DAMNED); |
570 | op->clr_flag (FLAG_DAMNED); |
589 | } |
571 | } |
590 | |
572 | |
591 | if (op->type == SPELL) |
573 | if (op->type == SPELL) |
592 | { |
574 | { |
593 | op->destroy (); |
575 | op->destroy (); |
594 | continue; |
576 | continue; |
595 | } |
577 | } |
596 | else if (op->type == SKILL) |
578 | else if (op->type == SKILL) |
597 | { |
579 | { |
598 | SET_FLAG (op, FLAG_CAN_USE_SKILL); |
580 | op->set_flag (FLAG_CAN_USE_SKILL); |
599 | op->stats.exp = 0; |
581 | op->stats.exp = 0; |
600 | op->level = 1; |
582 | op->level = 1; |
601 | } |
583 | } |
602 | else /* lock all 'normal items by default */ |
584 | else /* lock all 'normal items by default */ |
603 | SET_FLAG (op, FLAG_INV_LOCKED); |
585 | op->set_flag (FLAG_INV_LOCKED); |
604 | } /* for loop of objects in player inv */ |
586 | } /* for loop of objects in player inv */ |
605 | |
587 | |
606 | /* Need to set up the skill pointers */ |
588 | /* Need to set up the skill pointers */ |
607 | pl->contr->link_skills (); |
589 | pl->contr->link_skills (); |
608 | } |
590 | } |
… | |
… | |
622 | send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
604 | send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
623 | } |
605 | } |
624 | |
606 | |
625 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
607 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
626 | static int |
608 | static int |
627 | roll_stat (void) |
609 | roll_stat () |
628 | { |
610 | { |
629 | int a[4], i, j, k; |
611 | int a[4], i, j, k; |
630 | |
612 | |
631 | for (i = 0; i < 4; i++) |
613 | for (i = 0; i < 4; i++) |
632 | a[i] = (int) rndm (6) + 1; |
614 | a[i] = rndm (1, 6); |
633 | |
615 | |
634 | for (i = 0, j = 0, k = 7; i < 4; i++) |
616 | for (i = 0, j = 0, k = 7; i < 4; i++) |
635 | if (a[i] < k) |
617 | if (a[i] < k) |
636 | k = a[i], j = i; |
618 | k = a[i], j = i; |
637 | |
619 | |
… | |
… | |
729 | player::chargen_race_done () |
711 | player::chargen_race_done () |
730 | { |
712 | { |
731 | /* this must before then initial items are given */ |
713 | /* this must before then initial items are given */ |
732 | esrv_new_player (ob->contr); |
714 | esrv_new_player (ob->contr); |
733 | |
715 | |
734 | treasurelist *tl = treasurelist::find ("starting_wealth"); |
716 | treasurelist *tl = treasurelist::find (shstr_starting_wealth); |
735 | if (tl) |
717 | if (tl) |
736 | create_treasure (tl, ob, 0, 0, 0); |
718 | create_treasure (tl, ob, 0, 0, 0); |
737 | |
719 | |
738 | INVOKE_PLAYER (BIRTH, ob->contr); |
720 | INVOKE_PLAYER (BIRTH, ob->contr); |
739 | INVOKE_PLAYER (LOGIN, ob->contr); |
|
|
740 | |
721 | |
741 | ob->contr->ns->state = ST_PLAYING; |
722 | ob->contr->ns->state = ST_PLAYING; |
742 | |
723 | |
743 | if (ob->msg) |
724 | if (ob->msg) |
744 | ob->msg = 0; |
725 | ob->msg = 0; |
745 | |
726 | |
746 | start_info (ob); |
727 | start_info (ob); |
747 | CLEAR_FLAG (ob, FLAG_WIZ); |
728 | ob->clr_flag (FLAG_WIZ); |
748 | give_initial_items (ob, ob->randomitems); |
729 | give_initial_items (ob, ob->randomitems); |
749 | esrv_send_inventory (ob, ob); |
730 | esrv_send_inventory (ob, ob); |
750 | ob->update_stats (); |
731 | ob->update_stats (); |
751 | |
732 | |
752 | /* This moves the player to a different start map, if there |
733 | /* This moves the player to a different start map, if there |
… | |
… | |
754 | */ |
735 | */ |
755 | if (*first_map_ext_path) |
736 | if (*first_map_ext_path) |
756 | ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y); |
737 | ob->player_goto (format ("%s/%s", &first_map_ext_path, &ob->arch->archname), ob->x, ob->y); |
757 | else |
738 | else |
758 | LOG (llevDebug, "first_map_ext_path not set\n"); |
739 | LOG (llevDebug, "first_map_ext_path not set\n"); |
|
|
740 | } |
|
|
741 | |
|
|
742 | /* |
|
|
743 | * Returns true if the given player is a legal class. |
|
|
744 | * The function to add and remove class-bonuses to the stats doesn't |
|
|
745 | * check if the stat becomes negative, thus this function |
|
|
746 | * merely checks that all stats are 1 or more, and returns |
|
|
747 | * false otherwise. |
|
|
748 | */ |
|
|
749 | static int |
|
|
750 | allowed_class (const object *op) |
|
|
751 | { |
|
|
752 | return op->stats.Dex > 0 |
|
|
753 | && op->stats.Str > 0 |
|
|
754 | && op->stats.Con > 0 |
|
|
755 | && op->stats.Int > 0 |
|
|
756 | && op->stats.Wis > 0 |
|
|
757 | && op->stats.Pow > 0 |
|
|
758 | && op->stats.Cha > 0; |
759 | } |
759 | } |
760 | |
760 | |
761 | void |
761 | void |
762 | player::chargen_race_next () |
762 | player::chargen_race_next () |
763 | { |
763 | { |
… | |
… | |
792 | ob->stats.hp = ob->stats.maxhp; |
792 | ob->stats.hp = ob->stats.maxhp; |
793 | ob->stats.sp = ob->stats.maxsp; |
793 | ob->stats.sp = ob->stats.maxsp; |
794 | ob->stats.grace = 0; |
794 | ob->stats.grace = 0; |
795 | } |
795 | } |
796 | |
796 | |
797 | void |
797 | static void |
798 | flee_player (object *op) |
798 | flee_player (object *op) |
799 | { |
799 | { |
800 | int dir, diff; |
800 | int dir, diff; |
801 | rv_vector rv; |
801 | rv_vector rv; |
802 | |
802 | |
803 | if (op->stats.hp < 0) |
803 | if (op->stats.hp < 0) |
804 | { |
804 | { |
805 | LOG (llevDebug, "Fleeing player is dead.\n"); |
805 | LOG (llevDebug, "Fleeing player is dead.\n"); |
806 | CLEAR_FLAG (op, FLAG_SCARED); |
806 | op->clr_flag (FLAG_SCARED); |
807 | return; |
807 | return; |
808 | } |
808 | } |
809 | |
809 | |
810 | if (!op->enemy) |
810 | if (!op->enemy) |
811 | { |
811 | { |
812 | LOG (llevDebug, "Fleeing player had no enemy.\n"); |
812 | LOG (llevDebug, "Fleeing player had no enemy.\n"); |
813 | CLEAR_FLAG (op, FLAG_SCARED); |
813 | op->clr_flag (FLAG_SCARED); |
814 | return; |
814 | return; |
815 | } |
815 | } |
816 | |
816 | |
817 | if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0)) |
817 | if (!(random_roll (0, 4, op, PREFER_LOW)) && did_make_save (op, op->level, 0)) |
818 | { |
818 | { |
819 | op->enemy = NULL; |
819 | op->enemy = NULL; |
820 | CLEAR_FLAG (op, FLAG_SCARED); |
820 | op->clr_flag (FLAG_SCARED); |
821 | return; |
821 | return; |
822 | } |
822 | } |
823 | |
823 | |
824 | get_rangevector (op, op->enemy, &rv, 0); |
824 | get_rangevector (op, op->enemy, &rv, 0); |
825 | |
825 | |
826 | dir = absdir (4 + rv.direction); |
826 | dir = absdir (4 + rv.direction); |
827 | for (diff = 0; diff < 3; diff++) |
827 | for (diff = 0; diff < 3; diff++) |
828 | { |
828 | { |
829 | int m = 1 - rndm (2) * 2; |
829 | int m = 1 - rndm (2) * 2; |
830 | |
830 | |
831 | if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) |
831 | if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m)))) |
832 | return; |
832 | return; |
833 | } |
833 | } |
834 | |
834 | |
835 | /* Cornered, get rid of scared */ |
835 | /* Cornered, get rid of scared */ |
836 | CLEAR_FLAG (op, FLAG_SCARED); |
836 | op->clr_flag (FLAG_SCARED); |
837 | op->enemy = NULL; |
837 | op->enemy = NULL; |
838 | } |
838 | } |
839 | |
839 | |
840 | /* check_pick sees if there is stuff to be picked up/picks up stuff. |
840 | /* check_pick sees if there is stuff to be picked up/picks up stuff. |
841 | * It returns 1 if the player should keep on moving, 0 if he should |
841 | * It returns 1 if the player should keep on moving, 0 if he should |
… | |
… | |
846 | { |
846 | { |
847 | object *tmp, *next; |
847 | object *tmp, *next; |
848 | int stop = 0; |
848 | int stop = 0; |
849 | int wvratio; |
849 | int wvratio; |
850 | |
850 | |
851 | /* if you're flying, you cna't pick up anything */ |
851 | /* if you're flying, you can't pick up anything */ |
852 | if (op->move_type & MOVE_FLYING) |
852 | if (op->move_type & MOVE_FLYING) |
853 | return 1; |
853 | return 1; |
854 | |
854 | |
855 | next = op->below; |
855 | next = op->below; |
856 | |
856 | |
857 | int cnt = MAX_ITEM_PER_DROP; |
857 | int cnt = MAX_ITEM_PER_ACTION; |
858 | #define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0) |
858 | #define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0) |
859 | |
859 | |
860 | /* loop while there are items on the floor that are not marked as |
860 | /* loop while there are items on the floor that are not marked as |
861 | * destroyed */ |
861 | * destroyed */ |
862 | while (next && !next->destroyed ()) |
862 | while (next && !next->destroyed ()) |
… | |
… | |
888 | if (op->contr->mode & PU_DEBUG) |
888 | if (op->contr->mode & PU_DEBUG) |
889 | { |
889 | { |
890 | /* some debugging code to figure out item information */ |
890 | /* some debugging code to figure out item information */ |
891 | const char *str = tmp->name |
891 | const char *str = tmp->name |
892 | ? format ("item name: %s item type: %d weight/value: %d", |
892 | ? format ("item name: %s item type: %d weight/value: %d", |
893 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))) |
893 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))) |
894 | : format ("item name: %s item type: %d weight/value: %d", |
894 | : format ("item name: %s item type: %d weight/value: %d", |
895 | &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
895 | &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))); |
896 | |
896 | |
897 | new_draw_info (NDI_UNIQUE, 0, op, str); |
897 | new_draw_info (NDI_UNIQUE, 0, op, str); |
898 | } |
898 | } |
899 | |
899 | |
900 | if (op->contr->mode & PU_INHIBIT) |
900 | if (op->contr->mode & PU_INHIBIT) |
… | |
… | |
933 | * fighting */ |
933 | * fighting */ |
934 | if (op->contr->mode & PU_INHIBIT) |
934 | if (op->contr->mode & PU_INHIBIT) |
935 | return 1; |
935 | return 1; |
936 | |
936 | |
937 | /* prevent us from turning into auto-thieves :) */ |
937 | /* prevent us from turning into auto-thieves :) */ |
938 | if (QUERY_FLAG (tmp, FLAG_UNPAID)) |
938 | if (tmp->flag [FLAG_UNPAID]) |
939 | continue; |
939 | continue; |
940 | |
940 | |
941 | /* ignore known cursed objects */ |
941 | /* ignore known cursed objects */ |
942 | if (QUERY_FLAG (tmp, FLAG_KNOWN_CURSED) && op->contr->mode & PU_NOT_CURSED) |
942 | if (tmp->flag [FLAG_KNOWN_CURSED] && op->contr->mode & PU_NOT_CURSED) |
943 | continue; |
943 | continue; |
944 | |
944 | |
945 | /* all food and drink if desired */ |
945 | /* all food and drink if desired */ |
946 | /* question: don't pick up known-poisonous stuff? */ |
946 | /* question: don't pick up known-poisonous stuff? */ |
947 | if (op->contr->mode & PU_FOOD) |
947 | if (op->contr->mode & PU_FOOD) |
… | |
… | |
950 | CHK_PICK_PICKUP; |
950 | CHK_PICK_PICKUP; |
951 | continue; |
951 | continue; |
952 | } |
952 | } |
953 | |
953 | |
954 | if (op->contr->mode & PU_DRINK) |
954 | if (op->contr->mode & PU_DRINK) |
955 | if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) |
955 | if (tmp->type == DRINK || (tmp->type == POISON && !tmp->flag [FLAG_KNOWN_CURSED])) |
956 | { |
956 | { |
957 | CHK_PICK_PICKUP; |
957 | CHK_PICK_PICKUP; |
958 | continue; |
958 | continue; |
959 | } |
959 | } |
960 | |
960 | |
… | |
… | |
987 | continue; |
987 | continue; |
988 | } |
988 | } |
989 | |
989 | |
990 | /* wands/staves/rods/horns */ |
990 | /* wands/staves/rods/horns */ |
991 | if (op->contr->mode & PU_MAGIC_DEVICE) |
991 | if (op->contr->mode & PU_MAGIC_DEVICE) |
992 | if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) |
992 | if (tmp->type == WAND |
|
|
993 | || tmp->type == ROD |
|
|
994 | || tmp->type == HORN |
|
|
995 | || tmp->type == POWER_CRYSTAL) |
993 | { |
996 | { |
994 | CHK_PICK_PICKUP; |
997 | CHK_PICK_PICKUP; |
995 | continue; |
998 | continue; |
996 | } |
999 | } |
997 | |
1000 | |
998 | /* pick up all magical items */ |
1001 | /* pick up all magical items */ |
999 | if (op->contr->mode & PU_MAGICAL) |
1002 | if (op->contr->mode & PU_MAGICAL) |
1000 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
1003 | if (tmp->flag [FLAG_KNOWN_MAGICAL] |
|
|
1004 | && !tmp->flag [FLAG_KNOWN_CURSED]) |
1001 | { |
1005 | { |
1002 | CHK_PICK_PICKUP; |
1006 | CHK_PICK_PICKUP; |
1003 | continue; |
1007 | continue; |
1004 | } |
1008 | } |
1005 | |
1009 | |
… | |
… | |
1012 | } |
1016 | } |
1013 | } |
1017 | } |
1014 | |
1018 | |
1015 | /* rings & amulets - talismans seems to be typed AMULET */ |
1019 | /* rings & amulets - talismans seems to be typed AMULET */ |
1016 | if (op->contr->mode & PU_JEWELS) |
1020 | if (op->contr->mode & PU_JEWELS) |
1017 | if (tmp->type == RING || tmp->type == AMULET) |
1021 | if (tmp->type == RING |
|
|
1022 | || tmp->type == AMULET |
|
|
1023 | || tmp->type == GIRDLE |
|
|
1024 | || tmp->type == SKILL_TOOL) |
1018 | { |
1025 | { |
1019 | CHK_PICK_PICKUP; |
1026 | CHK_PICK_PICKUP; |
1020 | continue; |
1027 | continue; |
1021 | } |
1028 | } |
1022 | |
1029 | |
… | |
… | |
1071 | CHK_PICK_PICKUP; |
1078 | CHK_PICK_PICKUP; |
1072 | continue; |
1079 | continue; |
1073 | } |
1080 | } |
1074 | |
1081 | |
1075 | if (op->contr->mode & PU_GLOVES) |
1082 | if (op->contr->mode & PU_GLOVES) |
1076 | if (tmp->type == GLOVES) |
1083 | if (tmp->type == GLOVES || tmp->type == BRACERS) |
1077 | { |
1084 | { |
1078 | CHK_PICK_PICKUP; |
1085 | CHK_PICK_PICKUP; |
1079 | continue; |
1086 | continue; |
1080 | } |
1087 | } |
1081 | |
1088 | |
… | |
… | |
1086 | continue; |
1093 | continue; |
1087 | } |
1094 | } |
1088 | |
1095 | |
1089 | /* hoping to catch throwing daggers here */ |
1096 | /* hoping to catch throwing daggers here */ |
1090 | if (op->contr->mode & PU_MISSILEWEAPON) |
1097 | if (op->contr->mode & PU_MISSILEWEAPON) |
1091 | if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) |
1098 | if (tmp->type == WEAPON && tmp->flag [FLAG_IS_THROWN]) |
1092 | { |
1099 | { |
1093 | CHK_PICK_PICKUP; |
1100 | CHK_PICK_PICKUP; |
1094 | continue; |
1101 | continue; |
1095 | } |
1102 | } |
1096 | |
1103 | |
… | |
… | |
1131 | fprintf (stderr, "%s", tmp->name); |
1138 | fprintf (stderr, "%s", tmp->name); |
1132 | } |
1139 | } |
1133 | else |
1140 | else |
1134 | fprintf (stderr, "%s", tmp->arch->archname); |
1141 | fprintf (stderr, "%s", tmp->arch->archname); |
1135 | fprintf (stderr, ",%d] = ", tmp->type); |
1142 | fprintf (stderr, ",%d] = ", tmp->type); |
1136 | fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1143 | fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))); |
1137 | #endif |
1144 | #endif |
1138 | CHK_PICK_PICKUP; |
1145 | CHK_PICK_PICKUP; |
1139 | continue; |
1146 | continue; |
1140 | } |
1147 | } |
1141 | } /* the new pickup model */ |
1148 | } /* the new pickup model */ |
1142 | } |
1149 | } |
1143 | |
1150 | |
1144 | return !stop; |
1151 | return !stop; |
1145 | } |
1152 | } |
1146 | |
1153 | |
|
|
1154 | /* routine for both players and monsters. We call this when |
|
|
1155 | * there is a possibility for our action distrubing our hiding |
|
|
1156 | * place or invisiblity spell. Artefact invisiblity causes |
|
|
1157 | * "noise" instead. If we arent invisible to begin with, we |
|
|
1158 | * return 0. |
|
|
1159 | */ |
|
|
1160 | static int |
|
|
1161 | action_makes_visible (object *op) |
|
|
1162 | { |
|
|
1163 | if (op->invisible && op->flag [FLAG_ALIVE]) |
|
|
1164 | { |
|
|
1165 | if (op->flag [FLAG_MAKE_INVIS]) |
|
|
1166 | { |
|
|
1167 | // artefact invisibility is permanent, but we still make noise |
|
|
1168 | // this is important for game-balance. |
|
|
1169 | if (op->contr) |
|
|
1170 | op->make_noise (); |
|
|
1171 | |
|
|
1172 | return 0; |
|
|
1173 | } |
|
|
1174 | |
|
|
1175 | if (op->contr && op->contr->tmp_invis == 0) |
|
|
1176 | return 0; |
|
|
1177 | |
|
|
1178 | /* If monsters, they should become visible */ |
|
|
1179 | if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis)) |
|
|
1180 | { |
|
|
1181 | new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible"); |
|
|
1182 | return 1; |
|
|
1183 | } |
|
|
1184 | } |
|
|
1185 | |
|
|
1186 | return 0; |
|
|
1187 | } |
|
|
1188 | |
1147 | /* |
1189 | /* |
1148 | * Find an arrow in the inventory and after that |
1190 | * Find an arrow in the inventory and after that |
1149 | * in the right type container (quiver). Pointer to the |
1191 | * in the right type container (quiver). Pointer to the |
1150 | * found object is returned. |
1192 | * found object is returned. |
1151 | */ |
1193 | */ |
1152 | object * |
1194 | static object * |
1153 | find_arrow (object *op, const char *type) |
1195 | find_arrow (object *op, const char *type) |
1154 | { |
1196 | { |
1155 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1197 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1156 | if (tmp->type == ARROW && !strcmp (&tmp->race, type)) |
1198 | if (tmp->type == ARROW && !strcmp (&tmp->race, type)) |
1157 | return splay (tmp); |
1199 | return splay (tmp); |
1158 | |
1200 | |
1159 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1201 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1160 | if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type)) |
1202 | if (tmp->type == CONTAINER && tmp->flag [FLAG_APPLIED] && !strcmp (&tmp->race, type)) |
1161 | if (object *arrow = find_arrow (tmp, type)) |
1203 | if (object *arrow = find_arrow (tmp, type)) |
1162 | { |
1204 | { |
1163 | splay (tmp); |
1205 | splay (tmp); |
1164 | return arrow; |
1206 | return arrow; |
1165 | } |
1207 | } |
… | |
… | |
1171 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1213 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1172 | * against the target. A full test is not performed, simply a basic test |
1214 | * against the target. A full test is not performed, simply a basic test |
1173 | * of resistances. The archer is making a quick guess at what he sees down |
1215 | * of resistances. The archer is making a quick guess at what he sees down |
1174 | * the hall. Failing that it does it's best to pick the highest plus arrow. |
1216 | * the hall. Failing that it does it's best to pick the highest plus arrow. |
1175 | */ |
1217 | */ |
1176 | object * |
1218 | static object * |
1177 | find_better_arrow (object *op, object *target, shstr_cmp type, int *better) |
1219 | find_better_arrow (object *op, object *target, shstr_cmp type, int *better) |
1178 | { |
1220 | { |
1179 | object *tmp = NULL, *arrow, *ntmp; |
1221 | object *tmp = NULL, *arrow, *ntmp; |
1180 | int attacknum, attacktype, betterby = 0, i; |
1222 | int attacknum, attacktype, betterby = 0, i; |
1181 | |
1223 | |
1182 | if (!type) |
1224 | if (!type) |
1183 | return NULL; |
1225 | return NULL; |
1184 | |
1226 | |
1185 | for (arrow = op->inv; arrow; arrow = arrow->below) |
1227 | for (arrow = op->inv; arrow; arrow = arrow->below) |
1186 | { |
1228 | { |
1187 | if (arrow->type == CONTAINER && arrow->race == type && QUERY_FLAG (arrow, FLAG_APPLIED)) |
1229 | if (arrow->type == CONTAINER && arrow->race == type && arrow->flag [FLAG_APPLIED]) |
1188 | { |
1230 | { |
1189 | i = 0; |
1231 | i = 0; |
1190 | ntmp = find_better_arrow (arrow, target, type, &i); |
1232 | ntmp = find_better_arrow (arrow, target, type, &i); |
1191 | |
1233 | |
1192 | if (i > betterby) |
1234 | if (i > betterby) |
… | |
… | |
1250 | * find_better_arrow to find a decent arrow to use. |
1292 | * find_better_arrow to find a decent arrow to use. |
1251 | * op = the shooter |
1293 | * op = the shooter |
1252 | * type = bow->race |
1294 | * type = bow->race |
1253 | * dir = fire direction |
1295 | * dir = fire direction |
1254 | */ |
1296 | */ |
1255 | object * |
1297 | static object * |
1256 | pick_arrow_target (object *op, shstr_cmp type, int dir) |
1298 | pick_arrow_target (object *op, shstr_cmp type, int dir) |
1257 | { |
1299 | { |
1258 | object *tmp = NULL; |
1300 | object *tmp = NULL; |
1259 | maptile *m; |
1301 | maptile *m; |
1260 | int i, mflags, found, number; |
1302 | int i, mflags, found, number; |
… | |
… | |
1293 | break; |
1335 | break; |
1294 | } |
1336 | } |
1295 | |
1337 | |
1296 | if (mflags & P_IS_ALIVE) |
1338 | if (mflags & P_IS_ALIVE) |
1297 | for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
1339 | for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
1298 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
1340 | if (tmp->flag [FLAG_ALIVE]) |
1299 | break; |
1341 | break; |
1300 | } |
1342 | } |
1301 | |
1343 | |
1302 | if (!tmp) |
1344 | if (!tmp) |
1303 | return find_arrow (op, type); |
1345 | return find_arrow (op, type); |
… | |
… | |
1307 | |
1349 | |
1308 | return find_better_arrow (op, tmp, type, &i); |
1350 | return find_better_arrow (op, tmp, type, &i); |
1309 | } |
1351 | } |
1310 | |
1352 | |
1311 | /* |
1353 | /* |
1312 | * Creature fires a bow - op can be monster or player. Returns |
1354 | * Creature fires a bow - op can be monster or player. Returns |
1313 | * 1 if bow was actually fired, 0 otherwise. |
1355 | * 1 if bow was actually fired, 0 otherwise. |
1314 | * op is the object firing the bow. |
1356 | * op is the object firing the bow. |
1315 | * part is for multipart creatures - the part firing the bow. |
1357 | * part is for multipart creatures - the part firing the bow. |
1316 | * dir is the direction of fire. |
1358 | * dir is the direction of fire. |
1317 | * wc_mod is any special modifier to give (used in special player fire modes) |
1359 | * wc_mod is any special modifier to give (used in special player fire modes) |
… | |
… | |
1364 | { |
1406 | { |
1365 | if (op->type == PLAYER) |
1407 | if (op->type == PLAYER) |
1366 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1408 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1367 | /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */ |
1409 | /* FLAG_READY_BOW will get reset if the monsters picks up some arrows */ |
1368 | else |
1410 | else |
1369 | CLEAR_FLAG (op, FLAG_READY_BOW); |
1411 | op->clr_flag (FLAG_READY_BOW); |
1370 | |
1412 | |
1371 | return 0; |
1413 | return 0; |
1372 | } |
1414 | } |
1373 | } |
1415 | } |
1374 | |
1416 | |
… | |
… | |
1423 | #endif |
1465 | #endif |
1424 | |
1466 | |
1425 | SET_ANIMATION (arrow, arrow->direction); |
1467 | SET_ANIMATION (arrow, arrow->direction); |
1426 | |
1468 | |
1427 | /* update the speed */ |
1469 | /* update the speed */ |
1428 | arrow->speed = ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.f |
|
|
1429 | + bow->stats.dam / 7.f; |
|
|
1430 | |
1470 | |
1431 | arrow->set_speed (max (arrow->speed, 2.f)); |
|
|
1432 | arrow->speed_left = 0; |
1471 | arrow->speed_left = 0; |
|
|
1472 | arrow->set_speed (max (2.f, |
|
|
1473 | ((bow->flag [FLAG_NO_STRENGTH] ? 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.f |
|
|
1474 | + bow->stats.dam / 7.f |
|
|
1475 | )); |
1433 | |
1476 | |
1434 | int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; |
1477 | int wc = op->stats.wc + wc_mod - arrow->magic - arrow->stats.wc; |
1435 | |
1478 | |
1436 | if (op->type == PLAYER) |
1479 | if (op->type == PLAYER) |
1437 | { |
1480 | { |
… | |
… | |
1458 | arrow->stats.dam = clamp (arrow->stats.dam + op->stats.dam + arrow->magic, MIN_DAM, MAX_DAM); |
1501 | arrow->stats.dam = clamp (arrow->stats.dam + op->stats.dam + arrow->magic, MIN_DAM, MAX_DAM); |
1459 | |
1502 | |
1460 | arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC); |
1503 | arrow->stats.wc = clamp (wc, MIN_WC, MAX_WC); |
1461 | arrow->move_type = MOVE_FLY_LOW; |
1504 | arrow->move_type = MOVE_FLY_LOW; |
1462 | arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; |
1505 | arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; |
|
|
1506 | arrow->set_flag (FLAG_NO_PICK); |
1463 | |
1507 | |
1464 | op->play_sound (sound_find ("fire_arrow")); |
1508 | op->play_sound (sound_find ("fire_arrow")); |
1465 | m->insert (arrow, sx, sy, op); |
1509 | m->insert (arrow, sx, sy, op); |
1466 | |
1510 | |
1467 | if (!arrow->destroyed ()) |
1511 | if (!arrow->destroyed ()) |
… | |
… | |
1475 | * but monsters can't. Putting that code here |
1519 | * but monsters can't. Putting that code here |
1476 | * makes the fire_bow code much cleaner. |
1520 | * makes the fire_bow code much cleaner. |
1477 | * this function should only be called if 'op' is a player, |
1521 | * this function should only be called if 'op' is a player, |
1478 | * hence the function name. |
1522 | * hence the function name. |
1479 | */ |
1523 | */ |
1480 | int |
1524 | static int |
1481 | player_fire_bow (object *op, int dir) |
1525 | player_fire_bow (object *op, int dir) |
1482 | { |
1526 | { |
1483 | int ret; |
1527 | int ret; |
1484 | |
1528 | |
1485 | if (op->contr->bowtype == bow_bestarrow) |
1529 | if (op->contr->bowtype == bow_bestarrow) |
… | |
… | |
1513 | } |
1557 | } |
1514 | |
1558 | |
1515 | /* Fires a misc (wand/rod/horn) object in 'dir'. |
1559 | /* Fires a misc (wand/rod/horn) object in 'dir'. |
1516 | * Broken apart from 'fire' to keep it more readable. |
1560 | * Broken apart from 'fire' to keep it more readable. |
1517 | */ |
1561 | */ |
1518 | void |
1562 | static void |
1519 | fire_misc_object (object *op, int dir) |
1563 | fire_misc_object (object *op, int dir) |
1520 | { |
1564 | { |
1521 | object *item = op->contr->ranged_ob; |
1565 | object *item = op->contr->ranged_ob; |
1522 | |
1566 | |
1523 | if (!item) |
1567 | if (!item) |
… | |
… | |
1530 | { |
1574 | { |
1531 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1575 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1532 | return; |
1576 | return; |
1533 | } |
1577 | } |
1534 | |
1578 | |
1535 | if (!op->change_weapon (item)) |
1579 | if (!op->apply (item)) |
1536 | return; |
1580 | return; |
1537 | |
1581 | |
1538 | if (item->type == WAND) |
1582 | if (item->type == WAND) |
1539 | { |
1583 | { |
1540 | if (item->stats.food <= 0) |
1584 | if (item->stats.food <= 0) |
… | |
… | |
1545 | return; |
1589 | return; |
1546 | } |
1590 | } |
1547 | } |
1591 | } |
1548 | else if (item->type == ROD || item->type == HORN) |
1592 | else if (item->type == ROD || item->type == HORN) |
1549 | { |
1593 | { |
1550 | sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace); |
1594 | sint16 spell_sp = max (item->inv->stats.sp, item->inv->stats.grace); |
1551 | |
1595 | |
1552 | // using the maximum of the rods charge allows at least one spell cast |
1596 | // using the maximum of the rods charge allows at least one spell cast |
1553 | // for a rod or horn, this fixes some broken rods. |
1597 | // for a rod or horn, this fixes some broken rods. |
1554 | if (item->stats.hp < MIN (spell_sp, item->stats.maxhp)) |
1598 | if (item->stats.hp < min (spell_sp, item->stats.maxhp)) |
1555 | { |
1599 | { |
1556 | op->contr->play_sound (sound_find ("wand_poof")); |
1600 | op->contr->play_sound (sound_find ("wand_poof")); |
1557 | |
1601 | |
1558 | if (item->type == ROD) |
1602 | if (item->type == ROD) |
1559 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
1603 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
… | |
… | |
1570 | |
1614 | |
1571 | if (item->type == WAND) |
1615 | if (item->type == WAND) |
1572 | { |
1616 | { |
1573 | if (!(--item->stats.food)) |
1617 | if (!(--item->stats.food)) |
1574 | { |
1618 | { |
1575 | object *tmp; |
|
|
1576 | |
|
|
1577 | if (item->arch) |
1619 | if (item->arch) |
1578 | { |
1620 | { |
1579 | CLEAR_FLAG (item, FLAG_ANIMATE); |
1621 | item->clr_flag (FLAG_ANIMATE); |
1580 | item->face = item->arch->face; |
1622 | item->face = item->arch->face; |
1581 | item->set_speed (0); |
1623 | item->set_speed (0); |
1582 | } |
1624 | } |
1583 | |
1625 | |
1584 | if (object *pl = item->visible_to ()) |
1626 | if (object *pl = item->visible_to ()) |
… | |
… | |
1591 | } |
1633 | } |
1592 | |
1634 | |
1593 | /* Received a fire command for the player - go and do it. |
1635 | /* Received a fire command for the player - go and do it. |
1594 | */ |
1636 | */ |
1595 | bool |
1637 | bool |
1596 | fire (object *op, int dir) |
1638 | fire (object *who, int dir) |
1597 | { |
1639 | { |
1598 | int spellcost = 0; |
1640 | int spellcost = 0; |
1599 | |
1641 | |
1600 | player *pl = op->contr; |
1642 | player *pl = who->contr; |
1601 | |
1643 | |
1602 | if (pl->golem) |
1644 | if (pl->golem) |
1603 | { |
1645 | { |
1604 | control_golem (op->contr->golem, dir); |
1646 | control_golem (who->contr->golem, dir); |
1605 | return false; |
1647 | return false; |
1606 | } |
1648 | } |
1607 | |
1649 | |
1608 | object *ob = pl->ranged_ob; |
1650 | object *ob = pl->ranged_ob; |
1609 | |
1651 | |
1610 | if (!ob) |
1652 | if (!ob) |
1611 | return false; |
1653 | return false; |
1612 | |
1654 | |
1613 | if (op->speed_left > 0.f) |
1655 | if (who->speed_left > 0.f) |
1614 | --op->speed_left; |
1656 | --who->speed_left; |
1615 | else |
1657 | else |
1616 | return false; |
1658 | return false; |
1617 | |
1659 | |
1618 | if (!op->change_weapon (ob)) |
1660 | if (!who->apply (ob)) |
1619 | return false; |
1661 | return false; |
1620 | |
1662 | |
1621 | /* check for loss of invisiblity/hide */ |
1663 | /* check for loss of invisiblity/hide */ |
1622 | if (action_makes_visible (op)) |
1664 | if (action_makes_visible (who)) |
1623 | make_visible (op); |
1665 | make_visible (who); |
1624 | |
1666 | |
1625 | switch (ob->type) |
1667 | switch (ob->type) |
1626 | { |
1668 | { |
1627 | case BOW: |
1669 | case BOW: |
1628 | player_fire_bow (op, dir); |
1670 | player_fire_bow (who, dir); |
1629 | break; |
1671 | break; |
1630 | |
1672 | |
1631 | case SPELL: |
1673 | case SPELL: |
1632 | spellcost = cast_spell (op, op, dir, ob, *pl->spellparam ? pl->spellparam : 0); |
1674 | spellcost = cast_spell (who, who, dir, ob, *pl->spellparam ? pl->spellparam : 0); |
1633 | break; |
1675 | break; |
1634 | |
1676 | |
1635 | case BUILDER: |
1677 | case BUILDER: |
1636 | apply_map_builder (op, dir); |
1678 | apply_map_builder (who, dir); |
1637 | break; |
1679 | break; |
1638 | |
1680 | |
1639 | case SKILL: |
1681 | case SKILL: |
1640 | do_skill (op, op, ob, dir, 0); |
1682 | do_skill (who, who, ob, dir, 0); |
1641 | break; |
1683 | break; |
1642 | |
1684 | |
|
|
1685 | case RANGED: |
|
|
1686 | do_skill (who, ob, who->chosen_skill, dir, 0); |
|
|
1687 | break; |
|
|
1688 | |
1643 | default: |
1689 | default: |
1644 | fire_misc_object (op, dir); |
1690 | fire_misc_object (who, dir); |
1645 | break; |
1691 | break; |
1646 | } |
1692 | } |
1647 | |
1693 | |
1648 | return true; |
1694 | return true; |
1649 | } |
1695 | } |
1650 | |
1696 | |
1651 | /* find_key |
1697 | static object * |
1652 | * We try to find a key for the door as passed. If we find a key |
|
|
1653 | * and successfully use it, we return the key, otherwise NULL |
|
|
1654 | * This function merges both normal and locked door, since the logic |
|
|
1655 | * for both is the same - just the specific key is different. |
|
|
1656 | * pl is the player, |
|
|
1657 | * inv is the objects inventory to searched |
|
|
1658 | * door is the door we are trying to match against. |
|
|
1659 | * This function can be called recursively to search containers. |
|
|
1660 | */ |
|
|
1661 | object * |
|
|
1662 | find_key (object *pl, object *container, object *door) |
1698 | find_key_ (object *pl, object *container, object *door) |
1663 | { |
1699 | { |
1664 | object *tmp, *key; |
1700 | object *tmp, *key; |
1665 | |
1701 | |
1666 | /* Should not happen, but sanity checking is never bad */ |
1702 | /* Should not happen, but sanity checking is never bad */ |
1667 | if (!container->inv) |
1703 | if (!container->inv) |
… | |
… | |
1671 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1707 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1672 | { |
1708 | { |
1673 | if (door->type == DOOR && tmp->type == KEY) |
1709 | if (door->type == DOOR && tmp->type == KEY) |
1674 | break; |
1710 | break; |
1675 | |
1711 | |
1676 | /* For sanity, we should really check door type, but other stuff |
1712 | /* For sanity, we should really check door type, but other stuff |
1677 | * (like containers) can be locked with special keys |
1713 | * (like containers) can be locked with special keys |
1678 | */ |
1714 | */ |
1679 | if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying) |
1715 | if (tmp->slaying && tmp->type == SPECIAL_KEY && tmp->slaying == door->slaying) |
1680 | break; |
1716 | break; |
1681 | } |
1717 | } |
… | |
… | |
1688 | if (!tmp) |
1724 | if (!tmp) |
1689 | { |
1725 | { |
1690 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1726 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1691 | /* No reason to search empty containers */ |
1727 | /* No reason to search empty containers */ |
1692 | if (tmp->type == CONTAINER && tmp->inv) |
1728 | if (tmp->type == CONTAINER && tmp->inv) |
1693 | if ((key = find_key (pl, tmp, door))) |
1729 | if ((key = find_key_ (pl, tmp, door))) |
1694 | return key; |
1730 | return key; |
1695 | |
1731 | |
1696 | if (!tmp) |
1732 | if (!tmp) |
1697 | return 0; |
1733 | return 0; |
1698 | } |
1734 | } |
… | |
… | |
1717 | * inv must have been an container and must have been active. |
1753 | * inv must have been an container and must have been active. |
1718 | * |
1754 | * |
1719 | * Change the color so that the message doesn't disappear with |
1755 | * Change the color so that the message doesn't disappear with |
1720 | * all the others. |
1756 | * all the others. |
1721 | */ |
1757 | */ |
1722 | if (pl->contr->usekeys == key_inventory || |
1758 | if (pl->contr->usekeys == key_inventory |
1723 | !QUERY_FLAG (container, FLAG_APPLIED) || |
1759 | || !container->flag [FLAG_APPLIED] |
1724 | (pl->contr->usekeys == keyrings && container->race != shstr_keys)) |
1760 | || (pl->contr->usekeys == keyrings && container->race != shstr_keys)) |
1725 | { |
1761 | { |
1726 | new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, |
1762 | new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, |
1727 | "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); |
1763 | "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); |
1728 | return NULL; |
1764 | return NULL; |
1729 | } |
1765 | } |
1730 | } |
1766 | } |
1731 | |
1767 | |
1732 | return tmp; |
1768 | return tmp; |
|
|
1769 | } |
|
|
1770 | |
|
|
1771 | /* find_key |
|
|
1772 | * We try to find a key for the door as passed. If we find a key |
|
|
1773 | * and successfully use it, we return the key, otherwise NULL |
|
|
1774 | * This function merges both normal and locked door, since the logic |
|
|
1775 | * for both is the same - just the specific key is different. |
|
|
1776 | * pl is the player, |
|
|
1777 | * inv is the objects inventory to searched |
|
|
1778 | * door is the door we are trying to match against. |
|
|
1779 | * This function can be called recursively to search containers. |
|
|
1780 | */ |
|
|
1781 | object * |
|
|
1782 | find_key (object *pl, object *container, object *door) |
|
|
1783 | { |
|
|
1784 | if (door->slaying && is_match_expr (door->slaying)) |
|
|
1785 | { |
|
|
1786 | // for match expressions, we try to find the key by applying the match |
|
|
1787 | // to the op itself, which is supposed to find the "key", instead |
|
|
1788 | // of searching through containers ourselves. |
|
|
1789 | |
|
|
1790 | return match_one (door->slaying, container, door, pl, pl); |
|
|
1791 | } |
|
|
1792 | else |
|
|
1793 | return find_key_ (pl, container, door); |
1733 | } |
1794 | } |
1734 | |
1795 | |
1735 | /* moved door processing out of move_player_attack. |
1796 | /* moved door processing out of move_player_attack. |
1736 | * returns 1 if player has opened the door with a key |
1797 | * returns 1 if player has opened the door with a key |
1737 | * such that the caller should not do anything more, |
1798 | * such that the caller should not do anything more, |
… | |
… | |
1787 | * going to try and move (not fire weapons). |
1848 | * going to try and move (not fire weapons). |
1788 | */ |
1849 | */ |
1789 | bool |
1850 | bool |
1790 | move_player_attack (object *op, int dir) |
1851 | move_player_attack (object *op, int dir) |
1791 | { |
1852 | { |
1792 | if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op)) |
1853 | if (!op->contr->braced && op->speed_left > 0.f && op->move (dir)) |
1793 | { |
1854 | { |
1794 | --op->speed_left; |
1855 | --op->speed_left; |
1795 | return true; |
1856 | return true; |
1796 | } |
1857 | } |
1797 | |
1858 | |
1798 | int on_battleground; |
|
|
1799 | |
|
|
1800 | sint16 nx = freearr_x[dir] + op->x; |
1859 | sint16 nx = freearr_x[dir] + op->x; |
1801 | sint16 ny = freearr_y[dir] + op->y; |
1860 | sint16 ny = freearr_y[dir] + op->y; |
1802 | |
|
|
1803 | on_battleground = op_on_battleground (op, 0, 0); |
|
|
1804 | |
1861 | |
1805 | if (out_of_map (op->map, nx, ny)) |
1862 | if (out_of_map (op->map, nx, ny)) |
1806 | return false; |
1863 | return false; |
1807 | |
1864 | |
1808 | /* If braced, or can't move to the square, and it is not out of the |
1865 | /* If braced, or can't move to the square, and it is not out of the |
… | |
… | |
1829 | || mon->flag [FLAG_CAN_ROLL]) |
1886 | || mon->flag [FLAG_CAN_ROLL]) |
1830 | && mon != op) |
1887 | && mon != op) |
1831 | break; |
1888 | break; |
1832 | } |
1889 | } |
1833 | |
1890 | |
1834 | if (!mon) /* This happens anytime the player tries to move */ |
1891 | /* no monster == player tries to move into a wall or so */ |
1835 | return false; /* into a wall */ |
1892 | if (!mon) |
|
|
1893 | { |
|
|
1894 | for (object *ob = m->at (nx, ny).top; ob; ob = ob->below) |
|
|
1895 | if (op->move_type & ob->move_block) |
|
|
1896 | { |
|
|
1897 | if (ob->move_block == MOVE_ALL) |
|
|
1898 | move_into_wall (op, ob); |
|
|
1899 | else |
|
|
1900 | { |
|
|
1901 | if (op->contr->ns->bumpmsg) |
|
|
1902 | { |
|
|
1903 | op->play_sound (sound_find ("blocked_move")); |
|
|
1904 | |
|
|
1905 | op->statusmsg (ob->invisible |
|
|
1906 | ? "Something blocks you." |
|
|
1907 | : format ("Something blocks you from entering the %s.", query_name (ob)) |
|
|
1908 | ); |
|
|
1909 | } |
|
|
1910 | } |
|
|
1911 | |
|
|
1912 | break; |
|
|
1913 | } |
|
|
1914 | |
|
|
1915 | return false; |
|
|
1916 | } |
1836 | |
1917 | |
1837 | mon = mon->head_ (); |
1918 | mon = mon->head_ (); |
1838 | |
1919 | |
1839 | if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) |
1920 | if ((mon->type == DOOR && mon->stats.hp >= 0) || (mon->type == LOCKED_DOOR)) |
1840 | if (op->contr->weapon_sp_left > 0.f) |
1921 | if (op->contr->weapon_sp_left > 0.f) |
… | |
… | |
1858 | */ |
1939 | */ |
1859 | if (op->type == PLAYER |
1940 | if (op->type == PLAYER |
1860 | && ((mon->owner && mon->owner->contr |
1941 | && ((mon->owner && mon->owner->contr |
1861 | && same_party (mon->owner->contr->party, op->contr->party)) |
1942 | && same_party (mon->owner->contr->party, op->contr->party)) |
1862 | || mon->owner == op) |
1943 | || mon->owner == op) |
1863 | && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) |
1944 | && (mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY])) |
1864 | { |
1945 | { |
1865 | /* If we're braced, we don't want to switch places with it */ |
1946 | /* If we're braced, we don't want to switch places with it */ |
1866 | if (op->contr->braced) |
1947 | if (op->contr->braced) |
1867 | return false; |
1948 | return false; |
1868 | |
1949 | |
… | |
… | |
1879 | return true; |
1960 | return true; |
1880 | } |
1961 | } |
1881 | else |
1962 | else |
1882 | return false; |
1963 | return false; |
1883 | } |
1964 | } |
|
|
1965 | |
|
|
1966 | bool on_battleground = op_on_battleground (op, 0, 0); |
1884 | |
1967 | |
1885 | /* in certain circumstances, you shouldn't attack friendly |
1968 | /* in certain circumstances, you shouldn't attack friendly |
1886 | * creatures. Note that if you are braced, you can't push |
1969 | * creatures. Note that if you are braced, you can't push |
1887 | * someone, but put it inside this loop so that you won't |
1970 | * someone, but put it inside this loop so that you won't |
1888 | * attack them either. |
1971 | * attack them either. |
1889 | */ |
1972 | */ |
1890 | if ((mon->type == PLAYER || mon->enemy != op) |
1973 | if ((mon->type == PLAYER || mon->enemy != op) |
1891 | && (mon->type == PLAYER || QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY)) |
1974 | && (mon->type == PLAYER || mon->flag [FLAG_UNAGGRESSIVE] || mon->flag [FLAG_FRIENDLY]) |
1892 | && ((op->contr->peaceful |
1975 | && ((op->contr->peaceful |
1893 | || (mon->type == PLAYER && mon->contr->peaceful)) |
1976 | || (mon->type == PLAYER && mon->contr->peaceful)) |
1894 | && !on_battleground)) |
1977 | && !on_battleground)) |
1895 | { |
1978 | { |
1896 | if (op->speed_left > 0.f) |
1979 | if (op->speed_left > 0.f) |
… | |
… | |
1912 | } |
1995 | } |
1913 | } |
1996 | } |
1914 | /* If the object is a boulder or other rollable object, then |
1997 | /* If the object is a boulder or other rollable object, then |
1915 | * roll it if not braced. You can't roll it if you are braced. |
1998 | * roll it if not braced. You can't roll it if you are braced. |
1916 | */ |
1999 | */ |
1917 | else if (QUERY_FLAG (mon, FLAG_CAN_ROLL) && (!op->contr->braced)) |
2000 | else if (mon->flag [FLAG_CAN_ROLL] && (!op->contr->braced)) |
1918 | { |
2001 | { |
1919 | if (op->speed_left > 0.f) |
2002 | if (op->speed_left > 0.f) |
1920 | { |
2003 | { |
1921 | --op->speed_left; |
2004 | --op->speed_left; |
1922 | |
2005 | |
… | |
… | |
1931 | * Way it works is like this: First, it must have some hit points |
2014 | * Way it works is like this: First, it must have some hit points |
1932 | * and be living. Then, it must be one of the following: |
2015 | * and be living. Then, it must be one of the following: |
1933 | * 1) Not a player, 2) A player, but of a different party. Note |
2016 | * 1) Not a player, 2) A player, but of a different party. Note |
1934 | * that party_number -1 is no party, so attacks can still happen. |
2017 | * that party_number -1 is no party, so attacks can still happen. |
1935 | */ |
2018 | */ |
1936 | else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && |
2019 | else if ((mon->stats.hp >= 0) && mon->flag [FLAG_ALIVE] && |
1937 | ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) |
2020 | ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) |
1938 | { |
2021 | { |
1939 | if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS]) |
2022 | if (op->contr->weapon_sp_left > 0.f && !op->flag [FLAG_WIZPASS]) |
1940 | { |
2023 | { |
1941 | --op->contr->weapon_sp_left; |
2024 | --op->contr->weapon_sp_left; |
… | |
… | |
1953 | } |
2036 | } |
1954 | |
2037 | |
1955 | bool |
2038 | bool |
1956 | move_player (object *op, int dir) |
2039 | move_player (object *op, int dir) |
1957 | { |
2040 | { |
1958 | int pick; |
|
|
1959 | |
|
|
1960 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2041 | if (!op->map || op->map->state != MAP_ACTIVE) |
1961 | return 0; |
2042 | return 0; |
1962 | |
2043 | |
1963 | /* Sanity check: make sure dir is valid */ |
2044 | /* Sanity check: make sure dir is valid */ |
1964 | if ((dir < 0) || (dir >= 9)) |
2045 | if (dir < 0 || dir > 8) |
1965 | { |
2046 | { |
1966 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
2047 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
1967 | return 0; |
2048 | return 0; |
1968 | } |
2049 | } |
1969 | |
2050 | |
1970 | /* peterm: added following line */ |
2051 | /* peterm: added following line */ |
1971 | if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) |
2052 | if (op->flag [FLAG_CONFUSED] && dir) |
1972 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
2053 | dir = absdir (dir + rndm (3) + rndm (3) - 2); |
1973 | |
2054 | |
1974 | op->facing = dir; |
2055 | op->facing = dir; |
1975 | |
2056 | |
1976 | if (op->flag [FLAG_HIDDEN]) |
2057 | if (op->flag [FLAG_HIDDEN]) |
1977 | do_hidden_move (op); |
2058 | do_hidden_move (op); |
1978 | |
2059 | |
1979 | bool retval; |
2060 | bool retval; |
|
|
2061 | int pick = 0; |
1980 | |
2062 | |
1981 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
2063 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
1982 | retval = RESULT_INT (0); |
2064 | retval = RESULT_INT (0); |
1983 | else if (op->contr->fire_on) |
2065 | else if (op->contr->fire_on) |
1984 | retval = fire (op, dir); |
2066 | retval = fire (op, dir); |
… | |
… | |
2015 | * players. |
2097 | * players. |
2016 | */ |
2098 | */ |
2017 | bool |
2099 | bool |
2018 | handle_newcs_player (object *op) |
2100 | handle_newcs_player (object *op) |
2019 | { |
2101 | { |
2020 | if (QUERY_FLAG (op, FLAG_SCARED)) |
2102 | if (op->flag [FLAG_SCARED]) |
2021 | { |
2103 | { |
2022 | if (op->speed_left > 0.f) |
2104 | if (op->speed_left > 0.f) |
2023 | { |
2105 | { |
2024 | --op->speed_left; |
2106 | --op->speed_left; |
2025 | flee_player (op); |
2107 | flee_player (op); |
… | |
… | |
2041 | return move_player (op, op->direction); |
2123 | return move_player (op, op->direction); |
2042 | |
2124 | |
2043 | return false; |
2125 | return false; |
2044 | } |
2126 | } |
2045 | |
2127 | |
2046 | int |
2128 | static int |
2047 | save_life (object *op) |
2129 | save_life (object *op) |
2048 | { |
2130 | { |
2049 | if (!QUERY_FLAG (op, FLAG_LIFESAVE)) |
2131 | if (!op->flag [FLAG_LIFESAVE]) |
2050 | return 0; |
2132 | return 0; |
2051 | |
2133 | |
2052 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2134 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2053 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) |
2135 | if (tmp->flag [FLAG_APPLIED] && tmp->flag [FLAG_LIFESAVE]) |
2054 | { |
2136 | { |
2055 | op->play_sound (sound_find ("ob_evaporate")); |
2137 | op->play_sound (sound_find ("ob_evaporate")); |
2056 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); |
2138 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); |
2057 | |
2139 | |
2058 | tmp->destroy (); |
2140 | tmp->destroy (); |
2059 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2141 | op->clr_flag (FLAG_LIFESAVE); |
2060 | |
2142 | |
2061 | if (op->stats.hp < 0) |
2143 | if (op->stats.hp < 0) |
2062 | op->stats.hp = op->stats.maxhp; |
2144 | op->stats.hp = op->stats.maxhp; |
2063 | |
2145 | |
2064 | if (op->stats.food < 0) |
2146 | if (op->stats.food < 0) |
2065 | op->stats.food = 999; |
2147 | op->stats.food = MAX_FOOD; |
2066 | |
2148 | |
2067 | op->update_stats (); |
2149 | op->update_stats (); |
2068 | return 1; |
2150 | return 1; |
2069 | } |
2151 | } |
2070 | |
2152 | |
2071 | LOG (llevError, "Error: LIFESAVE set without applied object.\n"); |
2153 | LOG (llevError, "Error: LIFESAVE set without applied object.\n"); |
2072 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2154 | op->clr_flag (FLAG_LIFESAVE); |
2073 | enter_player_savebed (op); /* bring him home. */ |
2155 | enter_player_savebed (op); /* bring him home. */ |
2074 | return 0; |
2156 | return 0; |
2075 | } |
2157 | } |
2076 | |
2158 | |
2077 | /* This goes throws the inventory and removes unpaid objects, and puts them |
2159 | /* This goes throws the inventory and removes unpaid objects, and puts them |
… | |
… | |
2084 | { |
2166 | { |
2085 | while (op) |
2167 | while (op) |
2086 | { |
2168 | { |
2087 | object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ |
2169 | object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ |
2088 | |
2170 | |
2089 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
2171 | if (op->flag [FLAG_UNPAID]) |
2090 | op->insert_at (env); |
2172 | op->insert_at (env); |
2091 | else if (op->inv) |
2173 | else if (op->inv) |
2092 | drop_unpaid_items (op->inv, env); |
2174 | drop_unpaid_items (op->inv, env); |
2093 | |
2175 | |
2094 | op = next; |
2176 | op = next; |
… | |
… | |
2100 | { |
2182 | { |
2101 | if (!flag [FLAG_REMOVED]) |
2183 | if (!flag [FLAG_REMOVED]) |
2102 | ::drop_unpaid_items (inv, this); |
2184 | ::drop_unpaid_items (inv, this); |
2103 | } |
2185 | } |
2104 | |
2186 | |
2105 | /* |
|
|
2106 | * Returns pointer a static string containing gravestone text |
|
|
2107 | * Moved from apply.c to player.c - player.c is what |
|
|
2108 | * actually uses this function. player.c may not be quite the |
|
|
2109 | * best, a misc file for object actions is probably better, |
|
|
2110 | * but there isn't one in the server directory. |
|
|
2111 | */ |
|
|
2112 | const char * |
|
|
2113 | gravestone_text (object *op) |
|
|
2114 | { |
|
|
2115 | static dynbuf_text buf; |
|
|
2116 | |
|
|
2117 | buf << "---- R.I.P. ----\n\n" |
|
|
2118 | << op->name; |
|
|
2119 | |
|
|
2120 | if (op->type == PLAYER) |
|
|
2121 | buf << " the " << op->contr->title; |
|
|
2122 | |
|
|
2123 | buf << "\n\n"; |
|
|
2124 | |
|
|
2125 | buf << "who was level "; |
|
|
2126 | buf << (sint32)op->level << "\n\n" // OO breakdown |
|
|
2127 | << " when " << (op->contr ? "killed" : "died") << "\n\n"; |
|
|
2128 | |
|
|
2129 | if (op->type == PLAYER) |
|
|
2130 | buf << "by " << op->contr->killer_name () << ".\n\n"; |
|
|
2131 | |
|
|
2132 | { |
|
|
2133 | static char buf2[128]; |
|
|
2134 | time_t now = time (NULL); |
|
|
2135 | strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now)); |
|
|
2136 | buf << buf2; |
|
|
2137 | } |
|
|
2138 | |
|
|
2139 | return buf; |
|
|
2140 | } |
|
|
2141 | |
|
|
2142 | void |
2187 | void |
2143 | do_some_living (object *op) |
2188 | do_some_living (object *op) |
2144 | { |
2189 | { |
2145 | int last_food = op->stats.food; |
2190 | int last_food = op->stats.food; |
2146 | int gen_hp, gen_sp, gen_grace; |
2191 | int gen_hp, gen_sp, gen_grace; |
2147 | int over_hp, over_sp, over_grace; |
|
|
2148 | int i; |
|
|
2149 | int rate_hp = 1200; |
2192 | int rate_hp = 1200; |
2150 | int rate_sp = 2500; |
2193 | int rate_sp = 2500; |
2151 | int rate_grace = 2000; |
2194 | int rate_grace = 2000; |
2152 | const int max_hp = 1; |
2195 | const int max_hp = 1; |
2153 | const int max_sp = 1; |
2196 | const int max_sp = 1; |
2154 | const int max_grace = 1; |
2197 | const int max_grace = 1; |
2155 | |
2198 | |
|
|
2199 | #if 0 |
2156 | if (op->contr->hidden) |
2200 | if (op->contr->hidden) |
2157 | { |
2201 | { |
2158 | op->invisible = 1000; |
2202 | op->invisible = 1000; |
2159 | /* the socket code flashes the player visible/invisible |
2203 | /* the socket code flashes the player visible/invisible |
2160 | * depending on the value of invisible, so we need to |
2204 | * depending on the value of invisible, so we need to |
2161 | * alternate it here for it to work correctly. |
2205 | * alternate it here for it to work correctly. |
2162 | */ |
2206 | */ |
2163 | if (pticks & 2) |
2207 | if (server_tick & 2) |
2164 | op->invisible--; |
2208 | op->invisible--; |
2165 | } |
2209 | } |
|
|
2210 | else |
|
|
2211 | #endif |
2166 | else if (op->invisible && !(QUERY_FLAG (op, FLAG_MAKE_INVIS))) |
2212 | if (op->invisible && !(op->flag [FLAG_MAKE_INVIS])) |
2167 | { |
2213 | { |
2168 | if (!op->invisible--) |
2214 | if (!op->invisible--) |
2169 | { |
2215 | { |
2170 | make_visible (op); |
2216 | make_visible (op); |
2171 | new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out."); |
2217 | new_draw_info (NDI_UNIQUE, 0, op, "Your invisibility spell runs out."); |
… | |
… | |
2205 | if (--op->last_grace < 0) |
2251 | if (--op->last_grace < 0) |
2206 | { |
2252 | { |
2207 | if (op->stats.grace < op->stats.maxgrace / 2) |
2253 | if (op->stats.grace < op->stats.maxgrace / 2) |
2208 | op->stats.grace++; /* no penalty in food for regaining grace */ |
2254 | op->stats.grace++; /* no penalty in food for regaining grace */ |
2209 | |
2255 | |
|
|
2256 | int temp = gen_grace < 20 ? 30 : gen_grace + 10; |
|
|
2257 | |
2210 | if (max_grace > 1) |
2258 | if (max_grace > 1) |
2211 | { |
2259 | { |
2212 | over_grace = (gen_grace < 20 ? 30 : gen_grace + 10) / rate_grace; |
2260 | int over_grace = temp / rate_grace; |
|
|
2261 | |
2213 | if (over_grace > 0) |
2262 | if (over_grace > 0) |
2214 | { |
2263 | { |
2215 | op->stats.sp += over_grace |
2264 | op->stats.sp += over_grace + (random_roll (0, rate_grace - 1, op, PREFER_HIGH) > (temp % rate_grace)) ? -1 : 0; |
2216 | + (random_roll (0, rate_grace - 1, op, PREFER_HIGH) > ((gen_grace < 20 ? 30 : gen_grace + 10) % rate_grace)) ? -1 : 0; |
|
|
2217 | op->last_grace = 0; |
2265 | op->last_grace = 0; |
2218 | } |
2266 | } |
2219 | else |
2267 | else |
2220 | { |
2268 | op->last_grace = rate_grace / temp; |
2221 | op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10); |
|
|
2222 | } |
|
|
2223 | } |
2269 | } |
2224 | else |
2270 | else |
2225 | { |
2271 | op->last_grace = rate_grace / temp; |
2226 | op->last_grace = rate_grace / (gen_grace < 20 ? 30 : gen_grace + 10); |
2272 | |
2227 | } |
|
|
2228 | /* wearing stuff doesn't detract from grace generation. */ |
2273 | /* wearing stuff doesn't detract from grace generation. */ |
2229 | } |
2274 | } |
2230 | |
2275 | |
2231 | if (op->stats.food > 0) |
2276 | if (op->stats.food > 0) |
2232 | { |
2277 | { |
… | |
… | |
2238 | if (op->stats.sp < op->stats.maxsp) |
2283 | if (op->stats.sp < op->stats.maxsp) |
2239 | { |
2284 | { |
2240 | op->stats.sp++; |
2285 | op->stats.sp++; |
2241 | |
2286 | |
2242 | /* dms do not consume food */ |
2287 | /* dms do not consume food */ |
2243 | if (!QUERY_FLAG (op, FLAG_WIZ)) |
2288 | if (!op->flag [FLAG_WIZ]) |
2244 | { |
2289 | { |
2245 | op->stats.food--; |
2290 | op->stats.food--; |
2246 | |
2291 | |
2247 | if (op->contr->digestion < 0) |
2292 | if (op->contr->digestion < 0) |
2248 | op->stats.food += op->contr->digestion; |
2293 | op->stats.food += op->contr->digestion; |
… | |
… | |
2251 | } |
2296 | } |
2252 | } |
2297 | } |
2253 | |
2298 | |
2254 | if (max_sp > 1) |
2299 | if (max_sp > 1) |
2255 | { |
2300 | { |
2256 | over_sp = (gen_sp + 10) / rate_sp; |
2301 | int over_sp = (gen_sp + 10) / rate_sp; |
2257 | if (over_sp > 0) |
2302 | if (over_sp > 0) |
2258 | { |
2303 | { |
2259 | if (op->stats.sp < op->stats.maxsp) |
2304 | if (op->stats.sp < op->stats.maxsp) |
2260 | { |
2305 | { |
2261 | op->stats.sp += over_sp > max_sp ? max_sp : over_sp; |
2306 | op->stats.sp += over_sp > max_sp ? max_sp : over_sp; |
… | |
… | |
2282 | if (op->stats.hp < op->stats.maxhp) |
2327 | if (op->stats.hp < op->stats.maxhp) |
2283 | { |
2328 | { |
2284 | op->stats.hp++; |
2329 | op->stats.hp++; |
2285 | |
2330 | |
2286 | /* dms do not consume food */ |
2331 | /* dms do not consume food */ |
2287 | if (!QUERY_FLAG (op, FLAG_WIZ)) |
2332 | if (!op->flag [FLAG_WIZ]) |
2288 | { |
2333 | { |
2289 | op->stats.food--; |
2334 | op->stats.food--; |
2290 | |
2335 | |
2291 | if (op->contr->digestion < 0) |
2336 | if (op->contr->digestion < 0) |
2292 | op->stats.food += op->contr->digestion; |
2337 | op->stats.food += op->contr->digestion; |
2293 | else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) |
2338 | else if (op->contr->digestion > 0 && random_roll (0, op->contr->digestion, op, PREFER_HIGH)) |
2294 | op->stats.food = last_food; |
2339 | op->stats.food = last_food; |
2295 | } |
2340 | } |
2296 | } |
2341 | } |
2297 | |
2342 | |
|
|
2343 | int temp = gen_hp < 20 ? 30 : gen_hp + 10; |
|
|
2344 | |
2298 | if (max_hp > 1) |
2345 | if (max_hp > 1) |
2299 | { |
2346 | { |
2300 | over_hp = (gen_hp < 20 ? 30 : gen_hp + 10) / rate_hp; |
2347 | int over_hp = temp / rate_hp; |
2301 | |
2348 | |
2302 | if (over_hp > 0) |
2349 | if (over_hp > 0) |
2303 | { |
2350 | { |
2304 | op->stats.sp += over_hp + (rndm (rate_hp) > ((gen_hp < 20 ? 30 : gen_hp + 10) % rate_hp)) ? -1 : 0; |
2351 | op->stats.sp += over_hp + (random_roll (0, rate_hp - 1, op, PREFER_HIGH) > (temp % rate_hp)) ? -1 : 0; |
2305 | op->last_heal = 0; |
2352 | op->last_heal = 0; |
2306 | } |
2353 | } |
2307 | else |
2354 | else |
2308 | op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); |
2355 | op->last_heal = rate_hp / temp; |
2309 | } |
2356 | } |
2310 | else |
2357 | else |
2311 | op->last_heal = rate_hp / (gen_hp < 20 ? 30 : gen_hp + 10); |
2358 | op->last_heal = rate_hp / temp; |
2312 | } |
2359 | } |
2313 | } |
2360 | } |
2314 | |
2361 | |
2315 | /* Digestion */ |
2362 | /* Digestion */ |
2316 | if (--op->last_eat < 0) |
2363 | if (--op->last_eat < 0) |
… | |
… | |
2319 | penalty = max (0, -op->contr->digestion); |
2366 | penalty = max (0, -op->contr->digestion); |
2320 | |
2367 | |
2321 | op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1); |
2368 | op->last_eat = 25 * (1 + bonus) / (max (0, op->contr->gen_hp) + penalty + 1); |
2322 | |
2369 | |
2323 | /* dms do not consume food */ |
2370 | /* dms do not consume food */ |
2324 | if (!QUERY_FLAG (op, FLAG_WIZ)) |
2371 | if (!op->flag [FLAG_WIZ]) |
2325 | op->stats.food--; |
2372 | op->stats.food--; |
2326 | } |
2373 | } |
2327 | |
2374 | |
2328 | if (op->stats.food < 0 && op->stats.hp >= 0) |
2375 | if (op->stats.food < 0 && op->stats.hp >= 0) |
2329 | { |
2376 | { |
2330 | object *flesh = 0; |
2377 | object *flesh = 0; |
2331 | |
2378 | |
2332 | for_inv_removable (op, tmp) |
2379 | for_inv_removable (op, tmp) |
2333 | { |
2380 | { |
2334 | if (QUERY_FLAG (tmp, FLAG_UNPAID)) |
2381 | if (tmp->flag [FLAG_UNPAID]) |
2335 | continue; |
2382 | continue; |
2336 | |
2383 | |
2337 | if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) |
2384 | if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) |
2338 | { |
2385 | { |
2339 | op->statusmsg ("You blindly grab for a bite of food. " |
2386 | op->statusmsg ("You blindly grab for a bite of food. " |
2340 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2387 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2341 | manual_apply (op, tmp, 0); |
2388 | op->apply (tmp); |
2342 | |
2389 | |
2343 | if (op->stats.food >= 0 || op->stats.hp < 0) |
2390 | if (op->stats.food >= 0 || op->stats.hp < 0) |
2344 | break; |
2391 | break; |
2345 | } |
2392 | } |
2346 | else if (tmp->type == FLESH) |
2393 | else if (tmp->type == FLESH) |
… | |
… | |
2352 | */ |
2399 | */ |
2353 | if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) |
2400 | if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) |
2354 | { |
2401 | { |
2355 | op->statusmsg ("You blindly grab for a bite of food. " |
2402 | op->statusmsg ("You blindly grab for a bite of food. " |
2356 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2403 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2357 | manual_apply (op, flesh, 0); |
2404 | op->apply (flesh); |
2358 | } |
2405 | } |
2359 | |
2406 | |
2360 | // If player is still starving, alert him! |
2407 | // If player is still starving, alert him! |
2361 | if (op->stats.food < 0) |
2408 | if (op->stats.food < 0) |
2362 | op->failmsg ("You are starving! " |
2409 | op->failmsg ("You are starving! " |
… | |
… | |
2374 | op->contr->killer->destroy (); |
2421 | op->contr->killer->destroy (); |
2375 | } |
2422 | } |
2376 | } |
2423 | } |
2377 | |
2424 | |
2378 | /* killer should be set here already */ |
2425 | /* killer should be set here already */ |
2379 | if (op->stats.hp < 0 && !QUERY_FLAG (op, FLAG_WIZ)) |
2426 | if (op->stats.hp < 0 && !op->flag [FLAG_WIZ]) |
2380 | kill_player (op); |
2427 | kill_player (op); |
2381 | } |
2428 | } |
2382 | } |
2429 | } |
2383 | |
2430 | |
2384 | /* If the player should die (lack of hp, food, etc), we call this. |
2431 | /* If the player should die (lack of hp, food, etc), we call this. |
… | |
… | |
2399 | return; |
2446 | return; |
2400 | |
2447 | |
2401 | dynbuf_text deathtab; |
2448 | dynbuf_text deathtab; |
2402 | |
2449 | |
2403 | /* restore player */ |
2450 | /* restore player */ |
2404 | at = archetype::find ("poisoning"); |
2451 | at = archetype::find (shstr_poisoning); |
2405 | if (object *tmp = present_arch_in_ob (at, op)) |
2452 | if (object *tmp = present_arch_in_ob (at, op)) |
2406 | { |
2453 | { |
2407 | tmp->destroy (); |
2454 | tmp->destroy (); |
2408 | deathtab << "Your body feels cleansed...\r"; |
2455 | deathtab << "Your body feels cleansed...\r"; |
2409 | } |
2456 | } |
2410 | |
2457 | |
2411 | at = archetype::find ("confusion"); |
2458 | at = archetype::find (shstr_confusion); |
2412 | if (object *tmp = present_arch_in_ob (at, op)) |
2459 | if (object *tmp = present_arch_in_ob (at, op)) |
2413 | { |
2460 | { |
2414 | tmp->destroy (); |
2461 | tmp->destroy (); |
2415 | deathtab << "Your mind feels clearer...\r"; |
2462 | deathtab << "Your mind feels clearer...\r"; |
2416 | } |
2463 | } |
… | |
… | |
2418 | cure_disease (op, 0, 0); /* remove any disease */ |
2465 | cure_disease (op, 0, 0); /* remove any disease */ |
2419 | |
2466 | |
2420 | max_it (op->stats.hp , op->stats.maxhp); |
2467 | max_it (op->stats.hp , op->stats.maxhp); |
2421 | max_it (op->stats.sp , op->stats.maxsp); |
2468 | max_it (op->stats.sp , op->stats.maxsp); |
2422 | max_it (op->stats.grace, op->stats.maxgrace); |
2469 | max_it (op->stats.grace, op->stats.maxgrace); |
2423 | |
|
|
2424 | if (op->stats.food <= 0) |
2470 | max_it (op->stats.food , 200); |
2425 | op->stats.food = 999; |
|
|
2426 | |
2471 | |
2427 | // remove all spell effects that are active |
2472 | // remove all spell effects that are active |
2428 | // to avoid long-term effects such as word-of-recall |
2473 | // to avoid long-term effects such as word-of-recall |
2429 | for (object *item = op->inv; item; ) |
2474 | for (object *item = op->inv; item; ) |
2430 | { |
2475 | { |
… | |
… | |
2443 | if (op_on_battleground (op, &x, &y)) |
2488 | if (op_on_battleground (op, &x, &y)) |
2444 | { |
2489 | { |
2445 | deathtab << "You almost died in combat, but local medics have saved your life...\r"; |
2490 | deathtab << "You almost died in combat, but local medics have saved your life...\r"; |
2446 | |
2491 | |
2447 | /* create a bodypart-trophy to make the winner happy */ |
2492 | /* create a bodypart-trophy to make the winner happy */ |
2448 | if (object *tmp = arch_to_object (archetype::find ("finger"))) |
2493 | object *tmp = archetype::find (shstr_finger)->instance (); |
2449 | { |
2494 | |
2450 | tmp->name = format ("%s's finger" , &op->name); |
2495 | tmp->name = format ("%s's finger" , &op->name); |
2451 | tmp->name_pl = format ("%s's fingers", &op->name); |
2496 | tmp->name_pl = format ("%s's fingers", &op->name); |
2452 | tmp->msg = format ( |
2497 | tmp->msg = format ( |
2453 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
2498 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
2454 | &op->name, op->contr->title, |
2499 | &op->name, op->contr->title, |
2455 | (int)op->level, |
2500 | (int)op->level, |
2456 | op->contr->killer_name () |
2501 | op->contr->killer_name () |
2457 | ); |
2502 | ); |
2458 | tmp->value = 0, tmp->type = 0; |
2503 | tmp->value = 0, tmp->type = 0; |
2459 | tmp->materialname = "organics"; |
2504 | tmp->material = name_to_material (shstr_organic); |
2460 | tmp->insert_at (op, tmp); |
2505 | tmp->insert_at (op, tmp); |
2461 | } |
|
|
2462 | |
2506 | |
2463 | /* teleport defeated player to new destination */ |
2507 | /* teleport defeated player to new destination */ |
2464 | transfer_ob (op, x, y, 0, NULL); |
2508 | transfer_ob (op, x, y, 0, NULL); |
2465 | op->contr->braced = 0; |
2509 | op->contr->braced = 0; |
2466 | |
2510 | |
… | |
… | |
2528 | lost_a_stat = 1; |
2572 | lost_a_stat = 1; |
2529 | } |
2573 | } |
2530 | else |
2574 | else |
2531 | { |
2575 | { |
2532 | /* deplete a stat */ |
2576 | /* deplete a stat */ |
2533 | archetype *deparch = archetype::find ("depletion"); |
2577 | archetype *deparch = archetype::find (shstr_depletion); |
2534 | object *dep; |
2578 | object *dep; |
2535 | |
2579 | |
2536 | dep = present_arch_in_ob (deparch, op); |
2580 | dep = present_arch_in_ob (deparch, op); |
2537 | if (!dep) |
2581 | if (!dep) |
2538 | { |
2582 | { |
2539 | dep = arch_to_object (deparch); |
2583 | dep = deparch->instance (); |
2540 | insert_ob_in_ob (dep, op); |
2584 | insert_ob_in_ob (dep, op); |
2541 | } |
2585 | } |
2542 | lose_this_stat = 1; |
2586 | lose_this_stat = 1; |
2543 | if (settings.balanced_stat_loss) |
2587 | if (settings.balanced_stat_loss) |
2544 | { |
2588 | { |
… | |
… | |
2556 | |
2600 | |
2557 | /* There is a maximum depletion total per level. */ |
2601 | /* There is a maximum depletion total per level. */ |
2558 | if (this_stat < -1 - op->level / BALSL_MAX_LOSS_RATIO) |
2602 | if (this_stat < -1 - op->level / BALSL_MAX_LOSS_RATIO) |
2559 | { |
2603 | { |
2560 | lose_this_stat = 0; |
2604 | lose_this_stat = 0; |
2561 | /* Take loss chance vs keep chance to see if we |
2605 | /* Take loss chance vs keep chance to see if we |
2562 | retain the stat. */ |
2606 | retain the stat. */ |
2563 | } |
2607 | } |
2564 | else |
2608 | else |
2565 | { |
2609 | { |
2566 | if (random_roll (0, loss_chance + keep_chance - 1, op, PREFER_LOW) < keep_chance) |
2610 | if (random_roll (0, loss_chance + keep_chance - 1, op, PREFER_LOW) < keep_chance) |
… | |
… | |
2582 | * difference. |
2626 | * difference. |
2583 | */ |
2627 | */ |
2584 | if (this_stat >= -50) |
2628 | if (this_stat >= -50) |
2585 | { |
2629 | { |
2586 | change_attr_value (&(dep->stats), i, -1); |
2630 | change_attr_value (&(dep->stats), i, -1); |
2587 | SET_FLAG (dep, FLAG_APPLIED); |
2631 | dep->set_flag (FLAG_APPLIED); |
2588 | new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]); |
2632 | new_draw_info (NDI_UNIQUE, 0, op, lose_msg[i]); |
2589 | op->update_stats (); |
2633 | op->update_stats (); |
2590 | lost_a_stat = 1; |
2634 | lost_a_stat = 1; |
2591 | } |
2635 | } |
2592 | } |
2636 | } |
… | |
… | |
2610 | #endif |
2654 | #endif |
2611 | |
2655 | |
2612 | /* Put a gravestone up where the character 'almost' died. List the |
2656 | /* Put a gravestone up where the character 'almost' died. List the |
2613 | * exp loss on the stone. |
2657 | * exp loss on the stone. |
2614 | */ |
2658 | */ |
2615 | tmp = arch_to_object (archetype::find ("gravestone")); |
2659 | tmp = archetype::find (shstr_gravestone)->instance (); |
2616 | tmp->name = format ("%s's gravestone", &op->name); |
2660 | tmp->name = format ("%s's gravestone", &op->name); |
2617 | tmp->name_pl = format ("%s's gravestones", &op->name); |
2661 | tmp->name_pl = format ("%s's gravestones", &op->name); |
2618 | tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", |
2662 | tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", |
2619 | &op->name, op->contr->title, op->contr->killer_name ()); |
2663 | &op->name, op->contr->title, op->contr->killer_name ()); |
2620 | tmp->x = op->x, tmp->y = op->y; |
2664 | tmp->x = op->x, tmp->y = op->y; |
… | |
… | |
2659 | if (will_kill_again) |
2703 | if (will_kill_again) |
2660 | { |
2704 | { |
2661 | object *force; |
2705 | object *force; |
2662 | int at; |
2706 | int at; |
2663 | |
2707 | |
2664 | force = get_archetype (FORCE_NAME); |
2708 | force = archetype::get (FORCE_NAME); |
2665 | /* 50 ticks should be enough time for the spell to abate */ |
2709 | /* 50 ticks should be enough time for the spell to abate */ |
2666 | force->speed = 0.1f; |
|
|
2667 | force->speed_left = -5.f; |
2710 | force->speed_left = -5.f; |
2668 | SET_FLAG (force, FLAG_APPLIED); |
2711 | force->set_speed (0.1f); |
|
|
2712 | force->set_flag (FLAG_APPLIED); |
|
|
2713 | |
2669 | for (at = 0; at < NROFATTACKS; at++) |
2714 | for (at = 0; at < NROFATTACKS; at++) |
2670 | if (will_kill_again & (1 << at)) |
2715 | if (will_kill_again & (1 << at)) |
2671 | force->resist[at] = 100; |
2716 | force->resist[at] = 100; |
2672 | |
2717 | |
2673 | insert_ob_in_ob (force, op); |
2718 | insert_ob_in_ob (force, op); |
… | |
… | |
2675 | } |
2720 | } |
2676 | |
2721 | |
2677 | op->contr->infobox (MSG_CHANNEL ("death"), deathtab); |
2722 | op->contr->infobox (MSG_CHANNEL ("death"), deathtab); |
2678 | } |
2723 | } |
2679 | |
2724 | |
2680 | void |
2725 | static void |
2681 | loot_object (object *op) |
2726 | loot_object (object *op) |
2682 | { /* Grab and destroy some treasure */ |
2727 | { /* Grab and destroy some treasure */ |
2683 | object *tmp, *tmp2, *next; |
2728 | object *tmp, *next; |
2684 | |
2729 | |
2685 | op->close_container (); /* close open sack first */ |
2730 | op->close_container (); /* close open sack first */ |
2686 | |
2731 | |
2687 | for (tmp = op->inv; tmp; tmp = next) |
2732 | for (tmp = op->inv; tmp; tmp = next) |
2688 | { |
2733 | { |
… | |
… | |
2695 | tmp->x = op->x, tmp->y = op->y; |
2740 | tmp->x = op->x, tmp->y = op->y; |
2696 | |
2741 | |
2697 | if (tmp->type == CONTAINER) |
2742 | if (tmp->type == CONTAINER) |
2698 | loot_object (tmp); /* empty container to ground */ |
2743 | loot_object (tmp); /* empty container to ground */ |
2699 | |
2744 | |
2700 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) |
2745 | if (!tmp->flag [FLAG_UNIQUE] && (tmp->flag [FLAG_STARTEQUIP] || tmp->flag [FLAG_NO_DROP] || !(rndm (3)))) |
2701 | { |
2746 | { |
2702 | if (tmp->nrof > 1) |
2747 | if (tmp->nrof > 1) |
2703 | { |
2748 | { |
2704 | tmp->decrease (rndm (1, tmp->nrof - 1)); |
2749 | tmp->decrease (rndm (1, tmp->nrof - 1)); |
2705 | insert_ob_in_map (tmp, op->map, NULL, 0); |
2750 | insert_ob_in_map (tmp, op->map, NULL, 0); |
… | |
… | |
2716 | * fix_weight(): Check recursively the weight of all players, and fix |
2761 | * fix_weight(): Check recursively the weight of all players, and fix |
2717 | * what needs to be fixed. Refresh windows and fix speed if anything |
2762 | * what needs to be fixed. Refresh windows and fix speed if anything |
2718 | * was changed. |
2763 | * was changed. |
2719 | */ |
2764 | */ |
2720 | void |
2765 | void |
2721 | fix_weight (void) |
2766 | fix_weight () |
2722 | { |
2767 | { |
2723 | for_all_players (pl) |
2768 | for_all_players (pl) |
2724 | { |
2769 | { |
2725 | sint32 old = pl->ob->carrying; |
2770 | weight_t old = pl->ob->carrying; |
2726 | |
2771 | |
2727 | pl->ob->update_weight (); |
2772 | pl->ob->update_weight (); |
2728 | |
2773 | |
2729 | if (old != pl->ob->carrying) |
2774 | if (old != pl->ob->carrying) |
2730 | { |
2775 | { |
… | |
… | |
2733 | } |
2778 | } |
2734 | } |
2779 | } |
2735 | } |
2780 | } |
2736 | |
2781 | |
2737 | void |
2782 | void |
2738 | fix_luck (void) |
2783 | fix_luck () |
2739 | { |
2784 | { |
2740 | for_all_players (pl) |
2785 | for_all_players (pl) |
2741 | if (!pl->ob->contr->ns->state) |
2786 | if (!pl->ob->contr->ns->state) |
2742 | pl->ob->change_luck (0); |
2787 | pl->ob->change_luck (0); |
2743 | } |
2788 | } |
… | |
… | |
2795 | } |
2840 | } |
2796 | |
2841 | |
2797 | int |
2842 | int |
2798 | is_true_undead (object *op) |
2843 | is_true_undead (object *op) |
2799 | { |
2844 | { |
2800 | if (QUERY_FLAG (op->arch, FLAG_UNDEAD)) |
2845 | if (op->arch->flag [FLAG_UNDEAD]) |
2801 | return 1; |
2846 | return 1; |
2802 | |
2847 | |
2803 | return 0; |
2848 | return 0; |
2804 | } |
2849 | } |
2805 | |
2850 | |
… | |
… | |
2903 | |
2948 | |
2904 | if (who->type == PLAYER) |
2949 | if (who->type == PLAYER) |
2905 | player = 1; |
2950 | player = 1; |
2906 | |
2951 | |
2907 | else |
2952 | else |
2908 | friendly = QUERY_FLAG (who, FLAG_FRIENDLY); |
2953 | friendly = who->flag [FLAG_FRIENDLY]; |
2909 | |
2954 | |
2910 | /* search adjacent squares */ |
2955 | /* search adjacent squares */ |
2911 | for (i = 1; i < 9; i++) |
2956 | for (i = 1; i < 9; i++) |
2912 | { |
2957 | { |
2913 | x = who->x + freearr_x[i]; |
2958 | x = who->x + freearr_x[i]; |
… | |
… | |
2922 | if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y))) |
2967 | if (OB_TYPE_MOVE_BLOCK (who, GET_MAP_MOVE_BLOCK (m, x, y))) |
2923 | continue; |
2968 | continue; |
2924 | |
2969 | |
2925 | for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
2970 | for (tmp = GET_MAP_OB (m, x, y); tmp; tmp = tmp->above) |
2926 | { |
2971 | { |
2927 | if ((player ||friendly) &&QUERY_FLAG (tmp, FLAG_MONSTER) && !QUERY_FLAG (tmp, FLAG_UNAGGRESSIVE)) |
2972 | if ((player ||friendly) &&tmp->flag [FLAG_MONSTER] && !tmp->flag [FLAG_UNAGGRESSIVE]) |
2928 | return 1; |
2973 | return 1; |
2929 | else if (tmp->type == PLAYER) |
2974 | else if (tmp->type == PLAYER) |
2930 | { |
|
|
2931 | /*don't let a hidden DM prevent you from hiding */ |
|
|
2932 | if (!QUERY_FLAG (tmp, FLAG_WIZ) || tmp->contr->hidden == 0) |
|
|
2933 | return 1; |
2975 | return 1; |
2934 | } |
|
|
2935 | } |
2976 | } |
2936 | } |
2977 | } |
2937 | return 0; |
2978 | return 0; |
2938 | } |
2979 | } |
2939 | |
2980 | |
2940 | /* check the player los field for viewability of the |
2981 | /* check the player los field for viewability of the |
2941 | * object op. This function works fine for monsters, |
2982 | * object op. This function works fine for monsters, |
2942 | * but we dont worry if the object isnt the top one in |
2983 | * but we dont worry if the object isnt the top one in |
2943 | * a pile (say a coin under a table would return "viewable" |
2984 | * a pile (say a coin under a table would return "viewable" |
2944 | * by this routine). Another question, should we be |
2985 | * by this routine). Another question, should we be |
2945 | * concerned with the direction the player is looking |
2986 | * concerned with the direction the player is looking |
2946 | * in? Realistically, most of us can't see stuff behind |
2987 | * in? Realistically, most of us can't see stuff behind |
2947 | * our backs...on the other hand, does the "facing" direction |
2988 | * our backs...on the other hand, does the "facing" direction |
2948 | * imply the way your head, or body is facing? It's possible |
2989 | * imply the way your head, or body is facing? It's possible |
2949 | * for them to differ. Sigh, this fctn could get a bit more complex. |
2990 | * for them to differ. Sigh, this fctn could get a bit more complex. |
2950 | * -b.t. |
2991 | * -b.t. |
2951 | * This function is now map tiling safe. |
2992 | * This function is now map tiling safe. |
2952 | */ |
2993 | */ |
2953 | int |
2994 | int |
2954 | player_can_view (object *pl, object *op) |
2995 | player_can_view (object *pl, object *op) |
2955 | { |
2996 | { |
… | |
… | |
2969 | |
3010 | |
2970 | get_rangevector (pl, op, &rv, 0x1); |
3011 | get_rangevector (pl, op, &rv, 0x1); |
2971 | |
3012 | |
2972 | /* starting with the 'head' part, lets loop |
3013 | /* starting with the 'head' part, lets loop |
2973 | * through the object and find if it has any |
3014 | * through the object and find if it has any |
2974 | * part that is in the los array but isn't on |
3015 | * part that is in the los array but isn't on |
2975 | * a blocked los square. |
3016 | * a blocked los square. |
2976 | * we use the archetype to figure out offsets. |
3017 | * we use the archetype to figure out offsets. |
2977 | */ |
3018 | */ |
2978 | while (op) |
3019 | while (op) |
2979 | { |
3020 | { |
… | |
… | |
2982 | |
3023 | |
2983 | if (pl->contr->blocked_los (dx, dy) != LOS_BLOCKED) |
3024 | if (pl->contr->blocked_los (dx, dy) != LOS_BLOCKED) |
2984 | return 1; |
3025 | return 1; |
2985 | |
3026 | |
2986 | op = op->more; |
3027 | op = op->more; |
2987 | } |
|
|
2988 | |
|
|
2989 | return 0; |
|
|
2990 | } |
|
|
2991 | |
|
|
2992 | /* routine for both players and monsters. We call this when |
|
|
2993 | * there is a possibility for our action distrubing our hiding |
|
|
2994 | * place or invisiblity spell. Artefact invisiblity causes |
|
|
2995 | * "noise" instead. If we arent invisible to begin with, we |
|
|
2996 | * return 0. |
|
|
2997 | */ |
|
|
2998 | int |
|
|
2999 | action_makes_visible (object *op) |
|
|
3000 | { |
|
|
3001 | if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) |
|
|
3002 | { |
|
|
3003 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
|
|
3004 | { |
|
|
3005 | // artefact invisibility is permanent, but we still make noise |
|
|
3006 | // this is important for game-balance. |
|
|
3007 | if (op->contr) |
|
|
3008 | op->make_noise (); |
|
|
3009 | |
|
|
3010 | return 0; |
|
|
3011 | } |
|
|
3012 | |
|
|
3013 | if (op->contr && op->contr->tmp_invis == 0) |
|
|
3014 | return 0; |
|
|
3015 | |
|
|
3016 | /* If monsters, they should become visible */ |
|
|
3017 | if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis)) |
|
|
3018 | { |
|
|
3019 | new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible"); |
|
|
3020 | return 1; |
|
|
3021 | } |
|
|
3022 | } |
3028 | } |
3023 | |
3029 | |
3024 | return 0; |
3030 | return 0; |
3025 | } |
3031 | } |
3026 | |
3032 | |
… | |
… | |
3041 | * and the exit-coordinates sp/hp must both be > 0. |
3047 | * and the exit-coordinates sp/hp must both be > 0. |
3042 | * => The intention here is to prevent abuse of the battleground- |
3048 | * => The intention here is to prevent abuse of the battleground- |
3043 | * feature (like pickable or hidden battleground tiles). */ |
3049 | * feature (like pickable or hidden battleground tiles). */ |
3044 | for (object *tmp = op->below; tmp; tmp = tmp->below) |
3050 | for (object *tmp = op->below; tmp; tmp = tmp->below) |
3045 | { |
3051 | { |
3046 | if (QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
3052 | if (tmp->flag [FLAG_IS_FLOOR]) |
3047 | { |
3053 | { |
3048 | if (QUERY_FLAG (tmp, FLAG_NO_PICK) |
3054 | if (tmp->flag [FLAG_NO_PICK] |
3049 | && tmp->type == BATTLEGROUND |
3055 | && tmp->type == BATTLEGROUND |
3050 | && tmp->name == shstr_battleground |
3056 | && tmp->name == shstr_battleground |
3051 | && EXIT_X (tmp) && EXIT_Y (tmp)) |
3057 | && EXIT_X (tmp) && EXIT_Y (tmp)) |
3052 | { |
3058 | { |
3053 | /* before we assign the exit, check if this is a teambattle */ |
3059 | /* before we assign the exit, check if this is a teambattle */ |
3054 | if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) |
3060 | if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) |
3055 | { |
|
|
3056 | for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below) |
3061 | for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below) |
|
|
3062 | if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying) |
3057 | { |
3063 | { |
3058 | if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying) |
|
|
3059 | { |
|
|
3060 | if (x && y) |
3064 | if (x && y) |
3061 | *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); |
3065 | *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); |
3062 | |
3066 | |
3063 | return 1; |
3067 | return 1; |
3064 | } |
|
|
3065 | } |
3068 | } |
3066 | } |
|
|
3067 | |
3069 | |
3068 | if (x && y) |
3070 | if (x && y) |
3069 | *x = EXIT_X (tmp), *y = EXIT_Y (tmp); |
3071 | *x = EXIT_X (tmp), *y = EXIT_Y (tmp); |
3070 | |
3072 | |
3071 | return 1; |
3073 | return 1; |
… | |
… | |
3209 | else |
3211 | else |
3210 | j = 1; |
3212 | j = 1; |
3211 | strcat (buf, spellpathnames[i]); |
3213 | strcat (buf, spellpathnames[i]); |
3212 | } |
3214 | } |
3213 | } |
3215 | } |
|
|
3216 | |
3214 | strcat (buf, "."); |
3217 | strcat (buf, "."); |
3215 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); |
3218 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); |
3216 | } |
3219 | } |
3217 | |
3220 | |
3218 | /* evtl. adding flags: */ |
3221 | /* evtl. adding flags: */ |
3219 | if (QUERY_FLAG (item, FLAG_XRAYS)) |
3222 | if (item->flag [FLAG_XRAYS]) |
3220 | SET_FLAG (skin, FLAG_XRAYS); |
3223 | skin->set_flag (FLAG_XRAYS); |
3221 | if (QUERY_FLAG (item, FLAG_STEALTH)) |
3224 | if (item->flag [FLAG_STEALTH]) |
3222 | SET_FLAG (skin, FLAG_STEALTH); |
3225 | skin->set_flag (FLAG_STEALTH); |
3223 | if (QUERY_FLAG (item, FLAG_SEE_IN_DARK)) |
3226 | if (item->flag [FLAG_SEE_IN_DARK]) |
3224 | SET_FLAG (skin, FLAG_SEE_IN_DARK); |
3227 | skin->set_flag (FLAG_SEE_IN_DARK); |
3225 | |
3228 | |
3226 | /* print message if there is one */ |
3229 | /* print message if there is one */ |
3227 | if (item->msg != NULL) |
3230 | if (item->msg != NULL) |
3228 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); |
3231 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); |
3229 | } |
3232 | } |
3230 | else |
3233 | else |
3231 | { |
3234 | { |
3232 | /* generate misc. treasure */ |
3235 | /* generate misc. treasure */ |
3233 | tmp = arch_to_object (tr->item); |
3236 | tmp = tr->item->instance (); |
3234 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3237 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3235 | who->insert (tmp); |
3238 | who->insert (tmp); |
3236 | } |
3239 | } |
3237 | } |
3240 | } |
3238 | |
3241 | |
3239 | /** |
3242 | //-GPL |
3240 | * Unready an object for a player. This function does nothing if the object was |
|
|
3241 | * not readied. |
|
|
3242 | */ |
|
|
3243 | void |
|
|
3244 | player_unready_range_ob (player *pl, object *ob) |
|
|
3245 | { |
|
|
3246 | if (pl->ob->current_weapon == ob) |
|
|
3247 | pl->ob->current_weapon = 0; |
|
|
3248 | |
|
|
3249 | if (pl->combat_ob == ob) |
|
|
3250 | pl->combat_ob = 0; |
|
|
3251 | |
|
|
3252 | if (pl->ranged_ob == ob) |
|
|
3253 | pl->ranged_ob = 0; |
|
|
3254 | } |
|
|
3255 | |
3243 | |
3256 | sint8 |
3244 | sint8 |
3257 | player::darkness_at (maptile *map, int x, int y) const |
3245 | player::darkness_at (maptile *map, int x, int y) const |
3258 | { |
3246 | { |
3259 | if (!ns) |
3247 | if (!ns) |
… | |
… | |
3286 | { |
3274 | { |
3287 | play_sound (sound_find ("generic_failure")); |
3275 | play_sound (sound_find ("generic_failure")); |
3288 | statusmsg (msg, color); |
3276 | statusmsg (msg, color); |
3289 | } |
3277 | } |
3290 | |
3278 | |
|
|
3279 | void |
|
|
3280 | object::failmsgf (const char *format, ...) |
|
|
3281 | { |
|
|
3282 | if (!contr) |
|
|
3283 | return; |
|
|
3284 | |
|
|
3285 | va_list ap; |
|
|
3286 | va_start (ap, format); |
|
|
3287 | contr->failmsg (vformat (format, ap)); |
|
|
3288 | va_end (ap); |
|
|
3289 | } |
|
|
3290 | |
|
|
3291 | void |
|
|
3292 | player::failmsgf (const char *format, ...) |
|
|
3293 | { |
|
|
3294 | va_list ap; |
|
|
3295 | va_start (ap, format); |
|
|
3296 | failmsg (vformat (format, ap)); |
|
|
3297 | va_end (ap); |
|
|
3298 | } |
|
|
3299 | |