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.78 by root, Mon Sep 29 10:20:49 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)
607 592
608 /* We are only dropping some of the items. We split the current object 593 /* We are only dropping some of the items. We split the current object
609 * off 594 * off
610 */ 595 */
611 if (!can_split (op, tmp, nrof)) 596 if (!can_split (op, tmp, nrof))
612
613 if (INVOKE_OBJECT (DROP, tmp, ARG_OBJECT (op)))
614 return; 597 return;
615 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{
622 if (INVOKE_OBJECT (DROP, obj, ARG_OBJECT (dropper)))
623 return;
624
625 if (obj->destroyed () || obj->is_inserted ())
626 return;
627
616 if (QUERY_FLAG (tmp, FLAG_STARTEQUIP)) 628 if (QUERY_FLAG (obj, FLAG_STARTEQUIP))
617 { 629 {
618 op->statusmsg (format ("You drop the %s.", query_name (tmp))); 630 dropper->statusmsg (format ("You drop the %s.", query_name (obj)));
619 op->statusmsg ("The god who lent it to you retrieves it."); 631 dropper->statusmsg ("The god who lent it to you retrieves it.");
620 632
621 tmp->destroy (true); 633 obj->destroy ();
622 op->update_stats (); 634 dropper->update_stats ();
623 return; 635 return;
624 } 636 }
625 637
626 /* Call this before we update the various windows/players. At least 638 for (object *floor = GET_MAP_OB (dropper->map, dropper->x, dropper->y);
627 * 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:
628 */ 653 */
629 // 2007-11-26: moved op->update_stats away and calling it later after
630 // all items of a drop command have been processed.
631 654
632 for (object *floor = GET_MAP_OB (op->map, op->x, op->y); floor; floor = floor->above) 655 obj->x = dropper->x;
633 if (INVOKE_OBJECT (DROP_ON, floor, ARG_OBJECT (tmp), ARG_OBJECT (op))) 656 obj->y = dropper->y;
634 return;
635 657
636 if (is_in_shop (op) && !QUERY_FLAG (tmp, FLAG_UNPAID) && tmp->type != MONEY)
637 {
638 if (!sell_item (tmp, op))
639 return; // if we can't sell it we don't drop it
640 }
641
642 tmp->x = op->x;
643 tmp->y = op->y;
644
645 insert_ob_in_map (tmp, op->map, op, INS_BELOW_ORIGINATOR); 658 insert_ob_in_map (obj, dropper->map, dropper, INS_BELOW_ORIGINATOR);
646} 659}
647 660
648void 661void
649drop (object *op, object *tmp) 662drop (object *op, object *tmp)
650{ 663{
659 if (tmp->env && tmp->env->type != PLAYER) 672 if (tmp->env && tmp->env->type != PLAYER)
660 { 673 {
661 /* Just toss the object - probably shouldn't be hanging 674 /* Just toss the object - probably shouldn't be hanging
662 * around anyways 675 * around anyways
663 */ 676 */
664 tmp->destroy (true); 677 tmp->destroy ();
665 return; 678 return;
666 } 679 }
667 else 680 else
668 { 681 {
669 while (tmp && tmp->invisible) 682 while (tmp && tmp->invisible)
848 861
849/* draw_look(op);*/ 862/* draw_look(op);*/
850 return 0; 863 return 0;
851} 864}
852 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
853/* 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
854 * comma seperated list. 892 * comma seperated list.
855 */ 893 */
856int 894int
857command_drop (object *op, char *params) 895command_drop (object *op, char *params)
864 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?"); 902 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?");
865 return 0; 903 return 0;
866 } 904 }
867 else 905 else
868 { 906 {
869 int cnt = MAX_ITEM_PER_DROP; 907 vector<object *> matched_objs;
870 908
871 for (tmp = op->inv; tmp; tmp = next) 909 for (tmp = op->inv; tmp; tmp = next)
872 { 910 {
873 next = tmp->below; 911 next = tmp->below;
874 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible) 912 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible)
875 continue; 913 continue;
876 914
877 if (item_matched_string (op, tmp, params)) 915 if (item_matched_string (op, tmp, params))
878 { 916 matched_objs.push_back (tmp);
879 drop (op, tmp);
880 if (--cnt <= 0) break;
881 did_one = 1;
882 } 917 }
883 }
884 918
885 if (!did_one) 919 int cnt = MAX_ITEM_PER_DROP;
920
921 if (!drop_vector (op, matched_objs, &cnt))
886 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop."); 922 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop.");
887 923
888 if (cnt <= 0) 924 if (cnt <= 0)
889 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.");
890 } 926 }
1020} 1056}
1021 1057
1022std::string 1058std::string
1023object::long_desc (object *who) 1059object::long_desc (object *who)
1024{ 1060{
1025 std::string buf (query_name (this)); 1061 std::string buf (query_name ());
1026 1062
1027 switch (type) 1063 switch (type)
1028 { 1064 {
1029 case RING: 1065 case RING:
1030 case SKILL: 1066 case SKILL:
1042 case CLOAK: 1078 case CLOAK:
1043 case FOOD: 1079 case FOOD:
1044 case DRINK: 1080 case DRINK:
1045 case FLESH: 1081 case FLESH:
1046 case SKILL_TOOL: 1082 case SKILL_TOOL:
1083 case LAMP:
1047 case POWER_CRYSTAL: 1084 case POWER_CRYSTAL:
1048 { 1085 {
1049 const char *cp = ::describe_item (this, who); 1086 const char *cp = ::describe_item (this, who);
1050 1087
1051 if (*cp) 1088 if (*cp)
1080 1117
1081 switch (type) 1118 switch (type)
1082 { 1119 {
1083 case SPELLBOOK: 1120 case SPELLBOOK:
1084 if (flag [FLAG_IDENTIFIED] && inv) 1121 if (flag [FLAG_IDENTIFIED] && inv)
1085 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);
1086 break; 1123 break;
1087 1124
1088 case BOOK: 1125 case BOOK:
1089 if (msg) 1126 if (msg)
1090 buf << "Something is written in it.\r"; 1127 buf << "Something is written in it.\r";
1170static void 1207static void
1171display_new_pickup (object *op) 1208display_new_pickup (object *op)
1172{ 1209{
1173 int i = op->contr->mode; 1210 int i = op->contr->mode;
1174 1211
1175 if (!(i & PU_NEWMODE))
1176 return;
1177
1178 new_draw_info_format (NDI_UNIQUE, 0, op, "%d NEWMODE", i & PU_NEWMODE ? 1 : 0);
1179 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);
1180 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);
1181 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);
1182 1215
1183 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);
1234 }; 1267 };
1235 1268
1236 if (!params) 1269 if (!params)
1237 { 1270 {
1238 /* if the new mode is used, just print the settings */ 1271 /* if the new mode is used, just print the settings */
1239 if (op->contr->mode & PU_NEWMODE)
1240 {
1241 display_new_pickup (op); 1272 display_new_pickup (op);
1242 return 1;
1243 }
1244 if (1)
1245 LOG (llevDebug, "command_pickup: !params\n");
1246 set_pickup_mode (op, (op->contr->mode > 6) ? 0 : op->contr->mode + 1);
1247 return 0; 1273 return 0;
1248 } 1274 }
1249 1275
1250 while (*params == ' ' && *params) 1276 while (*params == ' ' && *params)
1251 params++; 1277 params++;
1257 for (mode = 0; names[mode]; mode++) 1283 for (mode = 0; names[mode]; mode++)
1258 { 1284 {
1259 if (!strcmp (names[mode], params + 1)) 1285 if (!strcmp (names[mode], params + 1))
1260 { 1286 {
1261 i = op->contr->mode; 1287 i = op->contr->mode;
1262 if (!(i & PU_NEWMODE)) 1288
1263 i = PU_NEWMODE;
1264 if (*params == '+') 1289 if (*params == '+')
1265 i = i | modes[mode]; 1290 i = i | modes[mode];
1266 else 1291 else
1267 i = i & ~modes[mode]; 1292 i = i & ~modes[mode];
1293
1268 op->contr->mode = i; 1294 op->contr->mode = i;
1269 display_new_pickup (op); 1295 display_new_pickup (op);
1270 return 1; 1296 return 1;
1271 } 1297 }
1272 } 1298 }
1274 return 1; 1300 return 1;
1275 } 1301 }
1276 1302
1277 if (sscanf (params, "%u", &i) != 1) 1303 if (sscanf (params, "%u", &i) != 1)
1278 { 1304 {
1279 if (1)
1280 LOG (llevDebug, "command_pickup: params==NULL\n");
1281 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.");
1282 return 1; 1306 return 1;
1283 } 1307 }
1284 set_pickup_mode (op, i); 1308
1309 if (i <= PU_RATIO)
1310 i |= op->contr->mode & ~PU_RATIO;
1311
1312 op->contr->mode = i;
1285 1313
1286 return 1; 1314 return 1;
1287}
1288
1289void
1290set_pickup_mode (object *op, int i)
1291{
1292 switch (op->contr->mode = i)
1293 {
1294 case 0:
1295 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Don't pick up.");
1296 break;
1297 case 1:
1298 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item.");
1299 break;
1300 case 2:
1301 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item and stop.");
1302 break;
1303 case 3:
1304 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Stop before picking up.");
1305 break;
1306 case 4:
1307 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items.");
1308 break;
1309 case 5:
1310 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items and stop.");
1311 break;
1312 case 6:
1313 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all magic items.");
1314 break;
1315 case 7:
1316 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all coins and gems");
1317 break;
1318 }
1319} 1315}
1320 1316
1321int 1317int
1322command_search_items (object *op, char *params) 1318command_search_items (object *op, char *params)
1323{ 1319{
1324 char buf[MAX_BUF]; 1320 char buf[MAX_BUF];
1325 1321
1326 if (settings.search_items == FALSE)
1327 return 1;
1328
1329 if (params == NULL) 1322 if (params == NULL)
1330 { 1323 {
1331 if (op->contr->search_str[0] == '\0') 1324 if (op->contr->search_str[0] == '\0')
1332 { 1325 {
1333 new_draw_info (NDI_UNIQUE, 0, op, "Example: search magic+1"); 1326 new_draw_info (NDI_UNIQUE, 0, op, "Example: search-items magic+1");
1334 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");
1335 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'.");
1336 return 1; 1329 return 1;
1337 } 1330 }
1338 1331
1340 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off."); 1333 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off.");
1341 op->update_stats (); 1334 op->update_stats ();
1342 return 1; 1335 return 1;
1343 } 1336 }
1344 1337
1345 if ((int) strlen (params) >= MAX_BUF) 1338 if (strlen (params) >= MAX_BUF)
1346 { 1339 {
1347 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long."); 1340 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long.");
1348 return 1; 1341 return 1;
1349 } 1342 }
1350 1343
1351 strcpy (op->contr->search_str, params); 1344 strcpy (op->contr->search_str, params);
1352 sprintf (buf, "Searching for '%s'.", op->contr->search_str); 1345 sprintf (buf, "Now searching for '%s'.", op->contr->search_str);
1353 new_draw_info (NDI_UNIQUE, 0, op, buf); 1346 new_draw_info (NDI_UNIQUE, 0, op, buf);
1354 op->update_stats (); 1347 op->update_stats ();
1348
1355 return 1; 1349 return 1;
1356} 1350}
1357 1351

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines