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.171 by root, Sat Sep 8 07:06:51 2007 UTC vs.
Revision 1.175 by elmex, Mon Nov 26 12:54:32 2007 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>
241 241
242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!"); 242 new_draw_info (NDI_UNIQUE, 0, ob, "Welcome Back!");
243 243
244 esrv_new_player (this, ob->weight + ob->carrying); 244 esrv_new_player (this, ob->weight + ob->carrying);
245 245
246 ob->update_stats ();
247
248 ns->floorbox_update ();
249 esrv_send_inventory (ob, ob);
250 esrv_add_spells (this, 0);
251
252 activate ();
253
254 send_rules (ob);
255 send_news (ob);
256 display_motd (ob);
257
258 INVOKE_PLAYER (CONNECT, this);
259 INVOKE_PLAYER (LOGIN, this);
260}
261
262void
263player::disconnect ()
264{
265 if (ob)
266 {
267 ob->close_container (); //TODO: client-specific
268 ob->drop_unpaid_items ();
269 }
270
271 if (ns)
272 {
273 if (active)
274 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
275
276 INVOKE_PLAYER (DISCONNECT, this);
277
278 ns->reset_stats ();
279 ns->pl = 0;
280 ns = 0;
281 }
282
283 observe = ob;
284
285 deactivate ();
286}
287
288// the need for this function can be explained
289// by load_object not returning the object
290void
291player::set_object (object *op)
292{
293 ob = observe = op;
294 ob->contr = this; /* this aren't yet in archetype */
295
296 ob->speed = 1.0f;
297 ob->speed_left = 0.5f;
298
299 ob->direction = 5; /* So player faces south */
300
246 ob->flag [FLAG_READY_WEAPON] = false; 301 ob->flag [FLAG_READY_WEAPON] = false;
247 ob->flag [FLAG_READY_SKILL] = false; 302 ob->flag [FLAG_READY_SKILL] = false;
248 ob->flag [FLAG_READY_BOW] = false; 303 ob->flag [FLAG_READY_BOW] = false;
249 304
250 for (object *op = ob->inv; op; op = op->below) 305 for (object *op = ob->inv; op; op = op->below)
266 combat_ob = op; 321 combat_ob = op;
267 break; 322 break;
268 } 323 }
269 324
270 ob->change_weapon (combat_ob ? combat_ob : ranged_ob); 325 ob->change_weapon (combat_ob ? combat_ob : ranged_ob);
271 ob->update_stats ();
272
273 ns->floorbox_update ();
274 esrv_send_inventory (ob, ob);
275 esrv_add_spells (this, 0);
276
277 activate ();
278
279 send_rules (ob);
280 send_news (ob);
281 display_motd (ob);
282
283 INVOKE_PLAYER (CONNECT, this);
284 INVOKE_PLAYER (LOGIN, this);
285}
286
287void
288player::disconnect ()
289{
290 if (ob)
291 {
292 ob->close_container (); //TODO: client-specific
293 ob->drop_unpaid_items ();
294 }
295
296 if (ns)
297 {
298 if (active)
299 INVOKE_PLAYER (LOGOUT, this, ARG_INT (0));
300
301 INVOKE_PLAYER (DISCONNECT, this);
302
303 ns->reset_stats ();
304 ns->pl = 0;
305 ns = 0;
306 }
307
308 observe = ob;
309
310 deactivate ();
311}
312
313// the need for this function can be explained
314// by load_object not returning the object
315void
316player::set_object (object *op)
317{
318 ob = observe = op;
319 ob->contr = this; /* this aren't yet in archetype */
320
321 ob->speed = 1.0f;
322 ob->speed_left = 0.5f;
323
324 ob->direction = 5; /* So player faces south */
325} 326}
326 327
327void 328void
328player::set_observe (object *op) 329player::set_observe (object *op)
329{ 330{
1007 if (op->move_type & MOVE_FLYING) 1008 if (op->move_type & MOVE_FLYING)
1008 return 1; 1009 return 1;
1009 1010
1010 next = op->below; 1011 next = op->below;
1011 1012
1013 int cnt = MAX_ITEM_PER_DROP;
1014#define CHK_PICK_PICKUP do { pick_up (op, tmp); cnt--; } while (0)
1015
1012 /* loop while there are items on the floor that are not marked as 1016 /* loop while there are items on the floor that are not marked as
1013 * destroyed */ 1017 * destroyed */
1014 while (next && !next->destroyed ()) 1018 while (next && !next->destroyed ())
1015 { 1019 {
1016 tmp = next; 1020 tmp = next;
1017 next = tmp->below; 1021 next = tmp->below;
1018 1022
1023 if (cnt <= 0)
1024 {
1025 op->failmsg ("Couldn't pickup all items at once.");
1026 return 0;
1027 }
1028
1019 if (op->destroyed ()) 1029 if (op->destroyed ())
1020 return 0; 1030 return 0;
1021 1031
1022 if (!can_pick (op, tmp)) 1032 if (!can_pick (op, tmp))
1023 continue; 1033 continue;
1024 1034
1025 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE) 1035 if (op->contr->search_str[0] != '\0' && settings.search_items == TRUE)
1026 { 1036 {
1027 if (item_matched_string (op, tmp, op->contr->search_str)) 1037 if (item_matched_string (op, tmp, op->contr->search_str))
1028 pick_up (op, tmp); 1038 CHK_PICK_PICKUP;
1029 continue; 1039 continue;
1030 } 1040 }
1031 1041
1032 /* high not bit set? We're using the old autopickup model */ 1042 /* high not bit set? We're using the old autopickup model */
1033 if (!(op->contr->mode & PU_NEWMODE)) 1043 if (!(op->contr->mode & PU_NEWMODE))
1035 switch (op->contr->mode) 1045 switch (op->contr->mode)
1036 { 1046 {
1037 case 0: 1047 case 0:
1038 return 1; /* don't pick up */ 1048 return 1; /* don't pick up */
1039 case 1: 1049 case 1:
1040 pick_up (op, tmp); 1050 CHK_PICK_PICKUP;
1041 return 1; 1051 return 1;
1042 case 2: 1052 case 2:
1043 pick_up (op, tmp); 1053 CHK_PICK_PICKUP;
1044 return 0; 1054 return 0;
1045 case 3: 1055 case 3:
1046 return 0; /* stop before pickup */ 1056 return 0; /* stop before pickup */
1047 case 4: 1057 case 4:
1048 pick_up (op, tmp); 1058 CHK_PICK_PICKUP;
1049 break; 1059 break;
1050 case 5: 1060 case 5:
1051 pick_up (op, tmp); 1061 CHK_PICK_PICKUP;
1052 stop = 1; 1062 stop = 1;
1053 break; 1063 break;
1054 case 6: 1064 case 6:
1055 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1065 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL)
1056 pick_up (op, tmp); 1066 && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1067 CHK_PICK_PICKUP;
1057 break; 1068 break;
1058 1069
1059 case 7: 1070 case 7:
1060 if (tmp->type == MONEY || tmp->type == GEM) 1071 if (tmp->type == MONEY || tmp->type == GEM)
1061 pick_up (op, tmp); 1072 CHK_PICK_PICKUP;
1062 break; 1073 break;
1063 1074
1064 default: 1075 default:
1065 /* use value density */ 1076 /* use value density */
1066 if (!QUERY_FLAG (tmp, FLAG_UNPAID) 1077 if (!QUERY_FLAG (tmp, FLAG_UNPAID)
1067 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode) 1078 && (query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= op->contr->mode)
1068 pick_up (op, tmp); 1079 CHK_PICK_PICKUP;
1069 } 1080 }
1070 } 1081 }
1071 else 1082 else
1072 { /* old model */ 1083 { /* old model */
1073 /* NEW pickup handling */ 1084 /* NEW pickup handling */
1128 /* all food and drink if desired */ 1139 /* all food and drink if desired */
1129 /* question: don't pick up known-poisonous stuff? */ 1140 /* question: don't pick up known-poisonous stuff? */
1130 if (op->contr->mode & PU_FOOD) 1141 if (op->contr->mode & PU_FOOD)
1131 if (tmp->type == FOOD) 1142 if (tmp->type == FOOD)
1132 { 1143 {
1133 pick_up (op, tmp); 1144 CHK_PICK_PICKUP;
1134 continue; 1145 continue;
1135 } 1146 }
1136 1147
1137 if (op->contr->mode & PU_DRINK) 1148 if (op->contr->mode & PU_DRINK)
1138 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))) 1149 if (tmp->type == DRINK || (tmp->type == POISON && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)))
1139 { 1150 {
1140 pick_up (op, tmp); 1151 CHK_PICK_PICKUP;
1141 continue; 1152 continue;
1142 } 1153 }
1143 1154
1144 if (op->contr->mode & PU_POTION) 1155 if (op->contr->mode & PU_POTION)
1145 if (tmp->type == POTION) 1156 if (tmp->type == POTION)
1146 { 1157 {
1147 pick_up (op, tmp); 1158 CHK_PICK_PICKUP;
1148 continue; 1159 continue;
1149 } 1160 }
1150 1161
1151 /* spellbooks, skillscrolls and normal books/scrolls */ 1162 /* spellbooks, skillscrolls and normal books/scrolls */
1152 if (op->contr->mode & PU_SPELLBOOK) 1163 if (op->contr->mode & PU_SPELLBOOK)
1153 if (tmp->type == SPELLBOOK) 1164 if (tmp->type == SPELLBOOK)
1154 { 1165 {
1155 pick_up (op, tmp); 1166 CHK_PICK_PICKUP;
1156 continue; 1167 continue;
1157 } 1168 }
1158 1169
1159 if (op->contr->mode & PU_SKILLSCROLL) 1170 if (op->contr->mode & PU_SKILLSCROLL)
1160 if (tmp->type == SKILLSCROLL) 1171 if (tmp->type == SKILLSCROLL)
1161 { 1172 {
1162 pick_up (op, tmp); 1173 CHK_PICK_PICKUP;
1163 continue; 1174 continue;
1164 } 1175 }
1165 1176
1166 if (op->contr->mode & PU_READABLES) 1177 if (op->contr->mode & PU_READABLES)
1167 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE) 1178 if (tmp->type == BOOK || tmp->type == SCROLL || tmp->type == INSCRIBABLE)
1168 { 1179 {
1169 pick_up (op, tmp); 1180 CHK_PICK_PICKUP;
1170 continue; 1181 continue;
1171 } 1182 }
1172 1183
1173 /* wands/staves/rods/horns */ 1184 /* wands/staves/rods/horns */
1174 if (op->contr->mode & PU_MAGIC_DEVICE) 1185 if (op->contr->mode & PU_MAGIC_DEVICE)
1175 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN) 1186 if (tmp->type == WAND || tmp->type == ROD || tmp->type == HORN)
1176 { 1187 {
1177 pick_up (op, tmp); 1188 CHK_PICK_PICKUP;
1178 continue; 1189 continue;
1179 } 1190 }
1180 1191
1181 /* pick up all magical items */ 1192 /* pick up all magical items */
1182 if (op->contr->mode & PU_MAGICAL) 1193 if (op->contr->mode & PU_MAGICAL)
1183 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED)) 1194 if (QUERY_FLAG (tmp, FLAG_KNOWN_MAGICAL) && !QUERY_FLAG (tmp, FLAG_KNOWN_CURSED))
1184 { 1195 {
1185 pick_up (op, tmp); 1196 CHK_PICK_PICKUP;
1186 continue; 1197 continue;
1187 } 1198 }
1188 1199
1189 if (op->contr->mode & PU_VALUABLES) 1200 if (op->contr->mode & PU_VALUABLES)
1190 { 1201 {
1191 if (tmp->type == MONEY || tmp->type == GEM) 1202 if (tmp->type == MONEY || tmp->type == GEM)
1192 { 1203 {
1193 pick_up (op, tmp); 1204 CHK_PICK_PICKUP;
1194 continue; 1205 continue;
1195 } 1206 }
1196 } 1207 }
1197 1208
1198 /* rings & amulets - talismans seems to be typed AMULET */ 1209 /* rings & amulets - talismans seems to be typed AMULET */
1199 if (op->contr->mode & PU_JEWELS) 1210 if (op->contr->mode & PU_JEWELS)
1200 if (tmp->type == RING || tmp->type == AMULET) 1211 if (tmp->type == RING || tmp->type == AMULET)
1201 { 1212 {
1202 pick_up (op, tmp); 1213 CHK_PICK_PICKUP;
1203 continue; 1214 continue;
1204 } 1215 }
1205 1216
1206 /* we don't forget dragon food */ 1217 /* we don't forget dragon food */
1207 if (op->contr->mode & PU_FLESH) 1218 if (op->contr->mode & PU_FLESH)
1208 if (tmp->type == FLESH) 1219 if (tmp->type == FLESH)
1209 { 1220 {
1210 pick_up (op, tmp); 1221 CHK_PICK_PICKUP;
1211 continue; 1222 continue;
1212 } 1223 }
1213 1224
1214 /* bows and arrows. Bows are good for selling! */ 1225 /* bows and arrows. Bows are good for selling! */
1215 if (op->contr->mode & PU_BOW) 1226 if (op->contr->mode & PU_BOW)
1216 if (tmp->type == BOW) 1227 if (tmp->type == BOW)
1217 { 1228 {
1218 pick_up (op, tmp); 1229 CHK_PICK_PICKUP;
1219 continue; 1230 continue;
1220 } 1231 }
1221 1232
1222 if (op->contr->mode & PU_ARROW) 1233 if (op->contr->mode & PU_ARROW)
1223 if (tmp->type == ARROW) 1234 if (tmp->type == ARROW)
1224 { 1235 {
1225 pick_up (op, tmp); 1236 CHK_PICK_PICKUP;
1226 continue; 1237 continue;
1227 } 1238 }
1228 1239
1229 /* all kinds of armor etc. */ 1240 /* all kinds of armor etc. */
1230 if (op->contr->mode & PU_ARMOUR) 1241 if (op->contr->mode & PU_ARMOUR)
1231 if (tmp->type == ARMOUR) 1242 if (tmp->type == ARMOUR)
1232 { 1243 {
1233 pick_up (op, tmp); 1244 CHK_PICK_PICKUP;
1234 continue; 1245 continue;
1235 } 1246 }
1236 1247
1237 if (op->contr->mode & PU_HELMET) 1248 if (op->contr->mode & PU_HELMET)
1238 if (tmp->type == HELMET) 1249 if (tmp->type == HELMET)
1239 { 1250 {
1240 pick_up (op, tmp); 1251 CHK_PICK_PICKUP;
1241 continue; 1252 continue;
1242 } 1253 }
1243 1254
1244 if (op->contr->mode & PU_SHIELD) 1255 if (op->contr->mode & PU_SHIELD)
1245 if (tmp->type == SHIELD) 1256 if (tmp->type == SHIELD)
1246 { 1257 {
1247 pick_up (op, tmp); 1258 CHK_PICK_PICKUP;
1248 continue; 1259 continue;
1249 } 1260 }
1250 1261
1251 if (op->contr->mode & PU_BOOTS) 1262 if (op->contr->mode & PU_BOOTS)
1252 if (tmp->type == BOOTS) 1263 if (tmp->type == BOOTS)
1253 { 1264 {
1254 pick_up (op, tmp); 1265 CHK_PICK_PICKUP;
1255 continue; 1266 continue;
1256 } 1267 }
1257 1268
1258 if (op->contr->mode & PU_GLOVES) 1269 if (op->contr->mode & PU_GLOVES)
1259 if (tmp->type == GLOVES) 1270 if (tmp->type == GLOVES)
1260 { 1271 {
1261 pick_up (op, tmp); 1272 CHK_PICK_PICKUP;
1262 continue; 1273 continue;
1263 } 1274 }
1264 1275
1265 if (op->contr->mode & PU_CLOAK) 1276 if (op->contr->mode & PU_CLOAK)
1266 if (tmp->type == CLOAK) 1277 if (tmp->type == CLOAK)
1267 { 1278 {
1268 pick_up (op, tmp); 1279 CHK_PICK_PICKUP;
1269 continue; 1280 continue;
1270 } 1281 }
1271 1282
1272 /* hoping to catch throwing daggers here */ 1283 /* hoping to catch throwing daggers here */
1273 if (op->contr->mode & PU_MISSILEWEAPON) 1284 if (op->contr->mode & PU_MISSILEWEAPON)
1274 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN)) 1285 if (tmp->type == WEAPON && QUERY_FLAG (tmp, FLAG_IS_THROWN))
1275 { 1286 {
1276 pick_up (op, tmp); 1287 CHK_PICK_PICKUP;
1277 continue; 1288 continue;
1278 } 1289 }
1279 1290
1280 /* careful: chairs and tables are weapons! */ 1291 /* careful: chairs and tables are weapons! */
1281 if (op->contr->mode & PU_ALLWEAPON) 1292 if (op->contr->mode & PU_ALLWEAPON)
1283 if (tmp->type == WEAPON && tmp->name != NULL) 1294 if (tmp->type == WEAPON && tmp->name != NULL)
1284 { 1295 {
1285 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL && 1296 if (strstr (tmp->name, "table") == NULL && strstr (tmp->arch->archname, "table") == NULL &&
1286 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL) 1297 strstr (tmp->name, "chair") && strstr (tmp->arch->archname, "chair") == NULL)
1287 { 1298 {
1288 pick_up (op, tmp); 1299 CHK_PICK_PICKUP;
1289 continue; 1300 continue;
1290 } 1301 }
1291 } 1302 }
1292 1303
1293 if (tmp->type == WEAPON && tmp->name == NULL) 1304 if (tmp->type == WEAPON && tmp->name == NULL)
1294 { 1305 {
1295 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL) 1306 if (strstr (tmp->arch->archname, "table") == NULL && strstr (tmp->arch->archname, "chair") == NULL)
1296 { 1307 {
1297 pick_up (op, tmp); 1308 CHK_PICK_PICKUP;
1298 continue; 1309 continue;
1299 } 1310 }
1300 } 1311 }
1301 } 1312 }
1302 1313
1303 /* misc stuff that's useful */ 1314 /* misc stuff that's useful */
1304 if (op->contr->mode & PU_KEY) 1315 if (op->contr->mode & PU_KEY)
1305 if (tmp->type == KEY || tmp->type == SPECIAL_KEY) 1316 if (tmp->type == KEY || tmp->type == SPECIAL_KEY)
1306 { 1317 {
1307 pick_up (op, tmp); 1318 CHK_PICK_PICKUP;
1308 continue; 1319 continue;
1309 } 1320 }
1310 1321
1311 /* any of the last 4 bits set means we use the ratio for value 1322 /* any of the last 4 bits set means we use the ratio for value
1312 * pickups */ 1323 * pickups */
1317 /* >=7 is the old standard setting. Now we take the last 4 bits 1328 /* >=7 is the old standard setting. Now we take the last 4 bits
1318 * and multiply them by 5, giving 0..15*5== 5..75 */ 1329 * and multiply them by 5, giving 0..15*5== 5..75 */
1319 wvratio = (op->contr->mode & PU_RATIO) * 5; 1330 wvratio = (op->contr->mode & PU_RATIO) * 5;
1320 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio) 1331 if ((query_cost (tmp, op, F_TRUE) * 100 / (tmp->weight * MAX (tmp->nrof, 1))) >= (unsigned int) wvratio)
1321 { 1332 {
1322 pick_up (op, tmp); 1333 CHK_PICK_PICKUP;
1323#if 0 1334#if 0
1324 fprintf (stderr, "HIGH WEIGHT/VALUE ["); 1335 fprintf (stderr, "HIGH WEIGHT/VALUE [");
1325 if (tmp->name != NULL) 1336 if (tmp->name != NULL)
1326 { 1337 {
1327 fprintf (stderr, "%s", tmp->name); 1338 fprintf (stderr, "%s", tmp->name);
1350{ 1361{
1351 object *tmp = 0; 1362 object *tmp = 0;
1352 1363
1353 for (op = op->inv; op; op = op->below) 1364 for (op = op->inv; op; op = op->below)
1354 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED)) 1365 if (!tmp && op->type == CONTAINER && op->race == type && QUERY_FLAG (op, FLAG_APPLIED))
1355 tmp = find_arrow (op, type); 1366 tmp = find_arrow (splay (op), type);
1356 else if (op->type == ARROW && op->race == type) 1367 else if (op->type == ARROW && op->race == type)
1357 return op; 1368 return splay (op);
1358 1369
1359 return tmp; 1370 return tmp;
1360} 1371}
1361 1372
1362/* 1373/*

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines