History

add cloak, gloves, boots armor slots

mischief committed 11 years ago

Commit 3d2cef11 parent b90525f7 files · +109 −104Browse files

Unified · Split

7 files
  1. dat.h +6 −4
  2. item.c +17 −4
  3. item.ndb +11 −2
  4. levelgen.c +7 −7
  5. monst.c +38 −54
  6. monster.ndb +13 −6
  7. ui.c +17 −27
dat.h+6−4
@@ -54,8 +54,12 @@ enum · 53 unmodified lines
54 /* possible item types */54 /* possible item types */
55 IWEAPON = 0,55 IWEAPON = 0,
56 IHELMET,56 IHELMET,
57 ICLOAK,
57 ISHIELD,58 ISHIELD,
58 IARMOR,59 IARMOR,
60 IGLOVES,
61 IBOOTS,
62 NEQUIP,
59 63
60 /* item flags */64 /* item flags */
61 IFSTACKS = 0x1,65 IFSTACKS = 0x1,
@@ -119,6 +123,7 @@ struct ItemList · 57 unmodified lines
119 123
120/* item.c */124/* item.c */
121#pragma varargck type "i" Item*125#pragma varargck type "i" Item*
126char *itypetoname(int type);
122int itemdbopen(char *file);127int itemdbopen(char *file);
123ItemData *idbyname(char *item);128ItemData *idbyname(char *item);
124Item *ibyname(char *item);129Item *ibyname(char *item);
@@ -240,10 +245,7 @@ struct Monster · 115 unmodified lines
240 ItemList inv;245 ItemList inv;
241 246
242 /* equipped weapon & armor */247 /* equipped weapon & armor */
243 Item *weapon;248 Item *armor[NEQUIP];
244 Item *helmet;
245 Item *shield;
246 Item *armor;
247 249
248 /* no free */250 /* no free */
249 MonsterData *md;251 MonsterData *md;
item.c+17−4
@@ -33,10 +33,21 @@ static char *itemdbcmd[] = { · 32 unmodified lines
33static char *itemtype[] = {33static char *itemtype[] = {
34[IWEAPON] "weapon",34[IWEAPON] "weapon",
35[IHELMET] "helmet",35[IHELMET] "helmet",
36[ICLOAK] "cloak",
36[ISHIELD] "shield",37[ISHIELD] "shield",
37[IARMOR] "armor",38[IARMOR] "armor",
39[IGLOVES] "gloves",
40[IBOOTS] "boots",
38};41};
39 42
43char*
44itypetoname(int type)
45{
46 if(type < 0 || type > nelem(itemtype)-1)
47 return nil;
48 return itemtype[type];
49}
50
40static Ndb *itemdb;51static Ndb *itemdb;
41 52
42static int53static int
@@ -58,8 +69,11 @@ ifmt(Fmt *f) · 15 unmodified lines
58 snprint(extra, sizeof(extra), " (%dd%d)", i->id->rolls, i->id->atk);69 snprint(extra, sizeof(extra), " (%dd%d)", i->id->rolls, i->id->atk);
59 break;70 break;
60 case IHELMET:71 case IHELMET:
72 case ICLOAK:
61 case ISHIELD:73 case ISHIELD:
62 case IARMOR:74 case IARMOR:
75 case IGLOVES:
76 case IBOOTS:
63 snprint(extra, sizeof(extra), " (ac %d)", i->id->ac);77 snprint(extra, sizeof(extra), " (ac %d)", i->id->ac);
64 break;78 break;
65 }79 }
@@ -150,7 +164,7 @@ idbylistname(char *list) · 84 unmodified lines
150 164
151 t = ndbsearch(itemdb, &search, "itemlist", list);165 t = ndbsearch(itemdb, &search, "itemlist", list);
152 if(t == nil)166 if(t == nil)
153 sysfatal("no such item list '%s'", list);167 sysfatal("no such itemlist '%s'", list);
154 168
155 /* count items */169 /* count items */
156 cnt = 0;170 cnt = 0;
@@ -160,7 +174,7 @@ idbylistname(char *list) · 3 unmodified lines
160 }174 }
161 175
162 if(cnt == 0)176 if(cnt == 0)
163 sysfatal("no items in list '%s'", list);177 sysfatal("no items in itemlist '%s'", list);
164 178
165 /* pick random item */179 /* pick random item */
166 pick = nrand(cnt);180 pick = nrand(cnt);
@@ -168,9 +182,8 @@ idbylistname(char *list) · 1 unmodified line
168 /* walk this many forward */182 /* walk this many forward */
169 i = 0;183 i = 0;
170 for(nt = t; nt != nil; nt = nt->entry){184 for(nt = t; nt != nil; nt = nt->entry){
171 if(i == pick)185 if(strcmp(nt->attr, "items") == 0 && i++ == pick)
172 return idbyname(nt->val);186 return idbyname(nt->val);
173 i++;
174 }187 }
175 return nil;188 return nil;
176}189}
item.ndb+11−2
@@ -11,16 +11,25 @@ item="runesword" · 10 unmodified lines
11 11
12# armor12# armor
13item="helmet"13item="helmet"
14 tile=472 type=helmet cost=5 weight=2 ac=214 tile=472 type=helmet cost=5 weight=2 ac=1
15item="tattered cape"
16 tile=521 type=cloak cost=5 weight=2 ac=1
15item="shield"17item="shield"
16 tile=525 type=shield cost=5 weight=10 ac=218 tile=525 type=shield cost=5 weight=10 ac=1
17item="plate armor"19item="plate armor"
18 tile=496 type=armor cost=50 weight=15 ac=420 tile=496 type=armor cost=50 weight=15 ac=4
21item="old gloves"
22 tile=532 type=gloves cost=5 weight=1 ac=1
23item="walking shoes"
24 tile=536 type=boots cost=5 weight=1 ac=1
19 25
20# item lists26# item lists
21itemlist="common"27itemlist="common"
22 items="dagger"28 items="dagger"
23 items="helmet"29 items="helmet"
30 items="tattered cape"
31 items="old gloves"
32 items="walking shoes"
24itemlist="uncommon"33itemlist="uncommon"
25 items="longsword"34 items="longsword"
26 items="shield"35 items="shield"
levelgen.c+7−7
@@ -434,16 +434,16 @@ mklgraveyard(Level *l) · 433 unmodified lines
434 434
435 addspawn(l, p, "lich", 101, 1);435 addspawn(l, p, "lich", 101, 1);
436 addspawn(l, p, "demilich", 157, 0);436 addspawn(l, p, "demilich", 157, 0);
437 addspawn(l, p, "ghost", 39, 2);437 addspawn(l, p, "ghost", 15, 2);
438 addspawn(l, p, "human zombie", 43, 2);438 addspawn(l, p, "human zombie", 27, 2);
439 addspawn(l, p, "skeleton", 127, 1);439 addspawn(l, p, "skeleton", 71, 1);
440 440
441 several(l, &p2, 1, "gnome king", 0);441 several(l, &p2, 1, "gnome king", 0);
442 several(l, &p2, 1, "gnome wizard", 1);442 several(l, &p2, 1, "gnome wizard", 1);
443 addspawn(l, p2, "gnome", 23, 1);443 addspawn(l, p2, "gnome", 29, 1);
444 addspawn(l, p2, "gnome lord", 25, 2);444 addspawn(l, p2, "gnome lord", 45, 2);
445 addspawn(l, p2, "gnome wizard", 37, 2);445 addspawn(l, p2, "gnome wizard", 57, 2);
446 addspawn(l, p2, "gnome king", 53, 1);446 addspawn(l, p2, "gnome king", 71, 1);
447 447
448 genmonsters(l, "ghost", space/64);448 genmonsters(l, "ghost", space/64);
449 genmonsters(l, "gnome", space/64);449 genmonsters(l, "gnome", space/64);
monst.c+38−54
@@ -204,6 +204,7 @@ missing: · 203 unmodified lines
204void204void
205mfree(Monster *m)205mfree(Monster *m)
206{206{
207 int n;
207 AIState *a;208 AIState *a;
208 209
209 if(decref(&m->ref) != 0)210 if(decref(&m->ref) != 0)
@@ -219,11 +220,13 @@ mfree(Monster *m) · 9 unmodified lines
219 freestate(a);220 freestate(a);
220 }221 }
221 222
223 for(n = 0; n < NEQUIP; n++){
224 if(m->armor[n] != nil){
225 munwield(m, n);
226 }
227 }
228
222 ilfree(&m->inv);229 ilfree(&m->inv);
223 ifree(m->weapon);
224 ifree(m->helmet);
225 ifree(m->shield);
226 ifree(m->armor);
227 230
228 free(m);231 free(m);
229}232}
@@ -249,12 +252,8 @@ mupdate(Monster *m) · 19 unmodified lines
249 252
250 /* gain some hp if you aren't dead. */253 /* gain some hp if you aren't dead. */
251 if((m->flags & Mdead) == 0)254 if((m->flags & Mdead) == 0)
252 if(m->hp < m->maxhp){255 if(m->hp < m->maxhp && m->turns % (42+(m->xpl+2)+1) == 0){
253 /* below half, 2%. above, 0.5%. */256 m->hp+=1.0;
254 if(m->hp < m->maxhp/2)
255 m->hp += 1.0 + (double)m->maxhp/50.0;
256 else
257 m->hp += (double)m->maxhp/200.0;
258 if(m->hp > m->maxhp)257 if(m->hp > m->maxhp)
259 m->hp = m->maxhp;258 m->hp = m->maxhp;
260 }259 }
@@ -314,12 +313,14 @@ maddxp(Monster *m, int xp) · 53 unmodified lines
314static int313static int
315mattack(Monster *m, Monster *mt)314mattack(Monster *m, Monster *mt)
316{315{
317 int hit, crit, dmg, xp;316 int n, hit, ac, crit, dmg, xp;
318 Item *i, *weap;317 Item *i, *weap;
319 Tile *t;318 Tile *t;
320 319
321 hit = roll(1, 100);320 hit = roll(1, 20);
322 if(hit < 10+abs(mt->ac-10)*2){321 ac = mt->ac >= 0 ? mt->ac : -(1+nrand(mt->ac));
322
323 if(hit > 10 + ac + m->xpl){
323 if(nearyou(m->pt))324 if(nearyou(m->pt))
324 warn("the %s misses the %s!", m->md->name, mt->md->name);325 warn("the %s misses the %s!", m->md->name, mt->md->name);
325 return 0;326 return 0;
@@ -328,7 +329,7 @@ mattack(Monster *m, Monster *mt) · 2 unmodified lines
328 dmg = roll(m->md->rolls, m->md->atk);329 dmg = roll(m->md->rolls, m->md->atk);
329 330
330 /* factor in weapon damage */331 /* factor in weapon damage */
331 weap = m->weapon;332 weap = m->armor[IWEAPON];
332 if(weap != nil)333 if(weap != nil)
333 dmg += roll(weap->id->rolls, weap->id->atk);334 dmg += roll(weap->id->rolls, weap->id->atk);
334 335
@@ -355,11 +356,14 @@ mattack(Monster *m, Monster *mt) · 20 unmodified lines
355 mt->hp = 0;356 mt->hp = 0;
356 mt->flags = Mdead;357 mt->flags = Mdead;
357 358
359 /* take off all armor */
360 for(n = 0; n < NEQUIP; n++){
361 if(mt->armor[n] != nil){
362 munwield(mt, n);
363 }
364 }
365
358 /* drop dead guy's stuff */366 /* drop dead guy's stuff */
359 munwield(mt, IWEAPON);
360 munwield(mt, IHELMET);
361 munwield(mt, ISHIELD);
362 munwield(mt, IARMOR);
363 while(mt->inv.count > 0){367 while(mt->inv.count > 0){
364 i = iltakenth(&mt->inv, 0);368 i = iltakenth(&mt->inv, 0);
365 t = tileat(mt->l, mt->pt);369 t = tileat(mt->l, mt->pt);
@@ -367,7 +371,7 @@ mattack(Monster *m, Monster *mt) · 1 unmodified line
367 iladd(&t->items, i);371 iladd(&t->items, i);
368 }372 }
369 373
370 xp = 10+10*pow(mt->xpl, 1.75);374 xp = 10 + pow(mt->xpl, 2.0);
371 if(nearyou(m->pt))375 if(nearyou(m->pt))
372 bad("the %s kills the %s, and gains %ld xp.", m->md->name, mt->md->name, xp);376 bad("the %s kills the %s, and gains %ld xp.", m->md->name, mt->md->name, xp);
373 377
@@ -393,6 +397,7 @@ mattack(Monster *m, Monster *mt) · 19 unmodified lines
393int397int
394maction(Monster *m, int what, Point where)398maction(Monster *m, int what, Point where)
395{399{
400 int n;
396 Tile *cur, *targ;401 Tile *cur, *targ;
397 Item *i;402 Item *i;
398 403
@@ -431,8 +436,9 @@ maction(Monster *m, int what, Point where) · 32 unmodified lines
431 m->pt = where;436 m->pt = where;
432 437
433 if(isyou(m) && hasflagat(m->l, where, Fhasitem)){438 if(isyou(m) && hasflagat(m->l, where, Fhasitem)){
434 i = ilnth(&targ->items, 0);439 n = 0;
435 warn("you see %i here.", i);440 while((i = ilnth(&targ->items, n++)) != nil)
441 warn("you see %i here.", i);
436 }442 }
437 443
438 if(isyou(m) && hasflagat(m->l, where, Fportal)){444 if(isyou(m) && hasflagat(m->l, where, Fportal)){
@@ -498,30 +504,21 @@ maction(Monster *m, int what, Point where) · 59 unmodified lines
498int504int
499mwield(Monster *m, int n)505mwield(Monster *m, int n)
500{506{
507 int type;
501 Item **ptr, *old, *new;508 Item **ptr, *old, *new;
502 509
503 old = nil;510 old = nil;
504 new = iltakenth(&m->inv, n);511 new = ilnth(&m->inv, n);
505 if(new == nil)512 if(new == nil)
506 return 0;513 return 0;
507 514
508 switch(new->id->type){515 type = new->id->type;
509 case IWEAPON:516 if(type < IWEAPON || type >= NEQUIP)
510 ptr = &m->weapon;
511 break;
512 case IHELMET:
513 ptr = &m->helmet;
514 break;
515 case ISHIELD:
516 ptr = &m->shield;
517 break;
518 case IARMOR:
519 ptr = &m->armor;
520 break;
521 default:
522 iladd(&m->inv, new);
523 return 0;517 return 0;
524 }518
519 new = iltakenth(&m->inv, n);
520 type = new->id->type;
521 ptr = &m->armor[type];
525 522
526 if(*ptr != nil)523 if(*ptr != nil)
527 old = *ptr;524 old = *ptr;
@@ -544,22 +541,9 @@ munwield(Monster *m, int type) · 16 unmodified lines
544{541{
545 Item **ptr;542 Item **ptr;
546 543
547 switch(type){544 assert(type >= IWEAPON && type < NEQUIP);
548 case IWEAPON:545
549 ptr = &m->weapon;546 ptr = &m->armor[type];
550 break;
551 case IHELMET:
552 ptr = &m->helmet;
553 break;
554 case ISHIELD:
555 ptr = &m->shield;
556 break;
557 case IARMOR:
558 ptr = &m->armor;
559 break;
560 default:
561 return 0;
562 }
563 547
564 if(*ptr == nil)548 if(*ptr == nil)
565 return 0;549 return 0;
monster.ndb+13−6
@@ -18,7 +18,7 @@ monster="gnome wizard" · 17 unmodified lines
18monster="gnome king"18monster="gnome king"
19 tile=169 xpl=5 align=50 mvr=10 hp=48 ac=10 atk=2d619 tile=169 xpl=5 align=50 mvr=10 hp=48 ac=10 atk=2d6
20 equip="uncommon" eqprob=0.220 equip="uncommon" eqprob=0.2
21 equip="rare" eqprob=0.521 equip="rare" eqprob=0.01
22 22
23# undead23# undead
24monster="lich"24monster="lich"
@@ -34,8 +34,10 @@ monster="human zombie" · 9 unmodified lines
34monster="skeleton"34monster="skeleton"
35 tile=250 xpl=12 align=-50 mvr=8 hp=48 ac=4 atk=2d635 tile=250 xpl=12 align=-50 mvr=8 hp=48 ac=4 atk=2d6
36 equip="uncommon" eqprob=0.0536 equip="uncommon" eqprob=0.05
37 equip="rare" eqprob=0.01
37monster="ghost"38monster="ghost"
38 tile=290 xpl=1 align=-50 mvr=6 hp=16 ac=-5 atk=1d439 tile=290 xpl=10 align=-50 mvr=3 hp=16 ac=-5 atk=1d4
40 equip="tattered cape" eqprob=0.05
39 41
40# military42# military
41monster="soldier"43monster="soldier"
@@ -51,11 +53,16 @@ monster="lieutenant" · 9 unmodified lines
51 equip="uncommon" eqprob=0.0553 equip="uncommon" eqprob=0.05
52monster="captain"54monster="captain"
53 tile=283 xpl=12 align=-20 mvr=10 hp=48 ac=10 atk=4d455 tile=283 xpl=12 align=-20 mvr=10 hp=48 ac=10 atk=4d4
54 equip="common" eqprob=0.156 equip="longsword"
55 equip="uncommon" eqprob=0.0557 equip="runesword" eqprob=0.1
56 equip="rare" eqprob=0.0158 equip="helmet"
59 equip="tattered cape"
60 equip="shield"
61 equip="plate armor"
62 equip="old gloves"
63 equip="walking shoes"
57 64
58# player65# player
59monster="wizard"66monster="wizard"
60 tile=349 xpl=0 align=127 mvr=14 hp=64 ac=5 atk=2d367 tile=349 xpl=1 align=127 mvr=14 hp=64 ac=5 atk=2d3
61 68
ui.c+17−27
@@ -458,33 +458,20 @@ inventorymenu(int idx, char *s, int sz) · 457 unmodified lines
458static Rune458static Rune
459equipmenu(int idx, char *s, int sz)459equipmenu(int idx, char *s, int sz)
460{460{
461 switch(idx){461 Item *ptr;
462 case 0:462 Rune key[NEQUIP] = { 'w', 'c', 'h', 's', 'a', 'g', 'b' };
463 if(player->weapon != nil){463
464 snprint(s, sz, "weapon: %i", player->weapon);464 if(idx >= NEQUIP)
465 return 'w';465 return Runemax;
466 }466
467 return 0;467 ptr = player->armor[idx];
468 case 1:468
469 if(player->helmet != nil){469 if(ptr != nil){
470 snprint(s, sz, "helmet: %i", player->helmet);470 snprint(s, sz, "%s: %i", itypetoname(ptr->id->type), ptr);
471 return 'h';471 return key[idx];
472 }
473 return 0;
474 case 2:
475 if(player->shield != nil){
476 snprint(s, sz, "shield: %i", player->shield);
477 return 's';
478 }
479 return 0;
480 case 3:
481 if(player->armor!= nil){
482 snprint(s, sz, "armor: %i", player->armor);
483 return 'a';
484 }
485 return 0;
486 }472 }
487 return Runemax;473
474 return 0;
488}475}
489 476
490static Rune477static Rune
@@ -597,8 +584,11 @@ cuse(Rune c) · 106 unmodified lines
597 switch(item->id->type){584 switch(item->id->type){
598 case IWEAPON:585 case IWEAPON:
599 case IHELMET:586 case IHELMET:
587 case ICLOAK:
600 case ISHIELD:588 case ISHIELD:
601 case IARMOR:589 case IARMOR:
590 case IGLOVES:
591 case IBOOTS:
602 if(!mwield(player, i)){592 if(!mwield(player, i)){
603 bad("can't equip that");593 bad("can't equip that");
604 return 0;594 return 0;
@@ -650,7 +640,7 @@ cstrip(Rune c) · 45 unmodified lines
650 /* take off armor */640 /* take off armor */
651 km = (KeyMenu){"take off what?", equipmenu};641 km = (KeyMenu){"take off what?", equipmenu};
652 i = menu(ui.kc, ui.mc, &km);642 i = menu(ui.kc, ui.mc, &km);
653 if(i >= 0 && i <= 3){643 if(i >= 0 && i < NEQUIP){
654 munwield(player, i);644 munwield(player, i);
655 item = ilnth(&player->inv, 0);645 item = ilnth(&player->inv, 0);
656 warn("you take off the %i.", item);646 warn("you take off the %i.", item);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t