1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001 Mark Wedel |
5 | * Copyright (©) 2001 Mark Wedel |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the Affero GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | //+GPL |
25 | //+GPL |
26 | |
26 | |
… | |
… | |
65 | * This table translates the attack numbers as used within the |
65 | * This table translates the attack numbers as used within the |
66 | * program to the value we use when sending STATS command to the |
66 | * program to the value we use when sending STATS command to the |
67 | * client. If a value is -1, then we don't send that to the |
67 | * client. If a value is -1, then we don't send that to the |
68 | * client. |
68 | * client. |
69 | */ |
69 | */ |
70 | static short atnr_cs_stat[NROFATTACKS] = { CS_STAT_RES_PHYS, |
70 | static short atnr_cs_stat[NROFATTACKS] = |
71 | CS_STAT_RES_MAG, CS_STAT_RES_FIRE, CS_STAT_RES_ELEC, |
71 | { |
72 | CS_STAT_RES_COLD, CS_STAT_RES_CONF, CS_STAT_RES_ACID, |
72 | CS_STAT_RES_PHYS, |
73 | CS_STAT_RES_DRAIN, -1 /* weaponmagic */ , |
73 | CS_STAT_RES_MAG, |
74 | CS_STAT_RES_GHOSTHIT, CS_STAT_RES_POISON, |
74 | CS_STAT_RES_FIRE, |
75 | CS_STAT_RES_SLOW, CS_STAT_RES_PARA, CS_STAT_TURN_UNDEAD, |
75 | CS_STAT_RES_ELEC, |
76 | CS_STAT_RES_FEAR, -1 /* Cancellation */ , |
76 | CS_STAT_RES_COLD, |
77 | CS_STAT_RES_DEPLETE, CS_STAT_RES_DEATH, |
77 | CS_STAT_RES_CONF, |
78 | -1 /* Chaos */ , -1 /* Counterspell */ , |
78 | CS_STAT_RES_ACID, |
79 | -1 /* Godpower */ , CS_STAT_RES_HOLYWORD, |
79 | CS_STAT_RES_DRAIN, |
|
|
80 | -1 /* weaponmagic */, |
|
|
81 | CS_STAT_RES_GHOSTHIT, |
|
|
82 | CS_STAT_RES_POISON, |
|
|
83 | CS_STAT_RES_SLOW, |
|
|
84 | CS_STAT_RES_PARA, |
|
|
85 | CS_STAT_TURN_UNDEAD, |
|
|
86 | CS_STAT_RES_FEAR, |
|
|
87 | -1 /* Cancellation */, |
|
|
88 | CS_STAT_RES_DEPLETE, |
|
|
89 | CS_STAT_RES_DEATH, |
|
|
90 | -1 /* Chaos */, |
|
|
91 | -1 /* Counterspell */, |
|
|
92 | -1 /* Godpower */, |
|
|
93 | CS_STAT_RES_HOLYWORD, |
80 | CS_STAT_RES_BLIND, |
94 | CS_STAT_RES_BLIND, |
81 | -1, /* Internal */ |
95 | -1, /* Internal */ |
82 | -1, /* life stealing */ |
96 | -1, /* life stealing */ |
83 | -1 /* Disease - not fully done yet */ |
97 | -1 /* Disease - not fully done yet */ |
84 | }; |
98 | }; |
… | |
… | |
132 | pl->ns->mapinfo_queue_clear (); |
146 | pl->ns->mapinfo_queue_clear (); |
133 | |
147 | |
134 | memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap)); |
148 | memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap)); |
135 | |
149 | |
136 | pl->ns->force_newmap = false; |
150 | pl->ns->force_newmap = false; |
137 | |
|
|
138 | if (pl->ns->newmapcmd == 1) |
|
|
139 | pl->ns->send_packet ("newmap"); |
151 | pl->ns->send_packet ("newmap"); |
140 | |
|
|
141 | pl->ns->floorbox_reset (); |
152 | pl->ns->floorbox_reset (); |
142 | } |
153 | } |
143 | |
154 | |
144 | static void |
155 | static void |
145 | send_map_info (player *pl) |
156 | send_map_info (player *pl) |
… | |
… | |
147 | client &socket = *pl->ns; |
158 | client &socket = *pl->ns; |
148 | object *ob = pl->viewpoint; |
159 | object *ob = pl->viewpoint; |
149 | |
160 | |
150 | if (socket.mapinfocmd) |
161 | if (socket.mapinfocmd) |
151 | { |
162 | { |
152 | if (ob->map && ob->map->path[0]) |
163 | if (ob->map && ob->map->path) |
153 | { |
164 | { |
154 | int flags = 0; |
165 | int flags = 0; |
155 | |
166 | |
|
|
167 | // due to historical glitches, the bit ordering and map index ordering differs |
156 | if (ob->map->tile_path[0]) flags |= 1; |
168 | if (ob->map->tile_path [TILE_NORTH]) flags |= 0x01; |
157 | if (ob->map->tile_path[1]) flags |= 2; |
169 | if (ob->map->tile_path [TILE_EAST ]) flags |= 0x02; |
158 | if (ob->map->tile_path[2]) flags |= 4; |
170 | if (ob->map->tile_path [TILE_SOUTH]) flags |= 0x04; |
159 | if (ob->map->tile_path[3]) flags |= 8; |
171 | if (ob->map->tile_path [TILE_WEST ]) flags |= 0x08; |
|
|
172 | // these two are debatable |
|
|
173 | if (ob->map->tile_path [TILE_UP ]) flags |= 0x10; |
|
|
174 | if (ob->map->tile_path [TILE_DOWN ]) flags |= 0x20; |
160 | |
175 | |
161 | socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", |
176 | socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", |
162 | flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, |
177 | flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, |
163 | ob->map->width, ob->map->height, &ob->map->path); |
178 | ob->map->width, ob->map->height, &ob->map->path); |
164 | } |
179 | } |
… | |
… | |
228 | send_skill_info (client *ns, char *params) |
243 | send_skill_info (client *ns, char *params) |
229 | { |
244 | { |
230 | packet sl; |
245 | packet sl; |
231 | sl << "replyinfo skill_info\n"; |
246 | sl << "replyinfo skill_info\n"; |
232 | |
247 | |
233 | for (int i = 1; i < NUM_SKILLS; i++) |
248 | for (int i = 0; i < skillvec.size (); ++i) |
234 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]); |
249 | sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name); |
235 | |
250 | |
236 | if (sl.length () > MAXSOCKBUF) |
251 | if (sl.length () > MAXSOCKBUF) |
237 | { |
|
|
238 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
252 | cleanup ("buffer overflow in send_skill_info!"); |
239 | fatal (0); |
|
|
240 | } |
|
|
241 | |
253 | |
242 | ns->send_packet (sl); |
254 | ns->send_packet (sl); |
243 | } |
255 | } |
244 | |
256 | |
245 | /** |
257 | /** |
… | |
… | |
255 | |
267 | |
256 | for (int i = 0; i < NRSPELLPATHS; i++) |
268 | for (int i = 0; i < NRSPELLPATHS; i++) |
257 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
269 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
258 | |
270 | |
259 | if (sl.length () > MAXSOCKBUF) |
271 | if (sl.length () > MAXSOCKBUF) |
260 | { |
|
|
261 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
272 | cleanup ("buffer overflow in send_spell_paths!"); |
262 | fatal (0); |
|
|
263 | } |
|
|
264 | |
273 | |
265 | ns->send_packet (sl); |
274 | ns->send_packet (sl); |
266 | } |
275 | } |
267 | |
276 | |
268 | /** |
277 | /** |
… | |
… | |
336 | |
345 | |
337 | while (*buf && map && max_distance) |
346 | while (*buf && map && max_distance) |
338 | { |
347 | { |
339 | int dir = *buf++ - '1'; |
348 | int dir = *buf++ - '1'; |
340 | |
349 | |
341 | if (dir >= 0 && dir <= 3) |
350 | // due to historical glitches, the mapinfo index and tile index differs |
|
|
351 | static unsigned char dirmap [] = { TILE_NORTH, TILE_EAST, TILE_SOUTH, TILE_WEST, TILE_UP, TILE_DOWN }; |
|
|
352 | |
|
|
353 | // maybe we should only allow the four flat directions |
|
|
354 | if (IN_RANGE_EXC (dir, 0, array_length (dirmap))) |
342 | { |
355 | { |
|
|
356 | dir = dirmap [dir]; |
|
|
357 | |
343 | if (!map->tile_path [dir]) |
358 | if (!map->tile_path [dir]) |
344 | map = 0; |
359 | map = 0; |
345 | else if (map->tile_available (dir, false)) |
360 | else if (map->tile_available (dir, false)) |
346 | { |
361 | { |
347 | maptile *neigh = map->tile_map [dir]; |
362 | maptile *neigh = map->tile_map [dir]; |
… | |
… | |
370 | send_packet_printf ("mapinfo %s nomap", token); |
385 | send_packet_printf ("mapinfo %s nomap", token); |
371 | else |
386 | else |
372 | { |
387 | { |
373 | int flags = 0; |
388 | int flags = 0; |
374 | |
389 | |
|
|
390 | // due to historical glitches, the bit ordering and map index ordering differs |
375 | if (map->tile_path[0]) flags |= 1; |
391 | if (map->tile_path [TILE_NORTH]) flags |= 0x01; |
376 | if (map->tile_path[1]) flags |= 2; |
392 | if (map->tile_path [TILE_EAST ]) flags |= 0x02; |
377 | if (map->tile_path[2]) flags |= 4; |
393 | if (map->tile_path [TILE_SOUTH]) flags |= 0x04; |
378 | if (map->tile_path[3]) flags |= 8; |
394 | if (map->tile_path [TILE_WEST ]) flags |= 0x08; |
|
|
395 | // these two are debatable |
|
|
396 | if (map->tile_path [TILE_UP ]) flags |= 0x10; |
|
|
397 | if (map->tile_path [TILE_DOWN ]) flags |= 0x20; |
379 | |
398 | |
380 | send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); |
399 | send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); |
381 | } |
400 | } |
382 | |
401 | |
383 | return 1; |
402 | return 1; |
… | |
… | |
445 | { |
464 | { |
446 | INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len)); |
465 | INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len)); |
447 | } |
466 | } |
448 | |
467 | |
449 | //+GPL |
468 | //+GPL |
450 | |
|
|
451 | /* |
|
|
452 | #define MSG_TYPE_BOOK 1 |
|
|
453 | #define MSG_TYPE_CARD 2 |
|
|
454 | #define MSG_TYPE_PAPER 3 |
|
|
455 | #define MSG_TYPE_SIGN 4 |
|
|
456 | #define MSG_TYPE_MONUMENT 5 |
|
|
457 | #define MSG_TYPE_SCRIPTED_DIALOG 6*/ |
|
|
458 | |
|
|
459 | /** Reply to ExtendedInfos command */ |
|
|
460 | void |
|
|
461 | ToggleExtendedText (char *buf, int len, client * ns) |
|
|
462 | { |
|
|
463 | char cmdback[MAX_BUF]; |
|
|
464 | char temp[10]; |
|
|
465 | char command[50]; |
|
|
466 | int info, nextinfo, i, flag; |
|
|
467 | |
|
|
468 | cmdback[0] = '\0'; |
|
|
469 | |
|
|
470 | nextinfo = 0; |
|
|
471 | while (1) |
|
|
472 | { |
|
|
473 | /* 1. Extract an info */ |
|
|
474 | info = nextinfo; |
|
|
475 | |
|
|
476 | while ((info < len) && (buf [info] == ' ')) |
|
|
477 | info++; |
|
|
478 | |
|
|
479 | if (info >= len) |
|
|
480 | break; |
|
|
481 | |
|
|
482 | nextinfo = info + 1; |
|
|
483 | |
|
|
484 | while ((nextinfo < len) && (buf [nextinfo] != ' ')) |
|
|
485 | nextinfo++; |
|
|
486 | |
|
|
487 | if (nextinfo - info >= 49) /*Erroneous info asked */ |
|
|
488 | continue; |
|
|
489 | |
|
|
490 | memcpy (command, buf + info, nextinfo - info); |
|
|
491 | command [nextinfo - info] = 0; |
|
|
492 | |
|
|
493 | /* 2. Interpret info */ |
|
|
494 | i = sscanf (command, "%d", &flag); |
|
|
495 | |
|
|
496 | if ((i == 1) && (flag > 0) && (flag <= MSG_TYPE_LAST)) |
|
|
497 | ns->supported_readables |= (1 << flag); |
|
|
498 | /*3. Next info */ |
|
|
499 | } |
|
|
500 | |
|
|
501 | /* Send resulting state */ |
|
|
502 | strcpy (cmdback, "ExtendedTextSet"); |
|
|
503 | |
|
|
504 | for (i = 0; i <= MSG_TYPE_LAST; i++) |
|
|
505 | if (ns->supported_readables & (1 << i)) |
|
|
506 | { |
|
|
507 | strcat (cmdback, " "); |
|
|
508 | snprintf (temp, sizeof (temp), "%d", i); |
|
|
509 | strcat (cmdback, temp); |
|
|
510 | } |
|
|
511 | |
|
|
512 | ns->send_packet (cmdback); |
|
|
513 | } |
|
|
514 | |
469 | |
515 | /** |
470 | /** |
516 | * This handles the general commands from the client (ie, north, fire, cast, |
471 | * This handles the general commands from the client (ie, north, fire, cast, |
517 | * etc.) |
472 | * etc.) |
518 | */ |
473 | */ |
… | |
… | |
629 | LOG (llevError, "Unknown input state: %d\n", ns->state); |
584 | LOG (llevError, "Unknown input state: %d\n", ns->state); |
630 | } |
585 | } |
631 | } |
586 | } |
632 | |
587 | |
633 | /** |
588 | /** |
634 | * Client tells its version. If there is a mismatch, we close the |
589 | * Client tells its version info. |
635 | * socket. In real life, all we should care about is the client having |
|
|
636 | * something older than the server. If we assume the client will be |
|
|
637 | * backwards compatible, having it be a later version should not be a |
|
|
638 | * problem. |
|
|
639 | */ |
590 | */ |
640 | void |
591 | void |
641 | VersionCmd (char *buf, int len, client * ns) |
592 | VersionCmd (char *buf, int len, client *ns) |
642 | { |
593 | { |
643 | if (!buf) |
594 | INVOKE_CLIENT (VERSION, ns, ARG_DATA (buf, len)); |
644 | { |
|
|
645 | LOG (llevError, "CS: received corrupted version command\n"); |
|
|
646 | return; |
|
|
647 | } |
|
|
648 | |
|
|
649 | ns->cs_version = atoi (buf); |
|
|
650 | ns->sc_version = ns->cs_version; |
|
|
651 | |
|
|
652 | LOG (llevDebug, "connection from client <%s>\n", buf); |
|
|
653 | |
|
|
654 | //TODO: should log here just for statistics |
|
|
655 | |
|
|
656 | //if (VERSION_CS != ns->cs_version) |
|
|
657 | // unchecked; |
|
|
658 | |
|
|
659 | char *cp = strchr (buf + 1, ' '); |
|
|
660 | if (!cp) |
|
|
661 | return; |
|
|
662 | |
|
|
663 | ns->sc_version = atoi (cp); |
|
|
664 | |
|
|
665 | //if (VERSION_SC != ns->sc_version) |
|
|
666 | // unchecked; |
|
|
667 | |
|
|
668 | cp = strchr (cp + 1, ' '); |
|
|
669 | |
|
|
670 | if (cp) |
|
|
671 | { |
|
|
672 | ns->version = cp + 1; |
|
|
673 | |
|
|
674 | if (ns->sc_version < 1026) |
|
|
675 | ns->send_packet_printf ("drawinfo %d %s", NDI_RED, |
|
|
676 | "**** VERSION WARNING ****\n**** CLIENT IS TOO OLD!! UPDATE THE CLIENT!! ****"); |
|
|
677 | } |
|
|
678 | } |
595 | } |
679 | |
596 | |
680 | /** sound related functions. */ |
597 | /** sound related functions. */ |
681 | void |
598 | void |
682 | SetSound (char *buf, int len, client * ns) |
599 | SetSound (char *buf, int len, client * ns) |
… | |
… | |
799 | * commands for now. |
716 | * commands for now. |
800 | */ |
717 | */ |
801 | void |
718 | void |
802 | esrv_update_stats (player *pl) |
719 | esrv_update_stats (player *pl) |
803 | { |
720 | { |
804 | char buf[MAX_BUF]; |
|
|
805 | uint16 flags; |
|
|
806 | |
|
|
807 | client *ns = pl->ns; |
721 | client *ns = pl->ns; |
808 | if (!ns) |
722 | if (!ns) |
809 | return; |
723 | return; |
810 | |
724 | |
811 | object *ob = pl->observe; |
725 | object *ob = pl->observe; |
… | |
… | |
828 | AddIfShort (ns->last_stats.Int, ob->stats.Int, CS_STAT_INT); |
742 | AddIfShort (ns->last_stats.Int, ob->stats.Int, CS_STAT_INT); |
829 | AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); |
743 | AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); |
830 | AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); |
744 | AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); |
831 | AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); |
745 | AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); |
832 | |
746 | |
833 | for (int s = 0; s < NUM_SKILLS; s++) |
747 | for (int s = 0; s < CS_NUM_SKILLS; s++) |
834 | if (object *skill = opl->last_skill_ob [s]) |
748 | if (object *skill = opl->last_skill_ob [s]) |
835 | if (skill->stats.exp != ns->last_skill_exp [s]) |
749 | if (skill->stats.exp != ns->last_skill_exp [s]) |
836 | { |
750 | { |
837 | ns->last_skill_exp [s] = skill->stats.exp; |
751 | ns->last_skill_exp [s] = skill->stats.exp; |
838 | |
752 | |
839 | /* Always send along the level if exp changes. This is only |
753 | /* Always send along the level if exp changes. This is only |
840 | * 1 extra byte, but keeps processing simpler. |
754 | * 1 extra byte, but keeps processing simpler. |
841 | */ |
755 | */ |
842 | sl << uint8 (s + CS_STAT_SKILLINFO) |
756 | sl << uint8 (CS_STAT_SKILLINFO + s) |
843 | << uint8 (skill->level) |
757 | << uint8 (skill->level) |
844 | << uint64 (skill->stats.exp); |
758 | << uint64 (skill->stats.exp); |
845 | } |
759 | } |
846 | |
760 | |
847 | AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); |
761 | AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); |
… | |
… | |
852 | AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK); |
766 | AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK); |
853 | AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); |
767 | AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); |
854 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); |
768 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); |
855 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
769 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
856 | |
770 | |
857 | flags = 0; |
771 | int flags = (opl->fire_on ? SF_FIREON : 0) |
858 | |
772 | | (opl->run_on ? SF_RUNON : 0); |
859 | if (opl->fire_on) |
|
|
860 | flags |= SF_FIREON; |
|
|
861 | |
|
|
862 | if (opl->run_on) |
|
|
863 | flags |= SF_RUNON; |
|
|
864 | |
773 | |
865 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
774 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
866 | |
775 | |
867 | for (int i = 0; i < NROFATTACKS; i++) |
776 | for (int i = 0; i < NROFATTACKS; i++) |
868 | { |
|
|
869 | /* Skip ones we won't send */ |
777 | /* Skip ones we won't send */ |
870 | if (atnr_cs_stat[i] == -1) |
778 | if (atnr_cs_stat[i] >= 0) |
871 | continue; |
|
|
872 | |
|
|
873 | AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); |
779 | AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); |
874 | } |
|
|
875 | |
780 | |
876 | if (pl->ns->monitor_spells) |
781 | if (pl->ns->monitor_spells) |
877 | { |
782 | { |
878 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
783 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
879 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
784 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
880 | AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); |
785 | AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); |
881 | } |
786 | } |
882 | |
787 | |
|
|
788 | char buf[MAX_BUF]; |
883 | rangetostring (opl, buf); /* we want use the new fire & run system in new client */ |
789 | rangetostring (opl, buf); /* we want use the new fire & run system in new client */ |
884 | AddIfString (ns->stats.range, buf, CS_STAT_RANGE); |
790 | AddIfString (ns->stats.range, buf, CS_STAT_RANGE); |
885 | set_title (ob, buf); |
791 | set_title (ob, buf); |
886 | AddIfString (ns->stats.title, buf, CS_STAT_TITLE); |
792 | AddIfString (ns->stats.title, buf, CS_STAT_TITLE); |
887 | |
793 | |
… | |
… | |
981 | |
887 | |
982 | /* Nothing changed */ |
888 | /* Nothing changed */ |
983 | return 0; |
889 | return 0; |
984 | } |
890 | } |
985 | |
891 | |
986 | //-GPL |
|
|
987 | |
|
|
988 | // prefetch (and touch) all maps within a specific distancd |
|
|
989 | static void |
|
|
990 | prefetch_surrounding_maps (maptile *map, int distance) |
|
|
991 | { |
|
|
992 | map->touch (); |
|
|
993 | |
|
|
994 | if (--distance) |
|
|
995 | for (int dir = 4; dir--; ) |
|
|
996 | if (const shstr &path = map->tile_path [dir]) |
|
|
997 | if (maptile *&neigh = map->tile_map [dir]) |
|
|
998 | prefetch_surrounding_maps (neigh, distance); |
|
|
999 | else |
|
|
1000 | neigh = maptile::find_async (path, map); |
|
|
1001 | } |
|
|
1002 | |
|
|
1003 | // prefetch a generous area around the player |
|
|
1004 | static void |
|
|
1005 | prefetch_surrounding_maps (object *op) |
|
|
1006 | { |
|
|
1007 | prefetch_surrounding_maps (op->map, 3); |
|
|
1008 | } |
|
|
1009 | |
|
|
1010 | //+GPL |
|
|
1011 | |
|
|
1012 | /** |
892 | /** |
1013 | * Draws client map. |
893 | * Draws client map. |
1014 | */ |
894 | */ |
1015 | void |
895 | void |
1016 | draw_client_map (player *pl) |
896 | draw_client_map (player *pl) |
… | |
… | |
1021 | |
901 | |
1022 | /* If player is just joining the game, he isn't here yet, so the map |
902 | /* If player is just joining the game, he isn't here yet, so the map |
1023 | * can get swapped out. If so, don't try to send them a map. All will |
903 | * can get swapped out. If so, don't try to send them a map. All will |
1024 | * be OK once they really log in. |
904 | * be OK once they really log in. |
1025 | */ |
905 | */ |
1026 | if (!ob->map || ob->map->in_memory != MAP_ACTIVE) |
906 | if (!ob->map || ob->map->state != MAP_ACTIVE) |
1027 | return; |
907 | return; |
1028 | |
908 | |
1029 | int startlen, oldlen; |
909 | int startlen, oldlen; |
1030 | |
910 | |
1031 | check_map_change (pl); |
911 | check_map_change (pl); |
1032 | prefetch_surrounding_maps (pl->ob); |
912 | pl->ob->prefetch_surrounding_maps (); |
1033 | |
913 | |
1034 | /* do LOS after calls to update_position */ |
914 | /* do LOS after calls to update_position */ |
1035 | /* unfortunately, we need to udpate los when observing, currently */ |
915 | /* unfortunately, we need to udpate los when observing, currently */ |
1036 | if (pl->do_los || pl->viewpoint != pl->ob) |
916 | if (pl->do_los || pl->viewpoint != pl->ob) |
1037 | { |
917 | { |
… | |
… | |
1062 | * look like. |
942 | * look like. |
1063 | */ |
943 | */ |
1064 | |
944 | |
1065 | client &socket = *pl->ns; |
945 | client &socket = *pl->ns; |
1066 | |
946 | |
1067 | packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); |
947 | packet sl ("map1a"); |
1068 | |
948 | |
1069 | startlen = sl.length (); |
949 | startlen = sl.length (); |
1070 | |
950 | |
1071 | int hx = socket.mapx / 2; |
951 | int hx = socket.mapx / 2; |
1072 | int hy = socket.mapy / 2; |
952 | int hy = socket.mapy / 2; |
… | |
… | |
1164 | { |
1044 | { |
1165 | if (op->stats.maxhp > op->stats.hp |
1045 | if (op->stats.maxhp > op->stats.hp |
1166 | && op->stats.maxhp > 0 |
1046 | && op->stats.maxhp > 0 |
1167 | && (op->type == PLAYER |
1047 | && (op->type == PLAYER |
1168 | || op->type == DOOR // does not work, have maxhp 0 |
1048 | || op->type == DOOR // does not work, have maxhp 0 |
1169 | || QUERY_FLAG (op, FLAG_MONSTER) |
1049 | || op->flag [FLAG_MONSTER] |
1170 | || QUERY_FLAG (op, FLAG_ALIVE) |
1050 | || op->flag [FLAG_ALIVE] |
1171 | || QUERY_FLAG (op, FLAG_GENERATOR))) |
1051 | || op->flag [FLAG_GENERATOR])) |
1172 | { |
1052 | { |
1173 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1053 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1174 | stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge |
1054 | stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge |
1175 | } |
1055 | } |
1176 | |
1056 | |
… | |
… | |
1355 | |
1235 | |
1356 | /* appends the spell *spell to the Socklist we will send the data to. */ |
1236 | /* appends the spell *spell to the Socklist we will send the data to. */ |
1357 | static void |
1237 | static void |
1358 | append_spell (player *pl, packet &sl, object *spell) |
1238 | append_spell (player *pl, packet &sl, object *spell) |
1359 | { |
1239 | { |
1360 | int i, skill = 0; |
1240 | int skill = 0; |
1361 | |
1241 | |
1362 | if (!(spell->name)) |
1242 | if (!(spell->name)) |
1363 | { |
1243 | { |
1364 | LOG (llevError, "item number %d is a spell with no name.\n", spell->count); |
1244 | LOG (llevError, "item number %d is a spell with no name.\n", spell->count); |
1365 | return; |
1245 | return; |
… | |
… | |
1371 | spell->cached_eat = casting_level (pl->ob, spell); |
1251 | spell->cached_eat = casting_level (pl->ob, spell); |
1372 | |
1252 | |
1373 | /* figure out which skill it uses, if it uses one */ |
1253 | /* figure out which skill it uses, if it uses one */ |
1374 | if (spell->skill) |
1254 | if (spell->skill) |
1375 | if (object *tmp = pl->find_skill (spell->skill)) |
1255 | if (object *tmp = pl->find_skill (spell->skill)) |
1376 | skill = tmp->subtype + CS_STAT_SKILLINFO; |
1256 | skill = CS_STAT_SKILLINFO + SKILL_INDEX (tmp); |
1377 | |
1257 | |
1378 | // spells better have a face |
1258 | // spells better have a face |
1379 | if (!spell->face) |
1259 | if (!spell->face) |
1380 | { |
1260 | { |
1381 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |
1261 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |
… | |
… | |
1455 | } |
1335 | } |
1456 | else |
1336 | else |
1457 | append_spell (pl, sl, spell); |
1337 | append_spell (pl, sl, spell); |
1458 | |
1338 | |
1459 | if (sl.length () > MAXSOCKBUF) |
1339 | if (sl.length () > MAXSOCKBUF) |
1460 | { |
|
|
1461 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
1340 | cleanup ("buffer overflow in esrv_add_spells!"); |
1462 | fatal (0); |
|
|
1463 | } |
|
|
1464 | |
1341 | |
1465 | /* finally, we can send the packet */ |
1342 | /* finally, we can send the packet */ |
1466 | pl->ns->flush_fx (); |
1343 | pl->ns->flush_fx (); |
1467 | pl->ns->send_packet (sl); |
1344 | pl->ns->send_packet (sl); |
1468 | } |
1345 | } |