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 | */ |
|
|
155 | int |
|
|
156 | command_search (object *op, char *params) |
|
|
157 | { |
|
|
158 | return use_skill (op, skill_names[SK_FIND_TRAPS]); |
|
|
159 | } |
|
|
160 | |
|
|
161 | int |
|
|
162 | command_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 | */ |
531 | void |
516 | void |
532 | put_object_in_sack (object *op, object *sack, object *tmp, uint32 nrof) |
517 | put_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 | |
|
|
619 | void |
|
|
620 | drop_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 | |
653 | void |
661 | void |
654 | drop (object *op, object *tmp) |
662 | drop (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 | */ |
|
|
874 | bool |
|
|
875 | drop_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 | */ |
861 | int |
894 | int |
862 | command_drop (object *op, char *params) |
895 | command_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 | |
1027 | std::string |
1058 | std::string |
1028 | object::long_desc (object *who) |
1059 | object::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: |
… | |
… | |
1085 | |
1116 | |
1086 | switch (type) |
1117 | switch (type) |
1087 | { |
1118 | { |
1088 | case SPELLBOOK: |
1119 | case SPELLBOOK: |
1089 | if (flag [FLAG_IDENTIFIED] && inv) |
1120 | if (flag [FLAG_IDENTIFIED] && inv) |
1090 | buf.printf ("%s is a %s %s spell.\r", &inv->name, get_levelnumber (inv->level), &inv->skill); |
1121 | buf.printf ("%s is a level %s %s spell.\r", &inv->name, get_levelnumber (inv->level), &inv->skill); |
1091 | break; |
1122 | break; |
1092 | |
1123 | |
1093 | case BOOK: |
1124 | case BOOK: |
1094 | if (msg) |
1125 | if (msg) |
1095 | buf << "Something is written in it.\r"; |
1126 | buf << "Something is written in it.\r"; |
… | |
… | |
1175 | static void |
1206 | static void |
1176 | display_new_pickup (object *op) |
1207 | display_new_pickup (object *op) |
1177 | { |
1208 | { |
1178 | int i = op->contr->mode; |
1209 | int i = op->contr->mode; |
1179 | |
1210 | |
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); |
1211 | 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); |
1212 | 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); |
1213 | new_draw_info_format (NDI_UNIQUE, 0, op, "%d STOP", i & PU_STOP ? 1 : 0); |
1187 | |
1214 | |
1188 | new_draw_info_format (NDI_UNIQUE, 0, op, "%d <= x pickup weight/value RATIO (0==off)", (i & PU_RATIO) * 5); |
1215 | new_draw_info_format (NDI_UNIQUE, 0, op, "%d <= x pickup weight/value RATIO (0==off)", (i & PU_RATIO) * 5); |
… | |
… | |
1239 | }; |
1266 | }; |
1240 | |
1267 | |
1241 | if (!params) |
1268 | if (!params) |
1242 | { |
1269 | { |
1243 | /* if the new mode is used, just print the settings */ |
1270 | /* if the new mode is used, just print the settings */ |
1244 | if (op->contr->mode & PU_NEWMODE) |
|
|
1245 | { |
|
|
1246 | display_new_pickup (op); |
1271 | 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; |
1272 | return 0; |
1253 | } |
1273 | } |
1254 | |
1274 | |
1255 | while (*params == ' ' && *params) |
1275 | while (*params == ' ' && *params) |
1256 | params++; |
1276 | params++; |
… | |
… | |
1262 | for (mode = 0; names[mode]; mode++) |
1282 | for (mode = 0; names[mode]; mode++) |
1263 | { |
1283 | { |
1264 | if (!strcmp (names[mode], params + 1)) |
1284 | if (!strcmp (names[mode], params + 1)) |
1265 | { |
1285 | { |
1266 | i = op->contr->mode; |
1286 | i = op->contr->mode; |
1267 | if (!(i & PU_NEWMODE)) |
1287 | |
1268 | i = PU_NEWMODE; |
|
|
1269 | if (*params == '+') |
1288 | if (*params == '+') |
1270 | i = i | modes[mode]; |
1289 | i = i | modes[mode]; |
1271 | else |
1290 | else |
1272 | i = i & ~modes[mode]; |
1291 | i = i & ~modes[mode]; |
|
|
1292 | |
1273 | op->contr->mode = i; |
1293 | op->contr->mode = i; |
1274 | display_new_pickup (op); |
1294 | display_new_pickup (op); |
1275 | return 1; |
1295 | return 1; |
1276 | } |
1296 | } |
1277 | } |
1297 | } |
… | |
… | |
1279 | return 1; |
1299 | return 1; |
1280 | } |
1300 | } |
1281 | |
1301 | |
1282 | if (sscanf (params, "%u", &i) != 1) |
1302 | if (sscanf (params, "%u", &i) != 1) |
1283 | { |
1303 | { |
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> ."); |
1304 | new_draw_info (NDI_UNIQUE, 0, op, "Usage: pickup <value_density> or [+-]type."); |
1287 | return 1; |
1305 | return 1; |
1288 | } |
1306 | } |
1289 | set_pickup_mode (op, i); |
1307 | |
|
|
1308 | if (i <= PU_RATIO) |
|
|
1309 | i |= op->contr->mode & ~PU_RATIO; |
|
|
1310 | |
|
|
1311 | op->contr->mode = i; |
1290 | |
1312 | |
1291 | return 1; |
1313 | return 1; |
1292 | } |
|
|
1293 | |
|
|
1294 | void |
|
|
1295 | set_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 | } |
1314 | } |
1325 | |
1315 | |
1326 | int |
1316 | int |
1327 | command_search_items (object *op, char *params) |
1317 | command_search_items (object *op, char *params) |
1328 | { |
1318 | { |
1329 | char buf[MAX_BUF]; |
1319 | char buf[MAX_BUF]; |
1330 | |
1320 | |
1331 | if (settings.search_items == FALSE) |
|
|
1332 | return 1; |
|
|
1333 | |
|
|
1334 | if (params == NULL) |
1321 | if (params == NULL) |
1335 | { |
1322 | { |
1336 | if (op->contr->search_str[0] == '\0') |
1323 | if (op->contr->search_str[0] == '\0') |
1337 | { |
1324 | { |
1338 | new_draw_info (NDI_UNIQUE, 0, op, "Example: search magic+1"); |
1325 | 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"); |
1326 | 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'."); |
1327 | new_draw_info (NDI_UNIQUE, 0, op, "items containing the word 'magic+1'."); |
1341 | return 1; |
1328 | return 1; |
1342 | } |
1329 | } |
1343 | |
1330 | |
… | |
… | |
1345 | new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off."); |
1332 | new_draw_info (NDI_UNIQUE, 0, op, "Search mode turned off."); |
1346 | op->update_stats (); |
1333 | op->update_stats (); |
1347 | return 1; |
1334 | return 1; |
1348 | } |
1335 | } |
1349 | |
1336 | |
1350 | if ((int) strlen (params) >= MAX_BUF) |
1337 | if (strlen (params) >= MAX_BUF) |
1351 | { |
1338 | { |
1352 | new_draw_info (NDI_UNIQUE, 0, op, "Search string too long."); |
1339 | new_draw_info (NDI_UNIQUE, 0, op, "Search string too long."); |
1353 | return 1; |
1340 | return 1; |
1354 | } |
1341 | } |
1355 | |
1342 | |
1356 | strcpy (op->contr->search_str, params); |
1343 | strcpy (op->contr->search_str, params); |
1357 | sprintf (buf, "Searching for '%s'.", op->contr->search_str); |
1344 | sprintf (buf, "Now searching for '%s'.", op->contr->search_str); |
1358 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1345 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1359 | op->update_stats (); |
1346 | op->update_stats (); |
|
|
1347 | |
1360 | return 1; |
1348 | return 1; |
1361 | } |
1349 | } |
1362 | |
1350 | |