1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | 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, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The author can be reached via e-mail to <crossfire@schmorp.de> |
22 | * The author can be reached via e-mail to <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #include <pwd.h> |
26 | #include <pwd.h> |
26 | #include <sproto.h> |
27 | #include <sproto.h> |
27 | #include <sounds.h> |
28 | #include <sounds.h> |
… | |
… | |
31 | #include <skills.h> |
32 | #include <skills.h> |
32 | |
33 | |
33 | #include <algorithm> |
34 | #include <algorithm> |
34 | #include <functional> |
35 | #include <functional> |
35 | |
36 | |
36 | player * |
37 | playervec players; |
37 | find_player (const char *plname) |
|
|
38 | { |
|
|
39 | player *pl; |
|
|
40 | |
|
|
41 | for (pl = first_player; pl; pl = pl->next) |
|
|
42 | if (pl->ob && !strcmp (query_name (pl->ob), plname)) |
|
|
43 | return pl; |
|
|
44 | |
|
|
45 | return 0; |
|
|
46 | } |
|
|
47 | |
38 | |
48 | void |
39 | void |
49 | display_motd (const object *op) |
40 | display_motd (const object *op) |
50 | { |
41 | { |
51 | char buf[MAX_BUF]; |
42 | char buf[MAX_BUF]; |
… | |
… | |
134 | |
125 | |
135 | if (*buf == '%') |
126 | if (*buf == '%') |
136 | { /* send one news */ |
127 | { /* send one news */ |
137 | if (size > 0) |
128 | if (size > 0) |
138 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */ |
129 | draw_ext_info_format (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_NEWS, "INFORMATION: %s\n%s", "%s\n%s", subject, news); /*send previously read news */ |
|
|
130 | |
139 | strcpy (subject, buf + 1); |
131 | strcpy (subject, buf + 1); |
140 | strip_endline (subject); |
132 | strip_endline (subject); |
141 | size = 0; |
133 | size = 0; |
142 | news[0] = '\0'; |
134 | news[0] = '\0'; |
143 | } |
135 | } |
… | |
… | |
160 | |
152 | |
161 | /* This loads the first map an puts the player on it. */ |
153 | /* This loads the first map an puts the player on it. */ |
162 | static void |
154 | static void |
163 | set_first_map (object *op) |
155 | set_first_map (object *op) |
164 | { |
156 | { |
165 | strcpy (op->contr->maplevel, first_map_path); |
157 | op->contr->maplevel = first_map_path; |
166 | op->x = -1; |
158 | op->x = -1; |
167 | op->y = -1; |
159 | op->y = -1; |
|
|
160 | } |
|
|
161 | |
|
|
162 | void |
|
|
163 | player::enter_map () |
|
|
164 | { |
|
|
165 | object *tmp = object::create (); |
|
|
166 | |
|
|
167 | EXIT_PATH (tmp) = maplevel; |
|
|
168 | EXIT_X (tmp) = ob->x; |
|
|
169 | EXIT_Y (tmp) = ob->y; |
168 | enter_exit (op, 0); |
170 | ob->enter_exit (tmp); |
|
|
171 | |
|
|
172 | tmp->destroy (); |
|
|
173 | } |
|
|
174 | |
|
|
175 | void |
|
|
176 | player::activate () |
|
|
177 | { |
|
|
178 | if (active) |
|
|
179 | return; |
|
|
180 | |
|
|
181 | players.insert (this); |
|
|
182 | ob->remove (); |
|
|
183 | ob->map = 0; |
|
|
184 | ob->activate_recursive (); |
|
|
185 | enter_map (); |
|
|
186 | } |
|
|
187 | |
|
|
188 | void |
|
|
189 | player::deactivate () |
|
|
190 | { |
|
|
191 | if (!active) |
|
|
192 | return; |
|
|
193 | |
|
|
194 | terminate_all_pets (ob); |
|
|
195 | ob->deactivate_recursive (); |
|
|
196 | ob->remove (); |
|
|
197 | ob->map = 0; |
|
|
198 | |
|
|
199 | players.erase (this); |
169 | } |
200 | } |
170 | |
201 | |
171 | // connect the player with a specific client |
202 | // connect the player with a specific client |
172 | // also changed, rationalises, and fixes some incorrect settings |
203 | // also changed, rationalises, and fixes some incorrect settings |
173 | void |
204 | void |
174 | player::connect (client *ns) |
205 | player::connect (client *ns) |
175 | { |
206 | { |
176 | this->ns = ns; |
207 | this->ns = ns; |
177 | ns->pl = this; |
208 | ns->pl = this; |
178 | |
209 | |
179 | next = first_player; |
|
|
180 | first_player = this; |
|
|
181 | |
|
|
182 | ns->update_look = 0; |
210 | ns->update_look = 0; |
183 | ns->look_position = 0; |
211 | ns->look_position = 0; |
184 | |
212 | |
185 | clear_los (ob); |
213 | clear_los (ob); |
186 | |
214 | |
|
|
215 | /* make sure he's a player -- needed because of class change. */ |
187 | ob->type = PLAYER; // we are paranoid |
216 | ob->type = PLAYER; // we are paranoid |
188 | ob->race = ob->arch->clone.race; |
217 | ob->race = ob->arch->clone.race; |
189 | |
218 | |
190 | if (!legal_range (ob, shoottype)) |
219 | if (!legal_range (ob, shoottype)) |
191 | shoottype = range_none; |
220 | shoottype = range_none; |
192 | |
221 | |
193 | ob->carrying = sum_weight (ob); |
222 | ob->carrying = sum_weight (ob); |
194 | link_player_skills (ob); |
223 | link_player_skills (ob); |
195 | |
224 | |
196 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
225 | CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); |
197 | ob->update_stats (); |
|
|
198 | update_ob_speed (ob); |
|
|
199 | |
226 | |
200 | assign (title, ob->arch->clone.name); |
227 | assign (title, ob->arch->clone.name); |
201 | |
228 | |
202 | /* can_use_shield is a new flag. However, the can_use.. seems to largely come |
229 | /* can_use_shield is a new flag. However, the can_use.. seems to largely come |
203 | * from the class, and not race. I don't see any way to get the class information |
230 | * from the class, and not race. I don't see any way to get the class information |
… | |
… | |
228 | } |
255 | } |
229 | |
256 | |
230 | CLEAR_FLAG (ob, FLAG_FRIENDLY); |
257 | CLEAR_FLAG (ob, FLAG_FRIENDLY); |
231 | add_friendly_object (ob); |
258 | add_friendly_object (ob); |
232 | |
259 | |
233 | LOG (llevInfo, "LOGIN: Player named %s from ip %s\n", &ob->name, ns->host); |
|
|
234 | |
|
|
235 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
260 | new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); |
236 | new_draw_info_format (NDI_UNIQUE | NDI_ALL | NDI_DK_ORANGE, 5, NULL, "%s has entered the game.", &ob->name); |
|
|
237 | |
261 | |
|
|
262 | esrv_new_player (this, ob->weight + ob->carrying); |
|
|
263 | |
|
|
264 | ob->update_stats (); |
238 | ns->floorbox_update (); |
265 | ns->floorbox_update (); |
239 | |
266 | |
240 | esrv_new_player (this, ob->weight + ob->carrying); |
|
|
241 | esrv_send_inventory (ob, ob); |
267 | esrv_send_inventory (ob, ob); |
242 | esrv_add_spells (this, 0); |
268 | esrv_add_spells (this, 0); |
243 | |
269 | |
244 | enter_exit (ob, 0); |
270 | activate (); |
245 | |
271 | |
246 | // send_rules (ob);//TODO |
272 | send_rules (ob); |
247 | // send_news (ob);//TODO |
273 | send_news (ob); |
248 | // display_motd (ob);//TODO |
274 | display_motd (ob); |
|
|
275 | |
|
|
276 | INVOKE_PLAYER (CONNECT, this); |
249 | INVOKE_PLAYER (LOGIN, this); |
277 | INVOKE_PLAYER (LOGIN, this); |
|
|
278 | } |
|
|
279 | |
|
|
280 | void |
|
|
281 | player::disconnect () |
|
|
282 | { |
|
|
283 | if (ns) |
|
|
284 | { |
|
|
285 | if (active) |
|
|
286 | INVOKE_PLAYER (LOGOUT, this, ARG_INT (0)); |
|
|
287 | |
|
|
288 | INVOKE_PLAYER (DISCONNECT, this); |
|
|
289 | |
|
|
290 | ns->pl = 0; |
|
|
291 | this->ns = 0; |
|
|
292 | } |
|
|
293 | |
|
|
294 | deactivate (); |
250 | } |
295 | } |
251 | |
296 | |
252 | // the need for this function can be explained |
297 | // the need for this function can be explained |
253 | // by load_object not returning the object |
298 | // by load_object not returning the object |
254 | void |
299 | void |
… | |
… | |
261 | ob->speed = 1.0; |
306 | ob->speed = 1.0; |
262 | ob->direction = 5; /* So player faces south */ |
307 | ob->direction = 5; /* So player faces south */ |
263 | ob->stats.wc = 2; |
308 | ob->stats.wc = 2; |
264 | ob->run_away = 25; /* Then we panick... */ |
309 | ob->run_away = 25; /* Then we panick... */ |
265 | |
310 | |
266 | set_first_map (ob); |
|
|
267 | |
|
|
268 | ob->roll_stats (); |
311 | ob->roll_stats (); |
269 | } |
312 | } |
270 | |
313 | |
271 | player::player () |
314 | player::player () |
272 | { |
315 | { |
273 | /* There are some elements we want initialized to non zero value - |
316 | /* There are some elements we want initialised to non zero value - |
274 | * we deal with that below this point. |
317 | * we deal with that below this point. |
275 | */ |
318 | */ |
276 | outputs_sync = 16; /* Every 2 seconds */ |
319 | outputs_sync = 16; /* Every 2 seconds */ |
277 | outputs_count = 8; /* Keeps present behaviour */ |
320 | outputs_count = 8; /* Keeps present behaviour */ |
278 | unapply = unapply_nochoice; |
321 | unapply = unapply_nochoice; |
279 | |
322 | |
280 | assign (savebed_map, first_map_path); /* Init. respawn position */ |
323 | savebed_map = first_map_path; /* Init. respawn position */ |
281 | |
324 | |
282 | gen_sp_armour = 10; |
325 | gen_sp_armour = 10; |
283 | last_speed = -1; |
326 | last_speed = -1; |
284 | shoottype = range_none; |
327 | shoottype = range_none; |
285 | bowtype = bow_normal; |
328 | bowtype = bow_normal; |
… | |
… | |
303 | |
346 | |
304 | last_stats.exp = -1; |
347 | last_stats.exp = -1; |
305 | last_weight = (uint32) - 1; |
348 | last_weight = (uint32) - 1; |
306 | } |
349 | } |
307 | |
350 | |
|
|
351 | void |
|
|
352 | player::do_destroy () |
|
|
353 | { |
|
|
354 | disconnect (); |
|
|
355 | |
|
|
356 | attachable::do_destroy (); |
|
|
357 | |
|
|
358 | if (ob) |
|
|
359 | { |
|
|
360 | ob->destroy_inv (false); |
|
|
361 | ob->destroy (); |
|
|
362 | } |
|
|
363 | } |
|
|
364 | |
308 | player::~player () |
365 | player::~player () |
309 | { |
366 | { |
310 | terminate_all_pets (ob); |
|
|
311 | |
|
|
312 | if (first_player != this) |
|
|
313 | { |
|
|
314 | player *prev = first_player; |
|
|
315 | |
|
|
316 | while (prev && prev->next && prev->next != this) |
|
|
317 | prev = prev->next; |
|
|
318 | |
|
|
319 | if (prev->next != this) |
|
|
320 | { |
|
|
321 | LOG (llevError, "Free_player: Can't find previous player.\n"); |
|
|
322 | abort (); |
|
|
323 | } |
|
|
324 | |
|
|
325 | prev->next = next; |
|
|
326 | } |
|
|
327 | else |
|
|
328 | first_player = next; |
|
|
329 | |
|
|
330 | if (ob) |
|
|
331 | { |
|
|
332 | ob->contr = 0; |
|
|
333 | ob->destroy (1); |
|
|
334 | } |
|
|
335 | |
|
|
336 | if (ns) |
|
|
337 | { |
|
|
338 | ns->send_packet ("goodbye"); |
|
|
339 | ns->flush (); |
|
|
340 | ns->pl = 0; |
|
|
341 | ns->destroy (); |
|
|
342 | } |
|
|
343 | |
|
|
344 | /* Clear item stack */ |
367 | /* Clear item stack */ |
345 | free (stack_items); |
368 | free (stack_items); |
346 | } |
369 | } |
347 | |
370 | |
348 | /* Tries to add player on the connection passed in ns. |
371 | /* Tries to add player on the connection passed in ns. |
… | |
… | |
353 | player::create () |
376 | player::create () |
354 | { |
377 | { |
355 | player *pl = new player; |
378 | player *pl = new player; |
356 | |
379 | |
357 | pl->set_object (arch_to_object (get_player_archetype (0))); |
380 | pl->set_object (arch_to_object (get_player_archetype (0))); |
|
|
381 | set_first_map (pl->ob); |
358 | |
382 | |
359 | return pl; |
383 | return pl; |
360 | } |
384 | } |
361 | |
385 | |
362 | /* |
386 | /* |
… | |
… | |
389 | |
413 | |
390 | object * |
414 | object * |
391 | get_nearest_player (object *mon) |
415 | get_nearest_player (object *mon) |
392 | { |
416 | { |
393 | object *op = NULL; |
417 | object *op = NULL; |
394 | player *pl = NULL; |
|
|
395 | objectlink *ol; |
418 | objectlink *ol; |
396 | unsigned lastdist; |
419 | unsigned lastdist; |
397 | rv_vector rv; |
420 | rv_vector rv; |
398 | |
421 | |
399 | for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next) |
422 | for (ol = first_friendly_object, lastdist = 1000; ol != NULL; ol = ol->next) |
… | |
… | |
431 | { |
454 | { |
432 | op = ol->ob; |
455 | op = ol->ob; |
433 | lastdist = rv.distance; |
456 | lastdist = rv.distance; |
434 | } |
457 | } |
435 | } |
458 | } |
436 | for (pl = first_player; pl != NULL; pl = pl->next) |
459 | |
437 | { |
460 | for_all_players (pl) |
438 | if (can_detect_enemy (mon, pl->ob, &rv)) |
461 | if (can_detect_enemy (mon, pl->ob, &rv)) |
439 | { |
|
|
440 | |
|
|
441 | if (lastdist > rv.distance) |
462 | if (lastdist > rv.distance) |
442 | { |
463 | { |
443 | op = pl->ob; |
464 | op = pl->ob; |
444 | lastdist = rv.distance; |
465 | lastdist = rv.distance; |
445 | } |
466 | } |
446 | } |
467 | |
447 | } |
|
|
448 | #if 0 |
468 | #if 0 |
449 | LOG (llevDebug, "get_nearest_player() finds player: %s\n", op ? &op->name : "(null)"); |
469 | LOG (llevDebug, "get_nearest_player() finds player: %s\n", op ? &op->name : "(null)"); |
450 | #endif |
470 | #endif |
451 | return op; |
471 | return op; |
452 | } |
472 | } |
… | |
… | |
832 | |
852 | |
833 | contr->orig_stats = stats; |
853 | contr->orig_stats = stats; |
834 | } |
854 | } |
835 | } |
855 | } |
836 | |
856 | |
|
|
857 | static void |
|
|
858 | start_info (object *op) |
|
|
859 | { |
|
|
860 | char buf[MAX_BUF]; |
|
|
861 | |
|
|
862 | sprintf (buf, "Welcome to Crossfire v%s!", VERSION); |
|
|
863 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
|
|
864 | //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help"); |
|
|
865 | //new_draw_info (NDI_UNIQUE, 0, op, " "); |
|
|
866 | } |
|
|
867 | |
837 | /* This function takes the key that is passed, and does the |
868 | /* This function takes the key that is passed, and does the |
838 | * appropriate action with it (change race, or other things). |
869 | * appropriate action with it (change race, or other things). |
839 | * The function name is for historical reasons - now we have |
870 | * The function name is for historical reasons - now we have |
840 | * separate race and class; this actually changes the RACE, |
871 | * separate race and class; this actually changes the RACE, |
841 | * not the class. |
872 | * not the class. |
… | |
… | |
886 | if (*first_map_ext_path) |
917 | if (*first_map_ext_path) |
887 | { |
918 | { |
888 | object *tmp; |
919 | object *tmp; |
889 | char mapname[MAX_BUF]; |
920 | char mapname[MAX_BUF]; |
890 | |
921 | |
891 | snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); |
922 | snprintf (mapname, MAX_BUF - 1, "%s/%s", &first_map_ext_path, &op->arch->name); |
892 | tmp = object::create (); |
923 | tmp = object::create (); |
893 | EXIT_PATH (tmp) = mapname; |
924 | EXIT_PATH (tmp) = mapname; |
894 | EXIT_X (tmp) = op->x; |
925 | EXIT_X (tmp) = op->x; |
895 | EXIT_Y (tmp) = op->y; |
926 | EXIT_Y (tmp) = op->y; |
896 | enter_exit (op, tmp); /* we don't really care if it succeeded; |
927 | op->enter_exit (tmp); /* we don't really care if it succeeded; |
897 | * if the map isn't there, then stay on the |
928 | * if the map isn't there, then stay on the |
898 | * default initial map */ |
929 | * default initial map */ |
899 | tmp->destroy (); |
930 | tmp->destroy (); |
900 | } |
931 | } |
901 | else |
932 | else |
… | |
… | |
940 | if (op->msg) |
971 | if (op->msg) |
941 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
972 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
942 | |
973 | |
943 | send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
974 | send_query (op->contr->ns, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
944 | return 0; |
975 | return 0; |
945 | } |
|
|
946 | |
|
|
947 | int |
|
|
948 | key_confirm_quit (object *op, char key) |
|
|
949 | { |
|
|
950 | if (key != 'y' && key != 'Y' && key != 'q' && key != 'Q') |
|
|
951 | { |
|
|
952 | op->contr->ns->state = ST_PLAYING; |
|
|
953 | new_draw_info (NDI_UNIQUE, 0, op, "OK, continuing to play."); |
|
|
954 | return 1; |
|
|
955 | } |
|
|
956 | |
|
|
957 | INVOKE_PLAYER (LOGOUT, op->contr); |
|
|
958 | INVOKE_PLAYER (QUIT, op->contr); |
|
|
959 | |
|
|
960 | terminate_all_pets (op); |
|
|
961 | leave_map (op); |
|
|
962 | op->direction = 0; |
|
|
963 | new_draw_info_format (NDI_UNIQUE | NDI_ALL, 5, NULL, "%s quits the game.", &op->name); |
|
|
964 | |
|
|
965 | strcpy (op->contr->killer, "quit"); |
|
|
966 | check_score (op); |
|
|
967 | op->contr->party = 0; |
|
|
968 | op->contr->own_title[0] = '\0'; |
|
|
969 | |
|
|
970 | object_ptr ob = op; |
|
|
971 | |
|
|
972 | delete ob->contr; |
|
|
973 | |
|
|
974 | /* We need to hunt for any per player unique maps in memory and |
|
|
975 | * get rid of them. The trailing slash in the path is intentional, |
|
|
976 | * so that players named 'Ab' won't match against players 'Abe' pathname |
|
|
977 | */ |
|
|
978 | char buf[MAX_BUF]; |
|
|
979 | sprintf (buf, "%s/%s/%s/", settings.localdir, settings.playerdir, &op->name); |
|
|
980 | |
|
|
981 | for (maptile *next, *mp = first_map; mp; mp = next) |
|
|
982 | { |
|
|
983 | next = mp->next; |
|
|
984 | |
|
|
985 | if (!strncmp (mp->path, buf, strlen (buf))) |
|
|
986 | delete_map (mp); |
|
|
987 | } |
|
|
988 | |
|
|
989 | delete_character (ob->name, 1); |
|
|
990 | |
|
|
991 | return 1; |
|
|
992 | } |
976 | } |
993 | |
977 | |
994 | void |
978 | void |
995 | flee_player (object *op) |
979 | flee_player (object *op) |
996 | { |
980 | { |
… | |
… | |
1133 | sprintf (putstring, "item name: %s item type: %d weight/value: %d", |
1117 | sprintf (putstring, "item name: %s item type: %d weight/value: %d", |
1134 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1118 | &tmp->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1135 | else |
1119 | else |
1136 | sprintf (putstring, "item name: %s item type: %d weight/value: %d", |
1120 | sprintf (putstring, "item name: %s item type: %d weight/value: %d", |
1137 | &tmp->arch->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
1121 | &tmp->arch->name, tmp->type, (int) (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1)))); |
|
|
1122 | |
1138 | new_draw_info (NDI_UNIQUE, 0, op, putstring); |
1123 | new_draw_info (NDI_UNIQUE, 0, op, putstring); |
1139 | |
|
|
1140 | sprintf (putstring, "...flags: "); |
|
|
1141 | for (k = 0; k < 4; k++) |
|
|
1142 | { |
|
|
1143 | for (j = 0; j < 32; j++) |
|
|
1144 | { |
|
|
1145 | if ((tmp->flags[k] >> j) & 0x01) |
|
|
1146 | { |
|
|
1147 | sprintf (tmpstr, "%d ", k * 32 + j); |
|
|
1148 | strcat (putstring, tmpstr); |
|
|
1149 | } |
|
|
1150 | } |
|
|
1151 | } |
|
|
1152 | new_draw_info (NDI_UNIQUE, 0, op, putstring); |
|
|
1153 | |
|
|
1154 | #if 0 |
|
|
1155 | /* print the flags too */ |
|
|
1156 | for (k = 0; k < 4; k++) |
|
|
1157 | { |
|
|
1158 | fprintf (stderr, "%d [%d] ", k, k * 32 + 31); |
|
|
1159 | for (j = 0; j < 32; j++) |
|
|
1160 | { |
|
|
1161 | fprintf (stderr, "%d", tmp->flags[k] >> (31 - j) & 0x01); |
|
|
1162 | if (!((j + 1) % 4)) |
|
|
1163 | fprintf (stderr, " "); |
|
|
1164 | } |
|
|
1165 | fprintf (stderr, " [%d]\n", k * 32); |
|
|
1166 | } |
|
|
1167 | #endif |
|
|
1168 | } |
1124 | } |
|
|
1125 | |
1169 | /* philosophy: |
1126 | /* philosophy: |
1170 | * It's easy to grab an item type from a pile, as long as it's |
1127 | * It's easy to grab an item type from a pile, as long as it's |
1171 | * generic. This takes no game-time. For more detailed pickups |
1128 | * generic. This takes no game-time. For more detailed pickups |
1172 | * and selections, select-items shoul dbe used. This is a |
1129 | * and selections, select-items should be used. This is a |
1173 | * grab-as-you-run type mode that's really useful for arrows for |
1130 | * grab-as-you-run type mode that's really useful for arrows for |
1174 | * example. |
1131 | * example. |
1175 | * The drawback: right now it has no frontend, so you need to |
1132 | * The drawback: right now it has no frontend, so you need to |
1176 | * stick the bits you want into a calculator in hex mode and then |
1133 | * stick the bits you want into a calculator in hex mode and then |
1177 | * convert to decimal and then 'pickup <#> |
1134 | * convert to decimal and then 'pickup <#> |
… | |
… | |
1677 | return 0; |
1634 | return 0; |
1678 | } |
1635 | } |
1679 | |
1636 | |
1680 | arrow->set_owner (op); |
1637 | arrow->set_owner (op); |
1681 | arrow->skill = bow->skill; |
1638 | arrow->skill = bow->skill; |
1682 | |
|
|
1683 | arrow->direction = dir; |
1639 | arrow->direction = dir; |
1684 | arrow->x = sx; |
|
|
1685 | arrow->y = sy; |
|
|
1686 | |
1640 | |
1687 | if (op->type == PLAYER) |
1641 | if (op->type == PLAYER) |
1688 | { |
1642 | { |
1689 | op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed; |
1643 | op->speed_left = 0.01 - (float) FABS (op->speed) * 100 / bowspeed; |
1690 | op->update_stats (); |
1644 | op->update_stats (); |
… | |
… | |
1705 | |
1659 | |
1706 | /* update the speed */ |
1660 | /* update the speed */ |
1707 | arrow->speed = (float) ((QUERY_FLAG (bow, FLAG_NO_STRENGTH) ? |
1661 | arrow->speed = (float) ((QUERY_FLAG (bow, FLAG_NO_STRENGTH) ? |
1708 | 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 + (float) bow->stats.dam / 7.0; |
1662 | 0 : dam_bonus[op->stats.Str]) + bow->magic + arrow->magic) / 5.0 + (float) bow->stats.dam / 7.0; |
1709 | |
1663 | |
1710 | if (arrow->speed < 1.0) |
1664 | arrow->set_speed (max (arrow->speed, 1.0)); |
1711 | arrow->speed = 1.0; |
|
|
1712 | update_ob_speed (arrow); |
|
|
1713 | arrow->speed_left = 0; |
1665 | arrow->speed_left = 0; |
1714 | |
1666 | |
1715 | if (op->type == PLAYER) |
1667 | if (op->type == PLAYER) |
1716 | { |
1668 | { |
1717 | arrow->stats.wc = 20 - bow->magic - arrow->magic - |
1669 | arrow->stats.wc = 20 - bow->magic - arrow->magic - |
… | |
… | |
1730 | arrow->attacktype |= bow->attacktype; |
1682 | arrow->attacktype |= bow->attacktype; |
1731 | |
1683 | |
1732 | if (bow->slaying) |
1684 | if (bow->slaying) |
1733 | arrow->slaying = bow->slaying; |
1685 | arrow->slaying = bow->slaying; |
1734 | |
1686 | |
1735 | arrow->map = m; |
|
|
1736 | arrow->move_type = MOVE_FLY_LOW; |
1687 | arrow->move_type = MOVE_FLY_LOW; |
1737 | arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; |
1688 | arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; |
1738 | |
1689 | |
1739 | play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); |
1690 | play_sound_map (op->map, op->x, op->y, SOUND_FIRE_ARROW); |
1740 | insert_ob_in_map (arrow, m, op, 0); |
1691 | m->insert (arrow, sx, sy, op); |
1741 | |
1692 | |
1742 | if (!arrow->destroyed ()) |
1693 | if (!arrow->destroyed ()) |
1743 | move_arrow (arrow); |
1694 | move_arrow (arrow); |
1744 | |
1695 | |
1745 | if (op->type == PLAYER) |
1696 | if (op->type == PLAYER) |
… | |
… | |
1771 | } |
1722 | } |
1772 | else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) |
1723 | else if (op->contr->bowtype >= bow_n && op->contr->bowtype <= bow_nw) |
1773 | { |
1724 | { |
1774 | if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) |
1725 | if (!similar_direction (dir, op->contr->bowtype - bow_n + 1)) |
1775 | wcmod = -1; |
1726 | wcmod = -1; |
|
|
1727 | |
1776 | ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y); |
1728 | ret = fire_bow (op, op, NULL, op->contr->bowtype - bow_n + 1, wcmod, op->x, op->y); |
1777 | } |
1729 | } |
1778 | else if (op->contr->bowtype == bow_threewide) |
1730 | else if (op->contr->bowtype == bow_threewide) |
1779 | { |
1731 | { |
1780 | ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); |
1732 | ret = fire_bow (op, op, NULL, dir, 0, op->x, op->y); |
… | |
… | |
1850 | |
1802 | |
1851 | if (item->arch) |
1803 | if (item->arch) |
1852 | { |
1804 | { |
1853 | CLEAR_FLAG (item, FLAG_ANIMATE); |
1805 | CLEAR_FLAG (item, FLAG_ANIMATE); |
1854 | item->face = item->arch->clone.face; |
1806 | item->face = item->arch->clone.face; |
1855 | item->speed = 0; |
1807 | item->set_speed (0); |
1856 | update_ob_speed (item); |
|
|
1857 | } |
1808 | } |
|
|
1809 | |
1858 | if ((tmp = item->in_player ())) |
1810 | if ((tmp = item->in_player ())) |
1859 | esrv_update_item (UPD_ANIM, tmp, item); |
1811 | esrv_update_item (UPD_ANIM, tmp, item); |
1860 | } |
1812 | } |
1861 | } |
1813 | } |
1862 | else if (item->type == ROD || item->type == HORN) |
1814 | else if (item->type == ROD || item->type == HORN) |
1863 | { |
|
|
1864 | drain_rod_charge (item); |
1815 | drain_rod_charge (item); |
1865 | } |
|
|
1866 | } |
1816 | } |
1867 | } |
1817 | } |
1868 | |
1818 | |
1869 | /* Received a fire command for the player - go and do it. |
1819 | /* Received a fire command for the player - go and do it. |
1870 | */ |
1820 | */ |
… | |
… | |
2086 | */ |
2036 | */ |
2087 | if ((op->contr->braced || !move_ob (op, dir, op)) && !out_of_map (op->map, nx, ny)) |
2037 | if ((op->contr->braced || !move_ob (op, dir, op)) && !out_of_map (op->map, nx, ny)) |
2088 | { |
2038 | { |
2089 | if (OUT_OF_REAL_MAP (op->map, nx, ny)) |
2039 | if (OUT_OF_REAL_MAP (op->map, nx, ny)) |
2090 | { |
2040 | { |
2091 | m = get_map_from_coord (op->map, &nx, &ny); |
2041 | m = op->map->xy_find (nx, ny); |
2092 | if (!m) |
2042 | if (!m) |
2093 | return; /* Don't think this should happen */ |
2043 | return; /* Don't think this should happen */ |
2094 | } |
2044 | } |
2095 | else |
2045 | else |
2096 | m = op->map; |
2046 | m = op->map; |
2097 | |
2047 | |
2098 | if ((tmp = GET_MAP_OB (m, nx, ny)) == NULL) |
2048 | if (!(tmp = m->at (nx, ny).bot)) |
2099 | { |
|
|
2100 | /* LOG(llevError,"player_move_attack: GET_MAP_OB returns NULL, but player can not move there.\n"); */ |
|
|
2101 | return; |
2049 | return; |
2102 | } |
|
|
2103 | |
2050 | |
2104 | mon = 0; |
2051 | mon = 0; |
2105 | /* Go through all the objects, and find ones of interest. Only stop if |
2052 | /* Go through all the objects, and find ones of interest. Only stop if |
2106 | * we find a monster - that is something we know we want to attack. |
2053 | * we find a monster - that is something we know we want to attack. |
2107 | * if its a door or barrel (can roll) see if there may be monsters |
2054 | * if its a door or barrel (can roll) see if there may be monsters |
… | |
… | |
2160 | && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) |
2107 | && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) |
2161 | { |
2108 | { |
2162 | /* If we're braced, we don't want to switch places with it */ |
2109 | /* If we're braced, we don't want to switch places with it */ |
2163 | if (op->contr->braced) |
2110 | if (op->contr->braced) |
2164 | return; |
2111 | return; |
|
|
2112 | |
2165 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2113 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2166 | (void) push_ob (mon, dir, op); |
2114 | (void) push_ob (mon, dir, op); |
2167 | if (op->contr->tmp_invis || op->hide) |
2115 | if (op->contr->tmp_invis || op->hide) |
2168 | make_visible (op); |
2116 | make_visible (op); |
|
|
2117 | |
2169 | return; |
2118 | return; |
2170 | } |
2119 | } |
2171 | |
2120 | |
2172 | /* in certain circumstances, you shouldn't attack friendly |
2121 | /* in certain circumstances, you shouldn't attack friendly |
2173 | * creatures. Note that if you are braced, you can't push |
2122 | * creatures. Note that if you are braced, you can't push |
… | |
… | |
2187 | !on_battleground)) |
2136 | !on_battleground)) |
2188 | { |
2137 | { |
2189 | if (!op->contr->braced) |
2138 | if (!op->contr->braced) |
2190 | { |
2139 | { |
2191 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2140 | play_sound_map (op->map, op->x, op->y, SOUND_PUSH_PLAYER); |
2192 | (void) push_ob (mon, dir, op); |
2141 | push_ob (mon, dir, op); |
2193 | } |
2142 | } |
2194 | else |
2143 | else |
2195 | new_draw_info (0, 0, op, "You withhold your attack"); |
2144 | new_draw_info (0, 0, op, "You withhold your attack"); |
2196 | |
2145 | |
2197 | if (op->contr->tmp_invis || op->hide) |
2146 | if (op->contr->tmp_invis || op->hide) |
… | |
… | |
2212 | * Way it works is like this: First, it must have some hit points |
2161 | * Way it works is like this: First, it must have some hit points |
2213 | * and be living. Then, it must be one of the following: |
2162 | * and be living. Then, it must be one of the following: |
2214 | * 1) Not a player, 2) A player, but of a different party. Note |
2163 | * 1) Not a player, 2) A player, but of a different party. Note |
2215 | * that party_number -1 is no party, so attacks can still happen. |
2164 | * that party_number -1 is no party, so attacks can still happen. |
2216 | */ |
2165 | */ |
2217 | |
|
|
2218 | else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && |
2166 | else if ((mon->stats.hp >= 0) && QUERY_FLAG (mon, FLAG_ALIVE) && |
2219 | ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) |
2167 | ((mon->type != PLAYER || op->contr->party == NULL || op->contr->party != mon->contr->party))) |
2220 | { |
2168 | { |
2221 | |
2169 | |
2222 | /* If the player hasn't hit something this tick, and does |
2170 | /* If the player hasn't hit something this tick, and does |
… | |
… | |
2256 | int |
2204 | int |
2257 | move_player (object *op, int dir) |
2205 | move_player (object *op, int dir) |
2258 | { |
2206 | { |
2259 | int pick; |
2207 | int pick; |
2260 | |
2208 | |
2261 | if (op->map == NULL || op->map->in_memory != MAP_IN_MEMORY) |
2209 | if (!op->map || op->map->in_memory != MAP_IN_MEMORY) |
2262 | return 0; |
2210 | return 0; |
2263 | |
2211 | |
2264 | /* Sanity check: make sure dir is valid */ |
2212 | /* Sanity check: make sure dir is valid */ |
2265 | if ((dir < 0) || (dir >= 9)) |
2213 | if ((dir < 0) || (dir >= 9)) |
2266 | { |
2214 | { |
2267 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
2215 | LOG (llevError, "move_player: invalid direction %d\n", dir); |
2268 | return 0; |
2216 | return 0; |
2269 | } |
2217 | } |
2270 | |
2218 | |
2271 | /* peterm: added following line */ |
2219 | /* peterm: added following line */ |
2272 | if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) |
2220 | if (QUERY_FLAG (op, FLAG_CONFUSED) && dir) |
2273 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
2221 | dir = absdir (dir + RANDOM () % 3 + RANDOM () % 3 - 2); |
2274 | |
2222 | |
2275 | op->facing = dir; |
2223 | op->facing = dir; |
2276 | |
2224 | |
… | |
… | |
2354 | |
2302 | |
2355 | /* call this here - we also will call this in do_ericserver, but |
2303 | /* call this here - we also will call this in do_ericserver, but |
2356 | * the players time has been increased when doericserver has been |
2304 | * the players time has been increased when doericserver has been |
2357 | * called, so we recheck it here. |
2305 | * called, so we recheck it here. |
2358 | */ |
2306 | */ |
2359 | //TODO: better than handling 8 commands, use some more intelligent rate-limiting |
2307 | if (op->contr->ns->handle_command ()) |
2360 | for (int rep = 8; --rep && op->contr->ns->handle_command (); ) |
2308 | return 1; |
2361 | ; |
|
|
2362 | |
2309 | |
2363 | if (op->speed_left < 0) |
2310 | if (op->speed_left > 0) |
2364 | return 0; |
2311 | { |
2365 | |
|
|
2366 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2312 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2367 | { |
2313 | { |
2368 | /* All move commands take 1 tick, at least for now */ |
2314 | /* All move commands take 1 tick, at least for now */ |
2369 | op->speed_left--; |
2315 | op->speed_left--; |
2370 | |
2316 | |
2371 | /* Instead of all the stuff below, let move_player take care |
2317 | /* Instead of all the stuff below, let move_player take care |
2372 | * of it. Also, some of the skill stuff is only put in |
2318 | * of it. Also, some of the skill stuff is only put in |
2373 | * there, as well as the confusion stuff. |
2319 | * there, as well as the confusion stuff. |
2374 | */ |
2320 | */ |
2375 | move_player (op, op->direction); |
2321 | move_player (op, op->direction); |
2376 | if (op->speed_left > 0) |
2322 | |
2377 | return 1; |
2323 | return op->speed_left > 0; |
2378 | else |
2324 | } |
2379 | return 0; |
|
|
2380 | } |
2325 | } |
2381 | |
2326 | |
2382 | return 0; |
2327 | return 0; |
2383 | } |
2328 | } |
2384 | |
2329 | |
… | |
… | |
2426 | { |
2371 | { |
2427 | object *next; |
2372 | object *next; |
2428 | |
2373 | |
2429 | while (op) |
2374 | while (op) |
2430 | { |
2375 | { |
2431 | next = op->below; /* Make sure we have a good value, in case |
2376 | object *next = op->below; /* Make sure we have a good value, in case we remove object 'op' */ |
2432 | * we remove object 'op' |
2377 | |
2433 | */ |
|
|
2434 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
2378 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
2435 | { |
2379 | { |
2436 | op->remove (); |
|
|
2437 | op->x = env->x; |
|
|
2438 | op->y = env->y; |
|
|
2439 | if (env->type == PLAYER) |
2380 | if (env->type == PLAYER) |
2440 | esrv_del_item (env->contr, op->count); |
2381 | esrv_del_item (env->contr, op->count); |
2441 | insert_ob_in_map (op, env->map, NULL, 0); |
2382 | |
|
|
2383 | op->insert_at (env); |
2442 | } |
2384 | } |
2443 | else if (op->inv) |
2385 | else if (op->inv) |
2444 | remove_unpaid_objects (op->inv, env); |
2386 | remove_unpaid_objects (op->inv, env); |
2445 | |
2387 | |
2446 | op = next; |
2388 | op = next; |
… | |
… | |
2739 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); |
2681 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "You have been defeated in combat!"); |
2740 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life..."); |
2682 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, op, "Local medics have saved your life..."); |
2741 | |
2683 | |
2742 | /* restore player */ |
2684 | /* restore player */ |
2743 | at = archetype::find ("poisoning"); |
2685 | at = archetype::find ("poisoning"); |
2744 | tmp = present_arch_in_ob (at, op); |
2686 | if (object *tmp = present_arch_in_ob (at, op)) |
2745 | if (tmp) |
|
|
2746 | { |
2687 | { |
2747 | tmp->destroy (); |
2688 | tmp->destroy (); |
2748 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2689 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2749 | } |
2690 | } |
2750 | |
2691 | |
2751 | at = archetype::find ("confusion"); |
2692 | at = archetype::find ("confusion"); |
2752 | tmp = present_arch_in_ob (at, op); |
2693 | if (object *tmp = present_arch_in_ob (at, op)) |
2753 | if (tmp) |
|
|
2754 | { |
2694 | { |
2755 | tmp->destroy (); |
2695 | tmp->destroy (); |
2756 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
2696 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
2757 | } |
2697 | } |
2758 | |
2698 | |
… | |
… | |
2760 | op->stats.hp = op->stats.maxhp; |
2700 | op->stats.hp = op->stats.maxhp; |
2761 | if (op->stats.food <= 0) |
2701 | if (op->stats.food <= 0) |
2762 | op->stats.food = 999; |
2702 | op->stats.food = 999; |
2763 | |
2703 | |
2764 | /* create a bodypart-trophy to make the winner happy */ |
2704 | /* create a bodypart-trophy to make the winner happy */ |
2765 | tmp = arch_to_object (archetype::find ("finger")); |
2705 | if (object *tmp = arch_to_object (archetype::find ("finger"))) |
2766 | if (tmp != NULL) |
|
|
2767 | { |
2706 | { |
2768 | sprintf (buf, "%s's finger", &op->name); |
2707 | sprintf (buf, "%s's finger", &op->name); |
2769 | tmp->name = buf; |
2708 | tmp->name = buf; |
2770 | sprintf (buf, " This finger has been cut off %s\n" |
2709 | sprintf (buf, " This finger has been cut off %s\n" |
2771 | " the %s, when he was defeated at\n level %d by %s.\n", |
2710 | " the %s, when he was defeated at\n level %d by %s.\n", |
2772 | &op->name, op->contr->title, (int) (op->level), op->contr->killer); |
2711 | &op->name, op->contr->title, (int) (op->level), op->contr->killer); |
2773 | tmp->msg = buf; |
2712 | tmp->msg = buf; |
2774 | tmp->value = 0, tmp->material = 0, tmp->type = 0; |
2713 | tmp->value = 0, tmp->material = 0, tmp->type = 0; |
2775 | tmp->materialname = NULL; |
2714 | tmp->materialname = NULL; |
2776 | tmp->x = op->x, tmp->y = op->y; |
2715 | tmp->insert_at (op, tmp); |
2777 | insert_ob_in_map (tmp, op->map, op, 0); |
|
|
2778 | } |
2716 | } |
2779 | |
2717 | |
2780 | /* teleport defeated player to new destination */ |
2718 | /* teleport defeated player to new destination */ |
2781 | transfer_ob (op, x, y, 0, NULL); |
2719 | transfer_ob (op, x, y, 0, NULL); |
2782 | op->contr->braced = 0; |
2720 | op->contr->braced = 0; |
… | |
… | |
2787 | |
2725 | |
2788 | command_kill_pets (op, 0); |
2726 | command_kill_pets (op, 0); |
2789 | |
2727 | |
2790 | if (op->stats.food < 0) |
2728 | if (op->stats.food < 0) |
2791 | { |
2729 | { |
2792 | if (op->contr->explore) |
|
|
2793 | { |
|
|
2794 | new_draw_info (NDI_UNIQUE, 0, op, "You would have starved, but you are"); |
|
|
2795 | new_draw_info (NDI_UNIQUE, 0, op, "in explore mode, so..."); |
|
|
2796 | op->stats.food = 999; |
|
|
2797 | return; |
|
|
2798 | } |
|
|
2799 | sprintf (buf, "%s starved to death.", &op->name); |
2730 | sprintf (buf, "%s starved to death.", &op->name); |
2800 | strcpy (op->contr->killer, "starvation"); |
2731 | strcpy (op->contr->killer, "starvation"); |
2801 | } |
2732 | } |
2802 | else |
2733 | else |
2803 | { |
|
|
2804 | if (op->contr->explore) |
|
|
2805 | { |
|
|
2806 | new_draw_info (NDI_UNIQUE, 0, op, "You would have died, but you are"); |
|
|
2807 | new_draw_info (NDI_UNIQUE, 0, op, "in explore mode, so..."); |
|
|
2808 | op->stats.hp = op->stats.maxhp; |
|
|
2809 | return; |
|
|
2810 | } |
|
|
2811 | sprintf (buf, "%s died.", &op->name); |
2734 | sprintf (buf, "%s died.", &op->name); |
2812 | } |
2735 | |
2813 | play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0); |
2736 | play_sound_player_only (op->contr, SOUND_PLAYER_DIES, 0, 0); |
2814 | |
2737 | |
2815 | /* save the map location for corpse, gravestone */ |
2738 | /* save the map location for corpse, gravestone */ |
2816 | x = op->x; |
2739 | x = op->x; |
2817 | y = op->y; |
2740 | y = op->y; |
2818 | map = op->map; |
2741 | map = op->map; |
2819 | |
|
|
2820 | |
2742 | |
2821 | /* NOT_PERMADEATH code. This basically brings the character back to |
2743 | /* NOT_PERMADEATH code. This basically brings the character back to |
2822 | * life if they are dead - it takes some exp and a random stat. |
2744 | * life if they are dead - it takes some exp and a random stat. |
2823 | * See the config.h file for a little more in depth detail about this. |
2745 | * See the config.h file for a little more in depth detail about this. |
2824 | */ |
2746 | */ |
… | |
… | |
2841 | num_stats_lose = 1; |
2763 | num_stats_lose = 1; |
2842 | else |
2764 | else |
2843 | num_stats_lose = 1 + op->level / BALSL_NUMBER_LOSSES_RATIO; |
2765 | num_stats_lose = 1 + op->level / BALSL_NUMBER_LOSSES_RATIO; |
2844 | } |
2766 | } |
2845 | else |
2767 | else |
2846 | { |
|
|
2847 | num_stats_lose = 1; |
2768 | num_stats_lose = 1; |
2848 | } |
2769 | |
2849 | lost_a_stat = 0; |
2770 | lost_a_stat = 0; |
2850 | |
2771 | |
2851 | for (z = 0; z < num_stats_lose; z++) |
2772 | for (z = 0; z < num_stats_lose; z++) |
2852 | { |
2773 | { |
2853 | i = RANDOM () % NUM_STATS; |
2774 | i = RANDOM () % NUM_STATS; |
… | |
… | |
3011 | /* */ |
2932 | /* */ |
3012 | /****************************************/ |
2933 | /****************************************/ |
3013 | |
2934 | |
3014 | enter_player_savebed (op); |
2935 | enter_player_savebed (op); |
3015 | |
2936 | |
3016 | /* Save the player before inserting the force to reduce |
|
|
3017 | * chance of abuse. |
|
|
3018 | */ |
|
|
3019 | op->contr->braced = 0; |
2937 | op->contr->braced = 0; |
3020 | op->contr->save (); |
|
|
3021 | |
2938 | |
3022 | /* it is possible that the player has blown something up |
2939 | /* it is possible that the player has blown something up |
3023 | * at his savebed location, and that can have long lasting |
2940 | * at his savebed location, and that can have long lasting |
3024 | * spell effects. So first see if there is a spell effect |
2941 | * spell effects. So first see if there is a spell effect |
3025 | * on the space that might harm the player. |
2942 | * on the space that might harm the player. |
… | |
… | |
3095 | */ |
3012 | */ |
3096 | |
3013 | |
3097 | void |
3014 | void |
3098 | fix_weight (void) |
3015 | fix_weight (void) |
3099 | { |
3016 | { |
3100 | for (player *pl = first_player; pl; pl = pl->next) |
3017 | for_all_players (pl) |
3101 | { |
3018 | { |
3102 | int old = pl->ob->carrying, sum = sum_weight (pl->ob); |
3019 | int old = pl->ob->carrying, sum = sum_weight (pl->ob); |
3103 | |
3020 | |
3104 | if (old == sum) |
3021 | if (old == sum) |
3105 | continue; |
3022 | continue; |
… | |
… | |
3109 | } |
3026 | } |
3110 | |
3027 | |
3111 | void |
3028 | void |
3112 | fix_luck (void) |
3029 | fix_luck (void) |
3113 | { |
3030 | { |
3114 | for (player *pl = first_player; pl; pl = pl->next) |
3031 | for_all_players (pl) |
3115 | if (!pl->ob->contr->ns->state) |
3032 | if (!pl->ob->contr->ns->state) |
3116 | pl->ob->change_luck (0); |
3033 | pl->ob->change_luck (0); |
3117 | } |
3034 | } |
3118 | |
3035 | |
3119 | /* cast_dust() - handles op throwing objects of type 'DUST'. |
3036 | /* cast_dust() - handles op throwing objects of type 'DUST'. |
… | |
… | |
3237 | |
3154 | |
3238 | skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); |
3155 | skop = find_obj_by_type_subtype (op, SKILL, SK_HIDING); |
3239 | |
3156 | |
3240 | /* its *extremely* hard to run and sneak/hide at the same time! */ |
3157 | /* its *extremely* hard to run and sneak/hide at the same time! */ |
3241 | if (op->type == PLAYER && op->contr->run_on) |
3158 | if (op->type == PLAYER && op->contr->run_on) |
3242 | { |
|
|
3243 | if (!skop || num >= skop->level) |
3159 | if (!skop || num >= skop->level) |
3244 | { |
3160 | { |
3245 | new_draw_info (NDI_UNIQUE, 0, op, "You ran too much! You are no longer hidden!"); |
3161 | new_draw_info (NDI_UNIQUE, 0, op, "You ran too much! You are no longer hidden!"); |
3246 | make_visible (op); |
3162 | make_visible (op); |
3247 | return; |
3163 | return; |
3248 | } |
3164 | } |
3249 | else |
3165 | else |
3250 | num += 20; |
3166 | num += 20; |
3251 | } |
3167 | |
3252 | num += op->map->difficulty; |
3168 | num += op->map->difficulty; |
3253 | hide = hideability (op); /* modify by terrain hidden level */ |
3169 | hide = hideability (op); /* modify by terrain hidden level */ |
3254 | num -= hide; |
3170 | num -= hide; |
|
|
3171 | |
3255 | if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) |
3172 | if ((op->type == PLAYER && hide < -10) || ((op->invisible -= num) <= 0)) |
3256 | { |
3173 | { |
3257 | make_visible (op); |
3174 | make_visible (op); |
3258 | if (op->type == PLAYER) |
3175 | if (op->type == PLAYER) |
3259 | new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); |
3176 | new_draw_info (NDI_UNIQUE, 0, op, "You moved out of hiding! You are visible!"); |
3260 | } |
3177 | } |
3261 | else if (op->type == PLAYER && skop) |
3178 | else if (op->type == PLAYER && skop) |
3262 | { |
|
|
3263 | change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); |
3179 | change_exp (op, calc_skill_exp (op, NULL, skop), skop->skill, 0); |
3264 | } |
|
|
3265 | } |
3180 | } |
3266 | |
3181 | |
3267 | /* determine if who is standing near a hostile creature. */ |
3182 | /* determine if who is standing near a hostile creature. */ |
3268 | |
3183 | |
3269 | int |
3184 | int |
… | |
… | |
3336 | if (pl->type != PLAYER) |
3251 | if (pl->type != PLAYER) |
3337 | { |
3252 | { |
3338 | LOG (llevError, "player_can_view() called for non-player object\n"); |
3253 | LOG (llevError, "player_can_view() called for non-player object\n"); |
3339 | return -1; |
3254 | return -1; |
3340 | } |
3255 | } |
|
|
3256 | |
3341 | if (!pl || !op) |
3257 | if (!pl || !op) |
3342 | return 0; |
3258 | return 0; |
3343 | |
3259 | |
3344 | if (op->head) |
|
|
3345 | { |
|
|
3346 | op = op->head; |
3260 | op = op->head_ (); |
3347 | } |
3261 | |
3348 | get_rangevector (pl, op, &rv, 0x1); |
3262 | get_rangevector (pl, op, &rv, 0x1); |
3349 | |
3263 | |
3350 | /* starting with the 'head' part, lets loop |
3264 | /* starting with the 'head' part, lets loop |
3351 | * through the object and find if it has any |
3265 | * through the object and find if it has any |
3352 | * part that is in the los array but isnt on |
3266 | * part that is in the los array but isnt on |
… | |
… | |
3482 | if (trlist == NULL || who->type != PLAYER) |
3396 | if (trlist == NULL || who->type != PLAYER) |
3483 | return; |
3397 | return; |
3484 | |
3398 | |
3485 | for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++); |
3399 | for (i = 0, tr = trlist->items; tr != NULL && i < level - 1; tr = tr->next, i++); |
3486 | |
3400 | |
3487 | if (tr == NULL || tr->item == NULL) |
3401 | if (!tr || !tr->item) |
3488 | { |
3402 | { |
3489 | /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */ |
3403 | /* LOG(llevDebug, "-> no more treasure for %s\n", change_resist_msg[atnr]); */ |
3490 | return; |
3404 | return; |
3491 | } |
3405 | } |
3492 | |
3406 | |