--- deliantra/server/socket/request.C 2010/04/11 00:34:07 1.171 +++ deliantra/server/socket/request.C 2010/10/16 22:51:52 1.177 @@ -67,16 +67,30 @@ * client. If a value is -1, then we don't send that to the * client. */ -static short atnr_cs_stat[NROFATTACKS] = { CS_STAT_RES_PHYS, - CS_STAT_RES_MAG, CS_STAT_RES_FIRE, CS_STAT_RES_ELEC, - CS_STAT_RES_COLD, CS_STAT_RES_CONF, CS_STAT_RES_ACID, - CS_STAT_RES_DRAIN, -1 /* weaponmagic */ , - CS_STAT_RES_GHOSTHIT, CS_STAT_RES_POISON, - CS_STAT_RES_SLOW, CS_STAT_RES_PARA, CS_STAT_TURN_UNDEAD, - CS_STAT_RES_FEAR, -1 /* Cancellation */ , - CS_STAT_RES_DEPLETE, CS_STAT_RES_DEATH, - -1 /* Chaos */ , -1 /* Counterspell */ , - -1 /* Godpower */ , CS_STAT_RES_HOLYWORD, +static short atnr_cs_stat[NROFATTACKS] = +{ + CS_STAT_RES_PHYS, + CS_STAT_RES_MAG, + CS_STAT_RES_FIRE, + CS_STAT_RES_ELEC, + CS_STAT_RES_COLD, + CS_STAT_RES_CONF, + CS_STAT_RES_ACID, + CS_STAT_RES_DRAIN, + -1 /* weaponmagic */, + CS_STAT_RES_GHOSTHIT, + CS_STAT_RES_POISON, + CS_STAT_RES_SLOW, + CS_STAT_RES_PARA, + CS_STAT_TURN_UNDEAD, + CS_STAT_RES_FEAR, + -1 /* Cancellation */, + CS_STAT_RES_DEPLETE, + CS_STAT_RES_DEATH, + -1 /* Chaos */, + -1 /* Counterspell */, + -1 /* Godpower */, + CS_STAT_RES_HOLYWORD, CS_STAT_RES_BLIND, -1, /* Internal */ -1, /* life stealing */ @@ -134,10 +148,7 @@ memset (&pl->ns->lastmap, 0, sizeof (pl->ns->lastmap)); pl->ns->force_newmap = false; - - if (pl->ns->newmapcmd == 1) - pl->ns->send_packet ("newmap"); - + pl->ns->send_packet ("newmap"); pl->ns->floorbox_reset (); } @@ -230,14 +241,11 @@ packet sl; sl << "replyinfo skill_info\n"; - for (int i = 1; i < NUM_SKILLS; i++) - sl.printf ("%d:%s\n", i + CS_STAT_SKILLINFO, &skill_names [i]); + for (int i = 0; i < skillvec.size (); ++i) + sl.printf ("%d:%s\n", CS_STAT_SKILLINFO + i, &skillvec [i]->name); if (sl.length () > MAXSOCKBUF) - { - LOG (llevError, "Buffer overflow in send_skill_info!\n"); - fatal (0); - } + cleanup ("buffer overflow in send_skill_info!"); ns->send_packet (sl); } @@ -257,10 +265,7 @@ sl.printf ("%d:%s\n", 1 << i, spellpathnames[i]); if (sl.length () > MAXSOCKBUF) - { - LOG (llevError, "Buffer overflow in send_spell_paths!\n"); - fatal (0); - } + cleanup ("buffer overflow in send_spell_paths!"); ns->send_packet (sl); } @@ -699,9 +704,6 @@ void esrv_update_stats (player *pl) { - char buf[MAX_BUF]; - uint16 flags; - client *ns = pl->ns; if (!ns) return; @@ -728,7 +730,7 @@ AddIfShort (ns->last_stats.Pow, ob->stats.Pow, CS_STAT_POW); AddIfShort (ns->last_stats.Cha, ob->stats.Cha, CS_STAT_CHA); - for (int s = 0; s < NUM_SKILLS; s++) + for (int s = 0; s < CS_NUM_SKILLS; s++) if (object *skill = opl->last_skill_ob [s]) if (skill->stats.exp != ns->last_skill_exp [s]) { @@ -737,7 +739,7 @@ /* Always send along the level if exp changes. This is only * 1 extra byte, but keeps processing simpler. */ - sl << uint8 (s + CS_STAT_SKILLINFO) + sl << uint8 (CS_STAT_SKILLINFO + s) << uint8 (skill->level) << uint64 (skill->stats.exp); } @@ -752,24 +754,15 @@ AddIfFloat (ns->last_weapon_sp, pl->weapon_sp, CS_STAT_WEAP_SP, 1.f / TICK); AddIfInt (ns->last_weight_limit, weight_limit[ob->stats.Str], CS_STAT_WEIGHT_LIM); - flags = 0; - - if (opl->fire_on) - flags |= SF_FIREON; - - if (opl->run_on) - flags |= SF_RUNON; + int flags = (opl->fire_on ? SF_FIREON : 0) + | (opl->run_on ? SF_RUNON : 0); AddIfShort (ns->last_flags, flags, CS_STAT_FLAGS); for (int i = 0; i < NROFATTACKS; i++) - { - /* Skip ones we won't send */ - if (atnr_cs_stat[i] == -1) - continue; - + /* Skip ones we won't send */ + if (atnr_cs_stat[i] >= 0) AddIfShort (ns->last_resist[i], ob->resist[i], atnr_cs_stat[i]); - } if (pl->ns->monitor_spells) { @@ -778,6 +771,7 @@ AddIfInt (ns->last_path_denied, ob->path_denied, CS_STAT_SPELL_DENY); } + char buf[MAX_BUF]; rangetostring (opl, buf); /* we want use the new fire & run system in new client */ AddIfString (ns->stats.range, buf, CS_STAT_RANGE); set_title (ob, buf); @@ -883,26 +877,19 @@ //-GPL -// prefetch (and touch) all maps within a specific distancd -static void -prefetch_surrounding_maps (maptile *map, int distance) -{ - map->touch (); - - if (--distance) - for (int dir = 4; dir--; ) - if (const shstr &path = map->tile_path [dir]) - if (maptile *&neigh = map->tile_map [dir]) - prefetch_surrounding_maps (neigh, distance); - else - neigh = maptile::find_async (path, map); -} +// prefetch maps in an area of PREFETCH x PREFETCH around the player +#define PREFETCH 40 // prefetch a generous area around the player static void prefetch_surrounding_maps (object *op) { - prefetch_surrounding_maps (op->map, 3); + for (maprect *rect = op->map->split_to_tiles (mapwalk_buf, + op->x - PREFETCH , op->y - PREFETCH , + op->x + PREFETCH + 1, op->y + PREFETCH + 1); + rect->m; + ++rect) + rect->m->touch (); } //+GPL @@ -962,7 +949,7 @@ client &socket = *pl->ns; - packet sl (socket.mapmode == Map1Cmd ? "map1" : "map1a"); + packet sl ("map1a"); startlen = sl.length (); @@ -1271,7 +1258,7 @@ /* figure out which skill it uses, if it uses one */ if (spell->skill) if (object *tmp = pl->find_skill (spell->skill)) - skill = tmp->subtype + CS_STAT_SKILLINFO; + skill = CS_STAT_SKILLINFO + SKILL_INDEX (tmp); // spells better have a face if (!spell->face) @@ -1355,10 +1342,7 @@ append_spell (pl, sl, spell); if (sl.length () > MAXSOCKBUF) - { - LOG (llevError, "Buffer overflow in esrv_add_spells!\n"); - fatal (0); - } + cleanup ("buffer overflow in esrv_add_spells!"); /* finally, we can send the packet */ pl->ns->flush_fx ();