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

Comparing deliantra/server/server/c_object.C (file contents):
Revision 1.80 by elmex, Sun Oct 5 12:40:21 2008 UTC vs.
Revision 1.89 by elmex, Mon Jan 12 00:17:23 2009 UTC

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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 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 * Deliantra 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
133 { 133 {
134 new_draw_info (NDI_UNIQUE, 0, pl, "Usage: ready_skill <skill name>"); 134 new_draw_info (NDI_UNIQUE, 0, pl, "Usage: ready_skill <skill name>");
135 return 0; 135 return 0;
136 } 136 }
137 137
138 skill = find_skill_by_name (pl, params); 138 skill = find_skill_by_name_fuzzy (pl, params);
139 139
140 if (!skill) 140 if (!skill)
141 { 141 {
142 new_draw_info_format (NDI_UNIQUE, 0, pl, "You have no knowledge of the skill %s", params); 142 new_draw_info_format (NDI_UNIQUE, 0, pl, "You have no knowledge of the skill %s", params);
143 return 0; 143 return 0;
144 } 144 }
145 145
146 pl->change_skill (0); 146 pl->change_skill (0);
147 apply_special (pl, skill, AP_APPLY); 147 apply_special (pl, skill, AP_APPLY);
148 return 1; 148 return 1;
149}
150
151/* These functions (command_search, command_disarm) are really just wrappers for
152 * things like 'use_skill ...'). In fact, they should really be obsoleted
153 * and replaced with those.
154 */
155int
156command_search (object *op, char *params)
157{
158 return use_skill (op, skill_names[SK_FIND_TRAPS]);
159}
160
161int
162command_disarm (object *op, char *params)
163{
164 return use_skill (op, skill_names[SK_DISARM_TRAPS]);
165} 149}
166 150
167/* A little special because we do want to pass the full params along 151/* A little special because we do want to pass the full params along
168 * as it includes the object to throw. 152 * as it includes the object to throw.
169 */ 153 */
520 504
521 return 0; 505 return 0;
522} 506}
523 507
524/* 508/*
525 * This function was part of drop, now is own function. 509 * This function was part of drop, now is own function.
526 * Player 'op' tries to put object 'tmp' into sack 'sack', 510 * Player 'op' tries to put object 'tmp' into sack 'sack',
527 * if nrof is non zero, then nrof objects is tried to put into sack. 511 * if nrof is non zero, then nrof objects is tried to put into sack.
512 *
528 * Note that the 'sack' in question can now be a transport, 513 * Note that the 'sack' in question can now be a transport,
529 * so this function isn't named very good anymore. 514 * so this function isn't named very good anymore.
530 */ 515 */
531void 516void
532put_object_in_sack (object *op, object *sack, object *tmp, uint32 nrof) 517put_object_in_sack (object *op, object *sack, object *tmp, uint32 nrof)
609 * off 594 * off
610 */ 595 */
611 if (!can_split (op, tmp, nrof)) 596 if (!can_split (op, tmp, nrof))
612 return; 597 return;
613 598
599 drop_object (op, tmp);
600
601 if (!tmp->destroyed () && !tmp->is_inserted ())
602 {
603 // if nothing happened with the object we give it back
604 op->insert (tmp);
605 }
606}
607
608/* In contrast to drop_object (op, tmp, nrof) above this function takes the
609 * already split off object, and feeds it to the event handlers and does
610 * other magic with it.
611 *
612 * <droppper> is the object that dropped this object and <obj> is the
613 * object that was dropped.
614 *
615 * Make sure to check what happened with <obj> after this function returns!
616 * Otherwise you may leak this object.
617 */
618
619void
620drop_object (object *dropper, object *obj)
621{
614 if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op))) 622 if (INVOKE_OBJECT (DROP, obj, ARG_OBJECT (dropper)))
615 return; 623 return;
624
625 if (obj->destroyed () || obj->is_inserted ())
626 return;
616 627
617 if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 628 if (QUERY_FLAG (obj, FLAG_STARTEQUIP))
618 { 629 {
619 op->statusmsg (format ("You drop the %s.", query_name (tmp))); 630 dropper->statusmsg (format ("You drop the %s.", query_name (obj)));
620 op->statusmsg ("The god who lent it to you retrieves it."); 631 dropper->statusmsg ("The god who lent it to you retrieves it.");
621 632
622 tmp->destroy (); 633 obj->destroy ();
623 op->update_stats (); 634 dropper->update_stats ();
624 return; 635 return;
625 } 636 }
626 637
627 /* Call this before we update the various windows/players. At least 638 for (object *floor = GET_MAP_OB (dropper->map, dropper->x, dropper->y);
628 * that we, we know the weight is correct. 639 floor;
640 floor = floor->above)
641 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (obj), ARG_OBJECT (dropper)))
642 return;
643
644 if (obj->destroyed () || obj->is_inserted ())
645 return;
646
647 if (is_in_shop (dropper) && !QUERY_FLAG (obj, FLAG_UNPAID) && obj->type != MONEY)
648 if (!sell_item (obj, dropper))
649 return;
650
651 /* If nothing special happened with this object, the default action is to
652 * insert it below the dropper:
629 */ 653 */
630 // 2007-11-26: moved op->update_stats away and calling it later after
631 // all items of a drop command have been processed.
632 654
633 for (object *floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above) 655 obj->x = dropper->x;
634 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op))) 656 obj->y = dropper->y;
635 return;
636 657
637 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY)
638 {
639 if (!sell_item (tmp, op))
640 {
641 // if we can't sell it we don't drop it, so give it back to the seller
642 op->insert (tmp);
643 return;
644 }
645 }
646
647 tmp->x = op->x;
648 tmp->y = op->y;
649
650 insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR); 658 insert_ob_in_map (obj, dropper->map, dropper, INS_BELOW_ORIGINATOR);
651} 659}
652 660
653void 661void
654drop (object *op, object *tmp) 662drop (object *op, object *tmp)
655{ 663{
853 861
854/* draw_look(op);*/ 862/* draw_look(op);*/
855 return 0; 863 return 0;
856} 864}
857 865
866
867/* This function tries to drop all objects in the <objs> vector.
868 * <dropper> is the object that wants to drop them.
869 * <cnt> can be a 0 pointer or a pointer to the maximum number of
870 * drop operations to perform.
871 *
872 * Returns true if at least one item was dropped.
873 */
874bool
875drop_vector (object *dropper, vector<object *> &objs, int *cnt)
876{
877 vector<object *>::iterator i;
878
879 bool did_one = false;
880
881 for (i = objs.begin (); i != objs.end (); i++)
882 {
883 drop (dropper, *i);
884 if (cnt && --*cnt <= 0) break;
885 did_one = true;
886 }
887
888 return did_one;
889}
890
858/* Object op wants to drop object(s) params. params can be a 891/* Object op wants to drop object(s) params. params can be a
859 * comma seperated list. 892 * comma seperated list.
860 */ 893 */
861int 894int
862command_drop (object *op, char *params) 895command_drop (object *op, char *params)
869 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?"); 902 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?");
870 return 0; 903 return 0;
871 } 904 }
872 else 905 else
873 { 906 {
874 int cnt = MAX_ITEM_PER_DROP; 907 vector<object *> matched_objs;
875 908
876 for (tmp = op->inv; tmp; tmp = next) 909 for (tmp = op->inv; tmp; tmp = next)
877 { 910 {
878 next = tmp->below; 911 next = tmp->below;
879 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible) 912 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible)
880 continue; 913 continue;
881 914
882 if (item_matched_string (op, tmp, params)) 915 if (item_matched_string (op, tmp, params))
883 { 916 matched_objs.push_back (tmp);
884 drop (op, tmp);
885 if (--cnt <= 0) break;
886 did_one = 1;
887 } 917 }
888 }
889 918
890 if (!did_one) 919 int cnt = MAX_ITEM_PER_DROP;
920
921 if (!drop_vector (op, matched_objs, &cnt))
891 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop."); 922 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop.");
892 923
893 if (cnt <= 0) 924 if (cnt <= 0)
894 op->failmsg ("Only dropped some items, can't drop that many items at once."); 925 op->failmsg ("Only dropped some items, can't drop that many items at once.");
895 } 926 }
1025} 1056}
1026 1057
1027std::string 1058std::string
1028object::long_desc (object *who) 1059object::long_desc (object *who)
1029{ 1060{
1030 std::string buf (query_name (this)); 1061 std::string buf (query_name ());
1031 1062
1032 switch (type) 1063 switch (type)
1033 { 1064 {
1034 case RING: 1065 case RING:
1035 case SKILL: 1066 case SKILL:
1047 case CLOAK: 1078 case CLOAK:
1048 case FOOD: 1079 case FOOD:
1049 case DRINK: 1080 case DRINK:
1050 case FLESH: 1081 case FLESH:
1051 case SKILL_TOOL: 1082 case SKILL_TOOL:
1083 case LAMP:
1052 case POWER_CRYSTAL: 1084 case POWER_CRYSTAL:
1053 { 1085 {
1054 const char *cp = ::describe_item (this, who); 1086 const char *cp = ::describe_item (this, who);
1055 1087
1056 if (*cp) 1088 if (*cp)
1085 1117
1086 switch (type) 1118 switch (type)
1087 { 1119 {
1088 case SPELLBOOK: 1120 case SPELLBOOK:
1089 if (flag [FLAG_IDENTIFIED] && inv) 1121 if (flag [FLAG_IDENTIFIED] && inv)
1090 buf.printf ("%s is a %s %s spell.\r", &inv->name, get_levelnumber (inv->level), &inv->skill); 1122 buf.printf ("%s is a level %s %s spell.\r", &inv->name, get_levelnumber (inv->level), &inv->skill);
1091 break; 1123 break;
1092 1124
1093 case BOOK: 1125 case BOOK:
1094 if (msg) 1126 if (msg)
1095 buf << "Something is written in it.\r"; 1127 buf << "Something is written in it.\r";
1175static void 1207static void
1176display_new_pickup (object *op) 1208display_new_pickup (object *op)
1177{ 1209{
1178 int i = op->contr->mode; 1210 int i = op->contr->mode;
1179 1211
1180 if (!(i & PU_NEWMODE))
1181 return;
1182
1183 new_draw_info_format (NDI_UNIQUE, 0, op, "%d NEWMODE", i & PU_NEWMODE ? 1 : 0);
1184 new_draw_info_format (NDI_UNIQUE, 0, op, "%d DEBUG", i & PU_DEBUG ? 1 : 0); 1212 new_draw_info_format (NDI_UNIQUE, 0, op, "%d DEBUG", i & PU_DEBUG ? 1 : 0);
1185 new_draw_info_format (NDI_UNIQUE, 0, op, "%d INHIBIT", i & PU_INHIBIT ? 1 : 0); 1213 new_draw_info_format (NDI_UNIQUE, 0, op, "%d INHIBIT", i & PU_INHIBIT ? 1 : 0);
1186 new_draw_info_format (NDI_UNIQUE, 0, op, "%d STOP", i & PU_STOP ? 1 : 0); 1214 new_draw_info_format (NDI_UNIQUE, 0, op, "%d STOP", i & PU_STOP ? 1 : 0);
1187 1215
1188 new_draw_info_format (NDI_UNIQUE, 0, op, "%d <= x pickup weight/value RATIO (0==off)", (i & PU_RATIO) * 5); 1216 new_draw_info_format (NDI_UNIQUE, 0, op, "%d <= x pickup weight/value RATIO (0==off)", (i & PU_RATIO) * 5);
1239 }; 1267 };
1240 1268
1241 if (!params) 1269 if (!params)
1242 { 1270 {
1243 /* if the new mode is used, just print the settings */ 1271 /* if the new mode is used, just print the settings */
1244 if (op->contr->mode & PU_NEWMODE)
1245 {
1246 display_new_pickup (op); 1272 display_new_pickup (op);
1247 return 1;
1248 }
1249 if (1)
1250 LOG (llevDebug, "command_pickup: !params\n");
1251 set_pickup_mode (op, (op->contr->mode > 6) ? 0 : op->contr->mode + 1);
1252 return 0; 1273 return 0;
1253 } 1274 }
1254 1275
1255 while (*params == ' ' && *params) 1276 while (*params == ' ' && *params)
1256 params++; 1277 params++;
1262 for (mode = 0; names[mode]; mode++) 1283 for (mode = 0; names[mode]; mode++)
1263 { 1284 {
1264 if (!strcmp (names[mode], params + 1)) 1285 if (!strcmp (names[mode], params + 1))
1265 { 1286 {
1266 i = op->contr->mode; 1287 i = op->contr->mode;
1267 if (!(i & PU_NEWMODE)) 1288
1268 i = PU_NEWMODE;
1269 if (*params == '+') 1289 if (*params == '+')
1270 i = i | modes[mode]; 1290 i = i | modes[mode];
1271 else 1291 else
1272 i = i & ~modes[mode]; 1292 i = i & ~modes[mode];
1293
1273 op->contr->mode = i; 1294 op->contr->mode = i;
1274 display_new_pickup (op); 1295 display_new_pickup (op);
1275 return 1; 1296 return 1;
1276 } 1297 }
1277 } 1298 }
1279 return 1; 1300 return 1;
1280 } 1301 }
1281 1302
1282 if (sscanf (params, "%u", &i) != 1) 1303 if (sscanf (params, "%u", &i) != 1)
1283 { 1304 {
1284 if (1)
1285 LOG (llevDebug, "command_pickup: params==NULL\n");
1286 new_draw_info (NDI_UNIQUE, 0, op, "Usage: pickup <0-7> or <value_density> ."); 1305 new_draw_info (NDI_UNIQUE, 0, op, "Usage: pickup <value_density> or [+-]type.");
1287 return 1; 1306 return 1;
1288 } 1307 }
1289 set_pickup_mode (op, i); 1308
1309 if (i <= PU_RATIO)
1310 i |= op->contr->mode & ~PU_RATIO;
1311
1312 op->contr->mode = i;
1290 1313
1291 return 1; 1314 return 1;
1292}
1293
1294void
1295set_pickup_mode (object *op, int i)
1296{
1297 switch (op->contr->mode = i)
1298 {
1299 case 0:
1300 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Don't pick up.");
1301 break;
1302 case 1:
1303 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item.");
1304 break;
1305 case 2:
1306 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item and stop.");
1307 break;
1308 case 3:
1309 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Stop before picking up.");
1310 break;
1311 case 4:
1312 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items.");
1313 break;
1314 case 5:
1315 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items and stop.");
1316 break;
1317 case 6:
1318 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all magic items.");
1319 break;
1320 case 7:
1321 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all coins and gems");
1322 break;
1323 }
1324} 1315}
1325 1316
1326int 1317int
1327command_search_items (object *op, char *params) 1318command_search_items (object *op, char *params)
1328{ 1319{
1329 char buf[MAX_BUF]; 1320 char buf[MAX_BUF];
1330 1321
1331 if (settings.search_items == FALSE)
1332 return 1;
1333
1334 if (params == NULL) 1322 if (params == NULL)
1335 { 1323 {
1336 if (op->contr->search_str[0] == '\0') 1324 if (op->contr->search_str[0] == '\0')
1337 { 1325 {
1338 new_draw_info (NDI_UNIQUE, 0, op, "Example: search magic+1"); 1326 new_draw_info (NDI_UNIQUE, 0, op, "Example: search-items magic+1");
1339 new_draw_info (NDI_UNIQUE, 0, op, "Would automatically pick up all"); 1327 new_draw_info (NDI_UNIQUE, 0, op, "Would automatically pick up all");
1340 new_draw_info (NDI_UNIQUE, 0, op, "items containing the word 'magic+1'."); 1328 new_draw_info (NDI_UNIQUE, 0, op, "items containing the word 'magic+1'.");
1341 return 1; 1329 return 1;
1342 } 1330 }
1343 1331
1345 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off."); 1333 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off.");
1346 op->update_stats (); 1334 op->update_stats ();
1347 return 1; 1335 return 1;
1348 } 1336 }
1349 1337
1350 if ((int) strlen (params) >= MAX_BUF) 1338 if (strlen (params) >= MAX_BUF)
1351 { 1339 {
1352 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long."); 1340 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long.");
1353 return 1; 1341 return 1;
1354 } 1342 }
1355 1343
1356 strcpy (op->contr->search_str, params); 1344 strcpy (op->contr->search_str, params);
1357 sprintf (buf, "Searching for '%s'.", op->contr->search_str); 1345 sprintf (buf, "Now searching for '%s'.", op->contr->search_str);
1358 new_draw_info (NDI_UNIQUE, 0, op, buf); 1346 new_draw_info (NDI_UNIQUE, 0, op, buf);
1359 op->update_stats (); 1347 op->update_stats ();
1348
1360 return 1; 1349 return 1;
1361} 1350}
1362 1351

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines