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.77 by root, Mon Sep 22 01:46:52 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 gods who lent it to you retrieves it."); 631 dropper->statusmsg ("The god who lent it to you retrieves it.");
620 632
621 tmp->destroy (); 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->remove ();
665 tmp->destroy (); 677 tmp->destroy ();
666 return; 678 return;
667 } 679 }
668 else 680 else
669 { 681 {
849 861
850/* draw_look(op);*/ 862/* draw_look(op);*/
851 return 0; 863 return 0;
852} 864}
853 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
854/* 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
855 * comma seperated list. 892 * comma seperated list.
856 */ 893 */
857int 894int
858command_drop (object *op, char *params) 895command_drop (object *op, char *params)
865 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?"); 902 new_draw_info (NDI_UNIQUE, 0, op, "Drop what?");
866 return 0; 903 return 0;
867 } 904 }
868 else 905 else
869 { 906 {
870 int cnt = MAX_ITEM_PER_DROP; 907 vector<object *> matched_objs;
871 908
872 for (tmp = op->inv; tmp; tmp = next) 909 for (tmp = op->inv; tmp; tmp = next)
873 { 910 {
874 next = tmp->below; 911 next = tmp->below;
875 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible) 912 if (QUERY_FLAG (tmp, FLAG_NO_DROP) || tmp->invisible)
876 continue; 913 continue;
877 914
878 if (item_matched_string (op, tmp, params)) 915 if (item_matched_string (op, tmp, params))
879 { 916 matched_objs.push_back (tmp);
880 drop (op, tmp);
881 if (--cnt <= 0) break;
882 did_one = 1;
883 } 917 }
884 }
885 918
886 if (!did_one) 919 int cnt = MAX_ITEM_PER_DROP;
920
921 if (!drop_vector (op, matched_objs, &cnt))
887 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop."); 922 new_draw_info (NDI_UNIQUE, 0, op, "Nothing to drop.");
888 923
889 if (cnt <= 0) 924 if (cnt <= 0)
890 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.");
891 } 926 }
1021} 1056}
1022 1057
1023std::string 1058std::string
1024object::long_desc (object *who) 1059object::long_desc (object *who)
1025{ 1060{
1026 std::string buf (query_name (this)); 1061 std::string buf (query_name ());
1027 1062
1028 switch (type) 1063 switch (type)
1029 { 1064 {
1030 case RING: 1065 case RING:
1031 case SKILL: 1066 case SKILL:
1043 case CLOAK: 1078 case CLOAK:
1044 case FOOD: 1079 case FOOD:
1045 case DRINK: 1080 case DRINK:
1046 case FLESH: 1081 case FLESH:
1047 case SKILL_TOOL: 1082 case SKILL_TOOL:
1083 case LAMP:
1048 case POWER_CRYSTAL: 1084 case POWER_CRYSTAL:
1049 { 1085 {
1050 const char *cp = ::describe_item (this, who); 1086 const char *cp = ::describe_item (this, who);
1051 1087
1052 if (*cp) 1088 if (*cp)
1081 1117
1082 switch (type) 1118 switch (type)
1083 { 1119 {
1084 case SPELLBOOK: 1120 case SPELLBOOK:
1085 if (flag [FLAG_IDENTIFIED] && inv) 1121 if (flag [FLAG_IDENTIFIED] && inv)
1086 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);
1087 break; 1123 break;
1088 1124
1089 case BOOK: 1125 case BOOK:
1090 if (msg) 1126 if (msg)
1091 buf << "Something is written in it.\r"; 1127 buf << "Something is written in it.\r";
1171static void 1207static void
1172display_new_pickup (object *op) 1208display_new_pickup (object *op)
1173{ 1209{
1174 int i = op->contr->mode; 1210 int i = op->contr->mode;
1175 1211
1176 if (!(i & PU_NEWMODE))
1177 return;
1178
1179 new_draw_info_format (NDI_UNIQUE, 0, op, "%d NEWMODE", i & PU_NEWMODE ? 1 : 0);
1180 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);
1181 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);
1182 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);
1183 1215
1184 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);
1235 }; 1267 };
1236 1268
1237 if (!params) 1269 if (!params)
1238 { 1270 {
1239 /* if the new mode is used, just print the settings */ 1271 /* if the new mode is used, just print the settings */
1240 if (op->contr->mode & PU_NEWMODE)
1241 {
1242 display_new_pickup (op); 1272 display_new_pickup (op);
1243 return 1;
1244 }
1245 if (1)
1246 LOG (llevDebug, "command_pickup: !params\n");
1247 set_pickup_mode (op, (op->contr->mode > 6) ? 0 : op->contr->mode + 1);
1248 return 0; 1273 return 0;
1249 } 1274 }
1250 1275
1251 while (*params == ' ' && *params) 1276 while (*params == ' ' && *params)
1252 params++; 1277 params++;
1258 for (mode = 0; names[mode]; mode++) 1283 for (mode = 0; names[mode]; mode++)
1259 { 1284 {
1260 if (!strcmp (names[mode], params + 1)) 1285 if (!strcmp (names[mode], params + 1))
1261 { 1286 {
1262 i = op->contr->mode; 1287 i = op->contr->mode;
1263 if (!(i & PU_NEWMODE)) 1288
1264 i = PU_NEWMODE;
1265 if (*params == '+') 1289 if (*params == '+')
1266 i = i | modes[mode]; 1290 i = i | modes[mode];
1267 else 1291 else
1268 i = i & ~modes[mode]; 1292 i = i & ~modes[mode];
1293
1269 op->contr->mode = i; 1294 op->contr->mode = i;
1270 display_new_pickup (op); 1295 display_new_pickup (op);
1271 return 1; 1296 return 1;
1272 } 1297 }
1273 } 1298 }
1275 return 1; 1300 return 1;
1276 } 1301 }
1277 1302
1278 if (sscanf (params, "%u", &i) != 1) 1303 if (sscanf (params, "%u", &i) != 1)
1279 { 1304 {
1280 if (1)
1281 LOG (llevDebug, "command_pickup: params==NULL\n");
1282 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.");
1283 return 1; 1306 return 1;
1284 } 1307 }
1285 set_pickup_mode (op, i); 1308
1309 if (i <= PU_RATIO)
1310 i |= op->contr->mode & ~PU_RATIO;
1311
1312 op->contr->mode = i;
1286 1313
1287 return 1; 1314 return 1;
1288}
1289
1290void
1291set_pickup_mode (object *op, int i)
1292{
1293 switch (op->contr->mode = i)
1294 {
1295 case 0:
1296 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Don't pick up.");
1297 break;
1298 case 1:
1299 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item.");
1300 break;
1301 case 2:
1302 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up one item and stop.");
1303 break;
1304 case 3:
1305 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Stop before picking up.");
1306 break;
1307 case 4:
1308 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items.");
1309 break;
1310 case 5:
1311 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all items and stop.");
1312 break;
1313 case 6:
1314 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all magic items.");
1315 break;
1316 case 7:
1317 new_draw_info (NDI_UNIQUE, 0, op, "Mode: Pick up all coins and gems");
1318 break;
1319 }
1320} 1315}
1321 1316
1322int 1317int
1323command_search_items (object *op, char *params) 1318command_search_items (object *op, char *params)
1324{ 1319{
1325 char buf[MAX_BUF]; 1320 char buf[MAX_BUF];
1326 1321
1327 if (settings.search_items == FALSE)
1328 return 1;
1329
1330 if (params == NULL) 1322 if (params == NULL)
1331 { 1323 {
1332 if (op->contr->search_str[0] == '\0') 1324 if (op->contr->search_str[0] == '\0')
1333 { 1325 {
1334 new_draw_info (NDI_UNIQUE, 0, op, "Example: search magic+1"); 1326 new_draw_info (NDI_UNIQUE, 0, op, "Example: search-items magic+1");
1335 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");
1336 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'.");
1337 return 1; 1329 return 1;
1338 } 1330 }
1339 1331
1341 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off."); 1333 new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off.");
1342 op->update_stats (); 1334 op->update_stats ();
1343 return 1; 1335 return 1;
1344 } 1336 }
1345 1337
1346 if ((int) strlen (params) >= MAX_BUF) 1338 if (strlen (params) >= MAX_BUF)
1347 { 1339 {
1348 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long."); 1340 new_draw_info (NDI_UNIQUE, 0, op, "Search string too long.");
1349 return 1; 1341 return 1;
1350 } 1342 }
1351 1343
1352 strcpy (op->contr->search_str, params); 1344 strcpy (op->contr->search_str, params);
1353 sprintf (buf, "Searching for '%s'.", op->contr->search_str); 1345 sprintf (buf, "Now searching for '%s'.", op->contr->search_str);
1354 new_draw_info (NDI_UNIQUE, 0, op, buf); 1346 new_draw_info (NDI_UNIQUE, 0, op, buf);
1355 op->update_stats (); 1347 op->update_stats ();
1348
1356 return 1; 1349 return 1;
1357} 1350}
1358 1351

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines