diff --git a/enemy.c b/enemy.c index d10731b..b1953d4 100644 --- a/enemy.c +++ b/enemy.c @@ -6,6 +6,8 @@ #include "mob.h" #include "effect.h" +extern Item default_items[]; + /** * Definitions of enemies */ @@ -48,23 +50,13 @@ Mob * create_enemy(enum EnemyType mobtype){ if (mobtype == ORC){ Item * sword = xalloc(Item); - - sword->count = 1; - sword->symbol = '/'; - sword->name = "Orcish Sword"; - sword->type = WEAPON; - sword->value = 5; + *sword = default_items[O_SWORD]; new->inventory = insert(new->inventory, &sword->inventory); wield_item(new, sword); if (rand() % 2) { Item * food = xalloc(Item); - - food->count =1; - food->symbol = '%'; - food->name = "Food Ration"; - food->type = FOOD; - food->value = 5; + *food = default_items[FOOD_RATION]; new->inventory = insert(new->inventory, &food->inventory); } } else if(mobtype == WOLFMAN) { @@ -72,33 +64,16 @@ Mob * create_enemy(enum EnemyType mobtype){ new->death_action = &hunter_death; Item * food = xalloc(Item); - - food->count = 1; - food->symbol = '%'; - food->name = "Nourishing Food Ration"; - food->type = FOOD; - food->value = 7; + *food = default_items[N_FOOD_RATION]; new->inventory = insert(new->inventory, &food->inventory); } else if(mobtype == FALLEN_ANGEL) { Item * sword = xalloc(Item); - - sword->count = 1; - sword->symbol = '/'; - sword->name = "Flaming Sword of Fire"; - sword->type = WEAPON; - sword->value = 10; - sword->luminous = true; - sword->fight_effect = &inflict_fire; + *sword = default_items[F_SWORD]; new->inventory = insert(new->inventory, &sword->inventory); wield_item(new, sword); Item * food = xalloc(Item); - - food->count = 1; - food->symbol = '%'; - food->name = "Manna"; - food->type = FOOD; - food->value = 50; + *food = default_items[MANNA]; new->inventory = insert(new->inventory, &food->inventory); new->is_bold = true; diff --git a/item.c b/item.c index 74df3cb..4ac537c 100644 --- a/item.c +++ b/item.c @@ -10,25 +10,50 @@ #include "effect.h" /** Definitions of special items. */ -#define ITEM(sym, n, t, val, dig, lit, atkeff) { \ +#define ITEM(sym, n, t, val, dig, lit, range, eff, atkeff) { \ .count = 1, .symbol = (sym), .name = (n), .type = (t),\ .value = (val), .can_dig = (dig), .luminous = (lit),\ - .fight_effect = (atkeff)} -#define ITEM_D(sym, n, t, val) ITEM(sym, n, t, val, true, false, NULL) -#define ITEM_L(sym, n, t, val) ITEM(sym, n, t, val, false, true, NULL) -#define ITEM_N(sym, n, t, val) ITEM(sym, n, t, val, false, false, NULL) -#define ITEM_E(sym, n, t, val, atkeff) ITEM(sym, n, t, val, false, false, atkeff) - -/* Should keep the same structure as SpecialItem in item.h. */ -const struct Item special_items[] = { - ITEM_D('/', "Pickaxe", WEAPON, 5), - ITEM_L('^', "Lanturn", WEAPON, 1), - ITEM_N('/', "Orcish Sword", WEAPON, 5), - ITEM_N(']', "Helmet", ARMOUR, 3), - ITEM_N('/', "Sword", WEAPON, 10), - ITEM_N(']', "Chain Mail", ARMOUR, 7), - ITEM_N(']', "Dragon Scale Mail", ARMOUR, 15), - ITEM_E('/', "Flaming Sword of Fire", WEAPON, 10, &inflict_fire), + .ranged = (range), .effect = (eff), .fight_effect = (atkeff)} +#define ITEM_D(sym, n, t, val) ITEM(sym, n, t, val, true, false, false, NULL, NULL) +#define ITEM_L(sym, n, t, val) ITEM(sym, n, t, val, false, true, false, NULL, NULL) +#define ITEM_N(sym, n, t, val) ITEM(sym, n, t, val, false, false, false, NULL, NULL) +#define ITEM_F(sym, n, t, val, atkeff) ITEM(sym, n, t, val, false, false, false, NULL, atkeff) +#define ITEM_R(sym, n, t, val) ITEM(sym, n, t, val, false, false, true, NULL, NULL) +#define ITEM_E(sym, n, t, val, eff) ITEM(sym, n, t, val, false, false, false, eff, NULL) + +/* Should keep the same structure as DefaultItem in item.h. */ +const struct Item default_items[] = { + ITEM_D('/', "Pickaxe", WEAPON, 5), + ITEM_L('^', "Lantern", WEAPON, 1), + ITEM_N('/', "Orcish Sword", WEAPON, 5), + ITEM_N(']', "Helmet", ARMOUR, 3), + ITEM_N('/', "Sword", WEAPON, 10), + ITEM_N(']', "Chain Mail", ARMOUR, 7), + ITEM_N(']', "Dragon Scale Mail", ARMOUR, 15), + ITEM_F('/', "Flaming Sword of Fire", WEAPON, 10, &inflict_fire), + ITEM_N('%', "Food Ration", FOOD, 5), + ITEM_N('%', "Nourishing Food Ration", FOOD, 7), + ITEM_N('%', "Manna", FOOD, 50), + ITEM_L('n', "Mining Helmet", ARMOUR, 5), + ITEM_N('v', "Book of Tax Code", WEAPON, 2), + ITEM_F('r', "Law Suit", ARMOUR, 8, &reflect_damage), + ITEM_R('c', "Clog", WEAPON, 2), + ITEM_N('y', "Clogging Apron", ARMOUR, 8), + ITEM_N('\'', "Hunting Knife", WEAPON, 8), + ITEM_N('h', "Cloak", ARMOUR, 2), + ITEM_N('q', "Frying Pan", WEAPON, 6), + ITEM_N('y', "Apron", ARMOUR, 4), + ITEM_N('k', "Camera", WEAPON, 1), + ITEM_N('t', "Hawaiian Shirt", ARMOUR, 9), + ITEM_N('l', "Bone", WEAPON, 3), + ITEM_N('d', "Fursuit", ARMOUR, 7), + ITEM_E('-', "Potion of Cure Poison", DRINK, 0, &cure_poison), + ITEM_N('$', "Gold", VALUABLE, 5), + ITEM_N('*', "Stone", NONE, 0), + ITEM_E('%', "Corpse", FOOD, 4, &corpse_effect), + ITEM_N('/', "Advanced Mining Pickaxe", WEAPON, 18), + ITEM_N('v', "Book of Tax Code Bound in Human Flesh", WEAPON, 15), + ITEM_R('c', "Wooden Boot", WEAPON, 15), }; #undef ITEM_N diff --git a/item.h b/item.h index e38072e..249107a 100755 --- a/item.h +++ b/item.h @@ -12,7 +12,7 @@ struct Mob; */ enum ItemType { NONE, WEAPON, ARMOUR, FOOD, DRINK, VALUABLE }; -enum SpecialItem { +enum DefaultItem { PICKAXE, LANTURN, O_SWORD, @@ -20,7 +20,30 @@ enum SpecialItem { SWORD, C_MAIL, D_MAIL, - F_SWORD + F_SWORD, + FOOD_RATION, + N_FOOD_RATION, + MANNA, + M_HELMET, + BOOK_TAX, + LAW_SUIT, + CLOG, + CLOG_APRON, + HUNT_KNIFE, + CLOAK, + FRY_PAN, + APRON, + CAMERA, + HAWAII, + BONE, + FURSUIT, + C_POISON_POTION, + GOLD, + STONE, + CORPSE, + A_PICKAXE, + FLESHBOOK, + W_BOOT }; /** diff --git a/level.c b/level.c index d217b95..76af5f8 100755 --- a/level.c +++ b/level.c @@ -12,7 +12,7 @@ extern bool quit; extern const struct Mob default_enemies[]; -extern const struct Item special_items[]; +extern const struct Item default_items[]; /** * (Shallow) Clone a cell and place it in the given position. @@ -308,41 +308,29 @@ void build_level(Level * level) { /* add 5 gold for the player to find */ for (int i = 0; i < 5; i++) { Item * item = xalloc(Item); + *item = default_items[GOLD]; int x = 1 + (rand() % (LEVELWIDTH-2)); int y = 1 + (rand() % (LEVELHEIGHT-2)); - item->count = 1; - item->symbol = '$'; - item->name = "Gold"; - item->type = VALUABLE; - item->value = 5; level->cells[x][y]->items = insert(level->cells[x][y]->items, &item->inventory); } /* add a regular item for the player to find */ { Item * item = xalloc(Item); - item->count = 1; - int x = 1 + (rand() % (LEVELWIDTH-2)); - int y = 1 + (rand() % (LEVELHEIGHT-2)); switch (rand() % 10) { - case 0: case 1: case 2: case 3: case 4: - item->symbol = '%'; - item->name = "Food Ration"; - item->type = FOOD; - item->value = 5; - break; - case 5: case 6: case 7: case 8: - item->symbol = '-'; - item->name = "Potion of Cure Poison"; - item->type = DRINK; - item->effect = &cure_poison; - break; - case 9: - item->symbol = '*'; - item->name = "Stone"; - break; + case 0: case 1: case 2: case 3: case 4: + *item = default_items[FOOD_RATION]; + break; + case 5: case 6: case 7: case 8: + *item = default_items[C_POISON_POTION]; + break; + case 9: + *item = default_items[STONE]; + break; } + int x = 1 + (rand() % (LEVELWIDTH-2)); + int y = 1 + (rand() % (LEVELHEIGHT-2)); level->cells[x][y]->items = insert(level->cells[x][y]->items, &item->inventory); } @@ -355,37 +343,47 @@ void build_level(Level * level) { switch (rand() % 10) { case 0: case 1: case 2: - *item = special_items[PICKAXE]; + *item = default_items[PICKAXE]; break; case 3: case 4: case 5: - *item = special_items[LANTURN]; + *item = default_items[LANTURN]; break; case 6: - *item = special_items[O_SWORD]; + *item = default_items[O_SWORD]; break; case 7: case 8: - *item = special_items[HELMET]; + *item = default_items[HELMET]; break; case 9: - switch (rand() % 10) { + switch (rand() % 13) { case 0: case 1: case 2: case 3: case 4: if (level->depth > 5) { - *item = special_items[SWORD]; + *item = default_items[SWORD]; } break; case 5: case 6: case 7: if (level->depth > 5) { - *item = special_items[C_MAIL]; + *item = default_items[C_MAIL]; } break; case 8: if (level->depth > 10) { - *item = special_items[D_MAIL]; + *item = default_items[D_MAIL]; } break; - case 9: + case 10: + if (level->depth > 20) { + *item = default_items[A_PICKAXE]; + } + break; + case 11: + if (level->depth > 20) { + *item = default_items[FLESHBOOK]; + } + break; + case 12: if (level->depth > 20) { - *item = special_items[F_SWORD]; + *item = default_items[W_BOOT]; } break; } diff --git a/mob.c b/mob.c index 1718185..0dec9b9 100755 --- a/mob.c +++ b/mob.c @@ -12,6 +12,8 @@ #include "status.h" #include "enemy.h" +extern Item default_items[]; + /** * Move the given mob to the new coordinates. * @param mob Entity to move. @@ -120,7 +122,7 @@ void attack_mob(Mob * attacker, Mob * defender) { "You cleave the %s in twain for %d damage.", NULL }; - + status_push((const char *)random_choice((const void **)messages), defender->name, damage); @@ -325,14 +327,10 @@ void drop_corpse(struct Mob * mob) { } } Item * corpse = xalloc(Item); - corpse->type = FOOD; - corpse->value = 4; - corpse->symbol = '%'; - corpse->count = 1; + *corpse = default_items[CORPSE]; size_t len = strlen(mob->name) + strlen(" Corpse") + 1; corpse->name = xcalloc(len, char); snprintf(corpse->name, len, "%s%s", mob->name, " Corpse"); - corpse->effect = &corpse_effect; cell->items = insert(cell->items, &corpse->inventory); } diff --git a/player.c b/player.c index e139d65..69ce45c 100755 --- a/player.c +++ b/player.c @@ -31,6 +31,7 @@ const char * professions[] = {"Miner", NULL}; extern bool quit; +extern Item default_items[]; /** * Randomise a player's name, race, and profession. @@ -123,69 +124,29 @@ static void apply_profession(Mob * player) { Item * weapon = xalloc(Item); Item * armour = xalloc(Item); - weapon->type = WEAPON; - armour->type = ARMOUR; - weapon->count = 1; - armour->count = 1; - if(strcmp(player->profession, "Miner") == 0) { - weapon->symbol = '/'; - weapon->name = "Pickaxe"; - weapon->can_dig = true; - weapon->value = 5; - - armour->symbol = 'n'; - armour->name = "Mining Helmet"; - armour->luminous = true; + *weapon = default_items[PICKAXE]; + *armour = default_items[M_HELMET]; } else if(strcmp(player->profession, "Attorney") == 0) { - weapon->symbol = 'v'; - weapon->name = "Book of Tax Code"; - weapon->value = 2; - - armour->symbol = 'r'; - armour->name = "Law Suit"; - armour->fight_effect = &reflect_damage; + *weapon = default_items[BOOK_TAX]; + *armour = default_items[LAW_SUIT]; } else if(strcmp(player->profession, "Clog Maker") == 0) { - weapon->symbol = 'c'; - weapon->name = "Clog"; - weapon->value = 2; - weapon->ranged = true; - weapon->count = 4; - - armour->symbol = 'y'; - armour->name = "Clogging Apron"; + *weapon = default_items[CLOG]; + *armour = default_items[CLOG_APRON]; } else if(strcmp(player->profession, "Huntsman") == 0) { - weapon->symbol = '\''; - weapon->name = "Hunting Knife"; - weapon->value = 8; - - armour->symbol = 'h'; - armour->name = "Cloak"; + *weapon = default_items[HUNT_KNIFE]; + *armour = default_items[CLOAK]; } else if(strcmp(player->profession, "Chef") == 0) { - weapon->symbol = 'q'; - weapon->name = "Frying Pan"; - weapon->value = 6; - - armour->symbol = 'y'; - armour->name = "Apron"; + *weapon = default_items[FRY_PAN]; + *armour = default_items[APRON]; } else if(strcmp(player->profession, "Tourist") == 0) { - weapon->symbol = 'k'; - weapon->name = "Camera"; - weapon->value = 1; - - armour->symbol = 't'; - armour->name = "Hawaiian Shirt"; + *weapon = default_items[CAMERA]; + *armour = default_items[HAWAII]; } else if(strcmp(player->profession, "Dog") == 0) { - weapon->symbol = 'l'; - weapon->name = "Bone"; - weapon->value = 3; - - armour->symbol = 'd'; - armour->name = "Fursuit"; + *weapon = default_items[BONE]; + *armour = default_items[FURSUIT]; } - armour->value = 10 - weapon->value; - player->inventory = insert(player->inventory, &weapon->inventory); player->inventory = insert(player->inventory, &armour->inventory); } @@ -210,18 +171,10 @@ Mob * create_player() { Item * lantern = xalloc(Item); - lantern->count = 1; - lantern->symbol = '^'; - lantern->name = "Lantern"; - lantern->type = WEAPON; - lantern->luminous = true; - lantern->value = 1; + *lantern = default_items[LANTURN]; Item * potion = xalloc(Item); - potion->count = 1; - potion->symbol = '-'; - potion->name = "Potion of Cure Poison"; - potion->type = DRINK; + *potion = default_items[C_POISON_POTION]; potion->effect = &cure_poison; player->inventory = insert(player->inventory, &lantern->inventory); @@ -377,7 +330,7 @@ void player_turn(Mob * player) { display_level(player->level); Direction dir = select_direction(true); - + /* Movement in a level */ if(dir.ch == 0) { move = true; @@ -508,7 +461,7 @@ void player_turn(Mob * player) { dir = select_direction(false); int curx = player->xpos; int cury = player->ypos; - + if (dir.dx != 0 || dir.dy != 0) { curx += dir.dx; cury += dir.dy; @@ -527,7 +480,7 @@ void player_turn(Mob * player) { } } break; - + /* Misc */ case '?': show_help();