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,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * option) any later version. |
11 | * 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, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
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 Affero GNU General Public License |
18 | * You should have received a copy of the Affero GNU General Public License |
19 | * and the GNU General Public License along with this program. If not, see |
19 | * and the GNU General Public License along with this program. If not, see |
20 | * <http://www.gnu.org/licenses/>. |
20 | * <http://www.gnu.org/licenses/>. |
21 | * |
21 | * |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | */ |
23 | */ |
24 | |
24 | |
25 | #include <global.h> |
25 | #include <global.h> |
26 | #include <sproto.h> |
26 | #include <sproto.h> |
… | |
… | |
356 | { |
356 | { |
357 | new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str); |
357 | new_draw_info_format (NDI_UNIQUE, 0, op, "No such god %s.", str); |
358 | return 1; |
358 | return 1; |
359 | } |
359 | } |
360 | |
360 | |
361 | become_follower (ob, god); |
361 | ob->become_follower (god); |
362 | return 1; |
362 | return 1; |
363 | } |
363 | } |
364 | |
364 | |
365 | int |
365 | int |
366 | command_freeze (object *op, char *params) |
366 | command_freeze (object *op, char *params) |
… | |
… | |
436 | |
436 | |
437 | int |
437 | int |
438 | command_summon (object *op, char *params) |
438 | command_summon (object *op, char *params) |
439 | { |
439 | { |
440 | int i; |
440 | int i; |
441 | object *dummy; |
|
|
442 | player *pl; |
441 | player *pl; |
443 | |
442 | |
444 | if (!op) |
443 | if (!op) |
445 | return 0; |
444 | return 0; |
446 | |
445 | |
… | |
… | |
452 | |
451 | |
453 | pl = get_other_player_from_name (op, params); |
452 | pl = get_other_player_from_name (op, params); |
454 | if (!pl) |
453 | if (!pl) |
455 | return 1; |
454 | return 1; |
456 | |
455 | |
457 | i = find_free_spot (op, op->map, op->x, op->y, 1, 9); |
456 | maptile *m = op->map; |
|
|
457 | sint16 nx = op->x; |
|
|
458 | sint16 ny = op->y; |
|
|
459 | |
|
|
460 | i = find_free_spot (op, m, nx, ny, 1, SIZEOFFREE1+1); |
458 | if (i == -1) |
461 | if (i == -1) |
459 | { |
462 | { |
460 | new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
463 | new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
461 | return 1; |
464 | return 1; |
462 | } |
465 | } |
463 | |
466 | |
464 | pl->ob->player_goto (op->map->path, op->x + freearr_x[i], op->y + freearr_y[i]); |
467 | nx += freearr_x [i]; |
|
|
468 | ny += freearr_y [i]; |
|
|
469 | |
|
|
470 | if (!xy_normalise (m, nx, ny)) |
|
|
471 | { |
|
|
472 | new_draw_info (NDI_UNIQUE, 0, op, "Can not find a free spot to place summoned player."); |
|
|
473 | return 1; |
|
|
474 | } |
|
|
475 | |
|
|
476 | pl->ob->player_goto (m->path, nx, ny); |
465 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); |
477 | new_draw_info (NDI_UNIQUE, 0, pl->ob, "You are summoned."); |
466 | new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
478 | new_draw_info (NDI_UNIQUE, 0, op, "OK."); |
467 | |
479 | |
468 | return 1; |
480 | return 1; |
469 | } |
481 | } |
… | |
… | |
486 | int |
498 | int |
487 | command_create (object *op, char *params) |
499 | command_create (object *op, char *params) |
488 | { |
500 | { |
489 | object *tmp = NULL; |
501 | object *tmp = NULL; |
490 | int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; |
502 | int nrof, i, magic, set_magic = 0, set_nrof = 0, gotquote, gotspace; |
491 | char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *bp4, *endline; |
503 | char buf[MAX_BUF], *cp, *bp = buf, *bp2, *bp3, *endline; |
492 | archetype *at, *at_spell = NULL; |
504 | archetype *at, *at_spell = NULL; |
493 | artifact *art = NULL; |
505 | artifact *art = NULL; |
494 | |
506 | |
495 | if (!op) |
507 | if (!op) |
496 | return 0; |
508 | return 0; |
… | |
… | |
621 | /* |
633 | /* |
622 | * Rather than have two different blocks with a lot of similar code, |
634 | * Rather than have two different blocks with a lot of similar code, |
623 | * just create one object, do all the processing, and then determine |
635 | * just create one object, do all the processing, and then determine |
624 | * if that one object should be inserted or if we need to make copies. |
636 | * if that one object should be inserted or if we need to make copies. |
625 | */ |
637 | */ |
626 | tmp = arch_to_object (at); |
638 | tmp = at->instance (); |
627 | |
639 | |
628 | if (set_magic) |
640 | if (set_magic) |
629 | set_abs_magic (tmp, magic); |
641 | set_abs_magic (tmp, magic); |
630 | |
642 | |
631 | if (art) |
643 | if (art) |
632 | give_artifact_abilities (tmp, art->item); |
644 | give_artifact_abilities (tmp, art->item); |
633 | |
645 | |
634 | if (need_identify (tmp)) |
646 | if (tmp->need_identify ()) |
635 | { |
647 | { |
636 | SET_FLAG (tmp, FLAG_IDENTIFIED); |
648 | tmp->set_flag (FLAG_IDENTIFIED); |
637 | CLEAR_FLAG (tmp, FLAG_KNOWN_MAGICAL); |
649 | tmp->clr_flag (FLAG_KNOWN_MAGICAL); |
638 | } |
650 | } |
639 | |
651 | |
640 | /* |
652 | /* |
641 | * This entire block here tries to find variable pairings, |
653 | * This entire block here tries to find variable pairings, |
642 | * eg, 'hp 4' or the like. The mess here is that values |
654 | * eg, 'hp 4' or the like. The mess here is that values |
… | |
… | |
644 | * is we want to find two spaces, but if we got a quote, |
656 | * is we want to find two spaces, but if we got a quote, |
645 | * any spaces there don't count. |
657 | * any spaces there don't count. |
646 | */ |
658 | */ |
647 | while (*bp2 && bp2 <= endline) |
659 | while (*bp2 && bp2 <= endline) |
648 | { |
660 | { |
649 | bp4 = NULL; |
|
|
650 | gotspace = 0; |
661 | gotspace = 0; |
651 | gotquote = 0; |
662 | gotquote = 0; |
652 | |
663 | |
653 | /* find the first quote */ |
664 | /* find the first quote */ |
654 | for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) |
665 | for (bp3 = bp2; *bp3 && gotspace < 2 && gotquote < 2; bp3++) |
… | |
… | |
714 | } |
725 | } |
715 | |
726 | |
716 | if (at->nrof) |
727 | if (at->nrof) |
717 | { |
728 | { |
718 | if (at_spell) |
729 | if (at_spell) |
719 | tmp->insert (arch_to_object (at_spell)); |
730 | tmp->insert (at_spell->instance ()); |
720 | |
731 | |
721 | tmp->x = op->x; |
732 | tmp->x = op->x; |
722 | tmp->y = op->y; |
733 | tmp->y = op->y; |
723 | tmp->map = op->map; |
734 | tmp->map = op->map; |
724 | |
735 | |
… | |
… | |
738 | { |
749 | { |
739 | object *prev = 0, *head = 0; |
750 | object *prev = 0, *head = 0; |
740 | |
751 | |
741 | for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
752 | for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
742 | { |
753 | { |
743 | object *dup = arch_to_object (atmp); |
754 | object *dup = atmp->instance (); |
744 | |
755 | |
745 | if (at_spell) |
756 | if (at_spell) |
746 | insert_ob_in_ob (arch_to_object (at_spell), dup); |
757 | insert_ob_in_ob (at_spell->instance (), dup); |
747 | |
758 | |
748 | /* |
759 | /* |
749 | * The head is what contains all the important bits, |
760 | * The head is what contains all the important bits, |
750 | * so just copying it over should be fine. |
761 | * so just copying it over should be fine. |
751 | */ |
762 | */ |
… | |
… | |
766 | } |
777 | } |
767 | |
778 | |
768 | prev = dup; |
779 | prev = dup; |
769 | } |
780 | } |
770 | |
781 | |
771 | if (QUERY_FLAG (head, FLAG_ALIVE)) |
782 | if (head->flag [FLAG_ALIVE]) |
772 | { |
783 | { |
773 | object *check = head; |
784 | object *check = head; |
774 | int size_x = 0; |
785 | int size_x = 0; |
775 | int size_y = 0; |
786 | int size_y = 0; |
776 | |
787 | |
777 | while (check) |
788 | while (check) |
778 | { |
789 | { |
779 | size_x = MAX (size_x, check->arch->x); |
790 | size_x = max (size_x, check->arch->x); |
780 | size_y = MAX (size_y, check->arch->y); |
791 | size_y = max (size_y, check->arch->y); |
781 | check = check->more; |
792 | check = check->more; |
782 | } |
793 | } |
783 | |
794 | |
784 | if (out_of_map (op->map, head->x + size_x, head->y + size_y)) |
795 | if (out_of_map (op->map, head->x + size_x, head->y + size_y)) |
785 | { |
796 | { |
… | |
… | |
867 | |
878 | |
868 | char *dump = dump_object (tmp); |
879 | char *dump = dump_object (tmp); |
869 | new_draw_info (NDI_UNIQUE, 0, op, dump); |
880 | new_draw_info (NDI_UNIQUE, 0, op, dump); |
870 | free (dump); |
881 | free (dump); |
871 | |
882 | |
872 | if (QUERY_FLAG (tmp, FLAG_OBJ_ORIGINAL)) |
883 | if (tmp->flag [FLAG_OBJ_ORIGINAL]) |
873 | new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); |
884 | new_draw_info (NDI_UNIQUE, 0, op, "Object is marked original"); |
874 | |
885 | |
875 | return 1; |
886 | return 1; |
876 | } |
887 | } |
877 | |
888 | |
… | |
… | |
922 | { |
933 | { |
923 | new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); |
934 | new_draw_info (NDI_UNIQUE, 0, op, "Unable to remove a player!"); |
924 | return 1; |
935 | return 1; |
925 | } |
936 | } |
926 | |
937 | |
927 | if (QUERY_FLAG (tmp, FLAG_REMOVED)) |
938 | if (tmp->flag [FLAG_REMOVED]) |
928 | { |
939 | { |
929 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); |
940 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s is already removed!", query_name (tmp)); |
930 | return 1; |
941 | return 1; |
931 | } |
942 | } |
932 | |
943 | |
… | |
… | |
1022 | /**************************************************************************/ |
1033 | /**************************************************************************/ |
1023 | |
1034 | |
1024 | int |
1035 | int |
1025 | command_stats (object *op, char *params) |
1036 | command_stats (object *op, char *params) |
1026 | { |
1037 | { |
1027 | char thing[20]; |
|
|
1028 | char buf[MAX_BUF]; |
1038 | char buf[MAX_BUF]; |
1029 | |
1039 | |
1030 | thing[0] = '\0'; |
1040 | if (params == NULL || params[0] == '\0') |
1031 | if (params == NULL || !sscanf (params, "%s", thing) || thing == NULL) |
|
|
1032 | { |
1041 | { |
1033 | new_draw_info (NDI_UNIQUE, 0, op, "Who?"); |
1042 | new_draw_info (NDI_UNIQUE, 0, op, "Who?"); |
1034 | return 1; |
1043 | return 1; |
1035 | } |
1044 | } |
1036 | |
1045 | |
1037 | for_all_players (pl) |
1046 | for_all_players (pl) |
1038 | if (!strcmp (&pl->ob->name, thing)) |
1047 | if (!strcmp (&pl->ob->name, params)) |
1039 | { |
1048 | { |
1040 | sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); |
1049 | sprintf (buf, "Str : %-2d H.P. : %-4d MAX : %d", pl->ob->stats.Str, pl->ob->stats.hp, pl->ob->stats.maxhp); |
1041 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1050 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1042 | sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); |
1051 | sprintf (buf, "Dex : %-2d S.P. : %-4d MAX : %d", pl->ob->stats.Dex, pl->ob->stats.sp, pl->ob->stats.maxsp); |
1043 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
1052 | new_draw_info (NDI_UNIQUE, 0, op, buf); |
… | |
… | |
1110 | } |
1119 | } |
1111 | |
1120 | |
1112 | int |
1121 | int |
1113 | command_nowiz (object *op, char *params) |
1122 | command_nowiz (object *op, char *params) |
1114 | { /* 'nodm' is alias */ |
1123 | { /* 'nodm' is alias */ |
1115 | CLEAR_FLAG (op, FLAG_WIZ); |
1124 | op->clr_flag (FLAG_WIZ); |
1116 | CLEAR_FLAG (op, FLAG_WIZPASS); |
1125 | op->clr_flag (FLAG_WIZPASS); |
1117 | CLEAR_FLAG (op, FLAG_WIZCAST); |
1126 | op->clr_flag (FLAG_WIZCAST); |
1118 | CLEAR_FLAG (op, FLAG_WIZLOOK); |
1127 | op->clr_flag (FLAG_WIZLOOK); |
1119 | op->contr->do_los = 1; |
1128 | op->contr->do_los = 1; |
1120 | |
1129 | |
1121 | if (op->contr->hidden) |
1130 | if (op->contr->hidden) |
1122 | { |
1131 | { |
1123 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); |
1132 | new_draw_info (NDI_UNIQUE, 0, op, "You are no longer hidden from other players"); |
… | |
… | |
1179 | do_wizard_dm (object *op, char *params, int silent) |
1188 | do_wizard_dm (object *op, char *params, int silent) |
1180 | { |
1189 | { |
1181 | if (!op->contr) |
1190 | if (!op->contr) |
1182 | return 0; |
1191 | return 0; |
1183 | |
1192 | |
1184 | if (QUERY_FLAG (op, FLAG_WIZ)) |
1193 | if (op->flag [FLAG_WIZ]) |
1185 | { |
1194 | { |
1186 | new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!"); |
1195 | new_draw_info (NDI_UNIQUE, 0, op, "You are already the Dungeon Master!"); |
1187 | return 0; |
1196 | return 0; |
1188 | } |
1197 | } |
1189 | |
1198 | |
1190 | if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host)) |
1199 | if (checkdm (op, op->name, (params ? params : "*"), op->contr->ns->host)) |
1191 | { |
1200 | { |
1192 | SET_FLAG (op, FLAG_WIZ); |
1201 | op->set_flag (FLAG_WIZ); |
1193 | SET_FLAG (op, FLAG_WIZPASS); |
1202 | op->set_flag (FLAG_WIZPASS); |
1194 | SET_FLAG (op, FLAG_WIZCAST); |
1203 | op->set_flag (FLAG_WIZCAST); |
1195 | SET_FLAG (op, FLAG_WIZLOOK); |
1204 | op->set_flag (FLAG_WIZLOOK); |
1196 | op->contr->do_los = 1; |
1205 | op->contr->do_los = 1; |
1197 | |
1206 | |
1198 | new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); |
1207 | new_draw_info (NDI_UNIQUE, 0, op, "Ok, you are the Dungeon Master!"); |
1199 | op->contr->write_buf[0] = '\0'; |
1208 | op->contr->write_buf[0] = '\0'; |
1200 | |
1209 | |
… | |
… | |
1249 | static object * |
1258 | static object * |
1250 | get_spell_by_name (object *op, shstr_cmp spell_name) |
1259 | get_spell_by_name (object *op, shstr_cmp spell_name) |
1251 | { |
1260 | { |
1252 | /* First check for full name matches. */ |
1261 | /* First check for full name matches. */ |
1253 | int conflict_found = 0; |
1262 | int conflict_found = 0; |
1254 | archetype *found; |
1263 | archetype *found = 0; |
|
|
1264 | |
1255 | for_all_archetypes (at) |
1265 | for_all_archetypes (at) |
1256 | { |
1266 | { |
1257 | if (at->type != SPELL) |
1267 | if (at->type != SPELL) |
1258 | continue; |
1268 | continue; |
1259 | |
1269 | |
… | |
… | |
1276 | found = at; |
1286 | found = at; |
1277 | } |
1287 | } |
1278 | |
1288 | |
1279 | /* Return if exactly one archetype matches. */ |
1289 | /* Return if exactly one archetype matches. */ |
1280 | if (found) |
1290 | if (found) |
1281 | return arch_to_object (found); |
1291 | return found->instance (); |
1282 | |
1292 | |
1283 | /* No spell found: just print an error message. */ |
1293 | /* No spell found: just print an error message. */ |
1284 | new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist."); |
1294 | new_draw_info_format (NDI_UNIQUE, 0, op, "The spell does not exist."); |
1285 | |
1295 | |
1286 | return 0; |
1296 | return 0; |
… | |
… | |
1335 | { |
1345 | { |
1336 | new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to forget?"); |
1346 | new_draw_info (NDI_UNIQUE, 0, op, "Which spell do you want to forget?"); |
1337 | return 0; |
1347 | return 0; |
1338 | } |
1348 | } |
1339 | |
1349 | |
1340 | spell = lookup_spell_by_name (op, params); |
1350 | spell = op->find_spell (params); |
1341 | if (spell == NULL) |
1351 | if (spell == NULL) |
1342 | { |
1352 | { |
1343 | new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); |
1353 | new_draw_info_format (NDI_UNIQUE, 0, op, "You do not know the spell %s.", params); |
1344 | return 0; |
1354 | return 0; |
1345 | } |
1355 | } |
… | |
… | |
1429 | } |
1439 | } |
1430 | |
1440 | |
1431 | int |
1441 | int |
1432 | command_insert_into (object *op, char *params) |
1442 | command_insert_into (object *op, char *params) |
1433 | { |
1443 | { |
1434 | object *left, *right, *inserted; |
1444 | object *left, *right; |
1435 | int left_from, right_from; |
1445 | int left_from, right_from; |
1436 | |
1446 | |
1437 | left = get_dm_object (op->contr, ¶ms, &left_from); |
1447 | left = get_dm_object (op->contr, ¶ms, &left_from); |
1438 | if (!left) |
1448 | if (!left) |
1439 | { |
1449 | { |
… | |
… | |
1482 | { |
1492 | { |
1483 | new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); |
1493 | new_draw_info (NDI_UNIQUE, 0, op, "Can't insert a player into something!"); |
1484 | return 0; |
1494 | return 0; |
1485 | } |
1495 | } |
1486 | |
1496 | |
1487 | if (!QUERY_FLAG (right, FLAG_REMOVED)) |
1497 | if (!right->flag [FLAG_REMOVED]) |
1488 | right->remove (); |
1498 | right->remove (); |
1489 | |
1499 | |
1490 | insert_ob_in_ob (right, left); |
1500 | object *inserted = insert_ob_in_ob (right, left); |
1491 | |
1501 | |
1492 | new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); |
1502 | new_draw_info_format (NDI_UNIQUE, 0, op, "Inserted %s in %s", query_name (inserted), query_name (left)); |
1493 | |
1503 | |
1494 | return 0; |
1504 | return 0; |
1495 | |
1505 | |