… | |
… | |
20 | |
20 | |
21 | The author can be reached via e-mail to <crossfire@schmorp.de> |
21 | The author can be reached via e-mail to <crossfire@schmorp.de> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #ifndef WIN32 /* ---win32 remove headers */ |
|
|
26 | # include <pwd.h> |
25 | #include <pwd.h> |
27 | #endif |
|
|
28 | #ifndef __CEXTRACT__ |
|
|
29 | # include <sproto.h> |
26 | #include <sproto.h> |
30 | #endif |
|
|
31 | #include <sounds.h> |
27 | #include <sounds.h> |
32 | #include <living.h> |
28 | #include <living.h> |
33 | #include <object.h> |
29 | #include <object.h> |
34 | #include <spells.h> |
30 | #include <spells.h> |
35 | #include <skills.h> |
31 | #include <skills.h> |
36 | #include <newclient.h> |
|
|
37 | |
32 | |
38 | #ifdef COZY_SERVER |
33 | #ifdef COZY_SERVER |
39 | extern int same_party (partylist *a, partylist *b); |
34 | extern int same_party (partylist *a, partylist *b); |
40 | #endif |
35 | #endif |
41 | |
36 | |
… | |
… | |
87 | int comp; |
82 | int comp; |
88 | int size; |
83 | int size; |
89 | |
84 | |
90 | sprintf (buf, "%s/%s", settings.confdir, settings.motd); |
85 | sprintf (buf, "%s/%s", settings.confdir, settings.motd); |
91 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
86 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
92 | { |
|
|
93 | return; |
87 | return; |
94 | } |
88 | |
95 | motd[0] = '\0'; |
89 | motd[0] = '\0'; |
96 | size = 0; |
90 | size = 0; |
|
|
91 | |
97 | while (fgets (buf, MAX_BUF, fp) != NULL) |
92 | while (fgets (buf, MAX_BUF, fp) != NULL) |
98 | { |
93 | { |
99 | if (*buf == '#') |
94 | if (*buf == '#') |
100 | continue; |
95 | continue; |
|
|
96 | |
101 | strncat (motd + size, buf, HUGE_BUF - size); |
97 | strncat (motd + size, buf, HUGE_BUF - size); |
102 | size += strlen (buf); |
98 | size += strlen (buf); |
103 | } |
99 | } |
|
|
100 | |
104 | draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL); |
101 | draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_MOTD, MSG_SUBTYPE_NONE, motd, NULL); |
105 | close_and_delete (fp, comp); |
102 | close_and_delete (fp, comp); |
106 | } |
103 | } |
107 | |
104 | |
108 | void |
105 | void |
… | |
… | |
114 | int comp; |
111 | int comp; |
115 | int size; |
112 | int size; |
116 | |
113 | |
117 | sprintf (buf, "%s/%s", settings.confdir, settings.rules); |
114 | sprintf (buf, "%s/%s", settings.confdir, settings.rules); |
118 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
115 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
119 | { |
|
|
120 | return; |
116 | return; |
121 | } |
117 | |
122 | rules[0] = '\0'; |
118 | rules[0] = '\0'; |
123 | size = 0; |
119 | size = 0; |
|
|
120 | |
124 | while (fgets (buf, MAX_BUF, fp) != NULL) |
121 | while (fgets (buf, MAX_BUF, fp) != NULL) |
125 | { |
122 | { |
126 | if (*buf == '#') |
123 | if (*buf == '#') |
127 | continue; |
124 | continue; |
|
|
125 | |
128 | if (size + strlen (buf) >= HUGE_BUF) |
126 | if (size + strlen (buf) >= HUGE_BUF) |
129 | { |
127 | { |
130 | LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF); |
128 | LOG (llevDebug, "Warning, rules size is > %d bytes.\n", HUGE_BUF); |
131 | break; |
129 | break; |
132 | } |
130 | } |
|
|
131 | |
133 | strncat (rules + size, buf, HUGE_BUF - size); |
132 | strncat (rules + size, buf, HUGE_BUF - size); |
134 | size += strlen (buf); |
133 | size += strlen (buf); |
135 | } |
134 | } |
|
|
135 | |
136 | draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL); |
136 | draw_ext_info (NDI_UNIQUE | NDI_GREEN, 0, op, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_RULES, rules, NULL); |
137 | close_and_delete (fp, comp); |
137 | close_and_delete (fp, comp); |
138 | } |
138 | } |
139 | |
139 | |
140 | void |
140 | void |
… | |
… | |
148 | int size; |
148 | int size; |
149 | |
149 | |
150 | sprintf (buf, "%s/%s", settings.confdir, settings.news); |
150 | sprintf (buf, "%s/%s", settings.confdir, settings.news); |
151 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
151 | if ((fp = open_and_uncompress (buf, 0, &comp)) == NULL) |
152 | return; |
152 | return; |
|
|
153 | |
153 | news[0] = '\0'; |
154 | news[0] = '\0'; |
154 | subject[0] = '\0'; |
155 | subject[0] = '\0'; |
155 | size = 0; |
156 | size = 0; |
|
|
157 | |
156 | while (fgets (buf, MAX_BUF, fp) != NULL) |
158 | while (fgets (buf, MAX_BUF, fp) != NULL) |
157 | { |
159 | { |
158 | if (*buf == '#') |
160 | if (*buf == '#') |
159 | continue; |
161 | continue; |
|
|
162 | |
160 | if (*buf == '%') |
163 | if (*buf == '%') |
161 | { /* send one news */ |
164 | { /* send one news */ |
162 | if (size > 0) |
165 | if (size > 0) |
163 | 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 */ |
166 | 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 */ |
164 | strcpy (subject, buf + 1); |
167 | strcpy (subject, buf + 1); |
… | |
… | |
191 | return 0; |
194 | return 0; |
192 | |
195 | |
193 | for (; *cp != '\0'; cp++) |
196 | for (; *cp != '\0'; cp++) |
194 | if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_') |
197 | if (!((*cp >= 'a' && *cp <= 'z') || (*cp >= 'A' && *cp <= 'Z')) && *cp != '-' && *cp != '_') |
195 | return 0; |
198 | return 0; |
|
|
199 | |
196 | return 1; |
200 | return 1; |
197 | } |
201 | } |
198 | |
202 | |
199 | /* This no longer sets the player map. Also, it now updates |
203 | /* This no longer sets the player map. Also, it now updates |
200 | * all the pointers so the caller doesn't need to do that. |
204 | * all the pointers so the caller doesn't need to do that. |
… | |
… | |
208 | * the one that is passed. |
212 | * the one that is passed. |
209 | */ |
213 | */ |
210 | static player * |
214 | static player * |
211 | get_player (player *p) |
215 | get_player (player *p) |
212 | { |
216 | { |
213 | object *op = arch_to_object (get_player_archetype (NULL)); |
217 | object *op = arch_to_object (get_player_archetype (0)); |
214 | int i; |
218 | int i; |
215 | |
|
|
216 | if (!p) |
|
|
217 | { |
|
|
218 | p = new player; |
|
|
219 | |
|
|
220 | /* This adds the player in the linked list. There is extra |
|
|
221 | * complexity here because we want to add the new player at the |
|
|
222 | * end of the list - there is in fact no compelling reason that |
|
|
223 | * that needs to be done except for things like output of |
|
|
224 | * 'who'. |
|
|
225 | */ |
|
|
226 | player *tmp = first_player; |
|
|
227 | |
|
|
228 | while (tmp != NULL && tmp->next != NULL) |
|
|
229 | tmp = tmp->next; |
|
|
230 | if (tmp != NULL) |
|
|
231 | tmp->next = p; |
|
|
232 | else |
|
|
233 | first_player = p; |
|
|
234 | |
|
|
235 | p->next = NULL; |
|
|
236 | } |
|
|
237 | |
219 | |
238 | /* Clears basically the entire player structure except |
220 | /* Clears basically the entire player structure except |
239 | * for next and socket. |
221 | * for next and socket. |
240 | */ |
222 | */ |
241 | p->clear (); |
223 | p->clear (); |
… | |
… | |
260 | op->speed_left = 0.5; |
242 | op->speed_left = 0.5; |
261 | op->speed = 1.0; |
243 | op->speed = 1.0; |
262 | op->direction = 5; /* So player faces south */ |
244 | op->direction = 5; /* So player faces south */ |
263 | op->stats.wc = 2; |
245 | op->stats.wc = 2; |
264 | op->run_away = 25; /* Then we panick... */ |
246 | op->run_away = 25; /* Then we panick... */ |
|
|
247 | |
|
|
248 | { |
|
|
249 | int oldmon = p->socket->monitor_spells; // what a hack |
265 | p->socket.monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ |
250 | p->socket->monitor_spells = 0; /* Needed because esrv_update_spells( ) gets called by roll_stats */ |
266 | |
|
|
267 | roll_stats (op); |
251 | roll_stats (op); |
|
|
252 | p->socket->monitor_spells = oldmon; |
|
|
253 | } |
268 | p->state = ST_ROLL_STAT; |
254 | p->state = ST_ROLL_STAT; |
269 | clear_los (op); |
255 | clear_los (op); |
270 | |
256 | |
271 | p->gen_sp_armour = 10; |
257 | p->gen_sp_armour = 10; |
272 | p->last_speed = -1; |
258 | p->last_speed = -1; |
… | |
… | |
277 | p->usekeys = containers; |
263 | p->usekeys = containers; |
278 | p->last_weapon_sp = -1; |
264 | p->last_weapon_sp = -1; |
279 | p->peaceful = 1; /* default peaceful */ |
265 | p->peaceful = 1; /* default peaceful */ |
280 | p->do_los = 1; |
266 | p->do_los = 1; |
281 | p->explore = 0; |
267 | p->explore = 0; |
282 | p->no_shout = 0; /* default can shout */ |
|
|
283 | |
268 | |
284 | assign (p->title, op->arch->clone.name); |
269 | assign (p->title, op->arch->clone.name); |
285 | op->race = op->arch->clone.race; |
270 | op->race = op->arch->clone.race; |
286 | |
271 | |
287 | CLEAR_FLAG (op, FLAG_READY_SKILL); |
272 | CLEAR_FLAG (op, FLAG_READY_SKILL); |
… | |
… | |
294 | for (i = 0; i < NUM_SKILLS; i++) |
279 | for (i = 0; i < NUM_SKILLS; i++) |
295 | { |
280 | { |
296 | p->last_skill_exp[i] = -1; |
281 | p->last_skill_exp[i] = -1; |
297 | p->last_skill_ob[i] = NULL; |
282 | p->last_skill_ob[i] = NULL; |
298 | } |
283 | } |
|
|
284 | |
299 | for (i = 0; i < NROFATTACKS; i++) |
285 | for (i = 0; i < NROFATTACKS; i++) |
300 | { |
|
|
301 | p->last_resist[i] = -1; |
286 | p->last_resist[i] = -1; |
302 | } |
287 | |
303 | p->last_stats.exp = -1; |
288 | p->last_stats.exp = -1; |
304 | p->last_weight = (uint32) - 1; |
289 | p->last_weight = (uint32) - 1; |
305 | |
290 | |
306 | p->socket.update_look = 0; |
291 | p->socket->update_look = 0; |
307 | p->socket.look_position = 0; |
292 | p->socket->look_position = 0; |
|
|
293 | |
308 | return p; |
294 | return p; |
309 | } |
295 | } |
310 | |
296 | |
311 | /* This loads the first map an puts the player on it. */ |
297 | /* This loads the first map an puts the player on it. */ |
312 | static void |
298 | static void |
313 | set_first_map (object *op) |
299 | set_first_map (object *op) |
314 | { |
300 | { |
315 | strcpy (op->contr->maplevel, first_map_path); |
301 | strcpy (op->contr->maplevel, first_map_path); |
316 | op->x = -1; |
302 | op->x = -1; |
317 | op->y = -1; |
303 | op->y = -1; |
318 | enter_exit (op, NULL); |
304 | enter_exit (op, 0); |
319 | } |
305 | } |
320 | |
306 | |
321 | /* Tries to add player on the connection passwd in ns. |
307 | /* Tries to add player on the connection passwd in ns. |
322 | * All we can really get in this is some settings like host and display |
308 | * All we can really get in this is some settings like host and display |
323 | * mode. |
309 | * mode. |
324 | */ |
310 | */ |
325 | |
311 | |
326 | int |
312 | int |
327 | add_player (NewSocket * ns) |
313 | add_player (client *ns) |
328 | { |
314 | { |
329 | player *p; |
315 | player *p = new player; |
330 | |
316 | |
331 | p = get_player (NULL); |
|
|
332 | p->socket = *ns; |
317 | p->socket = ns; |
333 | p->socket.faces_sent = (uint8 *) malloc (p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); |
318 | ns->pl = p; |
334 | |
319 | |
335 | if (p->socket.faces_sent == NULL) |
320 | p->next = first_player; |
336 | fatal (OUT_OF_MEMORY); |
321 | first_player = p; |
337 | |
322 | |
338 | memcpy (p->socket.faces_sent, ns->faces_sent, p->socket.faces_sent_len * sizeof (*p->socket.faces_sent)); |
323 | p = get_player (p); |
339 | /* Needed because the socket we just copied over needs to be cleared. |
324 | |
340 | * Note that this can result in a client reset if there is partial data |
|
|
341 | * on the uncoming socket. |
|
|
342 | */ |
|
|
343 | p->socket.inbuf.len = 0; |
|
|
344 | set_first_map (p->ob); |
325 | set_first_map (p->ob); |
345 | |
326 | |
346 | CLEAR_FLAG (p->ob, FLAG_FRIENDLY); |
327 | CLEAR_FLAG (p->ob, FLAG_FRIENDLY); |
347 | add_friendly_object (p->ob); |
328 | add_friendly_object (p->ob); |
348 | send_rules (p->ob); |
329 | send_rules (p->ob); |
… | |
… | |
367 | { |
348 | { |
368 | if (at == NULL || at->next == NULL) |
349 | if (at == NULL || at->next == NULL) |
369 | at = first_archetype; |
350 | at = first_archetype; |
370 | else |
351 | else |
371 | at = at->next; |
352 | at = at->next; |
|
|
353 | |
372 | if (at->clone.type == PLAYER) |
354 | if (at->clone.type == PLAYER) |
373 | return at; |
355 | return at; |
|
|
356 | |
374 | if (at == start) |
357 | if (at == start) |
375 | { |
358 | { |
376 | LOG (llevError, "No Player archetypes\n"); |
359 | LOG (llevError, "No Player archetypes\n"); |
377 | exit (-1); |
360 | exit (-1); |
378 | } |
361 | } |
379 | } |
362 | } |
380 | } |
363 | } |
381 | |
|
|
382 | |
364 | |
383 | object * |
365 | object * |
384 | get_nearest_player (object *mon) |
366 | get_nearest_player (object *mon) |
385 | { |
367 | { |
386 | object *op = NULL; |
368 | object *op = NULL; |
… | |
… | |
646 | (op->type == ARMOUR || op->type == BOOTS || |
628 | (op->type == ARMOUR || op->type == BOOTS || |
647 | op->type == CLOAK || op->type == HELMET || |
629 | op->type == CLOAK || op->type == HELMET || |
648 | op->type == SHIELD || op->type == GLOVES || |
630 | op->type == SHIELD || op->type == GLOVES || |
649 | op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) |
631 | op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) |
650 | { |
632 | { |
651 | remove_ob (op); |
633 | op->destroy (); |
652 | free_object (op); |
|
|
653 | continue; |
634 | continue; |
654 | } |
635 | } |
655 | } |
636 | } |
656 | |
637 | |
657 | /* This really needs to be better - we should really give |
638 | /* This really needs to be better - we should really give |
… | |
… | |
668 | if (tmp->type == op->type && tmp->name == op->name) |
649 | if (tmp->type == op->type && tmp->name == op->name) |
669 | break; |
650 | break; |
670 | |
651 | |
671 | if (tmp) |
652 | if (tmp) |
672 | { |
653 | { |
673 | remove_ob (op); |
654 | op->destroy (); |
674 | free_object (op); |
|
|
675 | LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); |
655 | LOG (llevError, "give_initial_items: Removing duplicate object %s\n", &tmp->name); |
676 | continue; |
656 | continue; |
677 | } |
657 | } |
|
|
658 | |
678 | if (op->nrof > 1) |
659 | if (op->nrof > 1) |
679 | op->nrof = 1; |
660 | op->nrof = 1; |
680 | } |
661 | } |
681 | |
662 | |
682 | if (op->type == SPELLBOOK && op->inv) |
663 | if (op->type == SPELLBOOK && op->inv) |
… | |
… | |
694 | CLEAR_FLAG (op, FLAG_CURSED); |
675 | CLEAR_FLAG (op, FLAG_CURSED); |
695 | CLEAR_FLAG (op, FLAG_DAMNED); |
676 | CLEAR_FLAG (op, FLAG_DAMNED); |
696 | } |
677 | } |
697 | if (op->type == SPELL) |
678 | if (op->type == SPELL) |
698 | { |
679 | { |
699 | remove_ob (op); |
680 | op->destroy (); |
700 | free_object (op); |
|
|
701 | continue; |
681 | continue; |
702 | } |
682 | } |
703 | else if (op->type == SKILL) |
683 | else if (op->type == SKILL) |
704 | { |
684 | { |
705 | SET_FLAG (op, FLAG_CAN_USE_SKILL); |
685 | SET_FLAG (op, FLAG_CAN_USE_SKILL); |
… | |
… | |
718 | void |
698 | void |
719 | get_name (object *op) |
699 | get_name (object *op) |
720 | { |
700 | { |
721 | op->contr->write_buf[0] = '\0'; |
701 | op->contr->write_buf[0] = '\0'; |
722 | op->contr->state = ST_GET_NAME; |
702 | op->contr->state = ST_GET_NAME; |
723 | send_query (&op->contr->socket, 0, "What is your name?\n:"); |
703 | send_query (op->contr->socket, 0, "What is your name?\n:"); |
724 | } |
704 | } |
725 | |
705 | |
726 | void |
706 | void |
727 | get_password (object *op) |
707 | get_password (object *op) |
728 | { |
708 | { |
729 | op->contr->write_buf[0] = '\0'; |
709 | op->contr->write_buf[0] = '\0'; |
730 | op->contr->state = ST_GET_PASSWORD; |
710 | op->contr->state = ST_GET_PASSWORD; |
731 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); |
711 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is your password?\n:"); |
732 | } |
712 | } |
733 | |
713 | |
734 | void |
714 | void |
735 | play_again (object *op) |
715 | play_again (object *op) |
736 | { |
716 | { |
737 | op->contr->state = ST_PLAY_AGAIN; |
717 | op->contr->state = ST_PLAY_AGAIN; |
738 | op->chosen_skill = NULL; |
718 | op->chosen_skill = NULL; |
739 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); |
719 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Do you want to play again (a/q)?"); |
740 | /* a bit of a hack, but there are various places early in th |
720 | /* a bit of a hack, but there are various places early in th |
741 | * player creation process that a user can quit (eg, roll |
721 | * player creation process that a user can quit (eg, roll |
742 | * stats) that isn't removing the player. Taking a quick |
722 | * stats) that isn't removing the player. Taking a quick |
743 | * look, there are many places that call play_again without |
723 | * look, there are many places that call play_again without |
744 | * removing the player - it probably makes more sense |
724 | * removing the player - it probably makes more sense |
745 | * to leave it to play_again to remove the object in all |
725 | * to leave it to play_again to remove the object in all |
746 | * cases. |
726 | * cases. |
747 | */ |
727 | */ |
748 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
728 | if (!QUERY_FLAG (op, FLAG_REMOVED)) |
749 | remove_ob (op); |
729 | op->remove (); |
750 | /* Need to set this to null - otherwise, it could point to garbage, |
730 | /* Need to set this to null - otherwise, it could point to garbage, |
751 | * and draw() doesn't check to see if the player is removed, only if |
731 | * and draw() doesn't check to see if the player is removed, only if |
752 | * the map is null or not swapped out. |
732 | * the map is null or not swapped out. |
753 | */ |
733 | */ |
754 | op->map = NULL; |
734 | op->map = NULL; |
… | |
… | |
793 | confirm_password (object *op) |
773 | confirm_password (object *op) |
794 | { |
774 | { |
795 | |
775 | |
796 | op->contr->write_buf[0] = '\0'; |
776 | op->contr->write_buf[0] = '\0'; |
797 | op->contr->state = ST_CONFIRM_PASSWORD; |
777 | op->contr->state = ST_CONFIRM_PASSWORD; |
798 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); |
778 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "Please type your password again.\n:"); |
799 | } |
779 | } |
800 | |
780 | |
801 | void |
781 | void |
802 | get_party_password (object *op, partylist *party) |
782 | get_party_password (object *op, partylist *party) |
803 | { |
783 | { |
… | |
… | |
807 | return; |
787 | return; |
808 | } |
788 | } |
809 | op->contr->write_buf[0] = '\0'; |
789 | op->contr->write_buf[0] = '\0'; |
810 | op->contr->state = ST_GET_PARTY_PASSWORD; |
790 | op->contr->state = ST_GET_PARTY_PASSWORD; |
811 | op->contr->party_to_join = party; |
791 | op->contr->party_to_join = party; |
812 | send_query (&op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
792 | send_query (op->contr->socket, CS_QUERY_HIDEINPUT, "What is the password?\n:"); |
813 | } |
793 | } |
814 | |
794 | |
815 | |
795 | |
816 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
796 | /* This rolls four 1-6 rolls and sums the best 3 of the 4. */ |
817 | int |
797 | int |
… | |
… | |
914 | |
894 | |
915 | void |
895 | void |
916 | Roll_Again (object *op) |
896 | Roll_Again (object *op) |
917 | { |
897 | { |
918 | esrv_new_player (op->contr, 0); |
898 | esrv_new_player (op->contr, 0); |
919 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, |
899 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, |
920 | "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? "); |
900 | "[y] to roll new stats [n] to use stats\n[1-7] [1-7] to swap stats.\nRoll again (y/n/1-7)? "); |
921 | } |
901 | } |
922 | |
902 | |
923 | void |
903 | void |
924 | Swap_Stat (object *op, int Swap_Second) |
904 | Swap_Stat (object *op, int Swap_Second) |
… | |
… | |
991 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
971 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
992 | } |
972 | } |
993 | else |
973 | else |
994 | Swap_Stat (op, stat_trans[keynum]); |
974 | Swap_Stat (op, stat_trans[keynum]); |
995 | |
975 | |
996 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
976 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
997 | return 1; |
977 | return 1; |
998 | } |
978 | } |
999 | switch (key) |
979 | switch (key) |
1000 | { |
980 | { |
1001 | case 'n': |
981 | case 'n': |
… | |
… | |
1015 | enter_exit (op, NULL); |
995 | enter_exit (op, NULL); |
1016 | #endif |
996 | #endif |
1017 | SET_ANIMATION (op, 2); /* So player faces south */ |
997 | SET_ANIMATION (op, 2); /* So player faces south */ |
1018 | /* Enter exit adds a player otherwise */ |
998 | /* Enter exit adds a player otherwise */ |
1019 | add_statbonus (op); |
999 | add_statbonus (op); |
1020 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, |
1000 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, |
1021 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); |
1001 | "Now choose a character.\nPress any key to change outlook.\nPress `d' when you're pleased.\n"); |
1022 | op->contr->state = ST_CHANGE_CLASS; |
1002 | op->contr->state = ST_CHANGE_CLASS; |
1023 | if (op->msg) |
1003 | if (op->msg) |
1024 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1004 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1025 | return 0; |
1005 | return 0; |
1026 | } |
1006 | } |
1027 | case 'y': |
1007 | case 'y': |
1028 | case 'Y': |
1008 | case 'Y': |
1029 | roll_stats (op); |
1009 | roll_stats (op); |
1030 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
1010 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, ""); |
1031 | return 1; |
1011 | return 1; |
1032 | |
1012 | |
1033 | case 'q': |
1013 | case 'q': |
1034 | case 'Q': |
1014 | case 'Q': |
1035 | play_again (op); |
1015 | play_again (op); |
1036 | return 1; |
1016 | return 1; |
1037 | |
1017 | |
1038 | default: |
1018 | default: |
1039 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); |
1019 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Yes, No, Quit or 1-6. Roll again?"); |
1040 | return 0; |
1020 | return 0; |
1041 | } |
1021 | } |
1042 | return 0; |
1022 | return 0; |
1043 | } |
1023 | } |
1044 | |
1024 | |
… | |
… | |
1054 | { |
1034 | { |
1055 | int tmp_loop; |
1035 | int tmp_loop; |
1056 | |
1036 | |
1057 | if (key == 'q' || key == 'Q') |
1037 | if (key == 'q' || key == 'Q') |
1058 | { |
1038 | { |
1059 | remove_ob (op); |
1039 | op->remove (); |
1060 | play_again (op); |
1040 | play_again (op); |
1061 | return 0; |
1041 | return 0; |
1062 | } |
1042 | } |
1063 | if (key == 'd' || key == 'D') |
1043 | if (key == 'd' || key == 'D') |
1064 | { |
1044 | { |
1065 | char buf[MAX_BUF]; |
1045 | char buf[MAX_BUF]; |
1066 | |
1046 | |
1067 | /* this must before then initial items are given */ |
1047 | /* this must before then initial items are given */ |
1068 | esrv_new_player (op->contr, op->weight + op->carrying); |
1048 | esrv_new_player (op->contr, op->weight + op->carrying); |
|
|
1049 | |
1069 | create_treasure (find_treasurelist ("starting_wealth"), op, 0, 0, 0); |
1050 | treasurelist *tl = find_treasurelist ("starting_wealth"); |
|
|
1051 | if (tl) |
|
|
1052 | create_treasure (tl, op, 0, 0, 0); |
1070 | |
1053 | |
1071 | INVOKE_PLAYER (BIRTH, op->contr); |
1054 | INVOKE_PLAYER (BIRTH, op->contr); |
1072 | INVOKE_PLAYER (LOGIN, op->contr); |
1055 | INVOKE_PLAYER (LOGIN, op->contr); |
1073 | |
1056 | |
1074 | op->contr->state = ST_PLAYING; |
1057 | op->contr->state = ST_PLAYING; |
… | |
… | |
1099 | { |
1082 | { |
1100 | object *tmp; |
1083 | object *tmp; |
1101 | char mapname[MAX_BUF]; |
1084 | char mapname[MAX_BUF]; |
1102 | |
1085 | |
1103 | snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); |
1086 | snprintf (mapname, MAX_BUF - 1, "%s/%s", first_map_ext_path, &op->arch->name); |
1104 | tmp = get_object (); |
1087 | tmp = object::create (); |
1105 | EXIT_PATH (tmp) = mapname; |
1088 | EXIT_PATH (tmp) = mapname; |
1106 | EXIT_X (tmp) = op->x; |
1089 | EXIT_X (tmp) = op->x; |
1107 | EXIT_Y (tmp) = op->y; |
1090 | EXIT_Y (tmp) = op->y; |
1108 | enter_exit (op, tmp); /* we don't really care if it succeeded; |
1091 | enter_exit (op, tmp); /* we don't really care if it succeeded; |
1109 | * if the map isn't there, then stay on the |
1092 | * if the map isn't there, then stay on the |
1110 | * default initial map */ |
1093 | * default initial map */ |
1111 | free_object (tmp); |
1094 | tmp->destroy (); |
1112 | } |
1095 | } |
1113 | else |
1096 | else |
1114 | { |
|
|
1115 | LOG (llevDebug, "first_map_ext_path not set\n"); |
1097 | LOG (llevDebug, "first_map_ext_path not set\n"); |
1116 | } |
1098 | |
1117 | return 0; |
1099 | return 0; |
1118 | } |
1100 | } |
1119 | |
1101 | |
1120 | /* Following actually changes the race - this is the default command |
1102 | /* Following actually changes the race - this is the default command |
1121 | * if we don't match with one of the options above. |
1103 | * if we don't match with one of the options above. |
… | |
… | |
1126 | { |
1108 | { |
1127 | shstr name = op->name; |
1109 | shstr name = op->name; |
1128 | int x = op->x, y = op->y; |
1110 | int x = op->x, y = op->y; |
1129 | |
1111 | |
1130 | remove_statbonus (op); |
1112 | remove_statbonus (op); |
1131 | remove_ob (op); |
1113 | op->remove (); |
1132 | op->arch = get_player_archetype (op->arch); |
1114 | op->arch = get_player_archetype (op->arch); |
1133 | copy_object (&op->arch->clone, op); |
1115 | op->arch->clone.copy_to (op); |
1134 | op->instantiate (); |
1116 | op->instantiate (); |
1135 | op->stats = op->contr->orig_stats; |
1117 | op->stats = op->contr->orig_stats; |
1136 | op->name = op->name_pl = name; |
1118 | op->name = op->name_pl = name; |
1137 | op->x = x; |
1119 | op->x = x; |
1138 | op->y = y; |
1120 | op->y = y; |
… | |
… | |
1151 | op->stats.grace = 0; |
1133 | op->stats.grace = 0; |
1152 | |
1134 | |
1153 | if (op->msg) |
1135 | if (op->msg) |
1154 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1136 | new_draw_info (NDI_BLUE, 0, op, op->msg); |
1155 | |
1137 | |
1156 | send_query (&op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
1138 | send_query (op->contr->socket, CS_QUERY_SINGLECHAR, "Press any key for the next race.\nPress `d' to play this race.\n"); |
1157 | return 0; |
1139 | return 0; |
1158 | } |
1140 | } |
1159 | |
1141 | |
1160 | int |
1142 | int |
1161 | key_confirm_quit (object *op, char key) |
1143 | key_confirm_quit (object *op, char key) |
… | |
… | |
1818 | if (!dir) |
1800 | if (!dir) |
1819 | { |
1801 | { |
1820 | new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); |
1802 | new_draw_info (NDI_UNIQUE, 0, op, "You can't shoot yourself!"); |
1821 | return 0; |
1803 | return 0; |
1822 | } |
1804 | } |
|
|
1805 | |
1823 | if (op->type == PLAYER) |
1806 | if (op->type == PLAYER) |
1824 | bow = op->contr->ranges[range_bow]; |
1807 | bow = op->contr->ranges[range_bow]; |
1825 | else |
1808 | else |
1826 | { |
1809 | { |
1827 | for (bow = op->inv; bow; bow = bow->below) |
1810 | for (bow = op->inv; bow; bow = bow->below) |
… | |
… | |
1835 | { |
1818 | { |
1836 | LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name); |
1819 | LOG (llevError, "Range: bow without activated bow (%s).\n", &op->name); |
1837 | return 0; |
1820 | return 0; |
1838 | } |
1821 | } |
1839 | } |
1822 | } |
|
|
1823 | |
1840 | if (!bow->race || !bow->skill) |
1824 | if (!bow->race || !bow->skill) |
1841 | { |
1825 | { |
1842 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); |
1826 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s is broken.", &bow->name); |
1843 | return 0; |
1827 | return 0; |
1844 | } |
1828 | } |
… | |
… | |
1846 | bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex]; |
1830 | bowspeed = bow->stats.sp + dex_bonus[op->stats.Dex]; |
1847 | |
1831 | |
1848 | /* penalize ROF for bestarrow */ |
1832 | /* penalize ROF for bestarrow */ |
1849 | if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow) |
1833 | if (op->type == PLAYER && op->contr->bowtype == bow_bestarrow) |
1850 | bowspeed -= dex_bonus[op->stats.Dex] + 5; |
1834 | bowspeed -= dex_bonus[op->stats.Dex] + 5; |
|
|
1835 | |
1851 | if (bowspeed < 1) |
1836 | if (bowspeed < 1) |
1852 | bowspeed = 1; |
1837 | bowspeed = 1; |
1853 | |
1838 | |
1854 | if (arrow == NULL) |
1839 | if (arrow == NULL) |
1855 | { |
1840 | { |
… | |
… | |
1861 | else |
1846 | else |
1862 | CLEAR_FLAG (op, FLAG_READY_BOW); |
1847 | CLEAR_FLAG (op, FLAG_READY_BOW); |
1863 | return 0; |
1848 | return 0; |
1864 | } |
1849 | } |
1865 | } |
1850 | } |
|
|
1851 | |
1866 | mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy); |
1852 | mflags = get_map_flags (op->map, &m, sx, sy, &sx, &sy); |
1867 | if (mflags & P_OUT_OF_MAP) |
1853 | if (mflags & P_OUT_OF_MAP) |
1868 | { |
|
|
1869 | return 0; |
1854 | return 0; |
1870 | } |
1855 | |
1871 | if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW) |
1856 | if (GET_MAP_MOVE_BLOCK (m, sx, sy) == MOVE_FLY_LOW) |
1872 | { |
1857 | { |
1873 | new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); |
1858 | new_draw_info (NDI_UNIQUE, 0, op, "Something is in the way."); |
1874 | return 0; |
1859 | return 0; |
1875 | } |
1860 | } |
1876 | |
1861 | |
1877 | /* this should not happen, but sometimes does */ |
1862 | /* this should not happen, but sometimes does */ |
1878 | if (arrow->nrof == 0) |
1863 | if (arrow->nrof == 0) |
1879 | { |
1864 | { |
1880 | remove_ob (arrow); |
1865 | arrow->destroy (); |
1881 | free_object (arrow); |
|
|
1882 | return 0; |
1866 | return 0; |
1883 | } |
1867 | } |
1884 | |
1868 | |
1885 | left = arrow; /* these are arrows left to the player */ |
1869 | left = arrow; /* these are arrows left to the player */ |
1886 | arrow = get_split_ob (arrow, 1); |
1870 | arrow = get_split_ob (arrow, 1); |
1887 | if (arrow == NULL) |
1871 | if (!arrow) |
1888 | { |
1872 | { |
1889 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1873 | new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); |
1890 | return 0; |
1874 | return 0; |
1891 | } |
1875 | } |
1892 | set_owner (arrow, op); |
1876 | |
|
|
1877 | arrow->set_owner (op); |
1893 | arrow->skill = bow->skill; |
1878 | arrow->skill = bow->skill; |
1894 | |
1879 | |
1895 | arrow->direction = dir; |
1880 | arrow->direction = dir; |
1896 | arrow->x = sx; |
1881 | arrow->x = sx; |
1897 | arrow->y = sy; |
1882 | arrow->y = sy; |
… | |
… | |
1905 | SET_ANIMATION (arrow, arrow->direction); |
1890 | SET_ANIMATION (arrow, arrow->direction); |
1906 | arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ |
1891 | arrow->stats.sp = arrow->stats.wc; /* save original wc and dam */ |
1907 | arrow->stats.hp = arrow->stats.dam; |
1892 | arrow->stats.hp = arrow->stats.dam; |
1908 | arrow->stats.grace = arrow->attacktype; |
1893 | arrow->stats.grace = arrow->attacktype; |
1909 | if (arrow->slaying != NULL) |
1894 | if (arrow->slaying != NULL) |
1910 | arrow->spellarg = strdup_local (arrow->slaying); |
1895 | arrow->spellarg = strdup (arrow->slaying); |
1911 | |
1896 | |
1912 | /* Note that this was different for monsters - they got their level |
1897 | /* Note that this was different for monsters - they got their level |
1913 | * added to the damage. I think the strength bonus is more proper. |
1898 | * added to the damage. I think the strength bonus is more proper. |
1914 | */ |
1899 | */ |
1915 | |
1900 | |
… | |
… | |
1939 | } |
1924 | } |
1940 | |
1925 | |
1941 | if (arrow->attacktype == AT_PHYSICAL) |
1926 | if (arrow->attacktype == AT_PHYSICAL) |
1942 | arrow->attacktype |= bow->attacktype; |
1927 | arrow->attacktype |= bow->attacktype; |
1943 | |
1928 | |
1944 | if (bow->slaying != NULL) |
1929 | if (bow->slaying) |
1945 | arrow->slaying = bow->slaying; |
1930 | arrow->slaying = bow->slaying; |
1946 | |
1931 | |
1947 | arrow->map = m; |
1932 | arrow->map = m; |
1948 | arrow->move_type = MOVE_FLY_LOW; |
1933 | arrow->move_type = MOVE_FLY_LOW; |
1949 | arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; |
1934 | arrow->move_on = MOVE_FLY_LOW | MOVE_WALK; |
… | |
… | |
2105 | case range_misc: |
2090 | case range_misc: |
2106 | fire_misc_object (op, dir); |
2091 | fire_misc_object (op, dir); |
2107 | return; |
2092 | return; |
2108 | |
2093 | |
2109 | case range_golem: /* Control summoned monsters from scrolls */ |
2094 | case range_golem: /* Control summoned monsters from scrolls */ |
2110 | if (op->contr->ranges[range_golem] == NULL || op->contr->golem_count != op->contr->ranges[range_golem]->count) |
2095 | if (QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED)) |
2111 | { |
2096 | { |
2112 | op->contr->ranges[range_golem] = NULL; |
2097 | op->contr->ranges[range_golem] = 0; |
2113 | op->contr->shoottype = range_none; |
2098 | op->contr->shoottype = range_none; |
2114 | op->contr->golem_count = 0; |
|
|
2115 | } |
2099 | } |
2116 | else |
2100 | else |
2117 | control_golem (op->contr->ranges[range_golem], dir); |
2101 | control_golem (op->contr->ranges[range_golem], dir); |
2118 | return; |
2102 | return; |
2119 | |
2103 | |
… | |
… | |
2365 | * player owns it and it is either friendly or unagressive. |
2349 | * player owns it and it is either friendly or unagressive. |
2366 | */ |
2350 | */ |
2367 | if ((op->type == PLAYER) |
2351 | if ((op->type == PLAYER) |
2368 | #if COZY_SERVER |
2352 | #if COZY_SERVER |
2369 | && |
2353 | && |
2370 | ((get_owner (mon) && get_owner (mon)->contr |
2354 | ((mon->owner && mon->owner->contr |
2371 | && same_party (get_owner (mon)->contr->party, op->contr->party)) || get_owner (mon) == op) |
2355 | && same_party (mon->owner->contr->party, op->contr->party)) || mon->owner == op) |
2372 | #else |
2356 | #else |
2373 | && get_owner (mon) == op |
2357 | && mon->owner == op |
2374 | #endif |
2358 | #endif |
2375 | && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) |
2359 | && (QUERY_FLAG (mon, FLAG_UNAGGRESSIVE) || QUERY_FLAG (mon, FLAG_FRIENDLY))) |
2376 | { |
2360 | { |
2377 | /* If we're braced, we don't want to switch places with it */ |
2361 | /* If we're braced, we don't want to switch places with it */ |
2378 | if (op->contr->braced) |
2362 | if (op->contr->braced) |
… | |
… | |
2565 | /* I've been seeing crashes where the golem has been destroyed, but |
2549 | /* I've been seeing crashes where the golem has been destroyed, but |
2566 | * the player object still points to the defunct golem. The code that |
2550 | * the player object still points to the defunct golem. The code that |
2567 | * destroys the golem looks correct, and it doesn't always happen, so |
2551 | * destroys the golem looks correct, and it doesn't always happen, so |
2568 | * put this in a a workaround to clean up the golem pointer. |
2552 | * put this in a a workaround to clean up the golem pointer. |
2569 | */ |
2553 | */ |
2570 | if (op->contr->ranges[range_golem] && |
|
|
2571 | ((op->contr->golem_count != op->contr->ranges[range_golem]->count) || QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED))) |
2554 | if (op->contr->ranges[range_golem] && QUERY_FLAG (op->contr->ranges[range_golem], FLAG_REMOVED)) |
2572 | { |
|
|
2573 | op->contr->ranges[range_golem] = NULL; |
2555 | op->contr->ranges[range_golem] = 0; |
2574 | op->contr->golem_count = 0; |
|
|
2575 | } |
|
|
2576 | |
2556 | |
2577 | /* call this here - we also will call this in do_ericserver, but |
2557 | /* call this here - we also will call this in do_ericserver, but |
2578 | * the players time has been increased when doericserver has been |
2558 | * the players time has been increased when doericserver has been |
2579 | * called, so we recheck it here. |
2559 | * called, so we recheck it here. |
2580 | */ |
2560 | */ |
2581 | HandleClient (&op->contr->socket, op->contr); |
2561 | //TODO: better than handling 8 commands, use some more intelligent rate-limiting |
|
|
2562 | for (int rep = 8; --rep && op->contr->socket->handle_command (); ) |
|
|
2563 | ; |
|
|
2564 | |
2582 | if (op->speed_left < 0) |
2565 | if (op->speed_left < 0) |
2583 | return 0; |
2566 | return 0; |
2584 | |
2567 | |
2585 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2568 | if (op->direction && (op->contr->run_on || op->contr->fire_on)) |
2586 | { |
2569 | { |
… | |
… | |
2595 | if (op->speed_left > 0) |
2578 | if (op->speed_left > 0) |
2596 | return 1; |
2579 | return 1; |
2597 | else |
2580 | else |
2598 | return 0; |
2581 | return 0; |
2599 | } |
2582 | } |
|
|
2583 | |
2600 | return 0; |
2584 | return 0; |
2601 | } |
2585 | } |
2602 | |
2586 | |
2603 | int |
2587 | int |
2604 | save_life (object *op) |
2588 | save_life (object *op) |
2605 | { |
2589 | { |
2606 | object *tmp; |
|
|
2607 | |
|
|
2608 | if (!QUERY_FLAG (op, FLAG_LIFESAVE)) |
2590 | if (!QUERY_FLAG (op, FLAG_LIFESAVE)) |
2609 | return 0; |
2591 | return 0; |
2610 | |
2592 | |
2611 | for (tmp = op->inv; tmp != NULL; tmp = tmp->below) |
2593 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
2612 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) |
2594 | if (QUERY_FLAG (tmp, FLAG_APPLIED) && QUERY_FLAG (tmp, FLAG_LIFESAVE)) |
2613 | { |
2595 | { |
2614 | play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); |
2596 | play_sound_map (op->map, op->x, op->y, SOUND_OB_EVAPORATE); |
2615 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); |
2597 | new_draw_info_format (NDI_UNIQUE, 0, op, "Your %s vibrates violently, then evaporates.", query_name (tmp)); |
|
|
2598 | |
2616 | if (op->contr) |
2599 | if (op->contr) |
2617 | esrv_del_item (op->contr, tmp->count); |
2600 | esrv_del_item (op->contr, tmp->count); |
2618 | remove_ob (tmp); |
2601 | |
2619 | free_object (tmp); |
2602 | tmp->destroy (); |
2620 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2603 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
|
|
2604 | |
2621 | if (op->stats.hp < 0) |
2605 | if (op->stats.hp < 0) |
2622 | op->stats.hp = op->stats.maxhp; |
2606 | op->stats.hp = op->stats.maxhp; |
|
|
2607 | |
2623 | if (op->stats.food < 0) |
2608 | if (op->stats.food < 0) |
2624 | op->stats.food = 999; |
2609 | op->stats.food = 999; |
|
|
2610 | |
2625 | fix_player (op); |
2611 | fix_player (op); |
2626 | return 1; |
2612 | return 1; |
2627 | } |
2613 | } |
|
|
2614 | |
2628 | LOG (llevError, "Error: LIFESAVE set without applied object.\n"); |
2615 | LOG (llevError, "Error: LIFESAVE set without applied object.\n"); |
2629 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2616 | CLEAR_FLAG (op, FLAG_LIFESAVE); |
2630 | enter_player_savebed (op); /* bring him home. */ |
2617 | enter_player_savebed (op); /* bring him home. */ |
2631 | return 0; |
2618 | return 0; |
2632 | } |
2619 | } |
… | |
… | |
2646 | next = op->below; /* Make sure we have a good value, in case |
2633 | next = op->below; /* Make sure we have a good value, in case |
2647 | * we remove object 'op' |
2634 | * we remove object 'op' |
2648 | */ |
2635 | */ |
2649 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
2636 | if (QUERY_FLAG (op, FLAG_UNPAID)) |
2650 | { |
2637 | { |
2651 | remove_ob (op); |
2638 | op->remove (); |
2652 | op->x = env->x; |
2639 | op->x = env->x; |
2653 | op->y = env->y; |
2640 | op->y = env->y; |
2654 | if (env->type == PLAYER) |
2641 | if (env->type == PLAYER) |
2655 | esrv_del_item (env->contr, op->count); |
2642 | esrv_del_item (env->contr, op->count); |
2656 | insert_ob_in_map (op, env->map, NULL, 0); |
2643 | insert_ob_in_map (op, env->map, NULL, 0); |
2657 | } |
2644 | } |
2658 | else if (op->inv) |
2645 | else if (op->inv) |
2659 | remove_unpaid_objects (op->inv, env); |
2646 | remove_unpaid_objects (op->inv, env); |
|
|
2647 | |
2660 | op = next; |
2648 | op = next; |
2661 | } |
2649 | } |
2662 | } |
2650 | } |
2663 | |
2651 | |
2664 | |
2652 | |
… | |
… | |
2679 | strcpy (buf2, " R.I.P.\n\n"); |
2667 | strcpy (buf2, " R.I.P.\n\n"); |
2680 | if (op->type == PLAYER) |
2668 | if (op->type == PLAYER) |
2681 | sprintf (buf, "%s the %s\n", &op->name, op->contr->title); |
2669 | sprintf (buf, "%s the %s\n", &op->name, op->contr->title); |
2682 | else |
2670 | else |
2683 | sprintf (buf, "%s\n", &op->name); |
2671 | sprintf (buf, "%s\n", &op->name); |
|
|
2672 | |
2684 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2673 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2685 | strcat (buf2, buf); |
2674 | strcat (buf2, buf); |
2686 | if (op->type == PLAYER) |
2675 | if (op->type == PLAYER) |
2687 | sprintf (buf, "who was in level %d when killed\n", op->level); |
2676 | sprintf (buf, "who was in level %d when killed\n", op->level); |
2688 | else |
2677 | else |
2689 | sprintf (buf, "who was in level %d when died.\n\n", op->level); |
2678 | sprintf (buf, "who was in level %d when died.\n\n", op->level); |
|
|
2679 | |
2690 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2680 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2691 | strcat (buf2, buf); |
2681 | strcat (buf2, buf); |
2692 | if (op->type == PLAYER) |
2682 | if (op->type == PLAYER) |
2693 | { |
2683 | { |
2694 | sprintf (buf, "by %s.\n\n", op->contr->killer); |
2684 | sprintf (buf, "by %s.\n\n", op->contr->killer); |
2695 | strncat (buf2, " ", 21 - strlen (buf) / 2); |
2685 | strncat (buf2, " ", 21 - strlen (buf) / 2); |
2696 | strcat (buf2, buf); |
2686 | strcat (buf2, buf); |
2697 | } |
2687 | } |
|
|
2688 | |
2698 | strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); |
2689 | strftime (buf, MAX_BUF, "%b %d %Y\n", localtime (&now)); |
2699 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2690 | strncat (buf2, " ", 20 - strlen (buf) / 2); |
2700 | strcat (buf2, buf); |
2691 | strcat (buf2, buf); |
|
|
2692 | |
2701 | return buf2; |
2693 | return buf2; |
2702 | } |
2694 | } |
2703 | |
2695 | |
2704 | |
2696 | |
2705 | |
2697 | |
… | |
… | |
2953 | /* restore player */ |
2945 | /* restore player */ |
2954 | at = archetype::find ("poisoning"); |
2946 | at = archetype::find ("poisoning"); |
2955 | tmp = present_arch_in_ob (at, op); |
2947 | tmp = present_arch_in_ob (at, op); |
2956 | if (tmp) |
2948 | if (tmp) |
2957 | { |
2949 | { |
2958 | remove_ob (tmp); |
2950 | tmp->destroy (); |
2959 | free_object (tmp); |
|
|
2960 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2951 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
2961 | } |
2952 | } |
2962 | |
2953 | |
2963 | at = archetype::find ("confusion"); |
2954 | at = archetype::find ("confusion"); |
2964 | tmp = present_arch_in_ob (at, op); |
2955 | tmp = present_arch_in_ob (at, op); |
2965 | if (tmp) |
2956 | if (tmp) |
2966 | { |
2957 | { |
2967 | remove_ob (tmp); |
2958 | tmp->destroy (); |
2968 | free_object (tmp); |
|
|
2969 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
2959 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
2970 | } |
2960 | } |
2971 | |
2961 | |
2972 | cure_disease (op, 0); /* remove any disease */ |
2962 | cure_disease (op, 0); /* remove any disease */ |
2973 | op->stats.hp = op->stats.maxhp; |
2963 | op->stats.hp = op->stats.maxhp; |
… | |
… | |
3183 | |
3173 | |
3184 | /* remove any poisoning and confusion the character may be suffering. */ |
3174 | /* remove any poisoning and confusion the character may be suffering. */ |
3185 | /* restore player */ |
3175 | /* restore player */ |
3186 | at = archetype::find ("poisoning"); |
3176 | at = archetype::find ("poisoning"); |
3187 | tmp = present_arch_in_ob (at, op); |
3177 | tmp = present_arch_in_ob (at, op); |
|
|
3178 | |
3188 | if (tmp) |
3179 | if (tmp) |
3189 | { |
3180 | { |
3190 | remove_ob (tmp); |
3181 | tmp->destroy (); |
3191 | free_object (tmp); |
|
|
3192 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
3182 | new_draw_info (NDI_UNIQUE, 0, op, "Your body feels cleansed"); |
3193 | } |
3183 | } |
3194 | |
3184 | |
3195 | at = archetype::find ("confusion"); |
3185 | at = archetype::find ("confusion"); |
3196 | tmp = present_arch_in_ob (at, op); |
3186 | tmp = present_arch_in_ob (at, op); |
3197 | if (tmp) |
3187 | if (tmp) |
3198 | { |
3188 | { |
3199 | remove_ob (tmp); |
3189 | tmp->destroy (); |
3200 | free_object (tmp); |
|
|
3201 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
3190 | new_draw_info (NDI_UNIQUE, 0, tmp, "Your mind feels clearer"); |
3202 | } |
3191 | } |
3203 | |
3192 | |
3204 | cure_disease (op, 0); /* remove any disease */ |
3193 | cure_disease (op, 0); /* remove any disease */ |
3205 | |
3194 | |
… | |
… | |
3276 | op->contr->party = NULL; |
3265 | op->contr->party = NULL; |
3277 | if (settings.set_title == TRUE) |
3266 | if (settings.set_title == TRUE) |
3278 | op->contr->own_title[0] = '\0'; |
3267 | op->contr->own_title[0] = '\0'; |
3279 | new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf); |
3268 | new_draw_info (NDI_UNIQUE | NDI_ALL, 0, NULL, buf); |
3280 | check_score (op); |
3269 | check_score (op); |
|
|
3270 | |
3281 | if (op->contr->ranges[range_golem] != NULL) |
3271 | if (op->contr->ranges[range_golem]) |
3282 | { |
3272 | { |
3283 | remove_friendly_object (op->contr->ranges[range_golem]); |
3273 | remove_friendly_object (op->contr->ranges[range_golem]); |
3284 | remove_ob (op->contr->ranges[range_golem]); |
3274 | op->contr->ranges[range_golem]->destroy (); |
3285 | free_object (op->contr->ranges[range_golem]); |
|
|
3286 | op->contr->ranges[range_golem] = NULL; |
3275 | op->contr->ranges[range_golem] = 0; |
3287 | op->contr->golem_count = 0; |
|
|
3288 | } |
3276 | } |
|
|
3277 | |
3289 | loot_object (op); /* Remove some of the items for good */ |
3278 | loot_object (op); /* Remove some of the items for good */ |
3290 | remove_ob (op); |
3279 | op->remove (); |
3291 | op->direction = 0; |
3280 | op->direction = 0; |
3292 | |
3281 | |
3293 | if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp) |
3282 | if (!QUERY_FLAG (op, FLAG_WAS_WIZ) && op->stats.exp) |
3294 | { |
3283 | { |
3295 | delete_character (op->name, 0); |
3284 | delete_character (op->name, 0); |
… | |
… | |
3348 | for (tmp = op->inv; tmp != NULL; tmp = next) |
3337 | for (tmp = op->inv; tmp != NULL; tmp = next) |
3349 | { |
3338 | { |
3350 | next = tmp->below; |
3339 | next = tmp->below; |
3351 | if (tmp->type == EXPERIENCE || tmp->invisible) |
3340 | if (tmp->type == EXPERIENCE || tmp->invisible) |
3352 | continue; |
3341 | continue; |
3353 | remove_ob (tmp); |
3342 | tmp->remove (); |
3354 | tmp->x = op->x, tmp->y = op->y; |
3343 | tmp->x = op->x, tmp->y = op->y; |
3355 | if (tmp->type == CONTAINER) |
3344 | if (tmp->type == CONTAINER) |
3356 | { /* empty container to ground */ |
3345 | { /* empty container to ground */ |
3357 | loot_object (tmp); |
3346 | loot_object (tmp); |
3358 | } |
3347 | } |
3359 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) |
3348 | if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(RANDOM () % 3))) |
3360 | { |
3349 | { |
3361 | if (tmp->nrof > 1) |
3350 | if (tmp->nrof > 1) |
3362 | { |
3351 | { |
3363 | tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); |
3352 | tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); |
3364 | free_object (tmp2); |
3353 | tmp2->destroy (); |
3365 | insert_ob_in_map (tmp, op->map, NULL, 0); |
3354 | insert_ob_in_map (tmp, op->map, NULL, 0); |
3366 | } |
3355 | } |
3367 | else |
3356 | else |
3368 | free_object (tmp); |
3357 | tmp->destroy (); |
3369 | } |
3358 | } |
3370 | else |
3359 | else |
3371 | insert_ob_in_map (tmp, op->map, NULL, 0); |
3360 | insert_ob_in_map (tmp, op->map, NULL, 0); |
3372 | } |
3361 | } |
3373 | } |
3362 | } |
… | |
… | |
3438 | if (op->type == PLAYER) |
3427 | if (op->type == PLAYER) |
3439 | new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); |
3428 | new_draw_info_format (NDI_UNIQUE, 0, op, "You cast %s.", &spob->name); |
3440 | |
3429 | |
3441 | cast_spell (op, throw_ob, dir, spob, NULL); |
3430 | cast_spell (op, throw_ob, dir, spob, NULL); |
3442 | |
3431 | |
3443 | if (!QUERY_FLAG (throw_ob, FLAG_REMOVED)) |
3432 | throw_ob->destroy (); |
3444 | remove_ob (throw_ob); |
|
|
3445 | free_object (throw_ob); |
|
|
3446 | } |
3433 | } |
3447 | |
3434 | |
3448 | void |
3435 | void |
3449 | make_visible (object *op) |
3436 | make_visible (object *op) |
3450 | { |
3437 | { |
… | |
… | |
3657 | |
3644 | |
3658 | /* only the viewable area the player sees is updated by LOS |
3645 | /* only the viewable area the player sees is updated by LOS |
3659 | * code, so we need to restrict ourselves to that range of values |
3646 | * code, so we need to restrict ourselves to that range of values |
3660 | * for any meaningful values. |
3647 | * for any meaningful values. |
3661 | */ |
3648 | */ |
3662 | if (FABS (dx) <= (pl->contr->socket.mapx / 2) && |
3649 | if (FABS (dx) <= (pl->contr->socket->mapx / 2) && |
3663 | FABS (dy) <= (pl->contr->socket.mapy / 2) && |
3650 | FABS (dy) <= (pl->contr->socket->mapy / 2) && |
3664 | !pl->contr->blocked_los[dx + (pl->contr->socket.mapx / 2)][dy + (pl->contr->socket.mapy / 2)]) |
3651 | !pl->contr->blocked_los[dx + (pl->contr->socket->mapx / 2)][dy + (pl->contr->socket->mapy / 2)]) |
3665 | return 1; |
3652 | return 1; |
3666 | op = op->more; |
3653 | op = op->more; |
3667 | } |
3654 | } |
3668 | return 0; |
3655 | return 0; |
3669 | } |
3656 | } |