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 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 |
… | |
… | |
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) |
… | |
… | |
151 | { |
162 | { |
152 | if (ob->map && ob->map->path[0]) |
163 | if (ob->map && ob->map->path[0]) |
153 | { |
164 | { |
154 | int flags = 0; |
165 | int flags = 0; |
155 | |
166 | |
156 | if (ob->map->tile_path[0]) flags |= 1; |
167 | if (ob->map->tile_path[0]) flags |= 0x01; |
157 | if (ob->map->tile_path[1]) flags |= 2; |
168 | if (ob->map->tile_path[1]) flags |= 0x02; |
158 | if (ob->map->tile_path[2]) flags |= 4; |
169 | if (ob->map->tile_path[2]) flags |= 0x04; |
159 | if (ob->map->tile_path[3]) flags |= 8; |
170 | if (ob->map->tile_path[3]) flags |= 0x08; |
|
|
171 | // these two are debatable |
|
|
172 | if (ob->map->tile_path[4]) flags |= 0x10; |
|
|
173 | if (ob->map->tile_path[5]) flags |= 0x20; |
160 | |
174 | |
161 | socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", |
175 | socket.send_packet_printf ("mapinfo - spatial %d %d %d %d %d %s", |
162 | flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, |
176 | flags, socket.mapx / 2 - ob->x, socket.mapy / 2 - ob->y, |
163 | ob->map->width, ob->map->height, &ob->map->path); |
177 | ob->map->width, ob->map->height, &ob->map->path); |
164 | } |
178 | } |
… | |
… | |
228 | send_skill_info (client *ns, char *params) |
242 | send_skill_info (client *ns, char *params) |
229 | { |
243 | { |
230 | packet sl; |
244 | packet sl; |
231 | sl << "replyinfo skill_info\n"; |
245 | sl << "replyinfo skill_info\n"; |
232 | |
246 | |
233 | for (int i = 1; i < NUM_SKILLS; i++) |
247 | for (int i = 0; i < skillvec.size (); ++i) |
234 | sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]); |
248 | sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name); |
235 | |
249 | |
236 | if (sl.length () > MAXSOCKBUF) |
250 | if (sl.length () > MAXSOCKBUF) |
237 | { |
|
|
238 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
251 | cleanup ("buffer overflow in send_skill_info!"); |
239 | fatal (0); |
|
|
240 | } |
|
|
241 | |
252 | |
242 | ns->send_packet (sl); |
253 | ns->send_packet (sl); |
243 | } |
254 | } |
244 | |
255 | |
245 | /** |
256 | /** |
… | |
… | |
255 | |
266 | |
256 | for (int i = 0; i < NRSPELLPATHS; i++) |
267 | for (int i = 0; i < NRSPELLPATHS; i++) |
257 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
268 | sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); |
258 | |
269 | |
259 | if (sl.length () > MAXSOCKBUF) |
270 | if (sl.length () > MAXSOCKBUF) |
260 | { |
|
|
261 | LOG (llevError, "Buffer overflow in send_spell_paths!\n"); |
271 | cleanup ("buffer overflow in send_spell_paths!"); |
262 | fatal (0); |
|
|
263 | } |
|
|
264 | |
272 | |
265 | ns->send_packet (sl); |
273 | ns->send_packet (sl); |
266 | } |
274 | } |
267 | |
275 | |
268 | /** |
276 | /** |
… | |
… | |
336 | |
344 | |
337 | while (*buf && map && max_distance) |
345 | while (*buf && map && max_distance) |
338 | { |
346 | { |
339 | int dir = *buf++ - '1'; |
347 | int dir = *buf++ - '1'; |
340 | |
348 | |
|
|
349 | // maybe we should only allow the four flat directions |
341 | if (dir >= 0 && dir <= 3) |
350 | if (dir >= 0 && dir < TILE_NUM) |
342 | { |
351 | { |
343 | if (!map->tile_path [dir]) |
352 | if (!map->tile_path [dir]) |
344 | map = 0; |
353 | map = 0; |
345 | else if (map->tile_available (dir, false)) |
354 | else if (map->tile_available (dir, false)) |
346 | { |
355 | { |
… | |
… | |
370 | send_packet_printf ("mapinfo %s nomap", token); |
379 | send_packet_printf ("mapinfo %s nomap", token); |
371 | else |
380 | else |
372 | { |
381 | { |
373 | int flags = 0; |
382 | int flags = 0; |
374 | |
383 | |
375 | if (map->tile_path[0]) flags |= 1; |
384 | if (map->tile_path[0]) flags |= 0x01; |
376 | if (map->tile_path[1]) flags |= 2; |
385 | if (map->tile_path[1]) flags |= 0x02; |
377 | if (map->tile_path[2]) flags |= 4; |
386 | if (map->tile_path[2]) flags |= 0x04; |
378 | if (map->tile_path[3]) flags |= 8; |
387 | if (map->tile_path[3]) flags |= 0x08; |
|
|
388 | // these two are debatable |
|
|
389 | if (map->tile_path[4]) flags |= 0x10; |
|
|
390 | if (map->tile_path[5]) flags |= 0x20; |
379 | |
391 | |
380 | send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); |
392 | send_packet_printf ("mapinfo %s spatial %d %d %d %d %d %s", token, flags, mapx, mapy, map->width, map->height, &map->path); |
381 | } |
393 | } |
382 | |
394 | |
383 | return 1; |
395 | return 1; |
… | |
… | |
697 | * commands for now. |
709 | * commands for now. |
698 | */ |
710 | */ |
699 | void |
711 | void |
700 | esrv_update_stats (player *pl) |
712 | esrv_update_stats (player *pl) |
701 | { |
713 | { |
702 | char buf[MAX_BUF]; |
|
|
703 | uint16 flags; |
|
|
704 | |
|
|
705 | client *ns = pl->ns; |
714 | client *ns = pl->ns; |
706 | if (!ns) |
715 | if (!ns) |
707 | return; |
716 | return; |
708 | |
717 | |
709 | object *ob = pl->observe; |
718 | object *ob = pl->observe; |
… | |
… | |
726 | AddIfShort (ns->last_stats.Int, ob->stats.Int, CS_STAT_INT); |
735 | AddIfShort (ns->last_stats.Int, ob->stats.Int, CS_STAT_INT); |
727 | AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); |
736 | AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); |
728 | AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); |
737 | AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); |
729 | AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); |
738 | AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); |
730 | |
739 | |
731 | for (int s = 0; s < NUM_SKILLS; s++) |
740 | for (int s = 0; s < CS_NUM_SKILLS; s++) |
732 | if (object *skill = opl->last_skill_ob [s]) |
741 | if (object *skill = opl->last_skill_ob [s]) |
733 | if (skill->stats.exp != ns->last_skill_exp [s]) |
742 | if (skill->stats.exp != ns->last_skill_exp [s]) |
734 | { |
743 | { |
735 | ns->last_skill_exp [s] = skill->stats.exp; |
744 | ns->last_skill_exp [s] = skill->stats.exp; |
736 | |
745 | |
737 | /* Always send along the level if exp changes. This is only |
746 | /* Always send along the level if exp changes. This is only |
738 | * 1 extra byte, but keeps processing simpler. |
747 | * 1 extra byte, but keeps processing simpler. |
739 | */ |
748 | */ |
740 | sl << uint8 (s + CS_STAT_SKILLINFO) |
749 | sl << uint8 (CS_STAT_SKILLINFO + s) |
741 | << uint8 (skill->level) |
750 | << uint8 (skill->level) |
742 | << uint64 (skill->stats.exp); |
751 | << uint64 (skill->stats.exp); |
743 | } |
752 | } |
744 | |
753 | |
745 | AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); |
754 | AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); |
… | |
… | |
750 | AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK); |
759 | AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK); |
751 | AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); |
760 | AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); |
752 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); |
761 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); |
753 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
762 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
754 | |
763 | |
755 | flags = 0; |
764 | int flags = (opl->fire_on ? SF_FIREON : 0) |
756 | |
765 | | (opl->run_on ? SF_RUNON : 0); |
757 | if (opl->fire_on) |
|
|
758 | flags |= SF_FIREON; |
|
|
759 | |
|
|
760 | if (opl->run_on) |
|
|
761 | flags |= SF_RUNON; |
|
|
762 | |
766 | |
763 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
767 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
764 | |
768 | |
765 | for (int i = 0; i < NROFATTACKS; i++) |
769 | for (int i = 0; i < NROFATTACKS; i++) |
766 | { |
|
|
767 | /* Skip ones we won't send */ |
770 | /* Skip ones we won't send */ |
768 | if (atnr_cs_stat[i] == -1) |
771 | if (atnr_cs_stat[i] >= 0) |
769 | continue; |
|
|
770 | |
|
|
771 | AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); |
772 | AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); |
772 | } |
|
|
773 | |
773 | |
774 | if (pl->ns->monitor_spells) |
774 | if (pl->ns->monitor_spells) |
775 | { |
775 | { |
776 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
776 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
777 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
777 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
778 | AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); |
778 | AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); |
779 | } |
779 | } |
780 | |
780 | |
|
|
781 | char buf[MAX_BUF]; |
781 | rangetostring (opl, buf); /* we want use the new fire & run system in new client */ |
782 | rangetostring (opl, buf); /* we want use the new fire & run system in new client */ |
782 | AddIfString (ns->stats.range, buf, CS_STAT_RANGE); |
783 | AddIfString (ns->stats.range, buf, CS_STAT_RANGE); |
783 | set_title (ob, buf); |
784 | set_title (ob, buf); |
784 | AddIfString (ns->stats.title, buf, CS_STAT_TITLE); |
785 | AddIfString (ns->stats.title, buf, CS_STAT_TITLE); |
785 | |
786 | |
… | |
… | |
881 | return 0; |
882 | return 0; |
882 | } |
883 | } |
883 | |
884 | |
884 | //-GPL |
885 | //-GPL |
885 | |
886 | |
886 | // prefetch (and touch) all maps within a specific distancd |
887 | // prefetch some flat area around the player |
887 | static void |
888 | static void |
888 | prefetch_surrounding_maps (maptile *map, int distance) |
889 | prefetch_surrounding_area (object *op, maptile *map, int range) |
889 | { |
890 | { |
890 | map->touch (); |
891 | for (maprect *rect = map->split_to_tiles (mapwalk_buf, |
891 | |
892 | op->x - range , op->y - range , |
892 | if (--distance) |
893 | op->x + range + 1, op->y + range + 1); |
893 | for (int dir = 4; dir--; ) |
894 | rect->m; |
894 | if (const shstr &path = map->tile_path [dir]) |
895 | ++rect) |
895 | if (maptile *&neigh = map->tile_map [dir]) |
896 | { |
896 | prefetch_surrounding_maps (neigh, distance); |
897 | rect->m->touch (); |
897 | else |
898 | rect->m->activate (); |
898 | neigh = maptile::find_async (path, map); |
899 | } |
899 | } |
900 | } |
900 | |
901 | |
901 | // prefetch a generous area around the player |
902 | // prefetch a generous area around the player, also up and down |
902 | static void |
903 | void |
903 | prefetch_surrounding_maps (object *op) |
904 | object::prefetch_surrounding_maps () |
904 | { |
905 | { |
905 | prefetch_surrounding_maps (op->map, 3); |
906 | prefetch_surrounding_area (this, map, 40); |
|
|
907 | |
|
|
908 | if (maptile *m = map->tile_available (TILE_DOWN)) |
|
|
909 | prefetch_surrounding_area (this, m, 20); |
|
|
910 | |
|
|
911 | if (maptile *m = map->tile_available (TILE_UP)) |
|
|
912 | prefetch_surrounding_area (this, m, 20); |
906 | } |
913 | } |
907 | |
914 | |
908 | //+GPL |
915 | //+GPL |
909 | |
916 | |
910 | /** |
917 | /** |
… | |
… | |
925 | return; |
932 | return; |
926 | |
933 | |
927 | int startlen, oldlen; |
934 | int startlen, oldlen; |
928 | |
935 | |
929 | check_map_change (pl); |
936 | check_map_change (pl); |
930 | prefetch_surrounding_maps (pl->ob); |
937 | pl->ob->prefetch_surrounding_maps (); |
931 | |
938 | |
932 | /* do LOS after calls to update_position */ |
939 | /* do LOS after calls to update_position */ |
933 | /* unfortunately, we need to udpate los when observing, currently */ |
940 | /* unfortunately, we need to udpate los when observing, currently */ |
934 | if (pl->do_los || pl->viewpoint != pl->ob) |
941 | if (pl->do_los || pl->viewpoint != pl->ob) |
935 | { |
942 | { |
… | |
… | |
960 | * look like. |
967 | * look like. |
961 | */ |
968 | */ |
962 | |
969 | |
963 | client &socket = *pl->ns; |
970 | client &socket = *pl->ns; |
964 | |
971 | |
965 | packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); |
972 | packet sl ("map1a"); |
966 | |
973 | |
967 | startlen = sl.length (); |
974 | startlen = sl.length (); |
968 | |
975 | |
969 | int hx = socket.mapx / 2; |
976 | int hx = socket.mapx / 2; |
970 | int hy = socket.mapy / 2; |
977 | int hy = socket.mapy / 2; |
… | |
… | |
1062 | { |
1069 | { |
1063 | if (op->stats.maxhp > op->stats.hp |
1070 | if (op->stats.maxhp > op->stats.hp |
1064 | && op->stats.maxhp > 0 |
1071 | && op->stats.maxhp > 0 |
1065 | && (op->type == PLAYER |
1072 | && (op->type == PLAYER |
1066 | || op->type == DOOR // does not work, have maxhp 0 |
1073 | || op->type == DOOR // does not work, have maxhp 0 |
1067 | || QUERY_FLAG (op, FLAG_MONSTER) |
1074 | || op->flag [FLAG_MONSTER] |
1068 | || QUERY_FLAG (op, FLAG_ALIVE) |
1075 | || op->flag [FLAG_ALIVE] |
1069 | || QUERY_FLAG (op, FLAG_GENERATOR))) |
1076 | || op->flag [FLAG_GENERATOR])) |
1070 | { |
1077 | { |
1071 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1078 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1072 | stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge |
1079 | stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge |
1073 | } |
1080 | } |
1074 | |
1081 | |
… | |
… | |
1269 | spell->cached_eat = casting_level (pl->ob, spell); |
1276 | spell->cached_eat = casting_level (pl->ob, spell); |
1270 | |
1277 | |
1271 | /* figure out which skill it uses, if it uses one */ |
1278 | /* figure out which skill it uses, if it uses one */ |
1272 | if (spell->skill) |
1279 | if (spell->skill) |
1273 | if (object *tmp = pl->find_skill (spell->skill)) |
1280 | if (object *tmp = pl->find_skill (spell->skill)) |
1274 | skill = tmp->subtype + CS_STAT_SKILLINFO; |
1281 | skill = CS_STAT_SKILLINFO + SKILL_INDEX (tmp); |
1275 | |
1282 | |
1276 | // spells better have a face |
1283 | // spells better have a face |
1277 | if (!spell->face) |
1284 | if (!spell->face) |
1278 | { |
1285 | { |
1279 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |
1286 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |
… | |
… | |
1353 | } |
1360 | } |
1354 | else |
1361 | else |
1355 | append_spell (pl, sl, spell); |
1362 | append_spell (pl, sl, spell); |
1356 | |
1363 | |
1357 | if (sl.length () > MAXSOCKBUF) |
1364 | if (sl.length () > MAXSOCKBUF) |
1358 | { |
|
|
1359 | LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); |
1365 | cleanup ("buffer overflow in esrv_add_spells!"); |
1360 | fatal (0); |
|
|
1361 | } |
|
|
1362 | |
1366 | |
1363 | /* finally, we can send the packet */ |
1367 | /* finally, we can send the packet */ |
1364 | pl->ns->flush_fx (); |
1368 | pl->ns->flush_fx (); |
1365 | pl->ns->send_packet (sl); |
1369 | pl->ns->send_packet (sl); |
1366 | } |
1370 | } |