static void test_give(CuTest * tc) { struct give env = { 0 }; test_setup_ex(tc); env.f2 = env.f1 = test_create_faction(NULL); setup_give(&env); i_change(&env.src->items, env.itype, 10); CuAssertIntEquals(tc, 0, give_item(10, env.itype, env.src, env.dst, NULL)); CuAssertIntEquals(tc, 0, i_get(env.src->items, env.itype)); CuAssertIntEquals(tc, 10, i_get(env.dst->items, env.itype)); CuAssertIntEquals(tc, -1, give_item(10, env.itype, env.src, env.dst, NULL)); CuAssertIntEquals(tc, 0, i_get(env.src->items, env.itype)); CuAssertIntEquals(tc, 10, i_get(env.dst->items, env.itype)); test_teardown(); }
void loot_chest(int ty, int tx) { char line[DEFLEN]; int tile; int gold_amount; tile = gtile(ty, tx); if (!game->skill_lockpick && game->weapon == WPN_UNARMED) { pwait("YOU HAVE NOTHING TO\n" "OPEN THE CHEST WITH"); return; } if (game->skill_lockpick) { strcpy(line, "YOU PICK THE LOCK\n\n"); } else if (game->weapon == WPN_AXE || game->weapon == WPN_MACE || game->weapon == WPN_DIAMOND || game->weapon == WPN_FLAIL || game->weapon == WPN_BONECLUB ) { strcpy(line, "YOU SMASH THE CHEST OPEN\n\n"); } else strcpy(line, "YOU PRY THE CHEST OPEN\n\n"); /* Weapon has a random chance of breaking, but even if it does we still get the loot. Don't damage weapon if we're capable of lockpicking. */ if (!game->skill_lockpick) damage_weapon(rand() % 10); if (tile == TL_P_UWCHEST) { gold_amount = 10 + rand() % UWCHEST_GOLD; stile(player->y, player->x, TL_UWWOOD); stile(player->y - 1, player->x - 2, TL_UW_UL); stile(player->y - 1, player->x - 1, TL_UW_HL); stile(player->y - 1, player->x, TL_UW_HL); stile(player->y - 1, player->x + 1, TL_UW_HL); stile(player->y - 1, player->x + 2, TL_UW_UR); } else { gold_amount = 10 + rand() % CHEST_GOLD; stile(player->y, player->x, TL_WOOD); stile(player->y - 1, player->x - 2, TL_BR_UL); stile(player->y - 1, player->x - 1, TL_BR_HL); stile(player->y - 1, player->x, TL_BR_HL); stile(player->y - 1, player->x + 1, TL_BR_HL); stile(player->y - 1, player->x + 2, TL_BR_UR); } draw_board(); give_item(line, gold_amount, LOOT_NORMAL); return; }
/* Interacts with the tile at players feet. This will usually change the tile to an identical-looking but functionally inert tile. */ int interact() { int tile; char line[DEFLEN]; tile = gtile(player->y, player->x); if (tile == TL_P_CHEST || tile == TL_P_UWCHEST) { loot_chest(player->y, player->x); } else if (tile == TL_P_NPC1) { shop_chef(); } else if (tile == TL_P_NPC3) { shop_train(); } else if (tile == TL_P_NPC4) { shop_map(); } else if (tile == TL_P_NPC_ARMOR) { shop_armor(); } else if (tile == TL_P_NPC_RANGED) { shop_weapons(1); } else if (tile == TL_P_NPC_WEAPONS) { shop_weapons(0); } else if (tile == TL_P_NPC_CLOSED) { pwait("SORRY WE ARE CLOSED FOR RENOVATION"); } else if (tile == TL_P_NPC_SCUBA) { shop_scuba(); } else if (tile == TL_P_NPC_BAR) { ye_olde_bar(); } else if (tile == TL_P_NPC_SUSHI) { shop_sushi(); } else if (tile == TL_P_COFFIN) { stile(player->y, player->x, TL_COFFIN_HL); stile(player->y - 1, player->x, TL_VOID); stile(player->y - 1, player->x - 1, TL_VOID); stile(player->y - 1, player->x + 1, TL_VOID); stile(player->y - 2, player->x, TL_VOID); if (player->flip) { stile(player->y, player->x + 4, TL_COFFIN_LID_R); stile(player->y - 1, player->x + 3, TL_COFFIN_LID_R); stile(player->y - 2, player->x + 2, TL_COFFIN_LID_R); } else { stile(player->y, player->x - 4, TL_COFFIN_LID_L); stile(player->y - 1, player->x - 3, TL_COFFIN_LID_L); stile(player->y - 2, player->x - 2, TL_COFFIN_LID_L); } strcpy(line, "YOU OPEN THE COFFIN\n\n"); if (rand() % 5 == 0) { strcat(line, "A GHOUL ESCAPES!"); if (rand() % 2 == 0) make_monster(player->y, player->x - 5, MOB_GHOUL); else make_monster(player->y, player->x + 5, MOB_GHOUL); draw_board(); pwait(line); } else if (rand() % 5 == 0) { draw_board(); find_random_armor(line); } else { draw_board_norefresh(); give_item(line, 10 + rand() % COFFIN_GOLD, LOOT_NORMAL); } } else if (tile == TL_P_FOUNTAIN || tile == TL_P_BLOOD_FOUNTAIN) { fountain(); } else if (tile == TL_P_SWSTONE) { sword_in_stone(); } else if (tile == TL_P_ORB) { gaze_orb(); } else if (tile == TL_P_TABLET) { stone_tablet(); } else if (tile == TL_P_HELL) { stile(player->y, player->x, TL_VOID); pwait("YOU ARE IN HELL"); draw_board(); } else if (tile == TL_P_PORTAL) { portal_travel(); } else if (tile == TL_P_IDOL) { idol(); } else if (tile == TL_P_MUSHROOMS) { mushrooms(); } else if (tile == TL_P_BOOKSHELF) { bookshelf(); } else if (tile == TL_P_CAMP) { if (anything_near()) { pwait("YOU CANNOT REST NOW!\nENEMIES ARE NEAR"); return false; } camp(); } else if (tile == TL_P_DISCO) { if (anything_near()) { pwait("YOU CANNOT DANCE WHILE\nSOMEONE IS WATCHING"); return false; } disco(); } else if (tile == TL_P_ALTAR) { altar(); } else if (tile == TL_P_CORPSE || tile == TL_P_SKELETON) { if (tile == TL_P_CORPSE) { stile(player->y, player->x, TL_VOID); strcpy(line, "YOU FIND A DECAYING CORPSE\n\n"); } else { stile(player->y, player->x, TL_VOID); strcpy(line, "YOU FIND A LONG-DEAD SKELETON\n\n"); } switch(rand() % 10) { case 0: case 1: case 2: find_random_armor(line); break; case 3: case 4: case 5: find_random_weapon(line); break; default: if (tile == TL_P_SKELETON) give_item(line, 5 + rand() % 25, LOOT_BONES); else give_item(line, 5 + rand() % 25, LOOT_NORMAL); break; } //pwait(line); return true; } return true; }