ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/player.C
(Generate patch)

Comparing deliantra/server/server/player.C (file contents):
Revision 1.173 by root, Mon Nov 5 23:20:49 2007 UTC vs.
Revision 1.187 by root, Mon Apr 21 07:07:36 2008 UTC

1/* 1/*
2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. 2 * This file is part of Deliantra, the Roguelike Realtime MMORPG.
3 * 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team 4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Crossfire TRT is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or 10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version. 11 * (at your 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,
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 GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * 20 *
21 * The authors can be reached via e-mail to <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <support@deliantra.net>
22 */ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <sproto.h> 25#include <sproto.h>
26#include <sounds.h> 26#include <sounds.h>
215 215
216 /* make sure he's a player -- needed because of class change. */ 216 /* make sure he's a player -- needed because of class change. */
217 ob->type = PLAYER; // we are paranoid 217 ob->type = PLAYER; // we are paranoid
218 ob->race = ob->arch->race; 218 ob->race = ob->arch->race;
219 219
220 ob->carrying = sum_weight (ob); 220 ob->update_weight ();
221 link_player_skills (ob); 221 link_player_skills (ob);
222 222
223 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER); 223 CLEAR_FLAG (ob, FLAG_NO_FIX_PLAYER);
224 224
225 assign (title, ob->arch->object::name); 225 assign (title, ob->arch->object::name);
321 combat_ob = op; 321 combat_ob = op;
322 break; 322 break;
323 } 323 }
324 324
325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
326 ob->deactivate (); // change_Weapon activates, fix this better
326} 327}
327 328
328void 329void
329player::set_observe (object *op) 330player::set_observe (object *op)
330{ 331{
403 * Note: there MUST be at least one player archetype! 404 * Note: there MUST be at least one player archetype!
404 */ 405 */
405archetype * 406archetype *
406get_player_archetype (archetype *at) 407get_player_archetype (archetype *at)
407{ 408{
409 // archetypes could have been reloaded
410 archetype *nat = at ? archetype::find (at->archname) : archetypes [0];
411
412 if (!nat)
413 return at;
414
408 archvec::iterator i = at ? archetypes.find (at) : archetypes.begin (); 415 archvec::iterator i = archetypes.find (nat);
409 416
410 for (;;) 417 for (;;)
411 { 418 {
412 if (++i == archetypes.end ()) 419 if (++i == archetypes.end ())
413 i = archetypes.begin (); 420 i = archetypes.begin ();
631 638
632 return firstdir; 639 return firstdir;
633} 640}
634 641
635void 642void
636give_initial_items (object *pl, treasurelist * items) 643give_initial_items (object *pl, treasurelist *items)
637{ 644{
638 object *op, *next = NULL;
639
640 if (pl->randomitems != NULL) 645 if (pl->randomitems)
641 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0); 646 create_treasure (items, pl, GT_STARTEQUIP | GT_ONLY_GOOD, 1, 0);
642 647
643 for (op = pl->inv; op; op = next) 648 for (object *next, *op = pl->inv; op; op = next)
644 { 649 {
645 next = op->below; 650 next = op->below;
646 651
647 /* Forces get applied per default, unless they have the 652 /* Forces get applied per default, unless they have the
648 * flag "neutral" set. Sorry but I can't think of a better way 653 * flag "neutral" set. Sorry but I can't think of a better way
653 /* we never give weapons/armour if these cannot be used 658 /* we never give weapons/armour if these cannot be used
654 * by this player due to race restrictions 659 * by this player due to race restrictions
655 */ 660 */
656 if (pl->type == PLAYER) 661 if (pl->type == PLAYER)
657 { 662 {
658 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR) && 663 if ((!QUERY_FLAG (pl, FLAG_USE_ARMOUR)
664 &&
659 (op->type == ARMOUR || op->type == BOOTS || 665 (op->type == ARMOUR || op->type == BOOTS
660 op->type == CLOAK || op->type == HELMET || 666 || op->type == CLOAK || op->type == HELMET
661 op->type == SHIELD || op->type == GLOVES || 667 || op->type == SHIELD || op->type == GLOVES
668 || op->type == BRACERS || op->type == GIRDLE))
662 op->type == BRACERS || op->type == GIRDLE)) || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON)) 669 || (!QUERY_FLAG (pl, FLAG_USE_WEAPON) && op->type == WEAPON))
663 { 670 {
664 op->destroy (); 671 op->destroy ();
665 continue; 672 continue;
666 } 673 }
667 } 674 }
690 if (op->nrof > 1) 697 if (op->nrof > 1)
691 op->nrof = 1; 698 op->nrof = 1;
692 } 699 }
693 700
694 if (op->type == SPELLBOOK && op->inv) 701 if (op->type == SPELLBOOK && op->inv)
695 {
696 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP); 702 CLEAR_FLAG (op->inv, FLAG_STARTEQUIP);
697 }
698 703
699 /* Give starting characters identified, uncursed, and undamned 704 /* Give starting characters identified, uncursed, and undamned
700 * items. Just don't identify gold or silver, or it won't be 705 * items. Just don't identify gold or silver, or it won't be
701 * merged properly. 706 * merged properly.
702 */ 707 */
703 if (need_identify (op)) 708 if (need_identify (op))
704 { 709 {
705 SET_FLAG (op, FLAG_IDENTIFIED); 710 SET_FLAG (op, FLAG_IDENTIFIED);
706 CLEAR_FLAG (op, FLAG_CURSED); 711 CLEAR_FLAG (op, FLAG_CURSED);
707 CLEAR_FLAG (op, FLAG_DAMNED); 712 CLEAR_FLAG (op, FLAG_DAMNED);
708 } 713 }
714
709 if (op->type == SPELL) 715 if (op->type == SPELL)
710 { 716 {
711 op->destroy (); 717 op->destroy ();
712 continue; 718 continue;
713 } 719 }
715 { 721 {
716 SET_FLAG (op, FLAG_CAN_USE_SKILL); 722 SET_FLAG (op, FLAG_CAN_USE_SKILL);
717 op->stats.exp = 0; 723 op->stats.exp = 0;
718 op->level = 1; 724 op->level = 1;
719 } 725 }
720 /* lock all 'normal items by default */ 726 else /* lock all 'normal items by default */
721 else
722 SET_FLAG (op, FLAG_INV_LOCKED); 727 SET_FLAG (op, FLAG_INV_LOCKED);
723 } /* for loop of objects in player inv */ 728 } /* for loop of objects in player inv */
724 729
725 /* Need to set up the skill pointers */ 730 /* Need to set up the skill pointers */
726 link_player_skills (pl); 731 link_player_skills (pl);
832static void 837static void
833start_info (object *op) 838start_info (object *op)
834{ 839{
835 char buf[MAX_BUF]; 840 char buf[MAX_BUF];
836 841
837 sprintf (buf, "Welcome to Crossfire v%s!", VERSION); 842 sprintf (buf, "Welcome to Deliantra v%s!", VERSION);
838 new_draw_info (NDI_UNIQUE, 0, op, buf); 843 new_draw_info (NDI_UNIQUE, 0, op, buf);
839 //new_draw_info (NDI_UNIQUE, 0, op, "Press `?' for help");
840 //new_draw_info (NDI_UNIQUE, 0, op, " ");
841} 844}
842 845
843/* This function takes the key that is passed, and does the 846/* This function takes the key that is passed, and does the
844 * appropriate action with it (change race, or other things). 847 * appropriate action with it (change race, or other things).
845 * The function name is for historical reasons - now we have 848 * The function name is for historical reasons - now we have
1008 if (op->move_type & MOVE_FLYING) 1011 if (op->move_type & MOVE_FLYING)
1009 return 1; 1012 return 1;
1010 1013
1011 next = op->below; 1014 next = op->below;
1012 1015
1016 int cnt = MAX_ITEM_PER_DROP;
1017#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
1018
1013 /* loop while there are items on the floor that are not marked as 1019 /* loop while there are items on the floor that are not marked as
1014 * destroyed */ 1020 * destroyed */
1015 while (next && !next->destroyed ()) 1021 while (next && !next->destroyed ())
1016 { 1022 {
1017 tmp = next; 1023 tmp = next;
1018 next = tmp->below; 1024 next = tmp->below;
1019 1025
1026 if (cnt <= 0)
1027 {
1028 op->failmsg ("Couldn't pickup all items at once.");
1029 return 0;
1030 }
1031
1020 if (op->destroyed ()) 1032 if (op->destroyed ())
1021 return 0; 1033 return 0;
1022 1034
1023 if (!can_pick (op, tmp)) 1035 if (!can_pick (op, tmp))
1024 continue; 1036 continue;
1025 1037
1026 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1038 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1027 { 1039 {
1028 if (item_matched_string (op, tmp, op->contr->search_str)) 1040 if (item_matched_string (op, tmp, op->contr->search_str))
1029 pick_up (op, tmp); 1041 CHK_PICK_PICKUP;
1030 continue; 1042 continue;
1031 } 1043 }
1032 1044
1033 /* high not bit set? We're using the old autopickup model */ 1045 /* high not bit set? We're using the old autopickup model */
1034 if (!(op->contr->mode & PU_NEWMODE)) 1046 if (!(op->contr->mode & PU_NEWMODE))
1036 switch (op->contr->mode) 1048 switch (op->contr->mode)
1037 { 1049 {
1038 case 0: 1050 case 0:
1039 return 1; /* don't pick up */ 1051 return 1; /* don't pick up */
1040 case 1: 1052 case 1:
1041 pick_up (op, tmp); 1053 CHK_PICK_PICKUP;
1042 return 1; 1054 return 1;
1043 case 2: 1055 case 2:
1044 pick_up (op, tmp); 1056 CHK_PICK_PICKUP;
1045 return 0; 1057 return 0;
1046 case 3: 1058 case 3:
1047 return 0; /* stop before pickup */ 1059 return 0; /* stop before pickup */
1048 case 4: 1060 case 4:
1049 pick_up (op, tmp); 1061 CHK_PICK_PICKUP;
1050 break; 1062 break;
1051 case 5: 1063 case 5:
1052 pick_up (op, tmp); 1064 CHK_PICK_PICKUP;
1053 stop = 1; 1065 stop = 1;
1054 break; 1066 break;
1055 case 6: 1067 case 6:
1056 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1068 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1057 pick_up (op, tmp); 1069 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1070 CHK_PICK_PICKUP;
1058 break; 1071 break;
1059 1072
1060 case 7: 1073 case 7:
1061 if (tmp->type == MONEY || tmp->type == GEM) 1074 if (tmp->type == MONEY || tmp->type == GEM)
1062 pick_up (op, tmp); 1075 CHK_PICK_PICKUP;
1063 break; 1076 break;
1064 1077
1065 default: 1078 default:
1066 /* use value density */ 1079 /* use value density */
1067 if (!QUERY_FLAG (tmp, FLAG_UNPAID) 1080 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1068 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) 1081 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1069 pick_up (op, tmp); 1082 CHK_PICK_PICKUP;
1070 } 1083 }
1071 } 1084 }
1072 else 1085 else
1073 { /* old model */ 1086 { /* old model */
1074 /* NEW pickup handling */ 1087 /* NEW pickup handling */
1129 /* all food and drink if desired */ 1142 /* all food and drink if desired */
1130 /* question: don't pick up known-poisonous stuff? */ 1143 /* question: don't pick up known-poisonous stuff? */
1131 if (op->contr->mode & PU_FOOD) 1144 if (op->contr->mode & PU_FOOD)
1132 if (tmp->type == FOOD) 1145 if (tmp->type == FOOD)
1133 { 1146 {
1134 pick_up (op, tmp); 1147 CHK_PICK_PICKUP;
1135 continue; 1148 continue;
1136 } 1149 }
1137 1150
1138 if (op->contr->mode & PU_DRINK) 1151 if (op->contr->mode & PU_DRINK)
1139 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1152 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1140 { 1153 {
1141 pick_up (op, tmp); 1154 CHK_PICK_PICKUP;
1142 continue; 1155 continue;
1143 } 1156 }
1144 1157
1145 if (op->contr->mode & PU_POTION) 1158 if (op->contr->mode & PU_POTION)
1146 if (tmp->type == POTION) 1159 if (tmp->type == POTION)
1147 { 1160 {
1148 pick_up (op, tmp); 1161 CHK_PICK_PICKUP;
1149 continue; 1162 continue;
1150 } 1163 }
1151 1164
1152 /* spellbooks, skillscrolls and normal books/scrolls */ 1165 /* spellbooks, skillscrolls and normal books/scrolls */
1153 if (op->contr->mode & PU_SPELLBOOK) 1166 if (op->contr->mode & PU_SPELLBOOK)
1154 if (tmp->type == SPELLBOOK) 1167 if (tmp->type == SPELLBOOK)
1155 { 1168 {
1156 pick_up (op, tmp); 1169 CHK_PICK_PICKUP;
1157 continue; 1170 continue;
1158 } 1171 }
1159 1172
1160 if (op->contr->mode & PU_SKILLSCROLL) 1173 if (op->contr->mode & PU_SKILLSCROLL)
1161 if (tmp->type == SKILLSCROLL) 1174 if (tmp->type == SKILLSCROLL)
1162 { 1175 {
1163 pick_up (op, tmp); 1176 CHK_PICK_PICKUP;
1164 continue; 1177 continue;
1165 } 1178 }
1166 1179
1167 if (op->contr->mode & PU_READABLES) 1180 if (op->contr->mode & PU_READABLES)
1168 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE) 1181 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1169 { 1182 {
1170 pick_up (op, tmp); 1183 CHK_PICK_PICKUP;
1171 continue; 1184 continue;
1172 } 1185 }
1173 1186
1174 /* wands/staves/rods/horns */ 1187 /* wands/staves/rods/horns */
1175 if (op->contr->mode & PU_MAGIC_DEVICE) 1188 if (op->contr->mode & PU_MAGIC_DEVICE)
1176 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1189 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1177 { 1190 {
1178 pick_up (op, tmp); 1191 CHK_PICK_PICKUP;
1179 continue; 1192 continue;
1180 } 1193 }
1181 1194
1182 /* pick up all magical items */ 1195 /* pick up all magical items */
1183 if (op->contr->mode & PU_MAGICAL) 1196 if (op->contr->mode & PU_MAGICAL)
1184 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1197 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1185 { 1198 {
1186 pick_up (op, tmp); 1199 CHK_PICK_PICKUP;
1187 continue; 1200 continue;
1188 } 1201 }
1189 1202
1190 if (op->contr->mode & PU_VALUABLES) 1203 if (op->contr->mode & PU_VALUABLES)
1191 { 1204 {
1192 if (tmp->type == MONEY || tmp->type == GEM) 1205 if (tmp->type == MONEY || tmp->type == GEM)
1193 { 1206 {
1194 pick_up (op, tmp); 1207 CHK_PICK_PICKUP;
1195 continue; 1208 continue;
1196 } 1209 }
1197 } 1210 }
1198 1211
1199 /* rings & amulets - talismans seems to be typed AMULET */ 1212 /* rings & amulets - talismans seems to be typed AMULET */
1200 if (op->contr->mode & PU_JEWELS) 1213 if (op->contr->mode & PU_JEWELS)
1201 if (tmp->type == RING || tmp->type == AMULET) 1214 if (tmp->type == RING || tmp->type == AMULET)
1202 { 1215 {
1203 pick_up (op, tmp); 1216 CHK_PICK_PICKUP;
1204 continue; 1217 continue;
1205 } 1218 }
1206 1219
1207 /* we don't forget dragon food */ 1220 /* we don't forget dragon food */
1208 if (op->contr->mode & PU_FLESH) 1221 if (op->contr->mode & PU_FLESH)
1209 if (tmp->type == FLESH) 1222 if (tmp->type == FLESH)
1210 { 1223 {
1211 pick_up (op, tmp); 1224 CHK_PICK_PICKUP;
1212 continue; 1225 continue;
1213 } 1226 }
1214 1227
1215 /* bows and arrows. Bows are good for selling! */ 1228 /* bows and arrows. Bows are good for selling! */
1216 if (op->contr->mode & PU_BOW) 1229 if (op->contr->mode & PU_BOW)
1217 if (tmp->type == BOW) 1230 if (tmp->type == BOW)
1218 { 1231 {
1219 pick_up (op, tmp); 1232 CHK_PICK_PICKUP;
1220 continue; 1233 continue;
1221 } 1234 }
1222 1235
1223 if (op->contr->mode & PU_ARROW) 1236 if (op->contr->mode & PU_ARROW)
1224 if (tmp->type == ARROW) 1237 if (tmp->type == ARROW)
1225 { 1238 {
1226 pick_up (op, tmp); 1239 CHK_PICK_PICKUP;
1227 continue; 1240 continue;
1228 } 1241 }
1229 1242
1230 /* all kinds of armor etc. */ 1243 /* all kinds of armor etc. */
1231 if (op->contr->mode & PU_ARMOUR) 1244 if (op->contr->mode & PU_ARMOUR)
1232 if (tmp->type == ARMOUR) 1245 if (tmp->type == ARMOUR)
1233 { 1246 {
1234 pick_up (op, tmp); 1247 CHK_PICK_PICKUP;
1235 continue; 1248 continue;
1236 } 1249 }
1237 1250
1238 if (op->contr->mode & PU_HELMET) 1251 if (op->contr->mode & PU_HELMET)
1239 if (tmp->type == HELMET) 1252 if (tmp->type == HELMET)
1240 { 1253 {
1241 pick_up (op, tmp); 1254 CHK_PICK_PICKUP;
1242 continue; 1255 continue;
1243 } 1256 }
1244 1257
1245 if (op->contr->mode & PU_SHIELD) 1258 if (op->contr->mode & PU_SHIELD)
1246 if (tmp->type == SHIELD) 1259 if (tmp->type == SHIELD)
1247 { 1260 {
1248 pick_up (op, tmp); 1261 CHK_PICK_PICKUP;
1249 continue; 1262 continue;
1250 } 1263 }
1251 1264
1252 if (op->contr->mode & PU_BOOTS) 1265 if (op->contr->mode & PU_BOOTS)
1253 if (tmp->type == BOOTS) 1266 if (tmp->type == BOOTS)
1254 { 1267 {
1255 pick_up (op, tmp); 1268 CHK_PICK_PICKUP;
1256 continue; 1269 continue;
1257 } 1270 }
1258 1271
1259 if (op->contr->mode & PU_GLOVES) 1272 if (op->contr->mode & PU_GLOVES)
1260 if (tmp->type == GLOVES) 1273 if (tmp->type == GLOVES)
1261 { 1274 {
1262 pick_up (op, tmp); 1275 CHK_PICK_PICKUP;
1263 continue; 1276 continue;
1264 } 1277 }
1265 1278
1266 if (op->contr->mode & PU_CLOAK) 1279 if (op->contr->mode & PU_CLOAK)
1267 if (tmp->type == CLOAK) 1280 if (tmp->type == CLOAK)
1268 { 1281 {
1269 pick_up (op, tmp); 1282 CHK_PICK_PICKUP;
1270 continue; 1283 continue;
1271 } 1284 }
1272 1285
1273 /* hoping to catch throwing daggers here */ 1286 /* hoping to catch throwing daggers here */
1274 if (op->contr->mode & PU_MISSILEWEAPON) 1287 if (op->contr->mode & PU_MISSILEWEAPON)
1275 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1288 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1276 { 1289 {
1277 pick_up (op, tmp); 1290 CHK_PICK_PICKUP;
1278 continue; 1291 continue;
1279 } 1292 }
1280 1293
1281 /* careful: chairs and tables are weapons! */ 1294 /* careful: chairs and tables are weapons! */
1282 if (op->contr->mode & PU_ALLWEAPON) 1295 if (op->contr->mode & PU_ALLWEAPON)
1284 if (tmp->type == WEAPON && tmp->name != NULL) 1297 if (tmp->type == WEAPON && tmp->name != NULL)
1285 { 1298 {
1286 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL && 1299 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1287 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL) 1300 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1288 { 1301 {
1289 pick_up (op, tmp); 1302 CHK_PICK_PICKUP;
1290 continue; 1303 continue;
1291 } 1304 }
1292 } 1305 }
1293 1306
1294 if (tmp->type == WEAPON && tmp->name == NULL) 1307 if (tmp->type == WEAPON && tmp->name == NULL)
1295 { 1308 {
1296 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL) 1309 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1297 { 1310 {
1298 pick_up (op, tmp); 1311 CHK_PICK_PICKUP;
1299 continue; 1312 continue;
1300 } 1313 }
1301 } 1314 }
1302 } 1315 }
1303 1316
1304 /* misc stuff that's useful */ 1317 /* misc stuff that's useful */
1305 if (op->contr->mode & PU_KEY) 1318 if (op->contr->mode & PU_KEY)
1306 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1319 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1307 { 1320 {
1308 pick_up (op, tmp); 1321 CHK_PICK_PICKUP;
1309 continue; 1322 continue;
1310 } 1323 }
1311 1324
1312 /* any of the last 4 bits set means we use the ratio for value 1325 /* any of the last 4 bits set means we use the ratio for value
1313 * pickups */ 1326 * pickups */
1318 /* >=7 is the old standard setting. Now we take the last 4 bits 1331 /* >=7 is the old standard setting. Now we take the last 4 bits
1319 * and multiply them by 5, giving 0..15*5== 5..75 */ 1332 * and multiply them by 5, giving 0..15*5== 5..75 */
1320 wvratio = (op->contr->mode & PU_RATIO) * 5; 1333 wvratio = (op->contr->mode & PU_RATIO) * 5;
1321 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio) 1334 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio)
1322 { 1335 {
1323 pick_up (op, tmp); 1336 CHK_PICK_PICKUP;
1324#if 0 1337#if 0
1325 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1338 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1326 if (tmp->name != NULL) 1339 if (tmp->name != NULL)
1327 { 1340 {
1328 fprintf (stderr, "%s", tmp->name); 1341 fprintf (stderr, "%s", tmp->name);
1347 * found object is returned. 1360 * found object is returned.
1348 */ 1361 */
1349object * 1362object *
1350find_arrow (object *op, const char *type) 1363find_arrow (object *op, const char *type)
1351{ 1364{
1352 object *tmp = 0;
1353
1354 for (op = op->inv; op; op = op->below) 1365 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1355 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1356 tmp = find_arrow (splay (op), type);
1357 else if (op->type == ARROW && op->race == type) 1366 if (tmp->type == ARROW && !strcmp (&tmp->race, type))
1358 return splay (op); 1367 return splay (tmp);
1359 1368
1369 for (object *tmp = op->inv; tmp; tmp = tmp->below)
1370 if (tmp->type == CONTAINER && QUERY_FLAG (tmp, FLAG_APPLIED) && !strcmp (&tmp->race, type))
1371 if (object *arrow = find_arrow (tmp, type))
1372 {
1373 splay (tmp);
1374 return arrow;
1375 }
1376
1360 return tmp; 1377 return 0;
1361} 1378}
1362 1379
1363/* 1380/*
1364 * Similar to find_arrow, but looks for (roughly) the best arrow to use 1381 * Similar to find_arrow, but looks for (roughly) the best arrow to use
1365 * against the target. A full test is not performed, simply a basic test 1382 * against the target. A full test is not performed, simply a basic test
1586 arrow->destroy (); 1603 arrow->destroy ();
1587 return 0; 1604 return 0;
1588 } 1605 }
1589 1606
1590 left = arrow; /* these are arrows left to the player */ 1607 left = arrow; /* these are arrows left to the player */
1591 arrow = get_split_ob (arrow, 1); 1608 arrow = arrow->split ();
1592 if (!arrow) 1609 if (!arrow)
1593 { 1610 {
1594 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race); 1611 new_draw_info_format (NDI_UNIQUE, 0, op, "You have no %s left.", &bow->race);
1595 return 0; 1612 return 0;
1596 } 1613 }
1663 op->play_sound (sound_find ("fire_arrow")); 1680 op->play_sound (sound_find ("fire_arrow"));
1664 m->insert (arrow, sx, sy, op); 1681 m->insert (arrow, sx, sy, op);
1665 1682
1666 if (!arrow->destroyed ()) 1683 if (!arrow->destroyed ())
1667 move_arrow (arrow); 1684 move_arrow (arrow);
1668
1669 if (op->type == PLAYER)
1670 {
1671 if (left->destroyed ())
1672 esrv_del_item (op->contr, left->count);
1673 else
1674 esrv_send_item (op, left);
1675 }
1676 1685
1677 return 1; 1686 return 1;
1678} 1687}
1679 1688
1680/* Special fire code for players - this takes into 1689/* Special fire code for players - this takes into
1970 op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN); 1979 op->statusmsg (format ("You open the door with the %s", query_short_name (key)), NDI_BROWN);
1971 remove_door2 (door); /* remove door without violence ;-) */ 1980 remove_door2 (door); /* remove door without violence ;-) */
1972 } 1981 }
1973 1982
1974 /* Do this after we print the message */ 1983 /* Do this after we print the message */
1975 decrease_ob (key); /* Use up one of the keys */ 1984 key->decrease (); /* Use up one of the keys */
1976 /* Need to update the weight the container the key was in */ 1985 /* Need to update the weight the container the key was in */
1977 if (container != op) 1986 if (container != op)
1978 esrv_update_item (UPD_WEIGHT, op, container); 1987 esrv_update_item (UPD_WEIGHT, op, container);
1979 1988
1980 return 1; /* Nothing more to do below */ 1989 return 1; /* Nothing more to do below */
2164bool 2173bool
2165move_player (object *op, int dir) 2174move_player (object *op, int dir)
2166{ 2175{
2167 int pick; 2176 int pick;
2168 2177
2169 if (!op->map || op->map->in_memory != MAP_IN_MEMORY) 2178 if (!op->map || op->map->in_memory != MAP_ACTIVE)
2170 return 0; 2179 return 0;
2171 2180
2172 /* Sanity check: make sure dir is valid */ 2181 /* Sanity check: make sure dir is valid */
2173 if ((dir < 0) || (dir >= 9)) 2182 if ((dir < 0) || (dir >= 9))
2174 { 2183 {
2917 2926
2918 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3)))) 2927 if (!QUERY_FLAG (tmp, FLAG_UNIQUE) && (QUERY_FLAG (tmp, FLAG_STARTEQUIP) || QUERY_FLAG (tmp, FLAG_NO_DROP) || !(rndm (3))))
2919 { 2928 {
2920 if (tmp->nrof > 1) 2929 if (tmp->nrof > 1)
2921 { 2930 {
2922 tmp2 = get_split_ob (tmp, 1 + RANDOM () % (tmp->nrof - 1)); 2931 tmp->decrease (rndm (1, tmp->nrof - 1));
2923 tmp2->destroy ();
2924 insert_ob_in_map (tmp, op->map, NULL, 0); 2932 insert_ob_in_map (tmp, op->map, NULL, 0);
2925 } 2933 }
2926 else 2934 else
2927 tmp->destroy (); 2935 tmp->destroy ();
2928 } 2936 }
2939void 2947void
2940fix_weight (void) 2948fix_weight (void)
2941{ 2949{
2942 for_all_players (pl) 2950 for_all_players (pl)
2943 { 2951 {
2944 int old = pl->ob->carrying, sum = sum_weight (pl->ob); 2952 sint32 old = pl->ob->carrying;
2945 2953
2946 if (old == sum) 2954 pl->ob->update_weight ();
2947 continue; 2955
2956 if (old != pl->ob->carrying)
2957 {
2948 pl->ob->update_stats (); 2958 pl->ob->update_stats ();
2949 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, old, sum); 2959 LOG (llevDebug, "Fixed inventory in %s (%d -> %d)\n", &pl->ob->name, (int)old, (int)pl->ob->carrying);
2960 }
2950 } 2961 }
2951} 2962}
2952 2963
2953void 2964void
2954fix_luck (void) 2965fix_luck (void)
3040 * as bad as carrying a light on a pitch dark map */ 3051 * as bad as carrying a light on a pitch dark map */
3041 if (has_carried_lights (ob)) 3052 if (has_carried_lights (ob))
3042 level = -(10 + (2 * ob->map->darkness)); 3053 level = -(10 + (2 * ob->map->darkness));
3043 3054
3044 /* scan through all nearby squares for terrain to hide in */ 3055 /* scan through all nearby squares for terrain to hide in */
3045 for (i = 0, x = ob->x, y = ob->y; i < 9; i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i]) 3056 for (i = 0, x = ob->x, y = ob->y;
3057 i <= SIZEOFFREE1;
3058 i++, x = ob->x + freearr_x[i], y = ob->y + freearr_y[i])
3046 { 3059 {
3047 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL); 3060 mflag = get_map_flags (ob->map, NULL, x, y, NULL, NULL);
3048 if (mflag & P_OUT_OF_MAP) 3061 if (mflag & P_OUT_OF_MAP)
3049 {
3050 continue; 3062 continue;
3051 } 3063
3052 if (mflag & P_BLOCKSVIEW) /* something to hide near! */ 3064 if (mflag & P_BLOCKSVIEW) /* something to hide near! */
3053 level += 2; 3065 level += 2;
3054 else /* open terrain! */ 3066 else /* open terrain! */
3055 level -= 1; 3067 level -= 1;
3056 } 3068 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines