forked from rogueforge/rogomatic14
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththings.c
More file actions
751 lines (619 loc) · 16.2 KB
/
things.c
File metadata and controls
751 lines (619 loc) · 16.2 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
/*
* Rog-O-Matic
* Automatically exploring the dungeons of doom.
*
* Copyright (C) 2008 by Anthony Molinaro
* Copyright (C) 1985 by Appel, Jacobson, Hamey, and Mauldin.
*
* This file is part of Rog-O-Matic.
*
* Rog-O-Matic is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Rog-O-Matic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Rog-O-Matic. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* things.c:
*
* This file contains much of the code to handle Rog-O-Matics inventory.
*/
# include <ctype.h>
# include <string.h>
# include "modern_curses.h"
# include "types.h"
# include "config.h"
# include "globals.h"
/* static declarations */
static int destroyjunk (int obj);
/*
* wear: This primitive function issues a command to put on armor.
*/
int
wear (int obj)
{
if (currentarmor != NONE) {
dwait (D_FATAL, __func__, "Trying wear 2nd armor");
return (0);
}
if (cursedarmor) return (0);
command (T_HANDLING, "W%c", LETTER (obj));
usesynch = false;
return (1);
}
/*
* takeoff: Remove the current armor.
*/
int
takeoff (void)
{
if (currentarmor == NONE) {
dwait (D_ERROR, __func__, "No armor to remove");
return (0);
}
if (cursedarmor) return (0);
command (T_HANDLING, "T");
usesynch = false;
return (1);
}
/*
* wield: This primitive function issues a command to wield a weapon.
*/
int
wield (int obj)
{
if (cursedweapon) return (0);
if (version >= RV54A) {
if (itemis(currentweapon, CURSED)) {
cursedweapon = true;
return (0);
}
else if (currentweapon == NONE) {
command (T_HANDLING, "w%c", LETTER (obj));
}
else if (itemis(currentweapon, UNCURSED)) {
cursedweapon = false;
command (T_HANDLING, "w%c", LETTER (obj));
}
else if (itemis(currentweapon, ENCHANTED)) {
remember(currentweapon, UNCURSED);
cursedweapon = false;
command (T_HANDLING, "w%c", LETTER (obj));
}
else {
/* current weapon might be cursed */
if (currentweapon != NONE) {
lastdrop = currentweapon;
command (T_HANDLING, "w%c;", ESC);
}
return (0);
}
}
/* send 2 escapes because I needed to patch the new rogue to not hang
* momentarily on the first escape
*/
else if (version == RV53A)
command (T_HANDLING, "w%cw%c%c", LETTER (obj), ESC, ctrl('p'));
else if (version >= RV54A)
/*
* For rogue version RV54A or later, we issue ";" to
* cause the "Illegal command ';'" sync message to be generated.
*/
command (T_HANDLING, "w%c;w%c;%c", LETTER (obj), ESC, ctrl('r'));
else
command (T_HANDLING, "w%cw%c%c", LETTER (obj), ESC, ctrl('r'));
return (1);
}
/*
* destroyjunk: When an object is thrown diagonally into a corner,
* Rogue can't find a place to put it, and the object is
* removed from the game (adapted from dropjunk).
*/
static int
destroyjunk (int obj)
{
if ((obj != NONE) && (gotocorner () || throw (obj, 7)))
return (1);
return (0);
}
/*
* drop: called with an integer from 0 to 25, drops the object if possible
* and returns 1 if it wins and 0 if it fails.
*/
int
drop (int obj)
{
/* Can't if not there, in use, or on something else or
dropped something else already */
if (inven[obj].count < 1 ||
itemis (obj, INUSE) ||
on (STUFF | TRAP | STAIRS | DOOR) ||
diddrop)
return (0);
if ((obj != NONE) && (inven[obj].type == wand))
return (destroyjunk (obj));
/* read unknown scrolls or good scrolls rather than dropping them */
if (inven[obj].type == Scroll &&
(!itemis (obj, KNOWN) ||
(stlmatch (inven[obj].str, "identify") && prepareident (pickident (), obj)) ||
stlmatch (inven[obj].str, "enchant") ||
stlmatch (inven[obj].str, "genocide") ||
stlmatch (inven[obj].str, "gold detection") ||
stlmatch (inven[obj].str, "hold monster") ||
stlmatch (inven[obj].str, "light") ||
stlmatch (inven[obj].str, "magic mapping") ||
stlmatch (inven[obj].str, "monster confusion") ||
stlmatch (inven[obj].str, "remove curse")) &&
reads (obj))
{ return (1); }
/* quaff unknown potions or good potions rather than dropping them */
if (inven[obj].type == potion &&
(!itemis (obj, KNOWN) ||
stlmatch (inven[obj].str, "magic detection") ||
stlmatch (inven[obj].str, "monster detection") ||
stlmatch (inven[obj].str, "raise level") ||
stlmatch (inven[obj].str, "healing") ||
(stlmatch (inven[obj].str, "haste self") && !hasted) ||
stlmatch (inven[obj].str, "extra healing") ||
stlmatch (inven[obj].str, "restore strength") ||
stlmatch (inven[obj].str, "gain strength")) &&
quaff (obj))
{ return (1); }
command (T_HANDLING, "d%c", LETTER (obj));
return (1);
}
/*
* quaff: build and send a quaff potion command.
*/
int
quaff (int obj)
{
if (inven[obj].type != potion) {
dwait (D_ERROR, __func__, "Trying to quaff: %c", LETTER (obj));
usesynch = false;
return (0);
}
command (T_HANDLING, "q%c", LETTER (obj));
return (1);
}
/*
* reads: build and send a read scroll command.
*/
int
reads (int obj)
{
if (inven[obj].type != Scroll) {
dwait (D_ERROR, __func__, "Trying to read: %c", LETTER (obj));
usesynch = false;
return (0);
}
command (T_HANDLING, "r%c", LETTER (obj));
return (1);
}
/*
* build and send a point with wand command.
*/
int
point (int obj, int dir)
{
if (inven[obj].type != wand) {
dwait (D_ERROR, __func__, "Trying to point: %c", LETTER (obj));
return (0);
}
if (itemis (obj, USELESS))
return (0);
else {
command (T_HANDLING, "%c%c%c",
(version < RV52A) ? 'p' : 'z', /* R5.2 MLM */
keydir[dir], LETTER (obj));
return (1);
}
}
/*
* throw: build and send a throw object command.
*/
int
throw (int obj, int dir)
{
if (obj < 0 || obj >= invcount) {
dwait (D_ERROR, __func__, "Trying to throw: %c", LETTER (obj));
return (0);
}
command (T_HANDLING, "t%c%c", keydir[dir], LETTER (obj));
return (1);
}
/*
* puton: build and send a command to put on a ring.
*/
int
puton (int obj)
{
if (leftring == NONE && rightring == NONE)
{ command (T_HANDLING, "P%cl", LETTER (obj)); return (1); }
if (leftring == NONE || rightring == NONE)
{ command (T_HANDLING, "P%c", LETTER (obj)); return (1); }
return (0);
}
/*
* removering: build a command to remove a ring. It is left in the pack.
*/
int
removering (int obj)
{
if (leftring != NONE && rightring != NONE && leftring == obj)
{ command (T_HANDLING, "Rl"); return (1); }
if (leftring != NONE && rightring != NONE && rightring == obj)
{ command (T_HANDLING, "Rr"); return (1); }
if (leftring == obj || rightring == obj)
{ command (T_HANDLING, "R"); return (1); }
return (0);
}
/*
* initstufflist: clear the list of objects on this level.
*/
void
initstufflist (void)
{
slistlen = 0;
}
/*
* addstuff: add an item to the list of items on this level.
*/
void
addstuff (char ch, int row, int col)
{
/* if (seerc ('@', row, col)) return (0); */ /* Removed MLM 10/28/83 */
if (onrc (STUFF, row, col))
deletestuff (row, col);
slist[slistlen].what = translate[(int)ch];
slist[slistlen].srow = row;
slist[slistlen].scol = col;
if (++slistlen >= MAXSTUFF) dwait (D_FATAL, __func__, "Too much stuff");
setrc (STUFF, row, col);
}
/*
* deletestuff: remove the object from the stuff list at location (x,y)
*/
void
deletestuff (int row, int col)
{
int i;
unsetrc (STUFF, row, col);
for (i = 0; i < slistlen; ++i)
if (slist[i].scol == col && slist[i].srow == row) {
slist[i] = slist[--slistlen];
i--; /* MLM 10/23/82 */
}
}
/*
* dumpstuff: (debugging) dump the list of objects on this level.
*/
void
dumpstuff (void)
{
int i;
at (1, 0);
for (i = 0; i < slistlen; ++i)
if (valrc (slist[i].srow, slist[i].scol)) {
printw ("%d at %d,%d (%c)\n",
slist[i].what, slist[i].srow, slist[i].scol,
screen[slist[i].srow][slist[i].scol]);
}
printw ("You are at %d,%d.", atrow, atcol);
at (row, col);
}
/*
* display: Print a message on line 1 of the screen.
*/
void
display (char *s)
{
saynow ("%s", s);
msgonscreen = true;
}
/*
* prepareident: Set nextid and afterid to proper values
*/
int
prepareident (int obj, int iscroll)
{
nextid = LETTER (obj);
afterid = (iscroll > obj || inven[iscroll].count > 1) ? nextid : nextid-1;
return (nextid >= 'a' && afterid >= 'a');
}
/*
* pickident: Pick an object to be identified. This is a preference
* ordering of objects. If nothing else, return 0 (the index of the
* first item in the pack).
*/
int
pickident (void)
{
int obj;
if ((obj=unknown (ring)) != NONE);
else if ((obj=unidentified (wand)) != NONE);
else if ((obj=unidentified (Scroll)) != NONE);
else if ((obj=unidentified (potion)) != NONE);
else if ((obj=unknown (Scroll)) != NONE);
else if ((obj=unknown (potion)) != NONE);
else if ((obj=unknown (hitter)) != NONE);
else obj = 0;
return (obj);
}
/*
* unknown: Return the index of any unknown object of type otype
*/
int
unknown (stuff otype)
{
int i;
for (i=0; i<invcount; ++i)
if (inven[i].count &&
(inven[i].type == otype) &&
(itemis (i, KNOWN) == 0))
return (i);
return (NONE);
}
/*
* unidentified: Return the index of any unidentified object of type otype
*/
int
unidentified (stuff otype)
{
int i;
for (i=0; i<invcount; ++i)
if (inven[i].count &&
(inven[i].type == otype) &&
(itemis (i, KNOWN) == 0) &&
(used (inven[i].str)))
return (i);
return (NONE);
}
/*
* haveother: Return the index of any unknown object of type 'otype',
* but not 'other'.
*/
int
haveother (stuff otype, int other)
{
int i;
for (i=0; i<invcount; ++i)
if (inven[i].count &&
(inven[i].type == otype) &&
(itemis (i, KNOWN) == 0) &&
(i != other))
return (i);
return (NONE);
}
/*
* have: Return the index of any object of type otype
*/
int
have (stuff otype)
{
int i;
for (i=0; i<invcount; ++i)
if (inven[i].count &&
inven[i].type == otype) return (i);
return (NONE);
}
/*
* havenamed: Return the index of any object of type otype named
* name which is not in use .
*/
int
havenamed (stuff otype, char *name)
{
int i;
for (i=0; i<invcount; ++i)
if (inven[i].count &&
inven[i].type == otype &&
(*name == 0 || streq (inven[i].str,name)) &&
!itemis (i, INUSE))
return (i);
return (NONE);
}
/*
* havewand: Return the index of a charged wand or staff
*/
int
havewand (char *name)
{
int i;
/* Find one with positive charges */
for (i=0; i<invcount; ++i)
if (inven[i].count &&
inven[i].type == wand &&
(*name == 0 || streq (inven[i].str,name)) &&
(inven[i].charges > 0))
return (i);
/* Find one with unknown charges */
for (i=0; i<invcount; ++i)
if (inven[i].count &&
inven[i].type == wand &&
(*name == 0 || streq (inven[i].str,name)) &&
inven[i].charges == UNKNOWN)
return (i);
return (NONE);
}
/*
* wearing: Return the index if wearing a ring with this title
*/
int
wearing (char *name)
{
int result = NONE;
if (leftring != NONE && itemis (leftring, INUSE) &&
streq (inven[leftring].str, name))
result = leftring;
else if (rightring != NONE && itemis (rightring, INUSE) &&
streq (inven[rightring].str, name))
result = rightring;
return (result);
}
/*
* Return the index of any object of type otype and name name only
* if we have count or more of them. This way we can avoid using the
* last of something .
*/
int
havemult (stuff otype, char *name, int count)
{
int i, num=count;
for (i=0; i<invcount; ++i)
if (inven[i].count &&
inven[i].type == otype &&
(*name == 0 || streq (inven[i].str,name)) &&
(num -= inven[i].count) <= 0)
return (i);
return (NONE);
}
/*
* haveminus: Return the index of something if it is a minus item
* (used to throw away stuff at end)
*/
int
haveminus (void)
{
int i;
for (i=0; i<invcount; ++i)
if (inven[i].count &&
inven[i].phit != UNKNOWN &&
inven[i].phit < 0)
return (i);
return (NONE);
}
/*
* haveuseless: return the index of useless stuff, in order by:
* - empty wands/staffs
* - worthless arrows
* - yucky potions
* - nasty scrolls
* - tarnished rings
* - dented armor
* - dull weapons
* - stringless bows
*
* Below level 15 we leave armor, weapons and bows alone, but
* after level 14 we only leave the top two of each alone...
*
* and if all those fail return NONE
*/
int
haveuseless (void)
{
int i;
for (i=0; i<invcount; ++i) {
if (inven[i].count > 0) {
if ((inven[i].type == wand && inven[i].charges == 0) ||
stlmatch (inven[i].str, "teleport to") ||
stlmatch (inven[i].str, "haste monster") ||
(itemis (i, WORTHLESS) && streq (inven[i].str, "arrow")))
return (i);
else if (inven[i].type == potion &&
(stlmatch (inven[i].str, "blindness") ||
stlmatch (inven[i].str, "poison") ||
stlmatch (inven[i].str, "confusion") ||
stlmatch (inven[i].str, "magic detection") ||
stlmatch (inven[i].str, "paralysis") ||
stlmatch (inven[i].str, "hallucination") ||
stlmatch (inven[i].str, "thirst") ||
stlmatch (inven[i].str, "food detection") ||
stlmatch (inven[i].str, "monster detection")))
return (i);
else if (inven[i].type == Scroll &&
(stlmatch (inven[i].str, "sleep") ||
stlmatch (inven[i].str, "blank") ||
stlmatch (inven[i].str, "create monster") ||
stlmatch (inven[i].str, "gold detection") ||
stlmatch (inven[i].str, "aggravate monsters")))
return (i);
else if (!itemis (i, INUSE) && itemis (i, KNOWN) &&
(inven[i].type == missile) &&
(((inven[i].phit != UNKNOWN) && (inven[i].phit < 0)) ||
((inven[i].pdam != UNKNOWN) && (inven[i].pdam < 0))))
return (i);
else if (inven[i].type == ring &&
(stlmatch (inven[i].str, "teleport") ||
stlmatch (inven[i].str, "adornment") ||
stlmatch (inven[i].str, "aggravate monster")))
return (i);
}
}
if (Level > 14) {
if (((i = havearmor (3, NOPRINT, ANY)) != NONE) && (!itemis (i, INUSE)))
return (i);
else if (((i = haveweapon (3, NOPRINT)) != NONE) && (!itemis (i, INUSE)))
return (i);
else if (((i = havebow (3, NOPRINT)) != NONE) && (!itemis (i, INUSE)))
return (i);
}
return (NONE);
}
/*
* willrust: return true if a suit of armor can rust
*/
int
willrust (int obj)
{
return (! (protected ||
armorclass (obj) > 8 || armorclass (obj) < -5 ||
itemis (obj, PROTECTED) ||
(stlmatch (inven[obj].str, "leather") && version > RV36B)));
}
/*
* wielding: return true if we are wielding an object of type 'otype'
*/
int
wielding (stuff otype)
{
return (inven[currentweapon].type == otype);
}
/*
* hungry: return true if we are hungry, weak, or fainting
*/
int
hungry (void)
{
return (*Ms == 'H' || *Ms == 'W' || *Ms == 'F');
}
/*
* weak: return true if we are weak or fainting
*/
int
weak (void)
{
return (*Ms == 'W' || *Ms == 'F');
}
/*
* fainting: return true if we are fainting
*/
int
fainting (void)
{
return (*Ms == 'F');
}
/*
* havefood: return true if we have more than 'n' foods, modified
* by the genetic variable k_food (higher values of k_food mean this
* routine returns true less often).
*/
int
havefood (int n)
{
int remaining, foodest, desired;
if (hungry () || weak () || fainting ())
return (0);
remaining = 800 - turns + lastate;
if (remaining < 0) remaining = 0;
foodest = larder * 1000 + remaining;
desired = n * 1000 * 50 / (100-k_food);
return (foodest > desired);
}