… | |
… | |
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 | }; |
… | |
… | |
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 | { |
251 | { |
238 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
252 | LOG (llevError, "Buffer overflow in send_skill_info!\n"); |
239 | fatal (0); |
253 | fatal (0); |
… | |
… | |
446 | INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len)); |
460 | INVOKE_CLIENT (ADDME, ns, ARG_DATA (buf, len)); |
447 | } |
461 | } |
448 | |
462 | |
449 | //+GPL |
463 | //+GPL |
450 | |
464 | |
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 | |
|
|
515 | /** |
465 | /** |
516 | * This handles the general commands from the client (ie, north, fire, cast, |
466 | * This handles the general commands from the client (ie, north, fire, cast, |
517 | * etc.) |
467 | * etc.) |
518 | */ |
468 | */ |
519 | void |
469 | void |
… | |
… | |
761 | * commands for now. |
711 | * commands for now. |
762 | */ |
712 | */ |
763 | void |
713 | void |
764 | esrv_update_stats (player *pl) |
714 | esrv_update_stats (player *pl) |
765 | { |
715 | { |
766 | char buf[MAX_BUF]; |
|
|
767 | uint16 flags; |
|
|
768 | |
|
|
769 | client *ns = pl->ns; |
716 | client *ns = pl->ns; |
770 | if (!ns) |
717 | if (!ns) |
771 | return; |
718 | return; |
772 | |
719 | |
773 | object *ob = pl->observe; |
720 | object *ob = pl->observe; |
… | |
… | |
790 | AddIfShort (ns->last_stats.Int, ob->stats.Int, CS_STAT_INT); |
737 | AddIfShort (ns->last_stats.Int, ob->stats.Int, CS_STAT_INT); |
791 | AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); |
738 | AddIfShort (ns->last_stats.Wis, ob->stats.Wis, CS_STAT_WIS); |
792 | AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); |
739 | AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); |
793 | AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); |
740 | AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); |
794 | |
741 | |
795 | for (int s = 0; s < NUM_SKILLS; s++) |
742 | for (int s = 0; s < CS_NUM_SKILLS; s++) |
796 | if (object *skill = opl->last_skill_ob [s]) |
743 | if (object *skill = opl->last_skill_ob [s]) |
797 | if (skill->stats.exp != ns->last_skill_exp [s]) |
744 | if (skill->stats.exp != ns->last_skill_exp [s]) |
798 | { |
745 | { |
799 | ns->last_skill_exp [s] = skill->stats.exp; |
746 | ns->last_skill_exp [s] = skill->stats.exp; |
800 | |
747 | |
801 | /* Always send along the level if exp changes. This is only |
748 | /* Always send along the level if exp changes. This is only |
802 | * 1 extra byte, but keeps processing simpler. |
749 | * 1 extra byte, but keeps processing simpler. |
803 | */ |
750 | */ |
804 | sl << uint8 (s + CS_STAT_SKILLINFO) |
751 | sl << uint8 (CS_STAT_SKILLINFO + s) |
805 | << uint8 (skill->level) |
752 | << uint8 (skill->level) |
806 | << uint64 (skill->stats.exp); |
753 | << uint64 (skill->stats.exp); |
807 | } |
754 | } |
808 | |
755 | |
809 | AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); |
756 | AddIfInt64 (ns->last_stats.exp, ob->stats.exp, CS_STAT_EXP64); |
… | |
… | |
814 | AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK); |
761 | AddIfFloat (ns->last_speed, ob->speed, CS_STAT_SPEED, 1.f / TICK); |
815 | AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); |
762 | AddIfShort (ns->last_stats.food, ob->stats.food, CS_STAT_FOOD); |
816 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); |
763 | AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); |
817 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
764 | AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); |
818 | |
765 | |
819 | flags = 0; |
766 | int flags = (opl->fire_on ? SF_FIREON : 0) |
820 | |
767 | | (opl->run_on ? SF_RUNON : 0); |
821 | if (opl->fire_on) |
|
|
822 | flags |= SF_FIREON; |
|
|
823 | |
|
|
824 | if (opl->run_on) |
|
|
825 | flags |= SF_RUNON; |
|
|
826 | |
768 | |
827 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
769 | AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); |
828 | |
770 | |
829 | for (int i = 0; i < NROFATTACKS; i++) |
771 | for (int i = 0; i < NROFATTACKS; i++) |
830 | { |
|
|
831 | /* Skip ones we won't send */ |
772 | /* Skip ones we won't send */ |
832 | if (atnr_cs_stat[i] == -1) |
773 | if (atnr_cs_stat[i] >= 0) |
833 | continue; |
|
|
834 | |
|
|
835 | AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); |
774 | AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); |
836 | } |
|
|
837 | |
775 | |
838 | if (pl->ns->monitor_spells) |
776 | if (pl->ns->monitor_spells) |
839 | { |
777 | { |
840 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
778 | AddIfInt (ns->last_path_attuned, ob->path_attuned, CS_STAT_SPELL_ATTUNE); |
841 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
779 | AddIfInt (ns->last_path_repelled, ob->path_repelled, CS_STAT_SPELL_REPEL); |
842 | AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); |
780 | AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); |
843 | } |
781 | } |
844 | |
782 | |
|
|
783 | char buf[MAX_BUF]; |
845 | rangetostring (opl, buf); /* we want use the new fire & run system in new client */ |
784 | rangetostring (opl, buf); /* we want use the new fire & run system in new client */ |
846 | AddIfString (ns->stats.range, buf, CS_STAT_RANGE); |
785 | AddIfString (ns->stats.range, buf, CS_STAT_RANGE); |
847 | set_title (ob, buf); |
786 | set_title (ob, buf); |
848 | AddIfString (ns->stats.title, buf, CS_STAT_TITLE); |
787 | AddIfString (ns->stats.title, buf, CS_STAT_TITLE); |
849 | |
788 | |
… | |
… | |
945 | return 0; |
884 | return 0; |
946 | } |
885 | } |
947 | |
886 | |
948 | //-GPL |
887 | //-GPL |
949 | |
888 | |
950 | // prefetch (and touch) all maps within a specific distancd |
889 | // prefetch maps in an area of PREFETCH x PREFETCH around the player |
951 | static void |
890 | #define PREFETCH 40 |
952 | prefetch_surrounding_maps (maptile *map, int distance) |
|
|
953 | { |
|
|
954 | map->touch (); |
|
|
955 | |
|
|
956 | if (--distance) |
|
|
957 | for (int dir = 4; dir--; ) |
|
|
958 | if (const shstr &path = map->tile_path [dir]) |
|
|
959 | if (maptile *&neigh = map->tile_map [dir]) |
|
|
960 | prefetch_surrounding_maps (neigh, distance); |
|
|
961 | else |
|
|
962 | neigh = maptile::find_async (path, map); |
|
|
963 | } |
|
|
964 | |
891 | |
965 | // prefetch a generous area around the player |
892 | // prefetch a generous area around the player |
966 | static void |
893 | static void |
967 | prefetch_surrounding_maps (object *op) |
894 | prefetch_surrounding_maps (object *op) |
968 | { |
895 | { |
969 | prefetch_surrounding_maps (op->map, 3); |
896 | for (maprect *rect = op->map->split_to_tiles (mapwalk_buf, |
|
|
897 | op->x - PREFETCH , op->y - PREFETCH , |
|
|
898 | op->x + PREFETCH + 1, op->y + PREFETCH + 1); |
|
|
899 | rect->m; |
|
|
900 | ++rect) |
|
|
901 | rect->m->touch (); |
970 | } |
902 | } |
971 | |
903 | |
972 | //+GPL |
904 | //+GPL |
973 | |
905 | |
974 | /** |
906 | /** |
… | |
… | |
1126 | { |
1058 | { |
1127 | if (op->stats.maxhp > op->stats.hp |
1059 | if (op->stats.maxhp > op->stats.hp |
1128 | && op->stats.maxhp > 0 |
1060 | && op->stats.maxhp > 0 |
1129 | && (op->type == PLAYER |
1061 | && (op->type == PLAYER |
1130 | || op->type == DOOR // does not work, have maxhp 0 |
1062 | || op->type == DOOR // does not work, have maxhp 0 |
1131 | || QUERY_FLAG (op, FLAG_MONSTER) |
1063 | || op->flag [FLAG_MONSTER] |
1132 | || QUERY_FLAG (op, FLAG_ALIVE) |
1064 | || op->flag [FLAG_ALIVE] |
1133 | || QUERY_FLAG (op, FLAG_GENERATOR))) |
1065 | || op->flag [FLAG_GENERATOR])) |
1134 | { |
1066 | { |
1135 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1067 | stat_hp = 255 - (op->stats.hp * 255 + 254) / op->stats.maxhp; |
1136 | stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge |
1068 | stat_width = op->arch->max_x - op->arch->x; //TODO: should be upper-left edge |
1137 | } |
1069 | } |
1138 | |
1070 | |
… | |
… | |
1333 | spell->cached_eat = casting_level (pl->ob, spell); |
1265 | spell->cached_eat = casting_level (pl->ob, spell); |
1334 | |
1266 | |
1335 | /* figure out which skill it uses, if it uses one */ |
1267 | /* figure out which skill it uses, if it uses one */ |
1336 | if (spell->skill) |
1268 | if (spell->skill) |
1337 | if (object *tmp = pl->find_skill (spell->skill)) |
1269 | if (object *tmp = pl->find_skill (spell->skill)) |
1338 | skill = tmp->subtype + CS_STAT_SKILLINFO; |
1270 | skill = CS_STAT_SKILLINFO + SKILL_INDEX (tmp); |
1339 | |
1271 | |
1340 | // spells better have a face |
1272 | // spells better have a face |
1341 | if (!spell->face) |
1273 | if (!spell->face) |
1342 | { |
1274 | { |
1343 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |
1275 | LOG (llevError, "%s: spell has no face, but face is mandatory.\n", &spell->name); |