1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 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 |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your 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 GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * and the GNU General Public License along with this program. If not, see |
|
|
20 | * <http://www.gnu.org/licenses/>. |
20 | * |
21 | * |
21 | * 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> |
22 | */ |
23 | */ |
|
|
24 | |
|
|
25 | //+GPL |
23 | |
26 | |
24 | #include <global.h> |
27 | #include <global.h> |
25 | #include <sproto.h> |
28 | #include <sproto.h> |
26 | #include <sounds.h> |
29 | #include <sounds.h> |
27 | #include <living.h> |
30 | #include <living.h> |
… | |
… | |
32 | #include <algorithm> |
35 | #include <algorithm> |
33 | #include <functional> |
36 | #include <functional> |
34 | |
37 | |
35 | playervec players; |
38 | playervec players; |
36 | |
39 | |
37 | void |
|
|
38 | display_motd (const object *op) |
|
|
39 | { |
|
|
40 | char buf[MAX_BUF]; |
|
|
41 | char motd[HUGE_BUF]; |
|
|
42 | FILE *fp; |
|
|
43 | int comp; |
|
|
44 | int size; |
|
|
45 | |
|
|
46 | sprintf (buf, "%s/%s", settings.confdir, settings.motd); |
|
|
47 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
|
|
48 | return; |
|
|
49 | |
|
|
50 | motd[0] = '\0'; |
|
|
51 | size = 0; |
|
|
52 | |
|
|
53 | while (fgets (buf, MAX_BUF, fp)) |
|
|
54 | { |
|
|
55 | if (*buf == '#') |
|
|
56 | continue; |
|
|
57 | |
|
|
58 | strncat (motd + size, buf, HUGE_BUF - size); |
|
|
59 | size += strlen (buf); |
|
|
60 | } |
|
|
61 | |
|
|
62 | draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL); |
|
|
63 | close_and_delete (fp, comp); |
|
|
64 | } |
|
|
65 | |
|
|
66 | void |
|
|
67 | send_rules (const object *op) |
|
|
68 | { |
|
|
69 | char buf[MAX_BUF]; |
|
|
70 | char rules[HUGE_BUF]; |
|
|
71 | FILE *fp; |
|
|
72 | int comp; |
|
|
73 | int size; |
|
|
74 | |
|
|
75 | sprintf (buf, "%s/%s", settings.confdir, settings.rules); |
|
|
76 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
|
|
77 | return; |
|
|
78 | |
|
|
79 | rules[0] = '\0'; |
|
|
80 | size = 0; |
|
|
81 | |
|
|
82 | while (fgets (buf, MAX_BUF, fp)) |
|
|
83 | { |
|
|
84 | if (*buf == '#') |
|
|
85 | continue; |
|
|
86 | |
|
|
87 | if (size + strlen (buf) >= HUGE_BUF) |
|
|
88 | { |
|
|
89 | LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF); |
|
|
90 | break; |
|
|
91 | } |
|
|
92 | |
|
|
93 | strncat (rules + size, buf, HUGE_BUF - size); |
|
|
94 | size += strlen (buf); |
|
|
95 | } |
|
|
96 | |
|
|
97 | draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL); |
|
|
98 | close_and_delete (fp, comp); |
|
|
99 | } |
|
|
100 | |
|
|
101 | void |
|
|
102 | send_news (const object *op) |
|
|
103 | { |
|
|
104 | char buf[MAX_BUF]; |
|
|
105 | char news[HUGE_BUF]; |
|
|
106 | char subject[MAX_BUF]; |
|
|
107 | FILE *fp; |
|
|
108 | int comp; |
|
|
109 | int size; |
|
|
110 | |
|
|
111 | sprintf (buf, "%s/%s", settings.confdir, settings.news); |
|
|
112 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
|
|
113 | return; |
|
|
114 | |
|
|
115 | news[0] = '\0'; |
|
|
116 | subject[0] = '\0'; |
|
|
117 | size = 0; |
|
|
118 | |
|
|
119 | while (fgets (buf, MAX_BUF, fp)) |
|
|
120 | { |
|
|
121 | if (*buf == '#') |
|
|
122 | continue; |
|
|
123 | |
|
|
124 | if (*buf == '%') |
|
|
125 | { /* send one news */ |
|
|
126 | if (size > 0) |
|
|
127 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, |
|
|
128 | MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, |
|
|
129 | "INFORMATION: %s\n%s", (char *)"%s\n%s", |
|
|
130 | subject, news); /*send previously read news */ |
|
|
131 | |
|
|
132 | strcpy (subject, buf + 1); |
|
|
133 | strip_endline (subject); |
|
|
134 | size = 0; |
|
|
135 | news[0] = '\0'; |
|
|
136 | } |
|
|
137 | else |
|
|
138 | { |
|
|
139 | if (size + strlen (buf) >= HUGE_BUF) |
|
|
140 | { |
|
|
141 | LOG (llevDebug, "Warning, one news item has size > %d bytes.\n", HUGE_BUF); |
|
|
142 | break; |
|
|
143 | } |
|
|
144 | strncat (news + size, buf, HUGE_BUF - size); |
|
|
145 | size += strlen (buf); |
|
|
146 | } |
|
|
147 | } |
|
|
148 | |
|
|
149 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, |
|
|
150 | MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s\n", (char *)"%s\n%s", subject, news); |
|
|
151 | close_and_delete (fp, comp); |
|
|
152 | } |
|
|
153 | |
|
|
154 | /* This loads the first map an puts the player on it. */ |
40 | /* This loads the first map an puts the player on it. */ |
155 | static void |
41 | static void |
156 | set_first_map (object *op) |
42 | set_first_map (object *op) |
157 | { |
43 | { |
158 | op->contr->maplevel = first_map_path; |
44 | op->contr->maplevel = first_map_path; |
… | |
… | |
190 | ob->remove (); |
76 | ob->remove (); |
191 | ob->enemy = 0; // sometimes keeps an extra refcount on itself |
77 | ob->enemy = 0; // sometimes keeps an extra refcount on itself |
192 | ob->map = 0; |
78 | ob->map = 0; |
193 | party = 0; |
79 | party = 0; |
194 | |
80 | |
195 | combat_ob = ranged_ob = 0; //TODO, should be special marker, non-refcounted, not this |
|
|
196 | |
|
|
197 | players.erase (this); |
81 | players.erase (this); |
198 | } |
82 | } |
199 | |
83 | |
200 | // connect the player with a specific client |
84 | // connect the player with a specific client |
201 | // also changes, rationalises, and fixes some incorrect settings |
85 | // also changes, rationalises, and fixes some incorrect settings |
… | |
… | |
221 | ob->race = ob->arch->race; |
105 | ob->race = ob->arch->race; |
222 | |
106 | |
223 | ob->update_weight (); |
107 | ob->update_weight (); |
224 | link_skills (); |
108 | link_skills (); |
225 | |
109 | |
226 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
|
|
227 | |
|
|
228 | assign (title, ob->arch->object::name); |
110 | assign (title, ob->arch->object::name); |
229 | |
111 | |
230 | /* if it's a dragon player, set the correct title here */ |
112 | /* if it's a dragon player, set the correct title here */ |
231 | if (is_dragon_pl (ob)) |
113 | if (ob->is_dragon ()) |
232 | { |
114 | { |
233 | object *tmp, *abil = 0, *skin = 0; |
115 | object *tmp, *abil = 0, *skin = 0; |
234 | |
116 | |
235 | for (tmp = ob->inv; tmp; tmp = tmp->below) |
117 | for (tmp = ob->inv; tmp; tmp = tmp->below) |
236 | if (tmp->type == FORCE) |
118 | if (tmp->type == FORCE) |
… | |
… | |
250 | |
132 | |
251 | ns->floorbox_update (); |
133 | ns->floorbox_update (); |
252 | esrv_send_inventory (ob, ob); |
134 | esrv_send_inventory (ob, ob); |
253 | esrv_add_spells (this, 0); |
135 | esrv_add_spells (this, 0); |
254 | |
136 | |
|
|
137 | ob->flag [FLAG_READY_WEAPON] = false; |
|
|
138 | ob->flag [FLAG_READY_SKILL] = false; |
|
|
139 | ob->flag [FLAG_READY_RANGE] = false; |
|
|
140 | ob->flag [FLAG_READY_BOW] = false; |
|
|
141 | |
|
|
142 | ob->update_stats (); // we unapplied stuff above |
255 | activate (); |
143 | activate (); |
256 | |
|
|
257 | send_rules (ob); |
|
|
258 | send_news (ob); |
|
|
259 | display_motd (ob); |
|
|
260 | |
144 | |
261 | INVOKE_PLAYER (CONNECT, this); |
145 | INVOKE_PLAYER (CONNECT, this); |
262 | INVOKE_PLAYER (LOGIN, this); |
146 | INVOKE_PLAYER (LOGIN, this); |
263 | } |
147 | } |
264 | |
148 | |
… | |
… | |
281 | ns->reset_stats (); |
165 | ns->reset_stats (); |
282 | ns->pl = 0; |
166 | ns->pl = 0; |
283 | ns = 0; |
167 | ns = 0; |
284 | } |
168 | } |
285 | |
169 | |
286 | observe = ob; |
170 | // this is important for the player scheduler to get the correct refcount |
|
|
171 | // when ns = 0 |
|
|
172 | observe = viewpoint = ob; |
287 | |
173 | |
288 | deactivate (); |
174 | deactivate (); |
289 | } |
175 | } |
|
|
176 | |
|
|
177 | //-GPL |
290 | |
178 | |
291 | // the need for this function can be explained |
179 | // the need for this function can be explained |
292 | // by load_object not returning the object |
180 | // by load_object not returning the object |
293 | void |
181 | void |
294 | player::set_object (object *op) |
182 | player::set_object (object *op) |
295 | { |
183 | { |
296 | ob = observe = op; |
184 | ob = observe = viewpoint = op; |
297 | ob->contr = this; /* this aren't yet in archetype */ |
185 | ob->contr = this; /* this aren't yet in archetype */ |
298 | |
186 | |
299 | ob->speed = 1.0f; |
187 | ob->speed = 1.0f; |
300 | ob->speed_left = 0.5f; |
188 | ob->speed_left = 0.5f; |
301 | |
189 | |
302 | ob->direction = 5; /* So player faces south */ |
190 | ob->direction = 5; /* So player faces south */ |
303 | |
|
|
304 | ob->flag [FLAG_READY_WEAPON] = false; |
|
|
305 | ob->flag [FLAG_READY_SKILL] = false; |
|
|
306 | ob->flag [FLAG_READY_BOW] = false; |
|
|
307 | |
|
|
308 | for (object *op = ob->inv; op; op = op->below) |
|
|
309 | if (op->flag [FLAG_APPLIED]) |
|
|
310 | switch (op->type) |
|
|
311 | { |
|
|
312 | case SKILL: |
|
|
313 | ob->flag [FLAG_APPLIED] = false; |
|
|
314 | break; |
|
|
315 | |
|
|
316 | case WAND: |
|
|
317 | case ROD: |
|
|
318 | case HORN: |
|
|
319 | case BOW: |
|
|
320 | ranged_ob = op; |
|
|
321 | break; |
|
|
322 | |
|
|
323 | case WEAPON: |
|
|
324 | combat_ob = op; |
|
|
325 | break; |
|
|
326 | } |
|
|
327 | |
|
|
328 | ob->change_weapon (combat_ob ? combat_ob : ranged_ob); |
|
|
329 | ob->deactivate (); // change_weapon activates, fix this better |
|
|
330 | } |
191 | } |
331 | |
192 | |
332 | void |
193 | void |
333 | player::set_observe (object *op) |
194 | player::set_observe (object *op) |
334 | { |
195 | { |
335 | observe = op ? op : ob; |
196 | observe = viewpoint = op ? op : ob; |
336 | do_los = 1; |
197 | do_los = 1; |
337 | } |
198 | } |
|
|
199 | |
|
|
200 | void |
|
|
201 | player::set_viewpoint (object *op) |
|
|
202 | { |
|
|
203 | viewpoint = op ? op : (object *)observe; |
|
|
204 | do_los = 1; |
|
|
205 | } |
|
|
206 | |
|
|
207 | //+GPL |
338 | |
208 | |
339 | player::player () |
209 | player::player () |
340 | { |
210 | { |
341 | /* There are some elements we want initialised to non zero value - |
211 | /* There are some elements we want initialised to non zero value - |
342 | * we deal with that below this point. |
212 | * we deal with that below this point. |
… | |
… | |
364 | disconnect (); |
234 | disconnect (); |
365 | |
235 | |
366 | attachable::do_destroy (); |
236 | attachable::do_destroy (); |
367 | |
237 | |
368 | if (ob) |
238 | if (ob) |
369 | { |
|
|
370 | ob->destroy_inv (false); |
|
|
371 | ob->destroy (); |
239 | ob->destroy (); |
372 | } |
|
|
373 | |
240 | |
374 | ob = observe = 0; |
241 | ob = observe = viewpoint = 0; |
375 | } |
242 | } |
376 | |
243 | |
377 | player::~player () |
244 | player::~player () |
378 | { |
245 | { |
379 | /* Clear item stack */ |
246 | /* Clear item stack */ |
380 | free (stack_items); |
247 | free (stack_items); |
|
|
248 | } |
|
|
249 | |
|
|
250 | /* |
|
|
251 | * get_player_archetype() return next player archetype from archetype |
|
|
252 | * list. Not very efficient routine, but used only creating new players. |
|
|
253 | * Note: there MUST be at least one player archetype! |
|
|
254 | */ |
|
|
255 | static archetype * |
|
|
256 | get_player_archetype (archetype *at) |
|
|
257 | { |
|
|
258 | // archetypes could have been reloaded |
|
|
259 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
260 | |
|
|
261 | if (!nat) |
|
|
262 | return at; |
|
|
263 | |
|
|
264 | archvec::iterator i = archetypes.find (nat); |
|
|
265 | |
|
|
266 | for (;;) |
|
|
267 | { |
|
|
268 | if (++i == archetypes.end ()) |
|
|
269 | i = archetypes.begin (); |
|
|
270 | else if (*i == at) |
|
|
271 | cleanup ("not a single player archetype found"); |
|
|
272 | |
|
|
273 | if ((*i)->type == PLAYER) |
|
|
274 | return *i; |
|
|
275 | } |
381 | } |
276 | } |
382 | |
277 | |
383 | /* Tries to add player on the connection passed in ns. |
278 | /* Tries to add player on the connection passed in ns. |
384 | * All we can really get in this is some settings like host and display |
279 | * All we can really get in this is some settings like host and display |
385 | * mode. |
280 | * mode. |
… | |
… | |
387 | player * |
282 | player * |
388 | player::create () |
283 | player::create () |
389 | { |
284 | { |
390 | player *pl = new player; |
285 | player *pl = new player; |
391 | |
286 | |
392 | pl->set_object (arch_to_object (get_player_archetype (0))); |
287 | pl->set_object (get_player_archetype (0)->instance ()); |
393 | |
288 | |
394 | pl->ob->roll_stats (); |
289 | pl->ob->roll_stats (); |
395 | pl->ob->stats.wc = 2; |
290 | pl->ob->stats.wc = 2; |
396 | pl->ob->run_away = 25; /* Then we panick... */ |
291 | pl->ob->run_away = 25; /* Then we panick... */ |
397 | |
292 | |
398 | set_first_map (pl->ob); |
293 | set_first_map (pl->ob); |
399 | |
294 | |
400 | return pl; |
295 | return pl; |
401 | } |
|
|
402 | |
|
|
403 | /* |
|
|
404 | * get_player_archetype() return next player archetype from archetype |
|
|
405 | * list. Not very efficient routine, but used only creating new players. |
|
|
406 | * Note: there MUST be at least one player archetype! |
|
|
407 | */ |
|
|
408 | archetype * |
|
|
409 | get_player_archetype (archetype *at) |
|
|
410 | { |
|
|
411 | // archetypes could have been reloaded |
|
|
412 | archetype *nat = at ? archetype::find (at->archname) : archetypes [0]; |
|
|
413 | |
|
|
414 | if (!nat) |
|
|
415 | return at; |
|
|
416 | |
|
|
417 | archvec::iterator i = archetypes.find (nat); |
|
|
418 | |
|
|
419 | for (;;) |
|
|
420 | { |
|
|
421 | if (++i == archetypes.end ()) |
|
|
422 | i = archetypes.begin (); |
|
|
423 | else if (*i == at) |
|
|
424 | cleanup ("not a single player archetype found"); |
|
|
425 | |
|
|
426 | if ((*i)->type == PLAYER) |
|
|
427 | return *i; |
|
|
428 | } |
|
|
429 | } |
296 | } |
430 | |
297 | |
431 | object * |
298 | object * |
432 | get_nearest_player (object *mon) |
299 | get_nearest_player (object *mon) |
433 | { |
300 | { |
… | |
… | |
742 | send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
609 | send_query (op->contr->ns, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
743 | } |
610 | } |
744 | |
611 | |
745 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
612 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
746 | static int |
613 | static int |
747 | roll_stat (void) |
614 | roll_stat () |
748 | { |
615 | { |
749 | int a[4], i, j, k; |
616 | int a[4], i, j, k; |
750 | |
617 | |
751 | for (i = 0; i < 4; i++) |
618 | for (i = 0; i < 4; i++) |
752 | a[i] = (int) rndm (6) + 1; |
619 | a[i] = (int) rndm (6) + 1; |
… | |
… | |
849 | player::chargen_race_done () |
716 | player::chargen_race_done () |
850 | { |
717 | { |
851 | /* this must before then initial items are given */ |
718 | /* this must before then initial items are given */ |
852 | esrv_new_player (ob->contr); |
719 | esrv_new_player (ob->contr); |
853 | |
720 | |
854 | treasurelist *tl = treasurelist::find ("starting_wealth"); |
721 | treasurelist *tl = treasurelist::find (shstr_starting_wealth); |
855 | if (tl) |
722 | if (tl) |
856 | create_treasure (tl, ob, 0, 0, 0); |
723 | create_treasure (tl, ob, 0, 0, 0); |
857 | |
724 | |
858 | INVOKE_PLAYER (BIRTH, ob->contr); |
725 | INVOKE_PLAYER (BIRTH, ob->contr); |
859 | INVOKE_PLAYER (LOGIN, ob->contr); |
726 | INVOKE_PLAYER (LOGIN, ob->contr); |
… | |
… | |
912 | ob->stats.hp = ob->stats.maxhp; |
779 | ob->stats.hp = ob->stats.maxhp; |
913 | ob->stats.sp = ob->stats.maxsp; |
780 | ob->stats.sp = ob->stats.maxsp; |
914 | ob->stats.grace = 0; |
781 | ob->stats.grace = 0; |
915 | } |
782 | } |
916 | |
783 | |
917 | void |
784 | static void |
918 | flee_player (object *op) |
785 | flee_player (object *op) |
919 | { |
786 | { |
920 | int dir, diff; |
787 | int dir, diff; |
921 | rv_vector rv; |
788 | rv_vector rv; |
922 | |
789 | |
… | |
… | |
946 | dir = absdir (4 + rv.direction); |
813 | dir = absdir (4 + rv.direction); |
947 | for (diff = 0; diff < 3; diff++) |
814 | for (diff = 0; diff < 3; diff++) |
948 | { |
815 | { |
949 | int m = 1 - rndm (2) * 2; |
816 | int m = 1 - rndm (2) * 2; |
950 | |
817 | |
951 | if (move_ob (op, absdir (dir + diff * m), op) || (diff == 0 && move_ob (op, absdir (dir - diff * m), op))) |
818 | if (op->move (absdir (dir + diff * m)) || (diff == 0 && op->move (absdir (dir - diff * m)))) |
952 | return; |
819 | return; |
953 | } |
820 | } |
954 | |
821 | |
955 | /* Cornered, get rid of scared */ |
822 | /* Cornered, get rid of scared */ |
956 | CLEAR_FLAG (op, FLAG_SCARED); |
823 | CLEAR_FLAG (op, FLAG_SCARED); |
… | |
… | |
966 | { |
833 | { |
967 | object *tmp, *next; |
834 | object *tmp, *next; |
968 | int stop = 0; |
835 | int stop = 0; |
969 | int wvratio; |
836 | int wvratio; |
970 | |
837 | |
971 | /* if you're flying, you cna't pick up anything */ |
838 | /* if you're flying, you can't pick up anything */ |
972 | if (op->move_type & MOVE_FLYING) |
839 | if (op->move_type & MOVE_FLYING) |
973 | return 1; |
840 | return 1; |
974 | |
841 | |
975 | next = op->below; |
842 | next = op->below; |
976 | |
843 | |
977 | int cnt = MAX_ITEM_PER_DROP; |
844 | int cnt = MAX_ITEM_PER_ACTION; |
978 | #define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0) |
845 | #define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0) |
979 | |
846 | |
980 | /* loop while there are items on the floor that are not marked as |
847 | /* loop while there are items on the floor that are not marked as |
981 | * destroyed */ |
848 | * destroyed */ |
982 | while (next && !next->destroyed ()) |
849 | while (next && !next->destroyed ()) |
… | |
… | |
1008 | if (op->contr->mode & PU_DEBUG) |
875 | if (op->contr->mode & PU_DEBUG) |
1009 | { |
876 | { |
1010 | /* some debugging code to figure out item information */ |
877 | /* some debugging code to figure out item information */ |
1011 | const char *str = tmp->name |
878 | const char *str = tmp->name |
1012 | ? format ("item name: %s item type: %d weight/value: %d", |
879 | ? format ("item name: %s item type: %d weight/value: %d", |
1013 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))) |
880 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))) |
1014 | : format ("item name: %s item type: %d weight/value: %d", |
881 | : format ("item name: %s item type: %d weight/value: %d", |
1015 | &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
882 | &tmp->arch->archname, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))); |
1016 | |
883 | |
1017 | new_draw_info (NDI_UNIQUE, 0, op, str); |
884 | new_draw_info (NDI_UNIQUE, 0, op, str); |
1018 | } |
885 | } |
1019 | |
886 | |
1020 | if (op->contr->mode & PU_INHIBIT) |
887 | if (op->contr->mode & PU_INHIBIT) |
… | |
… | |
1107 | continue; |
974 | continue; |
1108 | } |
975 | } |
1109 | |
976 | |
1110 | /* wands/staves/rods/horns */ |
977 | /* wands/staves/rods/horns */ |
1111 | if (op->contr->mode & PU_MAGIC_DEVICE) |
978 | if (op->contr->mode & PU_MAGIC_DEVICE) |
1112 | if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) |
979 | if (tmp->type == WAND |
|
|
980 | || tmp->type == ROD |
|
|
981 | || tmp->type == HORN |
|
|
982 | || tmp->type == POWER_CRYSTAL) |
1113 | { |
983 | { |
1114 | CHK_PICK_PICKUP; |
984 | CHK_PICK_PICKUP; |
1115 | continue; |
985 | continue; |
1116 | } |
986 | } |
1117 | |
987 | |
1118 | /* pick up all magical items */ |
988 | /* pick up all magical items */ |
1119 | if (op->contr->mode & PU_MAGICAL) |
989 | if (op->contr->mode & PU_MAGICAL) |
1120 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
990 | if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) |
|
|
991 | && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) |
1121 | { |
992 | { |
1122 | CHK_PICK_PICKUP; |
993 | CHK_PICK_PICKUP; |
1123 | continue; |
994 | continue; |
1124 | } |
995 | } |
1125 | |
996 | |
… | |
… | |
1132 | } |
1003 | } |
1133 | } |
1004 | } |
1134 | |
1005 | |
1135 | /* rings & amulets - talismans seems to be typed AMULET */ |
1006 | /* rings & amulets - talismans seems to be typed AMULET */ |
1136 | if (op->contr->mode & PU_JEWELS) |
1007 | if (op->contr->mode & PU_JEWELS) |
1137 | if (tmp->type == RING || tmp->type == AMULET) |
1008 | if (tmp->type == RING |
|
|
1009 | || tmp->type == AMULET |
|
|
1010 | || tmp->type == GIRDLE |
|
|
1011 | || tmp->type == SKILL_TOOL) |
1138 | { |
1012 | { |
1139 | CHK_PICK_PICKUP; |
1013 | CHK_PICK_PICKUP; |
1140 | continue; |
1014 | continue; |
1141 | } |
1015 | } |
1142 | |
1016 | |
… | |
… | |
1191 | CHK_PICK_PICKUP; |
1065 | CHK_PICK_PICKUP; |
1192 | continue; |
1066 | continue; |
1193 | } |
1067 | } |
1194 | |
1068 | |
1195 | if (op->contr->mode & PU_GLOVES) |
1069 | if (op->contr->mode & PU_GLOVES) |
1196 | if (tmp->type == GLOVES) |
1070 | if (tmp->type == GLOVES || tmp->type == BRACERS) |
1197 | { |
1071 | { |
1198 | CHK_PICK_PICKUP; |
1072 | CHK_PICK_PICKUP; |
1199 | continue; |
1073 | continue; |
1200 | } |
1074 | } |
1201 | |
1075 | |
… | |
… | |
1251 | fprintf (stderr, "%s", tmp->name); |
1125 | fprintf (stderr, "%s", tmp->name); |
1252 | } |
1126 | } |
1253 | else |
1127 | else |
1254 | fprintf (stderr, "%s", tmp->arch->archname); |
1128 | fprintf (stderr, "%s", tmp->arch->archname); |
1255 | fprintf (stderr, ",%d] = ", tmp->type); |
1129 | fprintf (stderr, ",%d] = ", tmp->type); |
1256 | fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1130 | fprintf (stderr, "%d\n", (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * max (tmp->nrof, 1)))); |
1257 | #endif |
1131 | #endif |
1258 | CHK_PICK_PICKUP; |
1132 | CHK_PICK_PICKUP; |
1259 | continue; |
1133 | continue; |
1260 | } |
1134 | } |
1261 | } /* the new pickup model */ |
1135 | } /* the new pickup model */ |
1262 | } |
1136 | } |
1263 | |
1137 | |
1264 | return !stop; |
1138 | return !stop; |
1265 | } |
1139 | } |
1266 | |
1140 | |
|
|
1141 | /* routine for both players and monsters. We call this when |
|
|
1142 | * there is a possibility for our action distrubing our hiding |
|
|
1143 | * place or invisiblity spell. Artefact invisiblity causes |
|
|
1144 | * "noise" instead. If we arent invisible to begin with, we |
|
|
1145 | * return 0. |
|
|
1146 | */ |
|
|
1147 | static int |
|
|
1148 | action_makes_visible (object *op) |
|
|
1149 | { |
|
|
1150 | if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) |
|
|
1151 | { |
|
|
1152 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
|
|
1153 | { |
|
|
1154 | // artefact invisibility is permanent, but we still make noise |
|
|
1155 | // this is important for game-balance. |
|
|
1156 | if (op->contr) |
|
|
1157 | op->make_noise (); |
|
|
1158 | |
|
|
1159 | return 0; |
|
|
1160 | } |
|
|
1161 | |
|
|
1162 | if (op->contr && op->contr->tmp_invis == 0) |
|
|
1163 | return 0; |
|
|
1164 | |
|
|
1165 | /* If monsters, they should become visible */ |
|
|
1166 | if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis)) |
|
|
1167 | { |
|
|
1168 | new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible"); |
|
|
1169 | return 1; |
|
|
1170 | } |
|
|
1171 | } |
|
|
1172 | |
|
|
1173 | return 0; |
|
|
1174 | } |
|
|
1175 | |
1267 | /* |
1176 | /* |
1268 | * Find an arrow in the inventory and after that |
1177 | * Find an arrow in the inventory and after that |
1269 | * in the right type container (quiver). Pointer to the |
1178 | * in the right type container (quiver). Pointer to the |
1270 | * found object is returned. |
1179 | * found object is returned. |
1271 | */ |
1180 | */ |
1272 | object * |
1181 | static object * |
1273 | find_arrow (object *op, const char *type) |
1182 | find_arrow (object *op, const char *type) |
1274 | { |
1183 | { |
1275 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1184 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1276 | if (tmp->type == ARROW && !strcmp (&tmp->race, type)) |
1185 | if (tmp->type == ARROW && !strcmp (&tmp->race, type)) |
1277 | return splay (tmp); |
1186 | return splay (tmp); |
… | |
… | |
1291 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1200 | * Similar to find_arrow, but looks for (roughly) the best arrow to use |
1292 | * against the target. A full test is not performed, simply a basic test |
1201 | * against the target. A full test is not performed, simply a basic test |
1293 | * of resistances. The archer is making a quick guess at what he sees down |
1202 | * of resistances. The archer is making a quick guess at what he sees down |
1294 | * the hall. Failing that it does it's best to pick the highest plus arrow. |
1203 | * the hall. Failing that it does it's best to pick the highest plus arrow. |
1295 | */ |
1204 | */ |
1296 | object * |
1205 | static object * |
1297 | find_better_arrow (object *op, object *target, shstr_cmp type, int *better) |
1206 | find_better_arrow (object *op, object *target, shstr_cmp type, int *better) |
1298 | { |
1207 | { |
1299 | object *tmp = NULL, *arrow, *ntmp; |
1208 | object *tmp = NULL, *arrow, *ntmp; |
1300 | int attacknum, attacktype, betterby = 0, i; |
1209 | int attacknum, attacktype, betterby = 0, i; |
1301 | |
1210 | |
… | |
… | |
1370 | * find_better_arrow to find a decent arrow to use. |
1279 | * find_better_arrow to find a decent arrow to use. |
1371 | * op = the shooter |
1280 | * op = the shooter |
1372 | * type = bow->race |
1281 | * type = bow->race |
1373 | * dir = fire direction |
1282 | * dir = fire direction |
1374 | */ |
1283 | */ |
1375 | object * |
1284 | static object * |
1376 | pick_arrow_target (object *op, shstr_cmp type, int dir) |
1285 | pick_arrow_target (object *op, shstr_cmp type, int dir) |
1377 | { |
1286 | { |
1378 | object *tmp = NULL; |
1287 | object *tmp = NULL; |
1379 | maptile *m; |
1288 | maptile *m; |
1380 | int i, mflags, found, number; |
1289 | int i, mflags, found, number; |
… | |
… | |
1595 | * but monsters can't. Putting that code here |
1504 | * but monsters can't. Putting that code here |
1596 | * makes the fire_bow code much cleaner. |
1505 | * makes the fire_bow code much cleaner. |
1597 | * this function should only be called if 'op' is a player, |
1506 | * this function should only be called if 'op' is a player, |
1598 | * hence the function name. |
1507 | * hence the function name. |
1599 | */ |
1508 | */ |
1600 | int |
1509 | static int |
1601 | player_fire_bow (object *op, int dir) |
1510 | player_fire_bow (object *op, int dir) |
1602 | { |
1511 | { |
1603 | int ret; |
1512 | int ret; |
1604 | |
1513 | |
1605 | if (op->contr->bowtype == bow_bestarrow) |
1514 | if (op->contr->bowtype == bow_bestarrow) |
… | |
… | |
1633 | } |
1542 | } |
1634 | |
1543 | |
1635 | /* Fires a misc (wand/rod/horn) object in 'dir'. |
1544 | /* Fires a misc (wand/rod/horn) object in 'dir'. |
1636 | * Broken apart from 'fire' to keep it more readable. |
1545 | * Broken apart from 'fire' to keep it more readable. |
1637 | */ |
1546 | */ |
1638 | void |
1547 | static void |
1639 | fire_misc_object (object *op, int dir) |
1548 | fire_misc_object (object *op, int dir) |
1640 | { |
1549 | { |
1641 | object *item = op->contr->ranged_ob; |
1550 | object *item = op->contr->ranged_ob; |
1642 | |
1551 | |
1643 | if (!item) |
1552 | if (!item) |
… | |
… | |
1650 | { |
1559 | { |
1651 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1560 | LOG (llevError, "Object %s lacks a spell\n", &item->name); |
1652 | return; |
1561 | return; |
1653 | } |
1562 | } |
1654 | |
1563 | |
1655 | if (!op->change_weapon (item)) |
1564 | if (!op->apply (item)) |
1656 | return; |
1565 | return; |
1657 | |
1566 | |
1658 | if (item->type == WAND) |
1567 | if (item->type == WAND) |
1659 | { |
1568 | { |
1660 | if (item->stats.food <= 0) |
1569 | if (item->stats.food <= 0) |
… | |
… | |
1665 | return; |
1574 | return; |
1666 | } |
1575 | } |
1667 | } |
1576 | } |
1668 | else if (item->type == ROD || item->type == HORN) |
1577 | else if (item->type == ROD || item->type == HORN) |
1669 | { |
1578 | { |
1670 | sint16 spell_sp = MAX (item->inv->stats.sp, item->inv->stats.grace); |
1579 | sint16 spell_sp = max (item->inv->stats.sp, item->inv->stats.grace); |
1671 | |
1580 | |
1672 | // using the maximum of the rods charge allows at least one spell cast |
1581 | // using the maximum of the rods charge allows at least one spell cast |
1673 | // for a rod or horn, this fixes some broken rods. |
1582 | // for a rod or horn, this fixes some broken rods. |
1674 | if (item->stats.hp < MIN (spell_sp, item->stats.maxhp)) |
1583 | if (item->stats.hp < min (spell_sp, item->stats.maxhp)) |
1675 | { |
1584 | { |
1676 | op->contr->play_sound (sound_find ("wand_poof")); |
1585 | op->contr->play_sound (sound_find ("wand_poof")); |
1677 | |
1586 | |
1678 | if (item->type == ROD) |
1587 | if (item->type == ROD) |
1679 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
1588 | new_draw_info_format (NDI_UNIQUE, 0, op, "The %s whines for a while, but nothing happens.", query_base_name (item, 0)); |
… | |
… | |
1711 | } |
1620 | } |
1712 | |
1621 | |
1713 | /* Received a fire command for the player - go and do it. |
1622 | /* Received a fire command for the player - go and do it. |
1714 | */ |
1623 | */ |
1715 | bool |
1624 | bool |
1716 | fire (object *op, int dir) |
1625 | fire (object *who, int dir) |
1717 | { |
1626 | { |
1718 | int spellcost = 0; |
1627 | int spellcost = 0; |
1719 | |
1628 | |
1720 | player *pl = op->contr; |
1629 | player *pl = who->contr; |
1721 | |
1630 | |
1722 | if (pl->golem) |
1631 | if (pl->golem) |
1723 | { |
1632 | { |
1724 | control_golem (op->contr->golem, dir); |
1633 | control_golem (who->contr->golem, dir); |
1725 | return false; |
1634 | return false; |
1726 | } |
1635 | } |
1727 | |
1636 | |
1728 | object *ob = pl->ranged_ob; |
1637 | object *ob = pl->ranged_ob; |
1729 | |
1638 | |
1730 | if (!ob) |
1639 | if (!ob) |
1731 | return false; |
1640 | return false; |
1732 | |
1641 | |
1733 | if (op->speed_left > 0.f) |
1642 | if (who->speed_left > 0.f) |
1734 | --op->speed_left; |
1643 | --who->speed_left; |
1735 | else |
1644 | else |
1736 | return false; |
1645 | return false; |
1737 | |
1646 | |
1738 | if (!op->change_weapon (ob)) |
1647 | if (!who->apply (ob)) |
1739 | return false; |
1648 | return false; |
1740 | |
1649 | |
1741 | /* check for loss of invisiblity/hide */ |
1650 | /* check for loss of invisiblity/hide */ |
1742 | if (action_makes_visible (op)) |
1651 | if (action_makes_visible (who)) |
1743 | make_visible (op); |
1652 | make_visible (who); |
1744 | |
1653 | |
1745 | switch (ob->type) |
1654 | switch (ob->type) |
1746 | { |
1655 | { |
1747 | case BOW: |
1656 | case BOW: |
1748 | player_fire_bow (op, dir); |
1657 | player_fire_bow (who, dir); |
1749 | break; |
1658 | break; |
1750 | |
1659 | |
1751 | case SPELL: |
1660 | case SPELL: |
1752 | spellcost = cast_spell (op, op, dir, ob, *pl->spellparam ? pl->spellparam : 0); |
1661 | spellcost = cast_spell (who, who, dir, ob, *pl->spellparam ? pl->spellparam : 0); |
1753 | break; |
1662 | break; |
1754 | |
1663 | |
1755 | case BUILDER: |
1664 | case BUILDER: |
1756 | apply_map_builder (op, dir); |
1665 | apply_map_builder (who, dir); |
1757 | break; |
1666 | break; |
1758 | |
1667 | |
1759 | case SKILL: |
1668 | case SKILL: |
1760 | do_skill (op, op, ob, dir, 0); |
1669 | do_skill (who, who, ob, dir, 0); |
1761 | break; |
1670 | break; |
1762 | |
1671 | |
|
|
1672 | case RANGED: |
|
|
1673 | do_skill (who, ob, who->chosen_skill, dir, 0); |
|
|
1674 | break; |
|
|
1675 | |
1763 | default: |
1676 | default: |
1764 | fire_misc_object (op, dir); |
1677 | fire_misc_object (who, dir); |
1765 | break; |
1678 | break; |
1766 | } |
1679 | } |
1767 | |
1680 | |
1768 | return true; |
1681 | return true; |
1769 | } |
1682 | } |
1770 | |
1683 | |
1771 | /* find_key |
1684 | static object * |
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) |
1685 | find_key_ (object *pl, object *container, object *door) |
1783 | { |
1686 | { |
1784 | object *tmp, *key; |
1687 | object *tmp, *key; |
1785 | |
1688 | |
1786 | /* Should not happen, but sanity checking is never bad */ |
1689 | /* Should not happen, but sanity checking is never bad */ |
1787 | if (!container->inv) |
1690 | if (!container->inv) |
… | |
… | |
1808 | if (!tmp) |
1711 | if (!tmp) |
1809 | { |
1712 | { |
1810 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1713 | for (tmp = container->inv; tmp; tmp = tmp->below) |
1811 | /* No reason to search empty containers */ |
1714 | /* No reason to search empty containers */ |
1812 | if (tmp->type == CONTAINER && tmp->inv) |
1715 | if (tmp->type == CONTAINER && tmp->inv) |
1813 | if ((key = find_key (pl, tmp, door))) |
1716 | if ((key = find_key_ (pl, tmp, door))) |
1814 | return key; |
1717 | return key; |
1815 | |
1718 | |
1816 | if (!tmp) |
1719 | if (!tmp) |
1817 | return 0; |
1720 | return 0; |
1818 | } |
1721 | } |
… | |
… | |
1837 | * inv must have been an container and must have been active. |
1740 | * inv must have been an container and must have been active. |
1838 | * |
1741 | * |
1839 | * Change the color so that the message doesn't disappear with |
1742 | * Change the color so that the message doesn't disappear with |
1840 | * all the others. |
1743 | * all the others. |
1841 | */ |
1744 | */ |
1842 | if (pl->contr->usekeys == key_inventory || |
1745 | if (pl->contr->usekeys == key_inventory |
1843 | !QUERY_FLAG (container, FLAG_APPLIED) || |
1746 | || !QUERY_FLAG (container, FLAG_APPLIED) |
1844 | (pl->contr->usekeys == keyrings && container->race != shstr_keys)) |
1747 | || (pl->contr->usekeys == keyrings && container->race != shstr_keys)) |
1845 | { |
1748 | { |
1846 | new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, |
1749 | new_draw_info_format (NDI_UNIQUE | NDI_BROWN, 0, pl, |
1847 | "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); |
1750 | "The %s in your %s vibrates as you approach the door", query_name (tmp), query_name (container)); |
1848 | return NULL; |
1751 | return NULL; |
1849 | } |
1752 | } |
1850 | } |
1753 | } |
1851 | |
1754 | |
1852 | return tmp; |
1755 | return tmp; |
|
|
1756 | } |
|
|
1757 | |
|
|
1758 | /* find_key |
|
|
1759 | * We try to find a key for the door as passed. If we find a key |
|
|
1760 | * and successfully use it, we return the key, otherwise NULL |
|
|
1761 | * This function merges both normal and locked door, since the logic |
|
|
1762 | * for both is the same - just the specific key is different. |
|
|
1763 | * pl is the player, |
|
|
1764 | * inv is the objects inventory to searched |
|
|
1765 | * door is the door we are trying to match against. |
|
|
1766 | * This function can be called recursively to search containers. |
|
|
1767 | */ |
|
|
1768 | object * |
|
|
1769 | find_key (object *pl, object *container, object *door) |
|
|
1770 | { |
|
|
1771 | if (door->slaying && is_match_expr (door->slaying)) |
|
|
1772 | { |
|
|
1773 | // for match expressions, we try to find the key by applying the match |
|
|
1774 | // to the op itself, which is supposed to find the "key", instead |
|
|
1775 | // of searching through containers ourselves. |
|
|
1776 | |
|
|
1777 | return match_one (door->slaying, container, door, pl, pl); |
|
|
1778 | } |
|
|
1779 | else |
|
|
1780 | return find_key_ (pl, container, door); |
1853 | } |
1781 | } |
1854 | |
1782 | |
1855 | /* moved door processing out of move_player_attack. |
1783 | /* moved door processing out of move_player_attack. |
1856 | * returns 1 if player has opened the door with a key |
1784 | * returns 1 if player has opened the door with a key |
1857 | * such that the caller should not do anything more, |
1785 | * such that the caller should not do anything more, |
… | |
… | |
1907 | * going to try and move (not fire weapons). |
1835 | * going to try and move (not fire weapons). |
1908 | */ |
1836 | */ |
1909 | bool |
1837 | bool |
1910 | move_player_attack (object *op, int dir) |
1838 | move_player_attack (object *op, int dir) |
1911 | { |
1839 | { |
1912 | if (!op->contr->braced && op->speed_left > 0.f && move_ob (op, dir, op)) |
1840 | if (!op->contr->braced && op->speed_left > 0.f && op->move (dir)) |
1913 | { |
1841 | { |
1914 | --op->speed_left; |
1842 | --op->speed_left; |
1915 | return true; |
1843 | return true; |
1916 | } |
1844 | } |
1917 | |
1845 | |
1918 | int on_battleground; |
|
|
1919 | |
|
|
1920 | sint16 nx = freearr_x[dir] + op->x; |
1846 | sint16 nx = freearr_x[dir] + op->x; |
1921 | sint16 ny = freearr_y[dir] + op->y; |
1847 | sint16 ny = freearr_y[dir] + op->y; |
1922 | |
|
|
1923 | on_battleground = op_on_battleground (op, 0, 0); |
|
|
1924 | |
1848 | |
1925 | if (out_of_map (op->map, nx, ny)) |
1849 | if (out_of_map (op->map, nx, ny)) |
1926 | return false; |
1850 | return false; |
1927 | |
1851 | |
1928 | /* If braced, or can't move to the square, and it is not out of the |
1852 | /* If braced, or can't move to the square, and it is not out of the |
… | |
… | |
2000 | } |
1924 | } |
2001 | else |
1925 | else |
2002 | return false; |
1926 | return false; |
2003 | } |
1927 | } |
2004 | |
1928 | |
|
|
1929 | bool on_battleground = op_on_battleground (op, 0, 0); |
|
|
1930 | |
2005 | /* in certain circumstances, you shouldn't attack friendly |
1931 | /* in certain circumstances, you shouldn't attack friendly |
2006 | * creatures. Note that if you are braced, you can't push |
1932 | * creatures. Note that if you are braced, you can't push |
2007 | * someone, but put it inside this loop so that you won't |
1933 | * someone, but put it inside this loop so that you won't |
2008 | * attack them either. |
1934 | * attack them either. |
2009 | */ |
1935 | */ |
… | |
… | |
2073 | } |
1999 | } |
2074 | |
2000 | |
2075 | bool |
2001 | bool |
2076 | move_player (object *op, int dir) |
2002 | move_player (object *op, int dir) |
2077 | { |
2003 | { |
2078 | int pick; |
|
|
2079 | |
|
|
2080 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2004 | if (!op->map || op->map->in_memory != MAP_ACTIVE) |
2081 | return 0; |
2005 | return 0; |
2082 | |
2006 | |
2083 | /* Sanity check: make sure dir is valid */ |
2007 | /* Sanity check: make sure dir is valid */ |
2084 | if ((dir < 0) || (dir >= 9)) |
2008 | if (dir < 0 || dir >= 9) |
2085 | { |
2009 | { |
2086 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
2010 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
2087 | return 0; |
2011 | return 0; |
2088 | } |
2012 | } |
2089 | |
2013 | |
… | |
… | |
2095 | |
2019 | |
2096 | if (op->flag [FLAG_HIDDEN]) |
2020 | if (op->flag [FLAG_HIDDEN]) |
2097 | do_hidden_move (op); |
2021 | do_hidden_move (op); |
2098 | |
2022 | |
2099 | bool retval; |
2023 | bool retval; |
|
|
2024 | int pick = 0; |
2100 | |
2025 | |
2101 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
2026 | if (INVOKE_PLAYER (MOVE, op->contr, ARG_INT (dir))) |
2102 | retval = RESULT_INT (0); |
2027 | retval = RESULT_INT (0); |
2103 | else if (op->contr->fire_on) |
2028 | else if (op->contr->fire_on) |
2104 | retval = fire (op, dir); |
2029 | retval = fire (op, dir); |
… | |
… | |
2161 | return move_player (op, op->direction); |
2086 | return move_player (op, op->direction); |
2162 | |
2087 | |
2163 | return false; |
2088 | return false; |
2164 | } |
2089 | } |
2165 | |
2090 | |
2166 | int |
2091 | static int |
2167 | save_life (object *op) |
2092 | save_life (object *op) |
2168 | { |
2093 | { |
2169 | if (!QUERY_FLAG (op, FLAG_LIFESAVE)) |
2094 | if (!QUERY_FLAG (op, FLAG_LIFESAVE)) |
2170 | return 0; |
2095 | return 0; |
2171 | |
2096 | |
… | |
… | |
2180 | |
2105 | |
2181 | if (op->stats.hp < 0) |
2106 | if (op->stats.hp < 0) |
2182 | op->stats.hp = op->stats.maxhp; |
2107 | op->stats.hp = op->stats.maxhp; |
2183 | |
2108 | |
2184 | if (op->stats.food < 0) |
2109 | if (op->stats.food < 0) |
2185 | op->stats.food = 999; |
2110 | op->stats.food = MAX_FOOD; |
2186 | |
2111 | |
2187 | op->update_stats (); |
2112 | op->update_stats (); |
2188 | return 1; |
2113 | return 1; |
2189 | } |
2114 | } |
2190 | |
2115 | |
… | |
… | |
2218 | void |
2143 | void |
2219 | object::drop_unpaid_items () |
2144 | object::drop_unpaid_items () |
2220 | { |
2145 | { |
2221 | if (!flag [FLAG_REMOVED]) |
2146 | if (!flag [FLAG_REMOVED]) |
2222 | ::drop_unpaid_items (inv, this); |
2147 | ::drop_unpaid_items (inv, this); |
2223 | } |
|
|
2224 | |
|
|
2225 | /* |
|
|
2226 | * Returns pointer a static string containing gravestone text |
|
|
2227 | * Moved from apply.c to player.c - player.c is what |
|
|
2228 | * actually uses this function. player.c may not be quite the |
|
|
2229 | * best, a misc file for object actions is probably better, |
|
|
2230 | * but there isn't one in the server directory. |
|
|
2231 | */ |
|
|
2232 | const char * |
|
|
2233 | gravestone_text (object *op) |
|
|
2234 | { |
|
|
2235 | static dynbuf_text buf; |
|
|
2236 | |
|
|
2237 | buf << "---- R.I.P. ----\n\n" |
|
|
2238 | << op->name; |
|
|
2239 | |
|
|
2240 | if (op->type == PLAYER) |
|
|
2241 | buf << " the " << op->contr->title; |
|
|
2242 | |
|
|
2243 | buf << "\n\n"; |
|
|
2244 | |
|
|
2245 | buf << "who was level "; |
|
|
2246 | buf << (sint32)op->level << "\n\n" // OO breakdown |
|
|
2247 | << " when " << (op->contr ? "killed" : "died") << "\n\n"; |
|
|
2248 | |
|
|
2249 | if (op->type == PLAYER) |
|
|
2250 | buf << "by " << op->contr->killer_name () << ".\n\n"; |
|
|
2251 | |
|
|
2252 | { |
|
|
2253 | static char buf2[128]; |
|
|
2254 | time_t now = time (NULL); |
|
|
2255 | strftime (buf2, 128, "%b %d %Y\n\n", localtime (&now)); |
|
|
2256 | buf << buf2; |
|
|
2257 | } |
|
|
2258 | |
|
|
2259 | return buf; |
|
|
2260 | } |
2148 | } |
2261 | |
2149 | |
2262 | void |
2150 | void |
2263 | do_some_living (object *op) |
2151 | do_some_living (object *op) |
2264 | { |
2152 | { |
… | |
… | |
2456 | |
2344 | |
2457 | if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) |
2345 | if (tmp->type == FOOD || tmp->type == DRINK || tmp->type == POISON) |
2458 | { |
2346 | { |
2459 | op->statusmsg ("You blindly grab for a bite of food. " |
2347 | op->statusmsg ("You blindly grab for a bite of food. " |
2460 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2348 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2461 | manual_apply (op, tmp, 0); |
2349 | op->apply (tmp); |
2462 | |
2350 | |
2463 | if (op->stats.food >= 0 || op->stats.hp < 0) |
2351 | if (op->stats.food >= 0 || op->stats.hp < 0) |
2464 | break; |
2352 | break; |
2465 | } |
2353 | } |
2466 | else if (tmp->type == FLESH) |
2354 | else if (tmp->type == FLESH) |
… | |
… | |
2472 | */ |
2360 | */ |
2473 | if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) |
2361 | if (op->stats.food < 0 && op->stats.hp >= 0 && flesh) |
2474 | { |
2362 | { |
2475 | op->statusmsg ("You blindly grab for a bite of food. " |
2363 | op->statusmsg ("You blindly grab for a bite of food. " |
2476 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2364 | "H<To prevent you from starving, you ate some random item from your backpack.>"); |
2477 | manual_apply (op, flesh, 0); |
2365 | op->apply (flesh); |
2478 | } |
2366 | } |
2479 | |
2367 | |
2480 | // If player is still starving, alert him! |
2368 | // If player is still starving, alert him! |
2481 | if (op->stats.food < 0) |
2369 | if (op->stats.food < 0) |
2482 | op->failmsg ("You are starving! " |
2370 | op->failmsg ("You are starving! " |
… | |
… | |
2519 | return; |
2407 | return; |
2520 | |
2408 | |
2521 | dynbuf_text deathtab; |
2409 | dynbuf_text deathtab; |
2522 | |
2410 | |
2523 | /* restore player */ |
2411 | /* restore player */ |
2524 | at = archetype::find ("poisoning"); |
2412 | at = archetype::find (shstr_poisoning); |
2525 | if (object *tmp = present_arch_in_ob (at, op)) |
2413 | if (object *tmp = present_arch_in_ob (at, op)) |
2526 | { |
2414 | { |
2527 | tmp->destroy (); |
2415 | tmp->destroy (); |
2528 | deathtab << "Your body feels cleansed...\r"; |
2416 | deathtab << "Your body feels cleansed...\r"; |
2529 | } |
2417 | } |
2530 | |
2418 | |
2531 | at = archetype::find ("confusion"); |
2419 | at = archetype::find (shstr_confusion); |
2532 | if (object *tmp = present_arch_in_ob (at, op)) |
2420 | if (object *tmp = present_arch_in_ob (at, op)) |
2533 | { |
2421 | { |
2534 | tmp->destroy (); |
2422 | tmp->destroy (); |
2535 | deathtab << "Your mind feels clearer...\r"; |
2423 | deathtab << "Your mind feels clearer...\r"; |
2536 | } |
2424 | } |
… | |
… | |
2538 | cure_disease (op, 0, 0); /* remove any disease */ |
2426 | cure_disease (op, 0, 0); /* remove any disease */ |
2539 | |
2427 | |
2540 | max_it (op->stats.hp , op->stats.maxhp); |
2428 | max_it (op->stats.hp , op->stats.maxhp); |
2541 | max_it (op->stats.sp , op->stats.maxsp); |
2429 | max_it (op->stats.sp , op->stats.maxsp); |
2542 | max_it (op->stats.grace, op->stats.maxgrace); |
2430 | max_it (op->stats.grace, op->stats.maxgrace); |
2543 | |
|
|
2544 | if (op->stats.food <= 0) |
2431 | max_it (op->stats.food , 200); |
2545 | op->stats.food = 999; |
|
|
2546 | |
2432 | |
2547 | // remove all spell effects that are active |
2433 | // remove all spell effects that are active |
2548 | // to avoid long-term effects such as word-of-recall |
2434 | // to avoid long-term effects such as word-of-recall |
2549 | for (object *item = op->inv; item; ) |
2435 | for (object *item = op->inv; item; ) |
2550 | { |
2436 | { |
… | |
… | |
2563 | if (op_on_battleground (op, &x, &y)) |
2449 | if (op_on_battleground (op, &x, &y)) |
2564 | { |
2450 | { |
2565 | deathtab << "You almost died in combat, but local medics have saved your life...\r"; |
2451 | deathtab << "You almost died in combat, but local medics have saved your life...\r"; |
2566 | |
2452 | |
2567 | /* create a bodypart-trophy to make the winner happy */ |
2453 | /* create a bodypart-trophy to make the winner happy */ |
2568 | if (object *tmp = arch_to_object (archetype::find ("finger"))) |
2454 | object *tmp = archetype::find (shstr_finger)->instance (); |
2569 | { |
2455 | |
2570 | tmp->name = format ("%s's finger" , &op->name); |
2456 | tmp->name = format ("%s's finger" , &op->name); |
2571 | tmp->name_pl = format ("%s's fingers", &op->name); |
2457 | tmp->name_pl = format ("%s's fingers", &op->name); |
2572 | tmp->msg = format ( |
2458 | tmp->msg = format ( |
2573 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
2459 | "This finger has been cut off of %s the %s, when he was defeated at level %d by %s.\n", |
2574 | &op->name, op->contr->title, |
2460 | &op->name, op->contr->title, |
2575 | (int)op->level, |
2461 | (int)op->level, |
2576 | op->contr->killer_name () |
2462 | op->contr->killer_name () |
2577 | ); |
2463 | ); |
2578 | tmp->value = 0, tmp->type = 0; |
2464 | tmp->value = 0, tmp->type = 0; |
2579 | tmp->materialname = "organics"; |
2465 | tmp->material = name_to_material (shstr_organic); |
2580 | tmp->insert_at (op, tmp); |
2466 | tmp->insert_at (op, tmp); |
2581 | } |
|
|
2582 | |
2467 | |
2583 | /* teleport defeated player to new destination */ |
2468 | /* teleport defeated player to new destination */ |
2584 | transfer_ob (op, x, y, 0, NULL); |
2469 | transfer_ob (op, x, y, 0, NULL); |
2585 | op->contr->braced = 0; |
2470 | op->contr->braced = 0; |
2586 | |
2471 | |
… | |
… | |
2648 | lost_a_stat = 1; |
2533 | lost_a_stat = 1; |
2649 | } |
2534 | } |
2650 | else |
2535 | else |
2651 | { |
2536 | { |
2652 | /* deplete a stat */ |
2537 | /* deplete a stat */ |
2653 | archetype *deparch = archetype::find ("depletion"); |
2538 | archetype *deparch = archetype::find (shstr_depletion); |
2654 | object *dep; |
2539 | object *dep; |
2655 | |
2540 | |
2656 | dep = present_arch_in_ob (deparch, op); |
2541 | dep = present_arch_in_ob (deparch, op); |
2657 | if (!dep) |
2542 | if (!dep) |
2658 | { |
2543 | { |
2659 | dep = arch_to_object (deparch); |
2544 | dep = deparch->instance (); |
2660 | insert_ob_in_ob (dep, op); |
2545 | insert_ob_in_ob (dep, op); |
2661 | } |
2546 | } |
2662 | lose_this_stat = 1; |
2547 | lose_this_stat = 1; |
2663 | if (settings.balanced_stat_loss) |
2548 | if (settings.balanced_stat_loss) |
2664 | { |
2549 | { |
… | |
… | |
2730 | #endif |
2615 | #endif |
2731 | |
2616 | |
2732 | /* Put a gravestone up where the character 'almost' died. List the |
2617 | /* Put a gravestone up where the character 'almost' died. List the |
2733 | * exp loss on the stone. |
2618 | * exp loss on the stone. |
2734 | */ |
2619 | */ |
2735 | tmp = arch_to_object (archetype::find ("gravestone")); |
2620 | tmp = archetype::find (shstr_gravestone)->instance (); |
2736 | tmp->name = format ("%s's gravestone", &op->name); |
2621 | tmp->name = format ("%s's gravestone", &op->name); |
2737 | tmp->name_pl = format ("%s's gravestones", &op->name); |
2622 | tmp->name_pl = format ("%s's gravestones", &op->name); |
2738 | tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", |
2623 | tmp->msg = format ("T<RIP>\n\nHere rests the hero %s the %s,\rwho was killed\rby %s.\n", |
2739 | &op->name, op->contr->title, op->contr->killer_name ()); |
2624 | &op->name, op->contr->title, op->contr->killer_name ()); |
2740 | tmp->x = op->x, tmp->y = op->y; |
2625 | tmp->x = op->x, tmp->y = op->y; |
… | |
… | |
2795 | } |
2680 | } |
2796 | |
2681 | |
2797 | op->contr->infobox (MSG_CHANNEL ("death"), deathtab); |
2682 | op->contr->infobox (MSG_CHANNEL ("death"), deathtab); |
2798 | } |
2683 | } |
2799 | |
2684 | |
2800 | void |
2685 | static void |
2801 | loot_object (object *op) |
2686 | loot_object (object *op) |
2802 | { /* Grab and destroy some treasure */ |
2687 | { /* Grab and destroy some treasure */ |
2803 | object *tmp, *tmp2, *next; |
2688 | object *tmp, *tmp2, *next; |
2804 | |
2689 | |
2805 | op->close_container (); /* close open sack first */ |
2690 | op->close_container (); /* close open sack first */ |
… | |
… | |
2836 | * fix_weight(): Check recursively the weight of all players, and fix |
2721 | * fix_weight(): Check recursively the weight of all players, and fix |
2837 | * what needs to be fixed. Refresh windows and fix speed if anything |
2722 | * what needs to be fixed. Refresh windows and fix speed if anything |
2838 | * was changed. |
2723 | * was changed. |
2839 | */ |
2724 | */ |
2840 | void |
2725 | void |
2841 | fix_weight (void) |
2726 | fix_weight () |
2842 | { |
2727 | { |
2843 | for_all_players (pl) |
2728 | for_all_players (pl) |
2844 | { |
2729 | { |
2845 | sint32 old = pl->ob->carrying; |
2730 | sint32 old = pl->ob->carrying; |
2846 | |
2731 | |
… | |
… | |
2853 | } |
2738 | } |
2854 | } |
2739 | } |
2855 | } |
2740 | } |
2856 | |
2741 | |
2857 | void |
2742 | void |
2858 | fix_luck (void) |
2743 | fix_luck () |
2859 | { |
2744 | { |
2860 | for_all_players (pl) |
2745 | for_all_players (pl) |
2861 | if (!pl->ob->contr->ns->state) |
2746 | if (!pl->ob->contr->ns->state) |
2862 | pl->ob->change_luck (0); |
2747 | pl->ob->change_luck (0); |
2863 | } |
2748 | } |
… | |
… | |
3107 | } |
2992 | } |
3108 | |
2993 | |
3109 | return 0; |
2994 | return 0; |
3110 | } |
2995 | } |
3111 | |
2996 | |
3112 | /* routine for both players and monsters. We call this when |
|
|
3113 | * there is a possibility for our action distrubing our hiding |
|
|
3114 | * place or invisiblity spell. Artefact invisiblity causes |
|
|
3115 | * "noise" instead. If we arent invisible to begin with, we |
|
|
3116 | * return 0. |
|
|
3117 | */ |
|
|
3118 | int |
|
|
3119 | action_makes_visible (object *op) |
|
|
3120 | { |
|
|
3121 | if (op->invisible && QUERY_FLAG (op, FLAG_ALIVE)) |
|
|
3122 | { |
|
|
3123 | if (QUERY_FLAG (op, FLAG_MAKE_INVIS)) |
|
|
3124 | { |
|
|
3125 | // artefact invisibility is permanent, but we still make noise |
|
|
3126 | // this is important for game-balance. |
|
|
3127 | if (op->contr) |
|
|
3128 | op->make_noise (); |
|
|
3129 | |
|
|
3130 | return 0; |
|
|
3131 | } |
|
|
3132 | |
|
|
3133 | if (op->contr && op->contr->tmp_invis == 0) |
|
|
3134 | return 0; |
|
|
3135 | |
|
|
3136 | /* If monsters, they should become visible */ |
|
|
3137 | if (op->flag [FLAG_HIDDEN] || !op->contr || (op->contr && op->contr->tmp_invis)) |
|
|
3138 | { |
|
|
3139 | new_draw_info_format (NDI_UNIQUE, 0, op, "You become %s!", op->flag [FLAG_HIDDEN] ? "unhidden" : "visible"); |
|
|
3140 | return 1; |
|
|
3141 | } |
|
|
3142 | } |
|
|
3143 | |
|
|
3144 | return 0; |
|
|
3145 | } |
|
|
3146 | |
|
|
3147 | /* op_on_battleground - checks if the given object op (usually |
2997 | /* op_on_battleground - checks if the given object op (usually |
3148 | * a player) is standing on a valid battleground-tile, |
2998 | * a player) is standing on a valid battleground-tile, |
3149 | * function returns TRUE/FALSE. If true x, y returns the battleground |
2999 | * function returns TRUE/FALSE. If true x, y returns the battleground |
3150 | * -exit-coord. (and if x, y not NULL) |
3000 | * -exit-coord. (and if x, y not NULL) |
3151 | * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set |
3001 | * 19 March 2005 - josh@woosworld.net modifed to check if the battleground also has slaying, maxhp, and maxsp set |
… | |
… | |
3170 | && tmp->name == shstr_battleground |
3020 | && tmp->name == shstr_battleground |
3171 | && EXIT_X (tmp) && EXIT_Y (tmp)) |
3021 | && EXIT_X (tmp) && EXIT_Y (tmp)) |
3172 | { |
3022 | { |
3173 | /* before we assign the exit, check if this is a teambattle */ |
3023 | /* before we assign the exit, check if this is a teambattle */ |
3174 | if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) |
3024 | if (EXIT_ALT_X (tmp) && EXIT_ALT_Y (tmp) && EXIT_PATH (tmp)) |
3175 | { |
|
|
3176 | for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below) |
3025 | for (object *invtmp = op->inv; invtmp; invtmp = invtmp->below) |
|
|
3026 | if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying) |
3177 | { |
3027 | { |
3178 | if (invtmp->type == FORCE && invtmp->slaying && tmp->slaying == invtmp->slaying) |
|
|
3179 | { |
|
|
3180 | if (x && y) |
3028 | if (x && y) |
3181 | *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); |
3029 | *x = EXIT_ALT_X (tmp), *y = EXIT_ALT_Y (tmp); |
3182 | |
3030 | |
3183 | return 1; |
3031 | return 1; |
3184 | } |
|
|
3185 | } |
3032 | } |
3186 | } |
|
|
3187 | |
3033 | |
3188 | if (x && y) |
3034 | if (x && y) |
3189 | *x = EXIT_X (tmp), *y = EXIT_Y (tmp); |
3035 | *x = EXIT_X (tmp), *y = EXIT_Y (tmp); |
3190 | |
3036 | |
3191 | return 1; |
3037 | return 1; |
… | |
… | |
3329 | else |
3175 | else |
3330 | j = 1; |
3176 | j = 1; |
3331 | strcat (buf, spellpathnames[i]); |
3177 | strcat (buf, spellpathnames[i]); |
3332 | } |
3178 | } |
3333 | } |
3179 | } |
|
|
3180 | |
3334 | strcat (buf, "."); |
3181 | strcat (buf, "."); |
3335 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); |
3182 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, buf); |
3336 | } |
3183 | } |
3337 | |
3184 | |
3338 | /* evtl. adding flags: */ |
3185 | /* evtl. adding flags: */ |
… | |
… | |
3348 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); |
3195 | new_draw_info (NDI_UNIQUE | NDI_BLUE, 0, who, item->msg); |
3349 | } |
3196 | } |
3350 | else |
3197 | else |
3351 | { |
3198 | { |
3352 | /* generate misc. treasure */ |
3199 | /* generate misc. treasure */ |
3353 | tmp = arch_to_object (tr->item); |
3200 | tmp = tr->item->instance (); |
3354 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3201 | new_draw_info_format (NDI_UNIQUE | NDI_BLUE, 0, who, "You gained %s", query_short_name (tmp)); |
3355 | who->insert (tmp); |
3202 | who->insert (tmp); |
3356 | } |
3203 | } |
3357 | } |
3204 | } |
3358 | |
3205 | |
3359 | /** |
3206 | //-GPL |
3360 | * Unready an object for a player. This function does nothing if the object was |
|
|
3361 | * not readied. |
|
|
3362 | */ |
|
|
3363 | void |
|
|
3364 | player_unready_range_ob (player *pl, object *ob) |
|
|
3365 | { |
|
|
3366 | if (pl->ob->current_weapon == ob) |
|
|
3367 | pl->ob->current_weapon = 0; |
|
|
3368 | |
|
|
3369 | if (pl->combat_ob == ob) |
|
|
3370 | pl->combat_ob = 0; |
|
|
3371 | |
|
|
3372 | if (pl->ranged_ob == ob) |
|
|
3373 | pl->ranged_ob = 0; |
|
|
3374 | } |
|
|
3375 | |
3207 | |
3376 | sint8 |
3208 | sint8 |
3377 | player::darkness_at (maptile *map, int x, int y) const |
3209 | player::darkness_at (maptile *map, int x, int y) const |
3378 | { |
3210 | { |
3379 | if (!ns) |
3211 | if (!ns) |