-
Notifications
You must be signed in to change notification settings - Fork 368
Expand file tree
/
Copy pathcmd-wizard.c
More file actions
2910 lines (2468 loc) · 74.4 KB
/
cmd-wizard.c
File metadata and controls
2910 lines (2468 loc) · 74.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* \file cmd-wizard.c
* \brief Implements debug commands in Angband 4's command system.
*
* Copyright (c) 2021 Eric Branlund
* Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke
*
* This work is free software; you can redistribute it and/or modify it
* under the terms of either:
*
* a) the GNU General Public License as published by the Free Software
* Foundation, version 2, or
*
* b) the "Angband licence":
* This software may be copied and distributed for educational, research,
* and not for profit purposes provided that this copyright and statement
* are included in all such copies. Other copyrights may also apply.
*/
#include "angband.h"
#include "cmds.h"
#include "effects.h"
#include "game-input.h"
#include "generate.h"
#include "init.h"
#include "mon-lore.h"
#include "mon-make.h"
#include "mon-util.h"
#include "obj-curse.h"
#include "obj-desc.h"
#include "obj-gear.h"
#include "obj-knowledge.h"
#include "obj-make.h"
#include "obj-pile.h"
#include "obj-power.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-calcs.h"
#include "player-timed.h"
#include "player-util.h"
#include "project.h"
#include "target.h"
#include "trap.h"
#include "ui-input.h"
#include "ui-map.h"
#include "ui-output.h"
#include "wizard.h"
/*
* Used by do_cmd_wiz_edit_player_*() functions to track the state of the
* editing process.
*/
enum EditPlayerState {
EDIT_PLAYER_UNKNOWN, EDIT_PLAYER_STARTED, EDIT_PLAYER_BREAK
} edit_player_state = EDIT_PLAYER_UNKNOWN;
/**
* Extract a decimal integer from a string while ensuring that only the
* decimal value and white space are present in the string.
* \param s is the string to parse.
* \param val is dereferenced and set to the extracted value.
* \return true if val was dereferenced and set; false if the extraction
* failed
*/
static bool get_int_from_string(const char *s, int *val)
{
char *endptr;
long lval = strtol(s, &endptr, 10);
/*
* Reject INT_MIN and INT_MAX so, for systems where
* sizeof(long) == sizeof(int), it isn't necessary to check errno to
* see if the value in the string was out of range.
*/
if (s[0] == '\0' ||
(*endptr != '\0' && !contains_only_spaces(endptr)) ||
lval <= INT_MIN || lval >= INT_MAX) {
return false;
}
*val = (int)lval;
return true;
}
/**
* Extract a long decimal integer from a string while ensuring that only the
* decimal value and white space are present in the string.
* \param s is the string to parse.
* \param val is dereferenced and set to the extracted value.
* \return true if val was dereferenced and set; false if the extraction
* failed
*/
static bool get_long_from_string(const char *s, long *val)
{
char *endptr;
long lval = strtol(s, &endptr, 10);
/*
* Reject LONG_MIN and LONG_MAX so it isn't necessary to check errno
* to see if the value in the string was out of range.
*/
if (s[0] == '\0' ||
(*endptr != '\0' && !contains_only_spaces(endptr)) ||
lval <= LONG_MIN || lval >= LONG_MAX) {
return false;
}
*val = lval;
return true;
}
/**
* Output part of a bitflag set in binary format.
*/
static void prt_binary(const bitflag *flags, int offset, int row, int col,
wchar_t ch, int num)
{
int flag;
/* Scan the flags. */
for (flag = FLAG_START + offset; flag < FLAG_START + offset + num; flag++) {
if (of_has(flags, flag)) {
Term_putch(col++, row, COLOUR_BLUE, ch);
} else {
Term_putch(col++, row, COLOUR_WHITE, L'-');
}
}
}
/**
* Create an instance of an artifact.
*
* \param art The artifact to instantiate.
* \return An object that represents the artifact.
*/
static struct object *wiz_create_object_from_artifact(const struct artifact *art)
{
struct object_kind *kind;
struct object *obj;
/* Ignore "empty" artifacts */
if (!art->name) return NULL;
/* Acquire the "kind" index */
kind = lookup_kind(art->tval, art->sval);
if (!kind) return NULL;
/* Create the artifact */
obj = object_new();
object_prep(obj, kind, art->alloc_min, RANDOMISE);
obj->artifact = art;
copy_artifact_data(obj, art);
mark_artifact_created(art, true);
return obj;
}
/**
* Create an instance of an object of a given kind.
*
* \param kind The base type of object to instantiate.
* \return An object of the provided object type.
*/
static struct object *wiz_create_object_from_kind(struct object_kind *kind)
{
struct object *obj;
if (tval_is_money_k(kind)) {
obj = make_gold(player->depth, kind->name);
} else {
obj = object_new();
object_prep(obj, kind, player->depth, RANDOMISE);
/* Apply magic (no messages, no artifacts) */
apply_magic(obj, player->depth, false, false, false, false);
}
return obj;
}
/**
* Display an item's properties.
*/
static void wiz_display_item(const struct object *obj, bool all,
const struct player *p)
{
static const char *flagLabels[] = {
#define OF(a, b) b,
#include "list-object-flags.h"
#undef OF
};
int j = 0, i, k, nflg;
bitflag f[OF_SIZE];
char buf[256];
bool *labelsDone;
/* Extract the flags. */
if (all) {
object_flags(obj, f);
} else {
object_flags_known(obj, f);
}
/* Clear screen. */
Term_clear();
/* Describe fully */
object_desc(buf, sizeof(buf), obj,
ODESC_PREFIX | ODESC_FULL | ODESC_SPOIL, p);
prt(buf, 2, j);
prt(format("combat = (%dd%d) (%+d,%+d) [%d,%+d]",
obj->dd, obj->ds, object_to_hit(all ? obj : obj->known),
object_to_dam(all ? obj : obj->known), obj->ac,
object_to_ac(all ? obj : obj->known)), 4, j);
prt(format("kind = %-5lu tval = %-5d sval = %-5d wgt = %-3d timeout = %-d",
(unsigned long)obj->kind->kidx, obj->tval, obj->sval,
object_weight_one(obj), obj->timeout), 5, j);
prt(format("number = %-3d pval = %-5d name1 = %-4ld egoidx = %-4ld cost = %ld",
obj->number, obj->pval,
obj->artifact ? (long)obj->artifact->aidx : 0L,
obj->ego ? (long)obj->ego->eidx : -1L,
(long)object_value(obj, 1)), 6, j);
nflg = MIN(OF_MAX - FLAG_START, 80);
/* Set up header line. */
if (nflg >= 6) {
buf[0] = '+';
k = (nflg - 6) / 2;
for (i = 1; i < k; ++i) {
buf[i] = '-';
}
} else {
k = 0;
}
buf[k] = 'F';
buf[k + 1] = 'L';
buf[k + 2] = 'A';
buf[k + 3] = 'G';
buf[k + 4] = 'S';
for (i = k + 5; i < nflg - 1; ++i) {
buf[i] = '-';
}
if (nflg >= 7) {
buf[nflg - 1] = '+';
buf[nflg] = '\0';
} else {
buf[k + 5] = '\0';
}
prt(buf, 16, j);
/* Display first five letters of flag labels vertically. */
labelsDone = mem_zalloc(nflg * sizeof(*labelsDone));
for (k = 0; k < 5; ++k) {
for (i = 0; i < nflg; ++i) {
if (labelsDone[i]) {
buf[i] = ' ';
} else if (flagLabels[i][k] == '\0') {
labelsDone[i] = true;
buf[i] = ' ';
} else {
buf[i] = flagLabels[i][k];
}
}
buf[nflg] = '\0';
prt(buf, 17 + k, j);
}
mem_free(labelsDone);
prt_binary(f, 0, 22, j, L'*', nflg);
if (obj->known) {
prt_binary(obj->known->flags, 0, 23, j, L'+', nflg);
}
}
/**
* Drop an object near the player in a manner suitable for debugging.
*
* \param obj The object to drop.
*/
static void wiz_drop_object(struct object *obj)
{
if (obj == NULL) return;
/* Mark as cheat and where it was created */
obj->origin = ORIGIN_CHEAT;
obj->origin_depth = convert_depth_to_origin(player->depth);
/* Drop the object from heaven. */
drop_near(cave, &obj, 0, player->grid, true, true);
}
/**
* Redraw the visible portion of the map to accentuate some chosen
* characteristic.
*
* \param c is the chunk to use as the source for data.
* \param p is the player to use.
* \param func is a pointer to a function which will set the value pointed
* to by its fourth argument to whether or not to display the given grid and,
* if displaying that grid, set its fifth argument to the color to use for the
* grid.
* \param closure is passed as the second argument to func.
*
* Assumes the active terminal displays a map.
*/
static void wiz_hack_map(struct chunk *c, struct player *p,
void (*func)(struct chunk *, void *, struct loc, bool *, uint8_t *),
void *closure)
{
int y;
for (y = Term->offset_y; y < Term->offset_y + SCREEN_HGT; y++) {
int x;
for (x = Term->offset_x; x < Term->offset_x + SCREEN_WID; x++) {
struct loc grid = loc(x, y);
bool show;
uint8_t color;
if (!square_in_bounds_fully(c, grid)) continue;
(*func)(c, closure, grid, &show, &color);
if (!show) continue;
if (loc_eq(grid, p->grid)) {
print_rel(L'@', color, y, x);
} else if (square_ispassable(c, grid)) {
print_rel(L'*', color, y, x);
} else {
print_rel(L'#', color, y, x);
}
}
}
}
/**
* Update the queued command object for do_cmd_wiz_play_item() to reflect
* that the item has changed.
*
* Hack: this assumes that there's only one command queued.
*/
static void wiz_play_item_notify_changed(void)
{
struct command *cmd = cmdq_peek();
if (cmd) {
assert(cmd->code == CMD_WIZ_PLAY_ITEM);
cmd_set_arg_choice(cmd, "changed", 1);
}
}
/**
* Handle the typical updates needed to upkeep flags after playing with an item.
*/
static void wiz_play_item_standard_upkeep(struct player *p, struct object *obj)
{
if (object_is_carried(p, obj)) {
p->upkeep->update |= (PU_BONUS | PU_INVEN);
p->upkeep->notice |= (PN_COMBINE);
p->upkeep->redraw |= (PR_INVEN | PR_EQUIP);
} else {
p->upkeep->redraw |= (PR_ITEMLIST);
}
}
/**
* Acquire some good or great objects and drop them near the player
* (CMD_WIZ_ACQUIRE). Can take the number of objects to acquire from the
* argument, "quantity", of type number in cmd. Can take whether to get good
* or great objects from the argument, "choice", of type choice in cmd: a
* non-zero value for that will select great objects.
*/
void do_cmd_wiz_acquire(struct command *cmd)
{
int n, great;
if (cmd_get_arg_choice(cmd, "choice", &great) != CMD_OK) {
great = (get_check("Acquire great objects? ")) ? 1 : 0;
cmd_set_arg_choice(cmd, "choice", great);
}
if (cmd_get_arg_number(cmd, "quantity", &n) != CMD_OK) {
n = get_quantity((great) ?
"How many great objects? " : "How many good objects? ",
40);
if (n < 1) return;
cmd_set_arg_number(cmd, "quantity", n);
}
acquirement(player->grid, player->depth, n, great);
}
/**
* Advance the player to level 50 with max stats and other bonuses
* (CMD_WIZ_ADVANCE). Takes no arguments from cmd.
*/
void do_cmd_wiz_advance(struct command *cmd)
{
int i;
/* Max stats */
for (i = 0; i < STAT_MAX; i++) {
player->stat_cur[i] = player->stat_max[i] = 118;
}
/* Lots of money */
player->au = 1000000L;
/* Level 50 */
player_exp_gain(player, PY_MAX_EXP);
/* Heal the player */
player->chp = player->mhp;
player->chp_frac = 0;
/* Restore mana */
player->csp = player->msp;
player->csp_frac = 0;
/* Get some awesome equipment */
/* Artifacts: 3, 5, 12, ... */
/* Flag update and redraw for things not handled in player_exp_gain() */
player->upkeep->redraw |= PR_GOLD | PR_HP | PR_MANA;
}
/**
* Banish nearby monsters (CMD_WIZ_BANISH). Can take the range of the effect
* from the argument, "range", of type number in cmd.
*/
void do_cmd_wiz_banish(struct command *cmd)
{
int d, i;
if (cmd_get_arg_number(cmd, "range", &d) != CMD_OK) {
d = get_quantity("Zap within what distance? ",
z_info->max_sight);
cmd_set_arg_number(cmd, "range", d);
}
for (i = 1; i < cave_monster_max(cave); i++) {
struct monster *mon = cave_monster(cave, i);
/* Skip dead monsters */
if (!mon->race) continue;
/* Skip distant monsters */
if (mon->cdis > d) continue;
/* Delete the monster */
delete_monster_idx(cave, i);
}
/* Update monster list window */
player->upkeep->redraw |= PR_MONLIST;
}
/**
* Change the quantity of an item (CMD_WIZ_CHANGE_ITEM_QUANTITY). Can take
* the item to modify from the argument, "item", of type item in cmd. Can
* take the new amount from the argument, "quantity", of type number in cmd.
* Takes whether to update player information from the argument, "update",
* of type choice in cmd.
*/
void do_cmd_wiz_change_item_quantity(struct command *cmd)
{
struct object *obj;
int n, nmax;
int update = 0;
if (cmd_get_arg_item(cmd, "item", &obj) != CMD_OK) {
if (!get_item(&obj, "Change quantity of which item? ",
"You have nothing to change.", cmd->code,
NULL, (USE_INVEN | USE_QUIVER | USE_FLOOR))) {
return;
}
cmd_set_arg_item(cmd, "item", obj);
} else if (object_is_equipped(player->body, obj)) {
msg("Can not change the quantity of an equipped item.");
return;
}
/* Don't allow multiple artifacts. */
if (obj->artifact) {
msg("Can not modify the quantity of an artifact.");
return;
}
/* Find limit on stack size. */
nmax = obj->kind->base->max_stack;
if (tval_can_have_charges(obj) && obj->pval > 0 && obj->number > 0) {
/* Items with charges have a limit imposed by MAX_PVAL. */
nmax = MIN((MAX_PVAL * obj->number) / obj->pval, nmax);
}
if (object_is_in_quiver(player, obj)) {
/* The quiver may have stricter limits. */
nmax = MIN(z_info->quiver_slot_size /
(tval_is_ammo(obj) ? 1 : z_info->thrown_quiver_mult),
nmax);
}
/* Get the new quantity. */
if (cmd_get_arg_number(cmd, "quantity", &n) != CMD_OK) {
char prompt[80], s[80];
strnfmt(prompt, sizeof(prompt), "Quantity (1-%d): ", nmax);
/* Set the default value. */
strnfmt(s, sizeof(s), "%d", obj->number);
if (!get_string(prompt, s, sizeof(s)) ||
!get_int_from_string(s, &n) ||
n < 1 || n > obj->kind->base->max_stack) {
return;
}
cmd_set_arg_number(cmd, "quantity", n);
}
/* Impose limits. */
n = MAX(1, MIN(nmax, n));
if (n != obj->number) {
/* Adjust charges or timeouts for devices. */
if (tval_can_have_charges(obj) && obj->number > 0) {
obj->pval = (obj->pval * n) / obj->number;
}
if (tval_can_have_timeout(obj) && obj->number > 0) {
obj->timeout = (obj->timeout * n) / obj->number;
}
/* Accept change. */
if (cmd_get_arg_choice(cmd, "update", &update) != CMD_OK ||
update) {
if (object_is_carried(player, obj)) {
/*
* Remove the weight of the old number of
* objects.
*/
player->upkeep->total_weight -=
obj->number * object_weight_one(obj);
/*
* Add the weight of the new number of objects.
*/
player->upkeep->total_weight +=
n * object_weight_one(obj);
}
wiz_play_item_standard_upkeep(player, obj);
} else {
wiz_play_item_notify_changed();
}
obj->number = n;
}
}
/**
* Generate levels and collect statistics about those with disconnected areas
* and those where the player is disconnected from stairs
* (CMD_WIZ_COLLECT_DISCONNECT_STATS). Can take the number of simulations
* from the argument, "quantity", of type number in cmd. Can take whether to
* stop if a disconnected level is found from the argument, "choice", of type
* choice in cmd (a nonzero value means stop).
*/
void do_cmd_wiz_collect_disconnect_stats(struct command *cmd)
{
/* Record last-used value to be the default in next run. */
static int default_nsim = 50;
int nsim, stop_on_disconnect;
if (!stats_are_enabled()) return;
if (cmd_get_arg_number(cmd, "quantity", &nsim) != CMD_OK) {
char s[80];
/* Set default. */
strnfmt(s, sizeof(s), "%d", default_nsim);
if (!get_string("Number of simulations: ", s, sizeof(s))) return;
if (!get_int_from_string(s, &nsim) || nsim < 1) return;
cmd_set_arg_number(cmd, "quantity", nsim);
}
default_nsim = nsim;
if (cmd_get_arg_choice(cmd, "choice", &stop_on_disconnect) != CMD_OK) {
stop_on_disconnect =
get_check("Stop if disconnected level found? ") ? 1 : 0;
cmd_set_arg_choice(cmd, "choice", stop_on_disconnect);
}
disconnect_stats(nsim, stop_on_disconnect != 0);
}
/**
* Generate levels and collect statistics about the included objects and
* monsters (CMD_WIZ_COLLECT_OBJ_MON_STATS). Can take the number of
* simulations from the argument, "quantity", of type number in cmd. Can take
* the type of simulation (diving (1), clearing (2), or clearing with randart
* regeneration (3)) from the argument, "choice", of type choice in cmd.
*/
void do_cmd_wiz_collect_obj_mon_stats(struct command *cmd)
{
/* Record last-used values to be the default in next run. */
static int default_nsim = 50;
static int default_simtype = 1;
int nsim, simtype;
char s[80];
if (!stats_are_enabled()) return;
if (cmd_get_arg_number(cmd, "quantity", &nsim) != CMD_OK) {
/* Set default. */
strnfmt(s, sizeof(s), "%d", default_nsim);
if (!get_string("Number of simulations: ", s, sizeof(s))) return;
if (!get_int_from_string(s, &nsim) || nsim < 1) return;
cmd_set_arg_number(cmd, "quantity", nsim);
}
default_nsim = nsim;
if (cmd_get_arg_choice(cmd, "choice", &simtype) != CMD_OK) {
/* Set default. */
strnfmt(s, sizeof(s), "%d", default_simtype);
if (!get_string("Type of Sim: Diving (1) or Clearing (2) ",
s, sizeof(s))) return;
if (!get_int_from_string(s, &simtype) || simtype < 1 ||
simtype > 2) return;
if (simtype == 2) {
if (get_check("Regen randarts (warning SLOW)? ")) {
simtype = 3;
}
}
cmd_set_arg_choice(cmd, "choice", simtype);
}
default_simtype = (simtype == 1) ? 1 : 2;
stats_collect(nsim, simtype);
}
/**
* Generate several pits and collect statistics about the types of monsters
* used (CMD_WIZ_COLLECT_PIT_STATS). Can take the number of simulations from
* the argument, "quantity", of type number in cmd. Can take the depth to use
* for the simulations from the argument, "depth", of type number in cmd. Can
* take the type of pit (pit (1), nest (2), or other (3)) from the argument,
* "choice", of type choice in cmd.
*/
void do_cmd_wiz_collect_pit_stats(struct command *cmd)
{
int nsim, depth_min, depth_max, pittype;
char s[80];
if (!stats_are_enabled()) return;
if (cmd_get_arg_number(cmd, "quantity", &nsim) != CMD_OK) {
/* Set default. */
strnfmt(s, sizeof(s), "%d", 1000);
if (!get_string("Number of simulations per depth: ", s,
sizeof(s))) return;
if (!get_int_from_string(s, &nsim) || nsim < 1) return;
cmd_set_arg_number(cmd, "quantity", nsim);
}
if (cmd_get_arg_choice(cmd, "choice", &pittype) != CMD_OK) {
/* Set default. */
strnfmt(s, sizeof(s), "%d", 1);
if (!get_string("Pit type (1-3): ", s, sizeof(s))) return;
if (!get_int_from_string(s, &pittype) || pittype < 1 ||
pittype > 3) return;
cmd_set_arg_choice(cmd, "choice", pittype);
}
if (cmd_get_arg_number(cmd, "depth_min", &depth_min) != CMD_OK) {
/* Set default. */
strnfmt(s, sizeof(s), "%d", player->depth);
if (!get_string("Minimum depth: ", s, sizeof(s))) return;
if (!get_int_from_string(s, &depth_min)
|| depth_min < 1) return;
cmd_set_arg_number(cmd, "depth_min", depth_min);
}
if (cmd_get_arg_number(cmd, "depth_max", &depth_max) != CMD_OK) {
/* Set default. */
strnfmt(s, sizeof(s), "%d", depth_min);
if (!get_string("Maximum depth: ", s, sizeof(s))) return;
if (!get_int_from_string(s, &depth_max)
|| depth_max < depth_min) return;
cmd_set_arg_number(cmd, "depth_max", depth_max);
} else if (depth_max < depth_min) {
return;
}
pit_stats(nsim, pittype, depth_min, depth_max);
}
/**
* Create all artifacts and drop them near the player
* (CMD_WIZ_CREATE_ALL_ARTIFACT). Takes no arguments from cmd.
*/
void do_cmd_wiz_create_all_artifact(struct command *cmd)
{
int i;
for (i = 1; i < z_info->a_max; i++) {
struct artifact *art = &a_info[i];
struct object *obj = wiz_create_object_from_artifact(art);
wiz_drop_object(obj);
}
}
/**
* Create all artifacts of a given tval and drop them near the player
* (CMD_WIZ_CREATE_ALL_ARTIFACT_FROM_TVAL). Can take the tval to use from
* the argument, "tval", of type number in cmd.
*/
void do_cmd_wiz_create_all_artifact_from_tval(struct command *cmd)
{
int tval, i;
if (cmd_get_arg_number(cmd, "tval", &tval) != CMD_OK) {
char prompt[80];
char s[80] = "";
strnfmt(prompt, sizeof(prompt),
"Create all artifacts of which tval (1-%d)? ",
TV_MAX - 1);
if (!get_string(prompt, s, sizeof(s))) return;
if (!get_int_from_string(s, &tval) || tval < 1 ||
tval >= TV_MAX) return;
cmd_set_arg_number(cmd, "tval", tval);
}
for (i = 1; i < z_info->a_max; i++) {
struct artifact *art = &a_info[i];
if (art->tval == tval) {
struct object *obj =
wiz_create_object_from_artifact(art);
wiz_drop_object(obj);
}
}
}
/**
* Create one of each kind of ordinary object and drop them near the player
* (CMD_WIZ_CREATE_ALL_OBJ). Takes no arguments from cmd.
*/
void do_cmd_wiz_create_all_obj(struct command *cmd)
{
int i;
for (i = 0; i < z_info->k_max; i++) {
struct object_kind *kind = &k_info[i];
struct object *obj;
if (kind->base == NULL || kind->base->name == NULL) continue;
if (kf_has(kind->kind_flags, KF_INSTA_ART)) continue;
obj = wiz_create_object_from_kind(kind);
wiz_drop_object(obj);
}
}
/**
* Create one of each kind of object from a tval and drop them near the player
* (CMD_WIZ_CREATE_ALL_OBJ_FROM_TVAL). Can take the tval to use from the
* argument, "tval", of type number in cmd. Can take whether to create instant
* artifacts from the argument, "choice", of type choice in cmd.
*/
void do_cmd_wiz_create_all_obj_from_tval(struct command *cmd)
{
int tval, art;
int i;
if (cmd_get_arg_number(cmd, "tval", &tval) != CMD_OK) {
char prompt[80];
char s[80] = "";
strnfmt(prompt, sizeof(prompt),
"Create all items of which tval (1-%d)? ", TV_MAX - 1);
if (!get_string(prompt, s, sizeof(s))) return;
if (!get_int_from_string(s, &tval) || tval < 1 ||
tval >= TV_MAX) return;
cmd_set_arg_number(cmd, "tval", tval);
}
if (cmd_get_arg_choice(cmd, "choice", &art) != CMD_OK) {
art = get_check("Create instant artifacts? ");
cmd_set_arg_choice(cmd, "choice", art);
}
for (i = 0; i < z_info->k_max; i++) {
struct object_kind *kind = &k_info[i];
struct object *obj;
if (kind->tval != tval ||
(!art && kf_has(kind->kind_flags, KF_INSTA_ART))) continue;
obj = wiz_create_object_from_kind(kind);
wiz_drop_object(obj);
}
}
/**
* Create a specified artifact (CMD_WIZ_CREATE_ARTIFACT). Can take the index
* of the artifact to create from the argument, "index", of type number in cmd.
*/
void do_cmd_wiz_create_artifact(struct command *cmd)
{
int ind;
if (cmd_get_arg_number(cmd, "index", &ind) != CMD_OK) {
char prompt[80];
char s[80] = "";
strnfmt(prompt, sizeof(prompt),
"Create which artifact (1-%d)? ", z_info->a_max - 1);
if (!get_string(prompt, s, sizeof(s))) return;
if (!get_int_from_string(s, &ind)) return;
cmd_set_arg_number(cmd, "index", ind);
}
if (ind >= 1 && ind < z_info->a_max) {
struct artifact *art = &a_info[ind];
struct object *obj = wiz_create_object_from_artifact(art);
wiz_drop_object(obj);
} else {
msg("That's not a valid artifact.");
}
}
/**
* Create an object of a given kind and drop it near the player
* (CMD_WIZ_CREATE_OBJ). Can take the index of the kind of object from the
* argument, "index", of type number in cmd.
*/
void do_cmd_wiz_create_obj(struct command *cmd)
{
int ind;
if (cmd_get_arg_number(cmd, "index", &ind) != CMD_OK) {
char prompt[80];
char s[80] = "";
strnfmt(prompt, sizeof(prompt),
"Create which object (0-%d)? ", z_info->k_max - 1);
if (!get_string(prompt, s, sizeof(s))) return;
if (!get_int_from_string(s, &ind)) return;
cmd_set_arg_number(cmd, "index", ind);
}
if (ind >= 0 && ind < z_info->k_max) {
struct object_kind *kind = &k_info[ind];
struct object *obj = wiz_create_object_from_kind(kind);
wiz_drop_object(obj);
} else {
msg("That's not a valid kind of object.");
}
}
/**
* Create a trap at the player's position (CMD_WIZ_CREATE_TRAP). Can take
* the type of trap to generate from the argument, "index", of type number
* in cmd.
*/
void do_cmd_wiz_create_trap(struct command *cmd)
{
int tidx;
if (cmd_get_arg_number(cmd, "index", &tidx) != CMD_OK) {
char s[80] = "";
if (!get_string("Create which trap? ", s, sizeof(s))) return;
if (!get_int_from_string(s, &tidx)) {
const struct trap_kind *trap = lookup_trap(s);
tidx = (trap) ? trap->tidx : z_info->trap_max;
}
cmd_set_arg_number(cmd, "index", tidx);
}
if (!square_isfloor(cave, player->grid)
|| square_isplayertrap(cave, player->grid)
|| square_iswebbed(cave, player->grid)
|| square_object(cave, player->grid)) {
msg("You can't place a trap there!");
} else if (player->depth == 0) {
msg("You can't place a trap in the town!");
} else if (tidx < 1 || tidx >= z_info->trap_max) {
msg("Trap not found.");
} else {
place_trap(cave, player->grid, tidx, 0);
/* Can not repeat since there's now a trap here. */
cmd_disable_repeat();
}
}
/**
* Instantly cure the player of everything (CMD_WIZ_CURE_ALL). Takes no
* arguments from cmd.
*/
void do_cmd_wiz_cure_all(struct command *cmd)
{
int i;
/* Remove curses */
for (i = 0; i < player->body.count; i++) {
if (player->body.slots[i].obj &&
player->body.slots[i].obj->curses) {
mem_free(player->body.slots[i].obj->curses);
player->body.slots[i].obj->curses = NULL;
}
}
/* Restore stats */
for (i = 0; i < STAT_MAX; i++) {
effect_simple(EF_RESTORE_STAT, source_player(), "0", i,
0, 0, 0, 0, NULL);
}
/* Restore the level */
effect_simple(EF_RESTORE_EXP, source_none(), "0", 0, 0, 0, 0, 0, NULL);
/* Heal the player */
player->chp = player->mhp;
player->chp_frac = 0;
/* Restore mana */
player->csp = player->msp;
player->csp_frac = 0;
/* Cure stuff */
(void) player_clear_timed(player, TMD_BLIND, true, false);
(void) player_clear_timed(player, TMD_CONFUSED, true, false);
(void) player_clear_timed(player, TMD_POISONED, true, false);
(void) player_clear_timed(player, TMD_AFRAID, true, false);
(void) player_clear_timed(player, TMD_PARALYZED, true, false);
(void) player_clear_timed(player, TMD_IMAGE, true, false);
(void) player_clear_timed(player, TMD_STUN, true, false);
(void) player_clear_timed(player, TMD_CUT, true, false);
(void) player_clear_timed(player, TMD_SLOW, true, false);
(void) player_clear_timed(player, TMD_AMNESIA, true, false);
/* No longer hungry */
player_set_timed(player, TMD_FOOD, PY_FOOD_FULL - 1, false, false);
/* Flag what needs to be updated or redrawn */
player->upkeep->update |= PU_TORCH | PU_UPDATE_VIEW | PU_MONSTERS;
player->upkeep->redraw |= PR_BASIC | PR_EXTRA | PR_MAP | PR_EQUIP;
/* Give the player some feedback */
msg("You feel *much* better!");
}
/**
* Change a curse on an item (CMD_WIZ_CURSE_ITEM). Can take the item to use
* from the argument, "item", of type item. Can take the index of the curse
* to use from the argument, "index", of type number. Can take the power of
* the curse from the argument, "power", of type number. Using a power of
* zero will remove a curse. Takes whether to update player information