diff --git a/draugnorak.nvgt b/draugnorak.nvgt index 172b0c5..048136c 100644 --- a/draugnorak.nvgt +++ b/draugnorak.nvgt @@ -82,6 +82,7 @@ void main() show_window("Draugnorak"); init_flying_creature_configs(); + init_item_registry(); bool game_started = false; while (!game_started) { @@ -400,7 +401,7 @@ void main() // Sling charge detection if (sling_equipped && (key_down(KEY_LCTRL) || key_down(KEY_RCTRL)) && !sling_charging) { - if (inv_stones > 0) { + if (get_personal_count(ITEM_STONES) > 0) { sling_charging = true; sling_charge_timer.restart(); sling_sound_handle = p.play_stationary("sounds/weapons/sling_swing.ogg", true); diff --git a/src/audio_utils.nvgt b/src/audio_utils.nvgt index e216f36..0469df2 100644 --- a/src/audio_utils.nvgt +++ b/src/audio_utils.nvgt @@ -123,11 +123,7 @@ int play_1d_with_volume_step(string sound_file, int listener_x, int sound_x, boo void play_positional_footstep(int listener_x, int step_x, int base_end, int grass_end, int max_distance, float volume_step) { - int distance = step_x - listener_x; - if (distance < 0) { - distance = -distance; - } - if (distance > max_distance) { + if (abs(step_x - listener_x) > max_distance) { return; } @@ -147,3 +143,14 @@ void play_land_sound(int current_x, int base_end, int grass_end) p.play_stationary(sound_file, false); } } + +// Safe sound handle cleanup - checks if handle is valid and sound is active before destroying +void safe_destroy_sound(int &inout handle) +{ + if (handle != -1) { + if (p.sound_is_active(handle)) { + p.destroy_sound(handle); + } + handle = -1; + } +} diff --git a/src/base_system.nvgt b/src/base_system.nvgt index ba79db5..fb74e77 100644 --- a/src/base_system.nvgt +++ b/src/base_system.nvgt @@ -7,10 +7,10 @@ int get_daily_food_requirement() { void consume_food_for_residents() { int needed = get_daily_food_requirement(); if (needed <= 0) return; - if (storage_meat >= needed) { - storage_meat -= needed; + if (get_storage_count(ITEM_MEAT) >= needed) { + add_storage_count(ITEM_MEAT, -needed); } else { - storage_meat = 0; + set_storage_count(ITEM_MEAT, 0); if (x <= BASE_END) { notify("No food, residents are hungry."); } @@ -19,19 +19,19 @@ void consume_food_for_residents() { void keep_base_fires_fed() { if (residents_count <= 0) return; - if (storage_meat <= 0) return; - if (storage_sticks <= 0 && storage_logs <= 0) return; + if (get_storage_count(ITEM_MEAT) <= 0) return; + if (get_storage_count(ITEM_STICKS) <= 0 && get_storage_count(ITEM_LOGS) <= 0) return; for (uint i = 0; i < world_fires.length(); i++) { if (world_fires[i].position > BASE_END) continue; if (!world_fires[i].is_burning()) continue; if (world_fires[i].fuel_remaining > 300000) continue; - if (storage_sticks > 0) { - storage_sticks--; + if (get_storage_count(ITEM_STICKS) > 0) { + add_storage_count(ITEM_STICKS, -1); world_fires[i].add_fuel(300000); // 5 minutes - } else if (storage_logs > 0) { - storage_logs--; + } else if (get_storage_count(ITEM_LOGS) > 0) { + add_storage_count(ITEM_LOGS, -1); world_fires[i].add_fuel(720000); // 12 minutes } break; @@ -40,10 +40,10 @@ void keep_base_fires_fed() { // Resident defense functions int get_available_defense_weapons() { - int count = storage_spears; + int count = get_storage_count(ITEM_SPEARS); // Slings only count if stones are available - if (storage_slings > 0 && storage_stones > 0) { - count += storage_slings; + if (get_storage_count(ITEM_SLINGS) > 0 && get_storage_count(ITEM_STONES) > 0) { + count += get_storage_count(ITEM_SLINGS); } return count; } @@ -55,8 +55,8 @@ bool can_residents_defend() { bool choose_defense_weapon() { // Returns true for spear, false for sling - int spearCount = storage_spears; - int slingCount = (storage_slings > 0 && storage_stones > 0) ? storage_slings : 0; + int spearCount = get_storage_count(ITEM_SPEARS); + int slingCount = (get_storage_count(ITEM_SLINGS) > 0 && get_storage_count(ITEM_STONES) > 0) ? get_storage_count(ITEM_SLINGS) : 0; int total = spearCount + slingCount; if (total == 0) return true; @@ -74,15 +74,15 @@ int perform_resident_defense() { bool useSpear = choose_defense_weapon(); int damage = 0; - if (useSpear && storage_spears > 0) { + if (useSpear && get_storage_count(ITEM_SPEARS) > 0) { damage = RESIDENT_SPEAR_DAMAGE; // Weapons don't get consumed on use - they break via daily breakage check // Just play the sound play_1d_with_volume_step("sounds/weapons/spear_swing.ogg", x, BASE_END + 1, false, RESIDENT_DEFENSE_VOLUME_STEP); - } else if (storage_slings > 0 && storage_stones > 0) { + } else if (get_storage_count(ITEM_SLINGS) > 0 && get_storage_count(ITEM_STONES) > 0) { damage = random(RESIDENT_SLING_DAMAGE_MIN, RESIDENT_SLING_DAMAGE_MAX); // Slings use stones as ammo, so consume a stone - storage_stones--; + add_storage_count(ITEM_STONES, -1); play_1d_with_volume_step("sounds/weapons/sling_hit.ogg", x, BASE_END + 1, false, RESIDENT_DEFENSE_VOLUME_STEP); } @@ -95,7 +95,7 @@ timer resident_sling_timer; void attempt_resident_sling_defense() { // Only if residents exist and have slings with stones if (residents_count <= 0) return; - if (storage_slings <= 0 || storage_stones <= 0) return; + if (get_storage_count(ITEM_SLINGS) <= 0 || get_storage_count(ITEM_STONES) <= 0) return; // Cooldown between shots if (resident_sling_timer.elapsed < RESIDENT_SLING_COOLDOWN) return; @@ -132,7 +132,7 @@ void attempt_resident_sling_defense() { // Shoot! resident_sling_timer.restart(); - storage_stones--; + add_storage_count(ITEM_STONES, -1); int damage = random(RESIDENT_SLING_DAMAGE_MIN, RESIDENT_SLING_DAMAGE_MAX); play_1d_with_volume_step("sounds/weapons/sling_hit.ogg", x, targetPos, false, RESIDENT_DEFENSE_VOLUME_STEP); @@ -150,7 +150,7 @@ void attempt_resident_sling_defense() { void process_daily_weapon_breakage() { if (residents_count <= 0) return; - int totalWeapons = storage_spears + storage_slings; + int totalWeapons = get_storage_count(ITEM_SPEARS) + get_storage_count(ITEM_SLINGS); if (totalWeapons == 0) return; // Number of breakage checks = min(residents, weapons) @@ -161,8 +161,8 @@ void process_daily_weapon_breakage() { int slingChecks = 0; for (int i = 0; i < checksToPerform; i++) { - int remainingSpears = storage_spears - spearChecks; - int remainingSlings = storage_slings - slingChecks; + int remainingSpears = get_storage_count(ITEM_SPEARS) - spearChecks; + int remainingSlings = get_storage_count(ITEM_SLINGS) - slingChecks; int remaining = remainingSpears + remainingSlings; if (remaining <= 0) break; @@ -193,8 +193,8 @@ void process_daily_weapon_breakage() { // Apply breakage if (spearsBroken > 0) { - storage_spears -= spearsBroken; - if (storage_spears < 0) storage_spears = 0; + add_storage_count(ITEM_SPEARS, -spearsBroken); + if (get_storage_count(ITEM_SPEARS) < 0) set_storage_count(ITEM_SPEARS, 0); string msg = (spearsBroken == 1) ? "A resident's spear broke from wear." : spearsBroken + " spears broke from wear."; @@ -202,8 +202,8 @@ void process_daily_weapon_breakage() { } if (slingsBroken > 0) { - storage_slings -= slingsBroken; - if (storage_slings < 0) storage_slings = 0; + add_storage_count(ITEM_SLINGS, -slingsBroken); + if (get_storage_count(ITEM_SLINGS) < 0) set_storage_count(ITEM_SLINGS, 0); string msg = (slingsBroken == 1) ? "A resident's sling broke from wear." : slingsBroken + " slings broke from wear."; @@ -221,10 +221,10 @@ void attempt_resident_collection() { if (residents_count <= 0) return; // Need baskets in storage to enable collection - if (storage_reed_baskets <= 0) return; + if (get_storage_count(ITEM_REED_BASKETS) <= 0) return; // Number of residents who can collect = min(residents, baskets) - int active_collectors = (residents_count < storage_reed_baskets) ? residents_count : storage_reed_baskets; + int active_collectors = (residents_count < get_storage_count(ITEM_REED_BASKETS)) ? residents_count : get_storage_count(ITEM_REED_BASKETS); // Each active collector has a 10% chance to collect something for (int i = 0; i < active_collectors; i++) { @@ -237,19 +237,19 @@ void attempt_resident_collection() { if (roll <= 40) { // 40% chance - stick - storage_sticks++; + add_storage_count(ITEM_STICKS, 1); item_name = "stick"; } else if (roll <= 70) { // 30% chance - vine - storage_vines++; + add_storage_count(ITEM_VINES, 1); item_name = "vine"; } else if (roll <= 85) { // 15% chance - stone - storage_stones++; + add_storage_count(ITEM_STONES, 1); item_name = "stone"; } else { // 15% chance - log - storage_logs++; + add_storage_count(ITEM_LOGS, 1); item_name = "log"; } diff --git a/src/bosses/unicorn/unicorn_boss.nvgt b/src/bosses/unicorn/unicorn_boss.nvgt index a203f11..e17d2c9 100644 --- a/src/bosses/unicorn/unicorn_boss.nvgt +++ b/src/bosses/unicorn/unicorn_boss.nvgt @@ -74,11 +74,28 @@ void cleanup_unicorn_adventure() { void run_unicorn_adventure() { // Stop main game sounds p.destroy_all(); - + init_unicorn_adventure(); - - speak_with_history("You enter a mountain pass. A massive Unicorn blocks the path! A wooden bridge spans a chasm ahead.", true); - + + // Show introduction in text reader + string[] intro; + intro.insert_last("=== Unicorn Hunt ==="); + intro.insert_last(""); + intro.insert_last("You enter a narrow mountain pass. A massive Unicorn blocks your path!"); + intro.insert_last("The beast charges back and forth relentlessly."); + intro.insert_last(""); + intro.insert_last("A wooden bridge spans a deep chasm ahead. The bridge has two supports"); + intro.insert_last("that can be destroyed with an axe."); + intro.insert_last(""); + intro.insert_last("Strategy:"); + intro.insert_last(" - Use your axe to destroy a bridge support"); + intro.insert_last(" - Lure the Unicorn onto the bridge"); + intro.insert_last(" - Jump (UP arrow) to avoid being trampled"); + intro.insert_last(" - When the bridge collapses with the Unicorn on it, you win!"); + intro.insert_last(""); + intro.insert_last("Controls: LEFT/RIGHT to move, UP to jump, CTRL to attack, ESC to flee"); + text_reader_lines(intro, "Adventure", true); + // Adventure Loop while (true) { wait(5); @@ -392,6 +409,7 @@ void play_unicorn_death_sequence() { p.destroy_sound(fall_handle); } play_1d_with_volume_step("sounds/bosses/unicorn/unicorn_falls.ogg", player_arena_x, unicorn.x, false, UNICORN_SOUND_VOLUME_STEP); + wait(1500); // Let the impact sound play before cleanup } void give_unicorn_rewards() { diff --git a/src/combat.nvgt b/src/combat.nvgt index 8b71c35..80c0bcb 100644 --- a/src/combat.nvgt +++ b/src/combat.nvgt @@ -125,7 +125,7 @@ void update_sling_charge() { void release_sling_attack(int player_x) { // Consume stone - inv_stones--; + add_personal_count(ITEM_STONES, -1); int elapsed = sling_charge_timer.elapsed; int cycle_time = 1500; diff --git a/src/constants.nvgt b/src/constants.nvgt index aa5b76b..111866e 100644 --- a/src/constants.nvgt +++ b/src/constants.nvgt @@ -235,3 +235,8 @@ const int FALL_DAMAGE_MAX = 4; const int RESIDENT_SLING_COOLDOWN = 4000; // 4 seconds between shots const int RESIDENT_COLLECTION_CHANCE = 10; // 10% chance per basket per hour +// Utility functions +int abs(int value) { + return value < 0 ? -value : value; +} + diff --git a/src/crafting/craft_barricade.nvgt b/src/crafting/craft_barricade.nvgt index 2c4537e..f1f3632 100644 --- a/src/crafting/craft_barricade.nvgt +++ b/src/crafting/craft_barricade.nvgt @@ -11,19 +11,19 @@ void run_barricade_menu() { string[] options; int[] action_types; // 0 = sticks, 1 = vines, 2 = log, 3 = stones - if (inv_sticks >= BARRICADE_STICK_COST) { + if (get_personal_count(ITEM_STICKS) >= BARRICADE_STICK_COST) { options.insert_last("Reinforce with sticks (" + BARRICADE_STICK_COST + " sticks, +" + BARRICADE_STICK_HEALTH + " health)"); action_types.insert_last(0); } - if (inv_vines >= BARRICADE_VINE_COST) { + if (get_personal_count(ITEM_VINES) >= BARRICADE_VINE_COST) { options.insert_last("Reinforce with vines (" + BARRICADE_VINE_COST + " vines, +" + BARRICADE_VINE_HEALTH + " health)"); action_types.insert_last(1); } - if (inv_logs >= BARRICADE_LOG_COST) { + if (get_personal_count(ITEM_LOGS) >= BARRICADE_LOG_COST) { options.insert_last("Reinforce with log (" + BARRICADE_LOG_COST + " log, +" + BARRICADE_LOG_HEALTH + " health)"); action_types.insert_last(2); } - if (inv_stones >= BARRICADE_STONE_COST) { + if (get_personal_count(ITEM_STONES) >= BARRICADE_STONE_COST) { options.insert_last("Reinforce with stones (" + BARRICADE_STONE_COST + " stones, +" + BARRICADE_STONE_HEALTH + " health)"); action_types.insert_last(3); } @@ -78,13 +78,13 @@ void reinforce_barricade_with_sticks() { speak_with_history("Barricade is already at full health.", true); return; } - if (inv_sticks < BARRICADE_STICK_COST) { + if (get_personal_count(ITEM_STICKS) < BARRICADE_STICK_COST) { speak_with_history("Not enough sticks.", true); return; } simulate_crafting(BARRICADE_STICK_COST); - inv_sticks -= BARRICADE_STICK_COST; + add_personal_count(ITEM_STICKS, -BARRICADE_STICK_COST); int gained = add_barricade_health(BARRICADE_STICK_HEALTH); speak_with_history("Reinforced barricade with sticks. +" + gained + " health. Now " + barricade_health + " of " + BARRICADE_MAX_HEALTH + ".", true); } @@ -94,13 +94,13 @@ void reinforce_barricade_with_vines() { speak_with_history("Barricade is already at full health.", true); return; } - if (inv_vines < BARRICADE_VINE_COST) { + if (get_personal_count(ITEM_VINES) < BARRICADE_VINE_COST) { speak_with_history("Not enough vines.", true); return; } simulate_crafting(BARRICADE_VINE_COST); - inv_vines -= BARRICADE_VINE_COST; + add_personal_count(ITEM_VINES, -BARRICADE_VINE_COST); int gained = add_barricade_health(BARRICADE_VINE_HEALTH); speak_with_history("Reinforced barricade with vines. +" + gained + " health. Now " + barricade_health + " of " + BARRICADE_MAX_HEALTH + ".", true); } @@ -110,13 +110,13 @@ void reinforce_barricade_with_log() { speak_with_history("Barricade is already at full health.", true); return; } - if (inv_logs < BARRICADE_LOG_COST) { + if (get_personal_count(ITEM_LOGS) < BARRICADE_LOG_COST) { speak_with_history("Not enough logs.", true); return; } simulate_crafting(BARRICADE_LOG_COST); - inv_logs -= BARRICADE_LOG_COST; + add_personal_count(ITEM_LOGS, -BARRICADE_LOG_COST); int gained = add_barricade_health(BARRICADE_LOG_HEALTH); speak_with_history("Reinforced barricade with log. +" + gained + " health. Now " + barricade_health + " of " + BARRICADE_MAX_HEALTH + ".", true); } @@ -126,13 +126,13 @@ void reinforce_barricade_with_stones() { speak_with_history("Barricade is already at full health.", true); return; } - if (inv_stones < BARRICADE_STONE_COST) { + if (get_personal_count(ITEM_STONES) < BARRICADE_STONE_COST) { speak_with_history("Not enough stones.", true); return; } simulate_crafting(BARRICADE_STONE_COST); - inv_stones -= BARRICADE_STONE_COST; + add_personal_count(ITEM_STONES, -BARRICADE_STONE_COST); int gained = add_barricade_health(BARRICADE_STONE_HEALTH); speak_with_history("Reinforced barricade with stones. +" + gained + " health. Now " + barricade_health + " of " + BARRICADE_MAX_HEALTH + ".", true); } @@ -143,20 +143,20 @@ void reinforce_barricade_max_with_sticks() { return; } - if (inv_sticks < BARRICADE_STICK_COST) { + if (get_personal_count(ITEM_STICKS) < BARRICADE_STICK_COST) { speak_with_history("Missing: " + BARRICADE_STICK_COST + " sticks", true); return; } int health_needed = BARRICADE_MAX_HEALTH - barricade_health; int max_reinforcements = (health_needed + BARRICADE_STICK_HEALTH - 1) / BARRICADE_STICK_HEALTH; - int can_afford = inv_sticks / BARRICADE_STICK_COST; + int can_afford = get_personal_count(ITEM_STICKS) / BARRICADE_STICK_COST; int to_do = (max_reinforcements < can_afford) ? max_reinforcements : can_afford; int total_cost = to_do * BARRICADE_STICK_COST; simulate_crafting(total_cost); - inv_sticks -= total_cost; + add_personal_count(ITEM_STICKS, -total_cost); barricade_health += (to_do * BARRICADE_STICK_HEALTH); if (barricade_health > BARRICADE_MAX_HEALTH) barricade_health = BARRICADE_MAX_HEALTH; @@ -169,20 +169,20 @@ void reinforce_barricade_max_with_vines() { return; } - if (inv_vines < BARRICADE_VINE_COST) { + if (get_personal_count(ITEM_VINES) < BARRICADE_VINE_COST) { speak_with_history("Missing: " + BARRICADE_VINE_COST + " vines", true); return; } int health_needed = BARRICADE_MAX_HEALTH - barricade_health; int max_reinforcements = (health_needed + BARRICADE_VINE_HEALTH - 1) / BARRICADE_VINE_HEALTH; - int can_afford = inv_vines / BARRICADE_VINE_COST; + int can_afford = get_personal_count(ITEM_VINES) / BARRICADE_VINE_COST; int to_do = (max_reinforcements < can_afford) ? max_reinforcements : can_afford; int total_cost = to_do * BARRICADE_VINE_COST; simulate_crafting(total_cost); - inv_vines -= total_cost; + add_personal_count(ITEM_VINES, -total_cost); barricade_health += (to_do * BARRICADE_VINE_HEALTH); if (barricade_health > BARRICADE_MAX_HEALTH) barricade_health = BARRICADE_MAX_HEALTH; @@ -195,20 +195,20 @@ void reinforce_barricade_max_with_log() { return; } - if (inv_logs < BARRICADE_LOG_COST) { + if (get_personal_count(ITEM_LOGS) < BARRICADE_LOG_COST) { speak_with_history("Missing: " + BARRICADE_LOG_COST + " log", true); return; } int health_needed = BARRICADE_MAX_HEALTH - barricade_health; int max_reinforcements = (health_needed + BARRICADE_LOG_HEALTH - 1) / BARRICADE_LOG_HEALTH; - int can_afford = inv_logs / BARRICADE_LOG_COST; + int can_afford = get_personal_count(ITEM_LOGS) / BARRICADE_LOG_COST; int to_do = (max_reinforcements < can_afford) ? max_reinforcements : can_afford; int total_cost = to_do * BARRICADE_LOG_COST; simulate_crafting(total_cost); - inv_logs -= total_cost; + add_personal_count(ITEM_LOGS, -total_cost); barricade_health += (to_do * BARRICADE_LOG_HEALTH); if (barricade_health > BARRICADE_MAX_HEALTH) barricade_health = BARRICADE_MAX_HEALTH; @@ -221,20 +221,20 @@ void reinforce_barricade_max_with_stones() { return; } - if (inv_stones < BARRICADE_STONE_COST) { + if (get_personal_count(ITEM_STONES) < BARRICADE_STONE_COST) { speak_with_history("Missing: " + BARRICADE_STONE_COST + " stones", true); return; } int health_needed = BARRICADE_MAX_HEALTH - barricade_health; int max_reinforcements = (health_needed + BARRICADE_STONE_HEALTH - 1) / BARRICADE_STONE_HEALTH; - int can_afford = inv_stones / BARRICADE_STONE_COST; + int can_afford = get_personal_count(ITEM_STONES) / BARRICADE_STONE_COST; int to_do = (max_reinforcements < can_afford) ? max_reinforcements : can_afford; int total_cost = to_do * BARRICADE_STONE_COST; simulate_crafting(total_cost); - inv_stones -= total_cost; + add_personal_count(ITEM_STONES, -total_cost); barricade_health += (to_do * BARRICADE_STONE_HEALTH); if (barricade_health > BARRICADE_MAX_HEALTH) barricade_health = BARRICADE_MAX_HEALTH; diff --git a/src/crafting/craft_buildings.nvgt b/src/crafting/craft_buildings.nvgt index 21763a1..10f4a1c 100644 --- a/src/crafting/craft_buildings.nvgt +++ b/src/crafting/craft_buildings.nvgt @@ -84,11 +84,11 @@ void craft_firepit() { } string missing = ""; - if (inv_stones < 9) missing += "9 stones "; + if (get_personal_count(ITEM_STONES) < 9) missing += "9 stones "; if (missing == "") { simulate_crafting(9); - inv_stones -= 9; + add_personal_count(ITEM_STONES, -9); add_world_firepit(x); speak_with_history("Firepit built here.", true); } else { @@ -105,13 +105,13 @@ void craft_campfire() { } string missing = ""; - if (inv_logs < 1) missing += "1 log "; - if (inv_sticks < 2) missing += "2 sticks "; + if (get_personal_count(ITEM_LOGS) < 1) missing += "1 log "; + if (get_personal_count(ITEM_STICKS) < 2) missing += "2 sticks "; if (missing == "") { simulate_crafting(3); - inv_logs--; - inv_sticks -= 2; + add_personal_count(ITEM_LOGS, -1); + add_personal_count(ITEM_STICKS, -2); // Build the fire at the firepit location, not player location add_world_fire(firepit.position); speak_with_history("Fire built at firepit.", true); @@ -134,15 +134,15 @@ void craft_herb_garden() { } string missing = ""; - if (inv_stones < 9) missing += "9 stones "; - if (inv_vines < 3) missing += "3 vines "; - if (inv_logs < 2) missing += "2 logs "; + if (get_personal_count(ITEM_STONES) < 9) missing += "9 stones "; + if (get_personal_count(ITEM_VINES) < 3) missing += "3 vines "; + if (get_personal_count(ITEM_LOGS) < 2) missing += "2 logs "; if (missing == "") { simulate_crafting(14); - inv_stones -= 9; - inv_vines -= 3; - inv_logs -= 2; + add_personal_count(ITEM_STONES, -9); + add_personal_count(ITEM_VINES, -3); + add_personal_count(ITEM_LOGS, -2); add_world_herb_garden(x); speak_with_history("Herb garden built. The base now heals faster.", true); } else { @@ -160,15 +160,15 @@ void craft_storage() { return; } string missing = ""; - if (inv_logs < STORAGE_LOG_COST) missing += STORAGE_LOG_COST + " logs "; - if (inv_stones < STORAGE_STONE_COST) missing += STORAGE_STONE_COST + " stones "; - if (inv_vines < STORAGE_VINE_COST) missing += STORAGE_VINE_COST + " vines "; + if (get_personal_count(ITEM_LOGS) < STORAGE_LOG_COST) missing += STORAGE_LOG_COST + " logs "; + if (get_personal_count(ITEM_STONES) < STORAGE_STONE_COST) missing += STORAGE_STONE_COST + " stones "; + if (get_personal_count(ITEM_VINES) < STORAGE_VINE_COST) missing += STORAGE_VINE_COST + " vines "; if (missing == "") { simulate_crafting(23); - inv_logs -= STORAGE_LOG_COST; - inv_stones -= STORAGE_STONE_COST; - inv_vines -= STORAGE_VINE_COST; + add_personal_count(ITEM_LOGS, -STORAGE_LOG_COST); + add_personal_count(ITEM_STONES, -STORAGE_STONE_COST); + add_personal_count(ITEM_VINES, -STORAGE_VINE_COST); add_world_storage(x); speak_with_history("Storage built.", true); } else { @@ -186,13 +186,13 @@ void craft_pasture() { return; } string missing = ""; - if (inv_logs < PASTURE_LOG_COST) missing += PASTURE_LOG_COST + " logs "; - if (inv_vines < PASTURE_VINE_COST) missing += PASTURE_VINE_COST + " vines "; + if (get_personal_count(ITEM_LOGS) < PASTURE_LOG_COST) missing += PASTURE_LOG_COST + " logs "; + if (get_personal_count(ITEM_VINES) < PASTURE_VINE_COST) missing += PASTURE_VINE_COST + " vines "; if (missing == "") { simulate_crafting(28); - inv_logs -= PASTURE_LOG_COST; - inv_vines -= PASTURE_VINE_COST; + add_personal_count(ITEM_LOGS, -PASTURE_LOG_COST); + add_personal_count(ITEM_VINES, -PASTURE_VINE_COST); add_world_pasture(x); speak_with_history("Pasture built.", true); } else { @@ -210,15 +210,15 @@ void craft_stable() { return; } string missing = ""; - if (inv_logs < STABLE_LOG_COST) missing += STABLE_LOG_COST + " logs "; - if (inv_stones < STABLE_STONE_COST) missing += STABLE_STONE_COST + " stones "; - if (inv_vines < STABLE_VINE_COST) missing += STABLE_VINE_COST + " vines "; + if (get_personal_count(ITEM_LOGS) < STABLE_LOG_COST) missing += STABLE_LOG_COST + " logs "; + if (get_personal_count(ITEM_STONES) < STABLE_STONE_COST) missing += STABLE_STONE_COST + " stones "; + if (get_personal_count(ITEM_VINES) < STABLE_VINE_COST) missing += STABLE_VINE_COST + " vines "; if (missing == "") { simulate_crafting(35); - inv_logs -= STABLE_LOG_COST; - inv_stones -= STABLE_STONE_COST; - inv_vines -= STABLE_VINE_COST; + add_personal_count(ITEM_LOGS, -STABLE_LOG_COST); + add_personal_count(ITEM_STONES, -STABLE_STONE_COST); + add_personal_count(ITEM_VINES, -STABLE_VINE_COST); add_world_stable(x); speak_with_history("Stable built.", true); } else { @@ -236,13 +236,13 @@ void craft_altar() { return; } string missing = ""; - if (inv_stones < ALTAR_STONE_COST) missing += ALTAR_STONE_COST + " stones "; - if (inv_sticks < ALTAR_STICK_COST) missing += ALTAR_STICK_COST + " sticks "; + if (get_personal_count(ITEM_STONES) < ALTAR_STONE_COST) missing += ALTAR_STONE_COST + " stones "; + if (get_personal_count(ITEM_STICKS) < ALTAR_STICK_COST) missing += ALTAR_STICK_COST + " sticks "; if (missing == "") { simulate_crafting(12); - inv_stones -= ALTAR_STONE_COST; - inv_sticks -= ALTAR_STICK_COST; + add_personal_count(ITEM_STONES, -ALTAR_STONE_COST); + add_personal_count(ITEM_STICKS, -ALTAR_STICK_COST); add_world_altar(x); speak_with_history("Altar built.", true); } else { diff --git a/src/crafting/craft_clothing.nvgt b/src/crafting/craft_clothing.nvgt index c07375a..9454849 100644 --- a/src/crafting/craft_clothing.nvgt +++ b/src/crafting/craft_clothing.nvgt @@ -59,18 +59,18 @@ void run_clothing_menu() { void craft_skin_hat() { string missing = ""; - if (inv_skins < 1) missing += "1 skin "; - if (inv_vines < 1) missing += "1 vine "; + if (get_personal_count(ITEM_SKINS) < 1) missing += "1 skin "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; if (missing == "") { - if (inv_skin_hats >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SKIN_HATS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more skin hats.", true); return; } simulate_crafting(2); - inv_skins--; - inv_vines--; - inv_skin_hats++; + add_personal_count(ITEM_SKINS, -1); + add_personal_count(ITEM_VINES, -1); + add_personal_count(ITEM_SKIN_HATS, 1); speak_with_history("Crafted a Skin Hat.", true); } else { speak_with_history("Missing: " + missing, true); @@ -78,23 +78,23 @@ void craft_skin_hat() { } void craft_skin_hat_max() { - if (inv_skin_hats >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SKIN_HATS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more skin hats.", true); return; } - int max_by_skins = inv_skins; - int max_by_vines = inv_vines; + int max_by_skins = get_personal_count(ITEM_SKINS); + int max_by_vines = get_personal_count(ITEM_VINES); int max_craft = max_by_skins; if (max_by_vines < max_craft) max_craft = max_by_vines; - int space = get_personal_stack_limit() - inv_skin_hats; + int space = get_personal_stack_limit() - get_personal_count(ITEM_SKIN_HATS); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_skins < 1) missing += "1 skin "; - if (inv_vines < 1) missing += "1 vine "; + if (get_personal_count(ITEM_SKINS) < 1) missing += "1 skin "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; speak_with_history("Missing: " + missing, true); return; } @@ -102,26 +102,26 @@ void craft_skin_hat_max() { int total_cost = max_craft * 2; // 1 skin + 1 vine per hat int craft_time = (total_cost < max_craft * 4) ? max_craft * 4 : total_cost; simulate_crafting(craft_time); - inv_skins -= max_craft; - inv_vines -= max_craft; - inv_skin_hats += max_craft; + add_personal_count(ITEM_SKINS, -max_craft); + add_personal_count(ITEM_VINES, -max_craft); + add_personal_count(ITEM_SKIN_HATS, max_craft); speak_with_history("Crafted " + max_craft + " Skin Hats.", true); } void craft_skin_gloves() { string missing = ""; - if (inv_skins < 1) missing += "1 skin "; - if (inv_vines < 1) missing += "1 vine "; + if (get_personal_count(ITEM_SKINS) < 1) missing += "1 skin "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; if (missing == "") { - if (inv_skin_gloves >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SKIN_GLOVES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more skin gloves.", true); return; } simulate_crafting(2); - inv_skins--; - inv_vines--; - inv_skin_gloves++; + add_personal_count(ITEM_SKINS, -1); + add_personal_count(ITEM_VINES, -1); + add_personal_count(ITEM_SKIN_GLOVES, 1); speak_with_history("Crafted Skin Gloves.", true); } else { speak_with_history("Missing: " + missing, true); @@ -129,23 +129,23 @@ void craft_skin_gloves() { } void craft_skin_gloves_max() { - if (inv_skin_gloves >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SKIN_GLOVES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more skin gloves.", true); return; } - int max_by_skins = inv_skins; - int max_by_vines = inv_vines; + int max_by_skins = get_personal_count(ITEM_SKINS); + int max_by_vines = get_personal_count(ITEM_VINES); int max_craft = max_by_skins; if (max_by_vines < max_craft) max_craft = max_by_vines; - int space = get_personal_stack_limit() - inv_skin_gloves; + int space = get_personal_stack_limit() - get_personal_count(ITEM_SKIN_GLOVES); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_skins < 1) missing += "1 skin "; - if (inv_vines < 1) missing += "1 vine "; + if (get_personal_count(ITEM_SKINS) < 1) missing += "1 skin "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; speak_with_history("Missing: " + missing, true); return; } @@ -153,26 +153,26 @@ void craft_skin_gloves_max() { int total_cost = max_craft * 2; // 1 skin + 1 vine per gloves int craft_time = (total_cost < max_craft * 4) ? max_craft * 4 : total_cost; simulate_crafting(craft_time); - inv_skins -= max_craft; - inv_vines -= max_craft; - inv_skin_gloves += max_craft; + add_personal_count(ITEM_SKINS, -max_craft); + add_personal_count(ITEM_VINES, -max_craft); + add_personal_count(ITEM_SKIN_GLOVES, max_craft); speak_with_history("Crafted " + max_craft + " Skin Gloves.", true); } void craft_skin_pants() { string missing = ""; - if (inv_skins < 6) missing += "6 skins "; - if (inv_vines < 3) missing += "3 vines "; + if (get_personal_count(ITEM_SKINS) < 6) missing += "6 skins "; + if (get_personal_count(ITEM_VINES) < 3) missing += "3 vines "; if (missing == "") { - if (inv_skin_pants >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SKIN_PANTS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more skin pants.", true); return; } simulate_crafting(9); - inv_skins -= 6; - inv_vines -= 3; - inv_skin_pants++; + add_personal_count(ITEM_SKINS, -6); + add_personal_count(ITEM_VINES, -3); + add_personal_count(ITEM_SKIN_PANTS, 1); speak_with_history("Crafted Skin Pants.", true); } else { speak_with_history("Missing: " + missing, true); @@ -180,49 +180,49 @@ void craft_skin_pants() { } void craft_skin_pants_max() { - if (inv_skin_pants >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SKIN_PANTS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more skin pants.", true); return; } - int max_by_skins = inv_skins / 6; - int max_by_vines = inv_vines / 3; + int max_by_skins = get_personal_count(ITEM_SKINS) / 6; + int max_by_vines = get_personal_count(ITEM_VINES) / 3; int max_craft = max_by_skins; if (max_by_vines < max_craft) max_craft = max_by_vines; - int space = get_personal_stack_limit() - inv_skin_pants; + int space = get_personal_stack_limit() - get_personal_count(ITEM_SKIN_PANTS); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_skins < 6) missing += "6 skins "; - if (inv_vines < 3) missing += "3 vines "; + if (get_personal_count(ITEM_SKINS) < 6) missing += "6 skins "; + if (get_personal_count(ITEM_VINES) < 3) missing += "3 vines "; speak_with_history("Missing: " + missing, true); return; } int total_cost = max_craft * 9; // 6 skins + 3 vines per pants simulate_crafting(total_cost); - inv_skins -= (max_craft * 6); - inv_vines -= (max_craft * 3); - inv_skin_pants += max_craft; + add_personal_count(ITEM_SKINS, -(max_craft * 6)); + add_personal_count(ITEM_VINES, -(max_craft * 3)); + add_personal_count(ITEM_SKIN_PANTS, max_craft); speak_with_history("Crafted " + max_craft + " Skin Pants.", true); } void craft_skin_tunic() { string missing = ""; - if (inv_skins < 4) missing += "4 skins "; - if (inv_vines < 2) missing += "2 vines "; + if (get_personal_count(ITEM_SKINS) < 4) missing += "4 skins "; + if (get_personal_count(ITEM_VINES) < 2) missing += "2 vines "; if (missing == "") { - if (inv_skin_tunics >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SKIN_TUNICS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more skin tunics.", true); return; } simulate_crafting(6); - inv_skins -= 4; - inv_vines -= 2; - inv_skin_tunics++; + add_personal_count(ITEM_SKINS, -4); + add_personal_count(ITEM_VINES, -2); + add_personal_count(ITEM_SKIN_TUNICS, 1); speak_with_history("Crafted a Skin Tunic.", true); } else { speak_with_history("Missing: " + missing, true); @@ -230,49 +230,49 @@ void craft_skin_tunic() { } void craft_skin_tunic_max() { - if (inv_skin_tunics >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SKIN_TUNICS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more skin tunics.", true); return; } - int max_by_skins = inv_skins / 4; - int max_by_vines = inv_vines / 2; + int max_by_skins = get_personal_count(ITEM_SKINS) / 4; + int max_by_vines = get_personal_count(ITEM_VINES) / 2; int max_craft = max_by_skins; if (max_by_vines < max_craft) max_craft = max_by_vines; - int space = get_personal_stack_limit() - inv_skin_tunics; + int space = get_personal_stack_limit() - get_personal_count(ITEM_SKIN_TUNICS); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_skins < 4) missing += "4 skins "; - if (inv_vines < 2) missing += "2 vines "; + if (get_personal_count(ITEM_SKINS) < 4) missing += "4 skins "; + if (get_personal_count(ITEM_VINES) < 2) missing += "2 vines "; speak_with_history("Missing: " + missing, true); return; } int total_cost = max_craft * 6; // 4 skins + 2 vines per tunic simulate_crafting(total_cost); - inv_skins -= (max_craft * 4); - inv_vines -= (max_craft * 2); - inv_skin_tunics += max_craft; + add_personal_count(ITEM_SKINS, -(max_craft * 4)); + add_personal_count(ITEM_VINES, -(max_craft * 2)); + add_personal_count(ITEM_SKIN_TUNICS, max_craft); speak_with_history("Crafted " + max_craft + " Skin Tunics.", true); } void craft_moccasins() { string missing = ""; - if (inv_skins < 2) missing += "2 skins "; - if (inv_vines < 1) missing += "1 vine "; + if (get_personal_count(ITEM_SKINS) < 2) missing += "2 skins "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; if (missing == "") { - if (inv_moccasins >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_MOCCASINS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more moccasins.", true); return; } simulate_crafting(3); - inv_skins -= 2; - inv_vines--; - inv_moccasins++; + add_personal_count(ITEM_SKINS, -2); + add_personal_count(ITEM_VINES, -1); + add_personal_count(ITEM_MOCCASINS, 1); speak_with_history("Crafted moccasins.", true); } else { speak_with_history("Missing: " + missing, true); @@ -280,23 +280,23 @@ void craft_moccasins() { } void craft_moccasins_max() { - if (inv_moccasins >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_MOCCASINS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more moccasins.", true); return; } - int max_by_skins = inv_skins / 2; - int max_by_vines = inv_vines; + int max_by_skins = get_personal_count(ITEM_SKINS) / 2; + int max_by_vines = get_personal_count(ITEM_VINES); int max_craft = max_by_skins; if (max_by_vines < max_craft) max_craft = max_by_vines; - int space = get_personal_stack_limit() - inv_moccasins; + int space = get_personal_stack_limit() - get_personal_count(ITEM_MOCCASINS); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_skins < 2) missing += "2 skins "; - if (inv_vines < 1) missing += "1 vine "; + if (get_personal_count(ITEM_SKINS) < 2) missing += "2 skins "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; speak_with_history("Missing: " + missing, true); return; } @@ -304,26 +304,26 @@ void craft_moccasins_max() { int total_cost = max_craft * 3; // 2 skins + 1 vine per moccasins int craft_time = (total_cost < max_craft * 4) ? max_craft * 4 : total_cost; simulate_crafting(craft_time); - inv_skins -= (max_craft * 2); - inv_vines -= max_craft; - inv_moccasins += max_craft; + add_personal_count(ITEM_SKINS, -(max_craft * 2)); + add_personal_count(ITEM_VINES, -max_craft); + add_personal_count(ITEM_MOCCASINS, max_craft); speak_with_history("Crafted " + max_craft + " Moccasins.", true); } void craft_skin_pouch() { string missing = ""; - if (inv_skins < 2) missing += "2 skins "; - if (inv_vines < 1) missing += "1 vine "; + if (get_personal_count(ITEM_SKINS) < 2) missing += "2 skins "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; if (missing == "") { - if (inv_skin_pouches >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SKIN_POUCHES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more skin pouches.", true); return; } simulate_crafting(3); - inv_skins -= 2; - inv_vines--; - inv_skin_pouches++; + add_personal_count(ITEM_SKINS, -2); + add_personal_count(ITEM_VINES, -1); + add_personal_count(ITEM_SKIN_POUCHES, 1); speak_with_history("Crafted a Skin Pouch.", true); } else { speak_with_history("Missing: " + missing, true); @@ -331,23 +331,23 @@ void craft_skin_pouch() { } void craft_skin_pouch_max() { - if (inv_skin_pouches >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SKIN_POUCHES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more skin pouches.", true); return; } - int max_by_skins = inv_skins / 2; - int max_by_vines = inv_vines; + int max_by_skins = get_personal_count(ITEM_SKINS) / 2; + int max_by_vines = get_personal_count(ITEM_VINES); int max_craft = max_by_skins; if (max_by_vines < max_craft) max_craft = max_by_vines; - int space = get_personal_stack_limit() - inv_skin_pouches; + int space = get_personal_stack_limit() - get_personal_count(ITEM_SKIN_POUCHES); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_skins < 2) missing += "2 skins "; - if (inv_vines < 1) missing += "1 vine "; + if (get_personal_count(ITEM_SKINS) < 2) missing += "2 skins "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; speak_with_history("Missing: " + missing, true); return; } @@ -355,28 +355,28 @@ void craft_skin_pouch_max() { int total_cost = max_craft * 3; // 2 skins + 1 vine per pouch int craft_time = (total_cost < max_craft * 4) ? max_craft * 4 : total_cost; simulate_crafting(craft_time); - inv_skins -= (max_craft * 2); - inv_vines -= max_craft; - inv_skin_pouches += max_craft; + add_personal_count(ITEM_SKINS, -(max_craft * 2)); + add_personal_count(ITEM_VINES, -max_craft); + add_personal_count(ITEM_SKIN_POUCHES, max_craft); speak_with_history("Crafted " + max_craft + " Skin Pouches.", true); } void craft_backpack() { string missing = ""; - if (inv_skins < 11) missing += "11 skins "; - if (inv_vines < 5) missing += "5 vines "; - if (inv_skin_pouches < 4) missing += "4 skin pouches "; + if (get_personal_count(ITEM_SKINS) < 11) missing += "11 skins "; + if (get_personal_count(ITEM_VINES) < 5) missing += "5 vines "; + if (get_personal_count(ITEM_SKIN_POUCHES) < 4) missing += "4 skin pouches "; if (missing == "") { - if (inv_backpacks >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_BACKPACKS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more backpacks.", true); return; } simulate_crafting(20); - inv_skins -= 11; - inv_vines -= 5; - inv_skin_pouches -= 4; - inv_backpacks++; + add_personal_count(ITEM_SKINS, -11); + add_personal_count(ITEM_VINES, -5); + add_personal_count(ITEM_SKIN_POUCHES, -4); + add_personal_count(ITEM_BACKPACKS, 1); speak_with_history("Crafted a Backpack.", true); } else { speak_with_history("Missing: " + missing, true); @@ -384,35 +384,35 @@ void craft_backpack() { } void craft_backpack_max() { - if (inv_backpacks >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_BACKPACKS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more backpacks.", true); return; } - int max_by_skins = inv_skins / 11; - int max_by_vines = inv_vines / 5; - int max_by_pouches = inv_skin_pouches / 4; + int max_by_skins = get_personal_count(ITEM_SKINS) / 11; + int max_by_vines = get_personal_count(ITEM_VINES) / 5; + int max_by_pouches = get_personal_count(ITEM_SKIN_POUCHES) / 4; int max_craft = max_by_skins; if (max_by_vines < max_craft) max_craft = max_by_vines; if (max_by_pouches < max_craft) max_craft = max_by_pouches; - int space = get_personal_stack_limit() - inv_backpacks; + int space = get_personal_stack_limit() - get_personal_count(ITEM_BACKPACKS); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_skins < 11) missing += "11 skins "; - if (inv_vines < 5) missing += "5 vines "; - if (inv_skin_pouches < 4) missing += "4 skin pouches "; + if (get_personal_count(ITEM_SKINS) < 11) missing += "11 skins "; + if (get_personal_count(ITEM_VINES) < 5) missing += "5 vines "; + if (get_personal_count(ITEM_SKIN_POUCHES) < 4) missing += "4 skin pouches "; speak_with_history("Missing: " + missing, true); return; } int total_cost = max_craft * 20; // 11 skins + 5 vines + 4 pouches per backpack simulate_crafting(total_cost); - inv_skins -= (max_craft * 11); - inv_vines -= (max_craft * 5); - inv_skin_pouches -= (max_craft * 4); - inv_backpacks += max_craft; + add_personal_count(ITEM_SKINS, -(max_craft * 11)); + add_personal_count(ITEM_VINES, -(max_craft * 5)); + add_personal_count(ITEM_SKIN_POUCHES, -(max_craft * 4)); + add_personal_count(ITEM_BACKPACKS, max_craft); speak_with_history("Crafted " + max_craft + " Backpacks.", true); } diff --git a/src/crafting/craft_materials.nvgt b/src/crafting/craft_materials.nvgt index e9195fd..7b22ca4 100644 --- a/src/crafting/craft_materials.nvgt +++ b/src/crafting/craft_materials.nvgt @@ -49,20 +49,20 @@ void craft_incense() { } string missing = ""; - if (inv_sticks < INCENSE_STICK_COST) missing += INCENSE_STICK_COST + " sticks "; - if (inv_vines < INCENSE_VINE_COST) missing += INCENSE_VINE_COST + " vines "; - if (inv_reeds < INCENSE_REED_COST) missing += INCENSE_REED_COST + " reed "; + if (get_personal_count(ITEM_STICKS) < INCENSE_STICK_COST) missing += INCENSE_STICK_COST + " sticks "; + if (get_personal_count(ITEM_VINES) < INCENSE_VINE_COST) missing += INCENSE_VINE_COST + " vines "; + if (get_personal_count(ITEM_REEDS) < INCENSE_REED_COST) missing += INCENSE_REED_COST + " reed "; if (missing == "") { - if (inv_incense >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_INCENSE) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more incense.", true); return; } simulate_crafting(INCENSE_STICK_COST + INCENSE_VINE_COST + INCENSE_REED_COST); - inv_sticks -= INCENSE_STICK_COST; - inv_vines -= INCENSE_VINE_COST; - inv_reeds -= INCENSE_REED_COST; - inv_incense++; + add_personal_count(ITEM_STICKS, -INCENSE_STICK_COST); + add_personal_count(ITEM_VINES, -INCENSE_VINE_COST); + add_personal_count(ITEM_REEDS, -INCENSE_REED_COST); + add_personal_count(ITEM_INCENSE, 1); speak_with_history("Crafted incense.", true); } else { speak_with_history("Missing: " + missing, true); @@ -75,36 +75,36 @@ void craft_incense_max() { return; } - if (inv_incense >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_INCENSE) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more incense.", true); return; } - int max_by_sticks = inv_sticks / INCENSE_STICK_COST; - int max_by_vines = inv_vines / INCENSE_VINE_COST; - int max_by_reeds = inv_reeds / INCENSE_REED_COST; + int max_by_sticks = get_personal_count(ITEM_STICKS) / INCENSE_STICK_COST; + int max_by_vines = get_personal_count(ITEM_VINES) / INCENSE_VINE_COST; + int max_by_reeds = get_personal_count(ITEM_REEDS) / INCENSE_REED_COST; int max_craft = max_by_sticks; if (max_by_vines < max_craft) max_craft = max_by_vines; if (max_by_reeds < max_craft) max_craft = max_by_reeds; - int space = get_personal_stack_limit() - inv_incense; + int space = get_personal_stack_limit() - get_personal_count(ITEM_INCENSE); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_sticks < INCENSE_STICK_COST) missing += INCENSE_STICK_COST + " sticks "; - if (inv_vines < INCENSE_VINE_COST) missing += INCENSE_VINE_COST + " vines "; - if (inv_reeds < INCENSE_REED_COST) missing += INCENSE_REED_COST + " reed "; + if (get_personal_count(ITEM_STICKS) < INCENSE_STICK_COST) missing += INCENSE_STICK_COST + " sticks "; + if (get_personal_count(ITEM_VINES) < INCENSE_VINE_COST) missing += INCENSE_VINE_COST + " vines "; + if (get_personal_count(ITEM_REEDS) < INCENSE_REED_COST) missing += INCENSE_REED_COST + " reed "; speak_with_history("Missing: " + missing, true); return; } int total_cost = (max_craft * INCENSE_STICK_COST) + (max_craft * INCENSE_VINE_COST) + (max_craft * INCENSE_REED_COST); simulate_crafting(total_cost); - inv_sticks -= (max_craft * INCENSE_STICK_COST); - inv_vines -= (max_craft * INCENSE_VINE_COST); - inv_reeds -= (max_craft * INCENSE_REED_COST); - inv_incense += max_craft; + add_personal_count(ITEM_STICKS, -(max_craft * INCENSE_STICK_COST)); + add_personal_count(ITEM_VINES, -(max_craft * INCENSE_VINE_COST)); + add_personal_count(ITEM_REEDS, -(max_craft * INCENSE_REED_COST)); + add_personal_count(ITEM_INCENSE, max_craft); speak_with_history("Crafted " + max_craft + " Incense.", true); } @@ -112,10 +112,10 @@ void butcher_small_game() { string missing = ""; // Check for knife - if (inv_knives < 1) missing += "Stone Knife "; + if (get_personal_count(ITEM_KNIVES) < 1) missing += "Stone Knife "; // Check for small game or boar - if (inv_small_game < 1 && inv_boar_carcasses < 1) missing += "Game "; + if (get_personal_count(ITEM_SMALL_GAME) < 1 && get_personal_count(ITEM_BOAR_CARCASSES) < 1) missing += "Game "; // Check for fire within 3 tiles (can hear it) WorldFire@ fire = get_fire_within_range(x, 3); @@ -125,39 +125,39 @@ void butcher_small_game() { } if (missing == "") { - if (inv_meat >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_MEAT) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more meat.", true); return; } - if (inv_skins >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SKINS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more skins.", true); return; } simulate_crafting(1); string game_type = ""; - if (inv_boar_carcasses > 0) { + if (get_personal_count(ITEM_BOAR_CARCASSES) > 0) { game_type = "boar carcass"; - inv_boar_carcasses--; + add_personal_count(ITEM_BOAR_CARCASSES, -1); } else { - game_type = inv_small_game_types[0]; - inv_small_game_types.remove_at(0); - inv_small_game--; + game_type = personal_small_game_types[0]; + personal_small_game_types.remove_at(0); + add_personal_count(ITEM_SMALL_GAME, -1); } if (game_type == "goose") { - inv_meat++; - inv_feathers += random(3, 6); - inv_down += random(1, 3); + add_personal_count(ITEM_MEAT, 1); + add_personal_count(ITEM_FEATHERS, random(3, 6)); + add_personal_count(ITEM_DOWN, random(1, 3)); speak_with_history("Butchered goose. Got 1 meat, feathers, and down.", true); } else if (game_type == "boar carcass") { - inv_meat += random(2, 3); - inv_skins += 3; - inv_sinew += 2; + add_personal_count(ITEM_MEAT, random(2, 3)); + add_personal_count(ITEM_SKINS, 3); + add_personal_count(ITEM_SINEW, 2); speak_with_history("Butchered boar. Got meat, 3 skins, and 2 sinew.", true); } else { - inv_meat++; - inv_skins++; + add_personal_count(ITEM_MEAT, 1); + add_personal_count(ITEM_SKINS, 1); speak_with_history("Butchered " + game_type + ". Got 1 meat and 1 skin.", true); } @@ -172,13 +172,13 @@ void butcher_small_game_max() { string missing = ""; // Check for knife - if (inv_knives < 1) { + if (get_personal_count(ITEM_KNIVES) < 1) { speak_with_history("Missing: Stone Knife", true); return; } // Check for small game or boar - if (inv_small_game < 1 && inv_boar_carcasses < 1) { + if (get_personal_count(ITEM_SMALL_GAME) < 1 && get_personal_count(ITEM_BOAR_CARCASSES) < 1) { speak_with_history("Missing: Game", true); return; } @@ -191,8 +191,8 @@ void butcher_small_game_max() { } // Calculate space constraints - int meat_space = get_personal_stack_limit() - inv_meat; - int skins_space = get_personal_stack_limit() - inv_skins; + int meat_space = get_personal_stack_limit() - get_personal_count(ITEM_MEAT); + int skins_space = get_personal_stack_limit() - get_personal_count(ITEM_SKINS); if (meat_space <= 0) { speak_with_history("You can't carry any more meat.", true); @@ -204,7 +204,7 @@ void butcher_small_game_max() { } // Count available game - int total_game = inv_small_game + inv_boar_carcasses; + int total_game = get_personal_count(ITEM_SMALL_GAME) + get_personal_count(ITEM_BOAR_CARCASSES); // Determine limiting factor int max_craft = total_game; @@ -232,14 +232,14 @@ void butcher_small_game_max() { for (int i = 0; i < max_craft; i++) { string game_type = ""; - if (inv_boar_carcasses > 0) { + if (get_personal_count(ITEM_BOAR_CARCASSES) > 0) { game_type = "boar carcass"; - inv_boar_carcasses--; + add_personal_count(ITEM_BOAR_CARCASSES, -1); boars_count++; } else { - game_type = inv_small_game_types[0]; - inv_small_game_types.remove_at(0); - inv_small_game--; + game_type = personal_small_game_types[0]; + personal_small_game_types.remove_at(0); + add_personal_count(ITEM_SMALL_GAME, -1); if (game_type == "goose") geese_count++; } @@ -258,11 +258,11 @@ void butcher_small_game_max() { } // Add all outputs at once - inv_meat += total_meat; - inv_skins += total_skins; - inv_feathers += total_feathers; - inv_down += total_down; - inv_sinew += total_sinew; + add_personal_count(ITEM_MEAT, total_meat); + add_personal_count(ITEM_SKINS, total_skins); + add_personal_count(ITEM_FEATHERS, total_feathers); + add_personal_count(ITEM_DOWN, total_down); + add_personal_count(ITEM_SINEW, total_sinew); // Build result message string result = "Butchered " + max_craft + " game. Got " + total_meat + " meat"; diff --git a/src/crafting/craft_runes.nvgt b/src/crafting/craft_runes.nvgt index 7a2a2c5..db86a06 100644 --- a/src/crafting/craft_runes.nvgt +++ b/src/crafting/craft_runes.nvgt @@ -20,33 +20,33 @@ string get_base_equipment_name(int equip_type) { // Get inventory count for an equipment type int get_unruned_equipment_count(int equip_type) { - if (equip_type == EQUIP_SPEAR) return inv_spears; - if (equip_type == EQUIP_AXE) return inv_axes; - if (equip_type == EQUIP_SLING) return inv_slings; - if (equip_type == EQUIP_BOW) return inv_bows; - if (equip_type == EQUIP_HAT) return inv_skin_hats; - if (equip_type == EQUIP_GLOVES) return inv_skin_gloves; - if (equip_type == EQUIP_PANTS) return inv_skin_pants; - if (equip_type == EQUIP_TUNIC) return inv_skin_tunics; - if (equip_type == EQUIP_MOCCASINS) return inv_moccasins; - if (equip_type == EQUIP_POUCH) return inv_skin_pouches; - if (equip_type == EQUIP_BACKPACK) return inv_backpacks; + if (equip_type == EQUIP_SPEAR) return get_personal_count(ITEM_SPEARS); + if (equip_type == EQUIP_AXE) return get_personal_count(ITEM_AXES); + if (equip_type == EQUIP_SLING) return get_personal_count(ITEM_SLINGS); + if (equip_type == EQUIP_BOW) return get_personal_count(ITEM_BOWS); + if (equip_type == EQUIP_HAT) return get_personal_count(ITEM_SKIN_HATS); + if (equip_type == EQUIP_GLOVES) return get_personal_count(ITEM_SKIN_GLOVES); + if (equip_type == EQUIP_PANTS) return get_personal_count(ITEM_SKIN_PANTS); + if (equip_type == EQUIP_TUNIC) return get_personal_count(ITEM_SKIN_TUNICS); + if (equip_type == EQUIP_MOCCASINS) return get_personal_count(ITEM_MOCCASINS); + if (equip_type == EQUIP_POUCH) return get_personal_count(ITEM_SKIN_POUCHES); + if (equip_type == EQUIP_BACKPACK) return get_personal_count(ITEM_BACKPACKS); return 0; } // Decrement inventory for an equipment type void decrement_unruned_equipment(int equip_type) { - if (equip_type == EQUIP_SPEAR) { inv_spears--; return; } - if (equip_type == EQUIP_AXE) { inv_axes--; return; } - if (equip_type == EQUIP_SLING) { inv_slings--; return; } - if (equip_type == EQUIP_BOW) { inv_bows--; return; } - if (equip_type == EQUIP_HAT) { inv_skin_hats--; return; } - if (equip_type == EQUIP_GLOVES) { inv_skin_gloves--; return; } - if (equip_type == EQUIP_PANTS) { inv_skin_pants--; return; } - if (equip_type == EQUIP_TUNIC) { inv_skin_tunics--; return; } - if (equip_type == EQUIP_MOCCASINS) { inv_moccasins--; return; } - if (equip_type == EQUIP_POUCH) { inv_skin_pouches--; return; } - if (equip_type == EQUIP_BACKPACK) { inv_backpacks--; return; } + if (equip_type == EQUIP_SPEAR) { add_personal_count(ITEM_SPEARS, -1); return; } + if (equip_type == EQUIP_AXE) { add_personal_count(ITEM_AXES, -1); return; } + if (equip_type == EQUIP_SLING) { add_personal_count(ITEM_SLINGS, -1); return; } + if (equip_type == EQUIP_BOW) { add_personal_count(ITEM_BOWS, -1); return; } + if (equip_type == EQUIP_HAT) { add_personal_count(ITEM_SKIN_HATS, -1); return; } + if (equip_type == EQUIP_GLOVES) { add_personal_count(ITEM_SKIN_GLOVES, -1); return; } + if (equip_type == EQUIP_PANTS) { add_personal_count(ITEM_SKIN_PANTS, -1); return; } + if (equip_type == EQUIP_TUNIC) { add_personal_count(ITEM_SKIN_TUNICS, -1); return; } + if (equip_type == EQUIP_MOCCASINS) { add_personal_count(ITEM_MOCCASINS, -1); return; } + if (equip_type == EQUIP_POUCH) { add_personal_count(ITEM_SKIN_POUCHES, -1); return; } + if (equip_type == EQUIP_BACKPACK) { add_personal_count(ITEM_BACKPACKS, -1); return; } } void run_runes_menu() { @@ -158,8 +158,8 @@ void run_rune_equipment_menu(int rune_type) { void engrave_rune(int equip_type, int rune_type) { // Validate requirements string missing = ""; - if (inv_knives < 1) missing += "Stone Knife "; - if (inv_clay < 1) missing += "1 clay "; + if (get_personal_count(ITEM_KNIVES) < 1) missing += "Stone Knife "; + if (get_personal_count(ITEM_CLAY) < 1) missing += "1 clay "; if (favor < 1.0) missing += "1 favor "; // Check equipment is still available @@ -170,7 +170,7 @@ void engrave_rune(int equip_type, int rune_type) { if (missing == "") { // Consume materials (knife is not consumed, it's a tool) - inv_clay--; + add_personal_count(ITEM_CLAY, -1); favor -= 1.0; // Remove one unruned item from inventory diff --git a/src/crafting/craft_tools.nvgt b/src/crafting/craft_tools.nvgt index c86c0c0..d884b63 100644 --- a/src/crafting/craft_tools.nvgt +++ b/src/crafting/craft_tools.nvgt @@ -59,16 +59,16 @@ void run_tools_menu() { void craft_knife() { string missing = ""; - if (inv_stones < 2) missing += "2 stones "; + if (get_personal_count(ITEM_STONES) < 2) missing += "2 stones "; if (missing == "") { - if (inv_knives >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_KNIVES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more stone knives.", true); return; } simulate_crafting(2); - inv_stones -= 2; - inv_knives++; + add_personal_count(ITEM_STONES, -2); + add_personal_count(ITEM_KNIVES, 1); speak_with_history("Crafted a Stone Knife.", true); } else { speak_with_history("Missing: " + missing, true); @@ -76,13 +76,13 @@ void craft_knife() { } void craft_knife_max() { - if (inv_knives >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_KNIVES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more stone knives.", true); return; } - int max_possible = inv_stones / 2; - int space = get_personal_stack_limit() - inv_knives; + int max_possible = get_personal_count(ITEM_STONES) / 2; + int space = get_personal_stack_limit() - get_personal_count(ITEM_KNIVES); if (max_possible > space) max_possible = space; if (max_possible <= 0) { @@ -93,25 +93,25 @@ void craft_knife_max() { int total_cost = max_possible * 2; int craft_time = (total_cost < max_possible * 4) ? max_possible * 4 : total_cost; simulate_crafting(craft_time); - inv_stones -= (max_possible * 2); - inv_knives += max_possible; + add_personal_count(ITEM_STONES, -(max_possible * 2)); + add_personal_count(ITEM_KNIVES, max_possible); speak_with_history("Crafted " + max_possible + " Stone Knives.", true); } void craft_snare() { string missing = ""; - if (inv_sticks < 1) missing += "1 stick "; - if (inv_vines < 2) missing += "2 vines "; + if (get_personal_count(ITEM_STICKS) < 1) missing += "1 stick "; + if (get_personal_count(ITEM_VINES) < 2) missing += "2 vines "; if (missing == "") { - if (inv_snares >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SNARES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more snares.", true); return; } simulate_crafting(3); - inv_sticks--; - inv_vines -= 2; - inv_snares++; + add_personal_count(ITEM_STICKS, -1); + add_personal_count(ITEM_VINES, -2); + add_personal_count(ITEM_SNARES, 1); speak_with_history("Crafted a Snare.", true); } else { speak_with_history("Missing: " + missing, true); @@ -119,23 +119,23 @@ void craft_snare() { } void craft_snare_max() { - if (inv_snares >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SNARES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more snares.", true); return; } - int max_by_sticks = inv_sticks; - int max_by_vines = inv_vines / 2; + int max_by_sticks = get_personal_count(ITEM_STICKS); + int max_by_vines = get_personal_count(ITEM_VINES) / 2; int max_craft = max_by_sticks; if (max_by_vines < max_craft) max_craft = max_by_vines; - int space = get_personal_stack_limit() - inv_snares; + int space = get_personal_stack_limit() - get_personal_count(ITEM_SNARES); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_sticks < 1) missing += "1 stick "; - if (inv_vines < 2) missing += "2 vines "; + if (get_personal_count(ITEM_STICKS) < 1) missing += "1 stick "; + if (get_personal_count(ITEM_VINES) < 2) missing += "2 vines "; speak_with_history("Missing: " + missing, true); return; } @@ -143,26 +143,26 @@ void craft_snare_max() { int total_cost = max_craft * 3; // 1 stick + 2 vines per snare int craft_time = (total_cost < max_craft * 4) ? max_craft * 4 : total_cost; simulate_crafting(craft_time); - inv_sticks -= max_craft; - inv_vines -= (max_craft * 2); - inv_snares += max_craft; + add_personal_count(ITEM_STICKS, -max_craft); + add_personal_count(ITEM_VINES, -(max_craft * 2)); + add_personal_count(ITEM_SNARES, max_craft); speak_with_history("Crafted " + max_craft + " Snares.", true); } void craft_fishing_pole() { string missing = ""; - if (inv_sticks < 1) missing += "1 stick "; - if (inv_vines < 2) missing += "2 vines "; + if (get_personal_count(ITEM_STICKS) < 1) missing += "1 stick "; + if (get_personal_count(ITEM_VINES) < 2) missing += "2 vines "; if (missing == "") { - if (inv_fishing_poles >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_FISHING_POLES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more fishing poles.", true); return; } simulate_crafting(3); - inv_sticks--; - inv_vines -= 2; - inv_fishing_poles++; + add_personal_count(ITEM_STICKS, -1); + add_personal_count(ITEM_VINES, -2); + add_personal_count(ITEM_FISHING_POLES, 1); speak_with_history("Crafted a Fishing Pole.", true); } else { speak_with_history("Missing: " + missing, true); @@ -170,23 +170,23 @@ void craft_fishing_pole() { } void craft_fishing_pole_max() { - if (inv_fishing_poles >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_FISHING_POLES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more fishing poles.", true); return; } - int max_by_sticks = inv_sticks; - int max_by_vines = inv_vines / 2; + int max_by_sticks = get_personal_count(ITEM_STICKS); + int max_by_vines = get_personal_count(ITEM_VINES) / 2; int max_craft = max_by_sticks; if (max_by_vines < max_craft) max_craft = max_by_vines; - int space = get_personal_stack_limit() - inv_fishing_poles; + int space = get_personal_stack_limit() - get_personal_count(ITEM_FISHING_POLES); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_sticks < 1) missing += "1 stick "; - if (inv_vines < 2) missing += "2 vines "; + if (get_personal_count(ITEM_STICKS) < 1) missing += "1 stick "; + if (get_personal_count(ITEM_VINES) < 2) missing += "2 vines "; speak_with_history("Missing: " + missing, true); return; } @@ -194,24 +194,24 @@ void craft_fishing_pole_max() { int total_cost = max_craft * 3; // 1 stick + 2 vines per pole int craft_time = (total_cost < max_craft * 4) ? max_craft * 4 : total_cost; simulate_crafting(craft_time); - inv_sticks -= max_craft; - inv_vines -= (max_craft * 2); - inv_fishing_poles += max_craft; + add_personal_count(ITEM_STICKS, -max_craft); + add_personal_count(ITEM_VINES, -(max_craft * 2)); + add_personal_count(ITEM_FISHING_POLES, max_craft); speak_with_history("Crafted " + max_craft + " Fishing Poles.", true); } void craft_rope() { string missing = ""; - if (inv_vines < 3) missing += "3 vines "; + if (get_personal_count(ITEM_VINES) < 3) missing += "3 vines "; if (missing == "") { - if (inv_ropes >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_ROPES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more rope.", true); return; } simulate_crafting(3); - inv_vines -= 3; - inv_ropes++; + add_personal_count(ITEM_VINES, -3); + add_personal_count(ITEM_ROPES, 1); speak_with_history("Crafted rope.", true); } else { speak_with_history("Missing: " + missing, true); @@ -219,14 +219,14 @@ void craft_rope() { } void craft_rope_max() { - if (inv_ropes >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_ROPES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more rope.", true); return; } - int max_craft = inv_vines / 3; + int max_craft = get_personal_count(ITEM_VINES) / 3; - int space = get_personal_stack_limit() - inv_ropes; + int space = get_personal_stack_limit() - get_personal_count(ITEM_ROPES); if (max_craft > space) max_craft = space; if (max_craft <= 0) { @@ -237,23 +237,23 @@ void craft_rope_max() { int total_cost = max_craft * 3; // 3 vines per rope int craft_time = (total_cost < max_craft * 4) ? max_craft * 4 : total_cost; simulate_crafting(craft_time); - inv_vines -= (max_craft * 3); - inv_ropes += max_craft; + add_personal_count(ITEM_VINES, -(max_craft * 3)); + add_personal_count(ITEM_ROPES, max_craft); speak_with_history("Crafted " + max_craft + " Rope.", true); } void craft_reed_basket() { string missing = ""; - if (inv_reeds < 3) missing += "3 reeds "; + if (get_personal_count(ITEM_REEDS) < 3) missing += "3 reeds "; if (missing == "") { - if (inv_reed_baskets >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_REED_BASKETS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more reed baskets.", true); return; } simulate_crafting(3); - inv_reeds -= 3; - inv_reed_baskets++; + add_personal_count(ITEM_REEDS, -3); + add_personal_count(ITEM_REED_BASKETS, 1); speak_with_history("Crafted a reed basket.", true); } else { speak_with_history("Missing: " + missing, true); @@ -261,14 +261,14 @@ void craft_reed_basket() { } void craft_reed_basket_max() { - if (inv_reed_baskets >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_REED_BASKETS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more reed baskets.", true); return; } - int max_craft = inv_reeds / 3; + int max_craft = get_personal_count(ITEM_REEDS) / 3; - int space = get_personal_stack_limit() - inv_reed_baskets; + int space = get_personal_stack_limit() - get_personal_count(ITEM_REED_BASKETS); if (max_craft > space) max_craft = space; if (max_craft <= 0) { @@ -279,14 +279,14 @@ void craft_reed_basket_max() { int total_cost = max_craft * 3; // 3 reeds per basket int craft_time = (total_cost < max_craft * 4) ? max_craft * 4 : total_cost; simulate_crafting(craft_time); - inv_reeds -= (max_craft * 3); - inv_reed_baskets += max_craft; + add_personal_count(ITEM_REEDS, -(max_craft * 3)); + add_personal_count(ITEM_REED_BASKETS, max_craft); speak_with_history("Crafted " + max_craft + " Reed Baskets.", true); } void craft_clay_pot() { string missing = ""; - if (inv_clay < 3) missing += "3 clay "; + if (get_personal_count(ITEM_CLAY) < 3) missing += "3 clay "; // Check for fire within 3 tiles (can hear it) WorldFire@ fire = get_fire_within_range(x, 3); @@ -296,13 +296,13 @@ void craft_clay_pot() { } if (missing == "") { - if (inv_clay_pots >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_CLAY_POTS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more clay pots.", true); return; } simulate_crafting(3); - inv_clay -= 3; - inv_clay_pots++; + add_personal_count(ITEM_CLAY, -3); + add_personal_count(ITEM_CLAY_POTS, 1); speak_with_history("Crafted a clay pot.", true); } else { speak_with_history("Missing: " + missing, true); @@ -317,14 +317,14 @@ void craft_clay_pot_max() { return; } - if (inv_clay_pots >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_CLAY_POTS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more clay pots.", true); return; } - int max_craft = inv_clay / 3; + int max_craft = get_personal_count(ITEM_CLAY) / 3; - int space = get_personal_stack_limit() - inv_clay_pots; + int space = get_personal_stack_limit() - get_personal_count(ITEM_CLAY_POTS); if (max_craft > space) max_craft = space; if (max_craft <= 0) { @@ -335,7 +335,7 @@ void craft_clay_pot_max() { int total_cost = max_craft * 3; // 3 clay per pot int craft_time = (total_cost < max_craft * 4) ? max_craft * 4 : total_cost; simulate_crafting(craft_time); - inv_clay -= (max_craft * 3); - inv_clay_pots += max_craft; + add_personal_count(ITEM_CLAY, -(max_craft * 3)); + add_personal_count(ITEM_CLAY_POTS, max_craft); speak_with_history("Crafted " + max_craft + " Clay Pots.", true); } diff --git a/src/crafting/craft_weapons.nvgt b/src/crafting/craft_weapons.nvgt index 044035f..08594d0 100644 --- a/src/crafting/craft_weapons.nvgt +++ b/src/crafting/craft_weapons.nvgt @@ -44,21 +44,21 @@ void run_weapons_menu() { void craft_spear() { string missing = ""; - if (inv_knives < 1) missing += "Stone Knife "; - if (inv_sticks < 1) missing += "1 stick "; - if (inv_vines < 1) missing += "1 vine "; - if (inv_stones < 1) missing += "1 stone "; + if (get_personal_count(ITEM_KNIVES) < 1) missing += "Stone Knife "; + if (get_personal_count(ITEM_STICKS) < 1) missing += "1 stick "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; + if (get_personal_count(ITEM_STONES) < 1) missing += "1 stone "; if (missing == "") { - if (inv_spears >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SPEARS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more spears.", true); return; } simulate_crafting(3); - inv_sticks--; - inv_vines--; - inv_stones--; - inv_spears++; + add_personal_count(ITEM_STICKS, -1); + add_personal_count(ITEM_VINES, -1); + add_personal_count(ITEM_STONES, -1); + add_personal_count(ITEM_SPEARS, 1); speak_with_history("Crafted a Spear.", true); } else { speak_with_history("Missing: " + missing, true); @@ -66,30 +66,30 @@ void craft_spear() { } void craft_spear_max() { - if (inv_knives < 1) { + if (get_personal_count(ITEM_KNIVES) < 1) { speak_with_history("Missing: Stone Knife", true); return; } - if (inv_spears >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SPEARS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more spears.", true); return; } - int max_by_sticks = inv_sticks; - int max_by_vines = inv_vines; - int max_by_stones = inv_stones; + int max_by_sticks = get_personal_count(ITEM_STICKS); + int max_by_vines = get_personal_count(ITEM_VINES); + int max_by_stones = get_personal_count(ITEM_STONES); int max_craft = max_by_sticks; if (max_by_vines < max_craft) max_craft = max_by_vines; if (max_by_stones < max_craft) max_craft = max_by_stones; - int space = get_personal_stack_limit() - inv_spears; + int space = get_personal_stack_limit() - get_personal_count(ITEM_SPEARS); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_sticks < 1) missing += "1 stick "; - if (inv_vines < 1) missing += "1 vine "; - if (inv_stones < 1) missing += "1 stone "; + if (get_personal_count(ITEM_STICKS) < 1) missing += "1 stick "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; + if (get_personal_count(ITEM_STONES) < 1) missing += "1 stone "; speak_with_history("Missing: " + missing, true); return; } @@ -97,27 +97,27 @@ void craft_spear_max() { int total_cost = max_craft * 3; // 1 stick + 1 vine + 1 stone per spear int craft_time = (total_cost < max_craft * 4) ? max_craft * 4 : total_cost; simulate_crafting(craft_time); - inv_sticks -= max_craft; - inv_vines -= max_craft; - inv_stones -= max_craft; - inv_spears += max_craft; + add_personal_count(ITEM_STICKS, -max_craft); + add_personal_count(ITEM_VINES, -max_craft); + add_personal_count(ITEM_STONES, -max_craft); + add_personal_count(ITEM_SPEARS, max_craft); speak_with_history("Crafted " + max_craft + " Spears.", true); } void craft_sling() { string missing = ""; - if (inv_skins < 1) missing += "1 skin "; - if (inv_vines < 2) missing += "2 vines "; + if (get_personal_count(ITEM_SKINS) < 1) missing += "1 skin "; + if (get_personal_count(ITEM_VINES) < 2) missing += "2 vines "; if (missing == "") { - if (inv_slings >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SLINGS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more slings.", true); return; } simulate_crafting(3); - inv_skins--; - inv_vines -= 2; - inv_slings++; + add_personal_count(ITEM_SKINS, -1); + add_personal_count(ITEM_VINES, -2); + add_personal_count(ITEM_SLINGS, 1); speak_with_history("Crafted a Sling.", true); } else { speak_with_history("Missing: " + missing, true); @@ -125,23 +125,23 @@ void craft_sling() { } void craft_sling_max() { - if (inv_slings >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SLINGS) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more slings.", true); return; } - int max_by_skins = inv_skins; - int max_by_vines = inv_vines / 2; + int max_by_skins = get_personal_count(ITEM_SKINS); + int max_by_vines = get_personal_count(ITEM_VINES) / 2; int max_craft = max_by_skins; if (max_by_vines < max_craft) max_craft = max_by_vines; - int space = get_personal_stack_limit() - inv_slings; + int space = get_personal_stack_limit() - get_personal_count(ITEM_SLINGS); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_skins < 1) missing += "1 skin "; - if (inv_vines < 2) missing += "2 vines "; + if (get_personal_count(ITEM_SKINS) < 1) missing += "1 skin "; + if (get_personal_count(ITEM_VINES) < 2) missing += "2 vines "; speak_with_history("Missing: " + missing, true); return; } @@ -149,29 +149,29 @@ void craft_sling_max() { int total_cost = max_craft * 3; // 1 skin + 2 vines per sling int craft_time = (total_cost < max_craft * 4) ? max_craft * 4 : total_cost; simulate_crafting(craft_time); - inv_skins -= max_craft; - inv_vines -= (max_craft * 2); - inv_slings += max_craft; + add_personal_count(ITEM_SKINS, -max_craft); + add_personal_count(ITEM_VINES, -(max_craft * 2)); + add_personal_count(ITEM_SLINGS, max_craft); speak_with_history("Crafted " + max_craft + " Slings.", true); } void craft_axe() { string missing = ""; - if (inv_knives < 1) missing += "Stone Knife "; - if (inv_sticks < 1) missing += "1 stick "; - if (inv_vines < 1) missing += "1 vine "; - if (inv_stones < 2) missing += "2 stones "; + if (get_personal_count(ITEM_KNIVES) < 1) missing += "Stone Knife "; + if (get_personal_count(ITEM_STICKS) < 1) missing += "1 stick "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; + if (get_personal_count(ITEM_STONES) < 2) missing += "2 stones "; if (missing == "") { - if (inv_axes >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_AXES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more stone axes.", true); return; } simulate_crafting(4); - inv_sticks--; - inv_vines--; - inv_stones -= 2; - inv_axes++; + add_personal_count(ITEM_STICKS, -1); + add_personal_count(ITEM_VINES, -1); + add_personal_count(ITEM_STONES, -2); + add_personal_count(ITEM_AXES, 1); speak_with_history("Crafted a Stone Axe.", true); } else { speak_with_history("Missing: " + missing, true); @@ -179,39 +179,39 @@ void craft_axe() { } void craft_axe_max() { - if (inv_knives < 1) { + if (get_personal_count(ITEM_KNIVES) < 1) { speak_with_history("Missing: Stone Knife", true); return; } - if (inv_axes >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_AXES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more stone axes.", true); return; } - int max_by_sticks = inv_sticks; - int max_by_vines = inv_vines; - int max_by_stones = inv_stones / 2; + int max_by_sticks = get_personal_count(ITEM_STICKS); + int max_by_vines = get_personal_count(ITEM_VINES); + int max_by_stones = get_personal_count(ITEM_STONES) / 2; int max_craft = max_by_sticks; if (max_by_vines < max_craft) max_craft = max_by_vines; if (max_by_stones < max_craft) max_craft = max_by_stones; - int space = get_personal_stack_limit() - inv_axes; + int space = get_personal_stack_limit() - get_personal_count(ITEM_AXES); if (max_craft > space) max_craft = space; if (max_craft <= 0) { string missing = ""; - if (inv_sticks < 1) missing += "1 stick "; - if (inv_vines < 1) missing += "1 vine "; - if (inv_stones < 2) missing += "2 stones "; + if (get_personal_count(ITEM_STICKS) < 1) missing += "1 stick "; + if (get_personal_count(ITEM_VINES) < 1) missing += "1 vine "; + if (get_personal_count(ITEM_STONES) < 2) missing += "2 stones "; speak_with_history("Missing: " + missing, true); return; } int total_cost = max_craft * 4; // 1 stick + 1 vine + 2 stones per axe simulate_crafting(total_cost); - inv_sticks -= max_craft; - inv_vines -= max_craft; - inv_stones -= (max_craft * 2); - inv_axes += max_craft; + add_personal_count(ITEM_STICKS, -max_craft); + add_personal_count(ITEM_VINES, -max_craft); + add_personal_count(ITEM_STONES, -(max_craft * 2)); + add_personal_count(ITEM_AXES, max_craft); speak_with_history("Crafted " + max_craft + " Stone Axes.", true); } diff --git a/src/environment.nvgt b/src/environment.nvgt index 3cf13f8..5a55333 100644 --- a/src/environment.nvgt +++ b/src/environment.nvgt @@ -81,8 +81,7 @@ class Tree { void update() { // Only play tree sound if not chopped and within 3 tiles distance if (!is_chopped) { - int tree_distance = x - position; - if (tree_distance < 0) tree_distance = -tree_distance; + int tree_distance = abs(x - position); if (tree_distance <= TREE_SOUND_RANGE) { if (sound_handle == -1 || !p.sound_is_active(sound_handle)) { @@ -235,9 +234,7 @@ bool tree_too_close_in_area(int pos, int areaStart, int areaEnd, Tree@ ignoreTre if (@trees[i] is ignoreTree) continue; if (trees[i].position < areaStart || trees[i].position > areaEnd) continue; - int distance = trees[i].position - pos; - if (distance < 0) distance = -distance; - if (distance < TREE_MIN_DISTANCE) { + if (abs(trees[i].position - pos) < TREE_MIN_DISTANCE) { return true; } } @@ -369,9 +366,7 @@ void normalize_tree_positions() { if (areaTreeIndices.length() == 2) { Tree@ firstTree = trees[areaTreeIndices[0]]; Tree@ secondTree = trees[areaTreeIndices[1]]; - int distance = firstTree.position - secondTree.position; - if (distance < 0) distance = -distance; - if (distance < TREE_MIN_DISTANCE) { + if (abs(firstTree.position - secondTree.position) < TREE_MIN_DISTANCE) { if (!place_tree_in_area(secondTree, areaStart, areaEnd)) { place_tree_in_area(firstTree, areaStart, areaEnd); } @@ -427,12 +422,12 @@ void damage_tree(int target_x, int damage) { int sticks_dropped = random(1, 3); int vines_dropped = random(1, 2); - int sticks_added = add_to_stack(inv_sticks, sticks_dropped); - int vines_added = add_to_stack(inv_vines, vines_dropped); - int logs_added = add_to_stack(inv_logs, 1); - inv_sticks += sticks_added; - inv_vines += vines_added; - inv_logs += logs_added; + int sticks_added = add_to_stack(get_personal_count(ITEM_STICKS), sticks_dropped); + int vines_added = add_to_stack(get_personal_count(ITEM_VINES), vines_dropped); + int logs_added = add_to_stack(get_personal_count(ITEM_LOGS), 1); + add_personal_count(ITEM_STICKS, sticks_added); + add_personal_count(ITEM_VINES, vines_added); + add_personal_count(ITEM_LOGS, logs_added); string drop_message = "Tree fell!"; if (sticks_added > 0 || vines_added > 0 || logs_added > 0) { @@ -478,24 +473,24 @@ void perform_search(int current_x) WorldSnare@ s = get_snare_at(check_x); if (s != null) { if (s.has_catch) { - if (inv_small_game >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SMALL_GAME) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more small game.", true); return; } - if (inv_snares >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SNARES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more snares.", true); return; } - inv_small_game++; - inv_small_game_types.insert_last(s.catch_type); - inv_snares++; // Recover snare + add_personal_count(ITEM_SMALL_GAME, 1); + personal_small_game_types.insert_last(s.catch_type); + add_personal_count(ITEM_SNARES, 1); // Recover snare speak_with_history("Collected " + s.catch_type + " and snare.", true); } else { - if (inv_snares >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SNARES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more snares.", true); return; } - inv_snares++; // Recover snare + add_personal_count(ITEM_SNARES, 1); // Recover snare speak_with_history("Collected snare.", true); } p.play_stationary("sounds/items/miscellaneous.ogg", false); @@ -516,9 +511,7 @@ void perform_search(int current_x) continue; } int center = world_streams[i].get_center_position(); - int distance = center - current_x; - if (distance < 0) distance = -distance; - if (distance <= 3) { + if (abs(center - current_x) <= 3) { near_stream_bank = true; break; } @@ -527,27 +520,27 @@ void perform_search(int current_x) if (near_stream_bank) { bool found_reed = random(1, 100) <= 30; if (found_reed) { - if (inv_reeds < get_personal_stack_limit()) { - inv_reeds++; + if (get_personal_count(ITEM_REEDS) < get_personal_stack_limit()) { + add_personal_count(ITEM_REEDS, 1); p.play_stationary("sounds/items/stick.ogg", false); speak_with_history("Found a reed.", true); return; } } else { - if (inv_clay < get_personal_stack_limit()) { - inv_clay++; + if (get_personal_count(ITEM_CLAY) < get_personal_stack_limit()) { + add_personal_count(ITEM_CLAY, 1); p.play_stationary("sounds/items/clay.ogg", false); speak_with_history("Found clay.", true); return; } } - if (!found_reed && inv_reeds < get_personal_stack_limit()) { - inv_reeds++; + if (!found_reed && get_personal_count(ITEM_REEDS) < get_personal_stack_limit()) { + add_personal_count(ITEM_REEDS, 1); p.play_stationary("sounds/items/stick.ogg", false); speak_with_history("Found a reed.", true); - } else if (found_reed && inv_clay < get_personal_stack_limit()) { - inv_clay++; + } else if (found_reed && get_personal_count(ITEM_CLAY) < get_personal_stack_limit()) { + add_personal_count(ITEM_CLAY, 1); p.play_stationary("sounds/items/clay.ogg", false); speak_with_history("Found clay.", true); } else if (found_reed) { @@ -569,8 +562,7 @@ void perform_search(int current_x) if (!skip_tree_search) { for(uint i=0; i 0 && inv_sticks < get_personal_stack_limit()) { + if (nearest.sticks > 0 && get_personal_count(ITEM_STICKS) < get_personal_stack_limit()) { nearest.sticks--; - inv_sticks++; + add_personal_count(ITEM_STICKS, 1); p.play_stationary("sounds/items/stick.ogg", false); speak_with_history("Found a stick.", true); took_item = true; - } else if (nearest.vines > 0 && inv_vines < get_personal_stack_limit()) { + } else if (nearest.vines > 0 && get_personal_count(ITEM_VINES) < get_personal_stack_limit()) { nearest.vines--; - inv_vines++; + add_personal_count(ITEM_VINES, 1); p.play_stationary("sounds/items/vine.ogg", false); speak_with_history("Found a vine.", true); took_item = true; } } else { - if (nearest.vines > 0 && inv_vines < get_personal_stack_limit()) { + if (nearest.vines > 0 && get_personal_count(ITEM_VINES) < get_personal_stack_limit()) { nearest.vines--; - inv_vines++; + add_personal_count(ITEM_VINES, 1); p.play_stationary("sounds/items/vine.ogg", false); speak_with_history("Found a vine.", true); took_item = true; - } else if (nearest.sticks > 0 && inv_sticks < get_personal_stack_limit()) { + } else if (nearest.sticks > 0 && get_personal_count(ITEM_STICKS) < get_personal_stack_limit()) { nearest.sticks--; - inv_sticks++; + add_personal_count(ITEM_STICKS, 1); p.play_stationary("sounds/items/stick.ogg", false); speak_with_history("Found a stick.", true); took_item = true; @@ -687,9 +679,9 @@ void perform_search(int current_x) if (is_stone_terrain) { - if (inv_stones < get_personal_stack_limit()) + if (get_personal_count(ITEM_STONES) < get_personal_stack_limit()) { - inv_stones++; + add_personal_count(ITEM_STONES, 1); p.play_stationary("sounds/items/stone.ogg", false); speak_with_history("Found a stone.", true); } @@ -728,8 +720,8 @@ void perform_search(int current_x) if (is_forest_terrain) { - bool can_find_stick = inv_sticks < get_personal_stack_limit(); - bool can_find_vine = inv_vines < get_personal_stack_limit(); + bool can_find_stick = get_personal_count(ITEM_STICKS) < get_personal_stack_limit(); + bool can_find_vine = get_personal_count(ITEM_VINES) < get_personal_stack_limit(); if (!can_find_stick && !can_find_vine) { speak_with_history("You can't carry any more sticks or vines.", true); @@ -740,11 +732,11 @@ void perform_search(int current_x) bool find_stick = can_find_stick && (!can_find_vine || random(0, 1) == 0); if (find_stick) { - inv_sticks++; + add_personal_count(ITEM_STICKS, 1); p.play_stationary("sounds/items/stick.ogg", false); speak_with_history("Found a stick.", true); } else { - inv_vines++; + add_personal_count(ITEM_VINES, 1); p.play_stationary("sounds/items/vine.ogg", false); speak_with_history("Found a vine.", true); } @@ -887,7 +879,7 @@ bool can_move_mountain(int from_x, int to_x) { // Check elevation change if (mountain.is_steep_section(from_x, to_x)) { // Need rope - if (inv_ropes < 1) { + if (get_personal_count(ITEM_ROPES) < 1) { speak_with_history("You'll need a rope to climb there.", true); return false; } @@ -930,8 +922,7 @@ void start_rope_climb(bool climbing_up, int target_x, int target_elevation) { } // Calculate distance to climb (use actual distance from current position) - int distance = elevation_diff; - if (distance < 0) distance = -distance; + int distance = abs(elevation_diff); string direction = rope_climb_up ? "up" : "down"; speak_with_history("Climbing " + direction + ". " + distance + " feet.", true); diff --git a/src/flying_creature_template.nvgt b/src/flying_creature_template.nvgt index 024557e..c5b1baa 100644 --- a/src/flying_creature_template.nvgt +++ b/src/flying_creature_template.nvgt @@ -64,8 +64,8 @@ // Example: // if (game_type == "duck") { -// inv_meat++; -// inv_feathers += random(2, 4); -// inv_down += random(1, 2); +// add_personal_count(ITEM_MEAT, 1); +// add_personal_count(ITEM_FEATHERS, random(2, 4)); +// add_personal_count(ITEM_DOWN, random(1, 2)); // speak_with_history("Butchered duck. Got 1 meat, feathers, and down.", true); // } diff --git a/src/inventory.nvgt b/src/inventory.nvgt index 797dc5a..58be70a 100644 --- a/src/inventory.nvgt +++ b/src/inventory.nvgt @@ -1,4 +1,5 @@ // Inventory module includes +#include "src/item_registry.nvgt" #include "src/inventory_items.nvgt" #include "src/runes/rune_data.nvgt" #include "src/runes/rune_effects.nvgt" diff --git a/src/inventory_items.nvgt b/src/inventory_items.nvgt index 0b2ad16..8c7f1a6 100644 --- a/src/inventory_items.nvgt +++ b/src/inventory_items.nvgt @@ -1,135 +1,33 @@ // Inventory items and equipment -int inv_stones = 0; -int inv_sticks = 0; -int inv_vines = 0; -int inv_reeds = 0; -int inv_logs = 0; -int inv_clay = 0; -int inv_small_game = 0; // Total small game caught (any type) -string[] inv_small_game_types; // Array to track what types of small game we have +// Item storage is now handled by item_registry.nvgt -int inv_meat = 0; -int inv_skins = 0; -int inv_feathers = 0; -int inv_down = 0; -int inv_incense = 0; -int inv_bows = 0; -int inv_arrows = 0; -int inv_quivers = 0; -int inv_bowstrings = 0; -int inv_sinew = 0; -int inv_boar_carcasses = 0; - -int inv_spears = 0; -int inv_snares = 0; -int inv_axes = 0; -int inv_knives = 0; -int inv_fishing_poles = 0; -int inv_slings = 0; -int inv_ropes = 0; -int inv_reed_baskets = 0; -int inv_clay_pots = 0; -int inv_skin_hats = 0; -int inv_skin_gloves = 0; -int inv_skin_pants = 0; -int inv_skin_tunics = 0; -int inv_moccasins = 0; -int inv_skin_pouches = 0; -int inv_backpacks = 0; - -int storage_stones = 0; -int storage_sticks = 0; -int storage_vines = 0; -int storage_reeds = 0; -int storage_logs = 0; -int storage_clay = 0; -int storage_small_game = 0; -string[] storage_small_game_types; -int storage_meat = 0; -int storage_skins = 0; -int storage_feathers = 0; -int storage_down = 0; -int storage_incense = 0; -int storage_bows = 0; -int storage_arrows = 0; -int storage_quivers = 0; -int storage_bowstrings = 0; -int storage_sinew = 0; -int storage_boar_carcasses = 0; - -int storage_spears = 0; -int storage_snares = 0; -int storage_axes = 0; -int storage_knives = 0; -int storage_fishing_poles = 0; -int storage_slings = 0; -int storage_ropes = 0; -int storage_reed_baskets = 0; -int storage_clay_pots = 0; -int storage_skin_hats = 0; -int storage_skin_gloves = 0; -int storage_skin_pants = 0; -int storage_skin_tunics = 0; -int storage_moccasins = 0; -int storage_skin_pouches = 0; -int storage_backpacks = 0; - -bool spear_equipped = false; -bool axe_equipped = false; -bool sling_equipped = false; -bool bow_equipped = false; -int[] quick_slots; +// Equipment type constants const int EQUIP_NONE = -1; const int EQUIP_SPEAR = 0; const int EQUIP_AXE = 1; const int EQUIP_SLING = 2; -const int EQUIP_BOW = 9; // Next available ID const int EQUIP_HAT = 3; const int EQUIP_GLOVES = 4; const int EQUIP_PANTS = 5; const int EQUIP_TUNIC = 6; const int EQUIP_MOCCASINS = 7; const int EQUIP_POUCH = 8; +const int EQUIP_BOW = 9; const int EQUIP_BACKPACK = 10; -const int ITEM_STICKS = 0; -const int ITEM_VINES = 1; -const int ITEM_REEDS = 2; -const int ITEM_STONES = 3; -const int ITEM_LOGS = 4; -const int ITEM_CLAY = 5; -const int ITEM_SMALL_GAME = 6; -const int ITEM_MEAT = 7; -const int ITEM_SKINS = 8; -const int ITEM_SPEARS = 9; -const int ITEM_SLINGS = 10; -const int ITEM_AXES = 11; -const int ITEM_SNARES = 12; -const int ITEM_KNIVES = 13; -const int ITEM_FISHING_POLES = 14; -const int ITEM_SKIN_HATS = 15; -const int ITEM_SKIN_GLOVES = 16; -const int ITEM_SKIN_PANTS = 17; -const int ITEM_SKIN_TUNICS = 18; -const int ITEM_MOCCASINS = 19; -const int ITEM_SKIN_POUCHES = 20; -const int ITEM_ROPES = 21; -const int ITEM_REED_BASKETS = 22; -const int ITEM_CLAY_POTS = 23; -const int ITEM_FEATHERS = 24; -const int ITEM_DOWN = 25; -const int ITEM_INCENSE = 26; -const int ITEM_BOWS = 27; -const int ITEM_ARROWS = 28; -const int ITEM_QUIVERS = 29; -const int ITEM_BOWSTRINGS = 30; -const int ITEM_SINEW = 31; -const int ITEM_BOAR_CARCASSES = 32; -const int ITEM_BACKPACKS = 33; + +// Health bonuses from equipment const int HAT_MAX_HEALTH_BONUS = 1; const int GLOVES_MAX_HEALTH_BONUS = 1; const int PANTS_MAX_HEALTH_BONUS = 3; const int TUNIC_MAX_HEALTH_BONUS = 4; const int MOCCASINS_MAX_HEALTH_BONUS = 2; + +// Equipment state +bool spear_equipped = false; +bool axe_equipped = false; +bool sling_equipped = false; +bool bow_equipped = false; + int equipped_head = EQUIP_NONE; int equipped_torso = EQUIP_NONE; int equipped_arms = EQUIP_NONE; @@ -137,6 +35,9 @@ int equipped_hands = EQUIP_NONE; int equipped_legs = EQUIP_NONE; int equipped_feet = EQUIP_NONE; +// Quick slots +int[] quick_slots; + void reset_quick_slots() { quick_slots.resize(10); for (uint i = 0; i < quick_slots.length(); i++) { @@ -157,8 +58,9 @@ int get_personal_stack_limit() { int get_arrow_limit() { // Quiver required to hold arrows // Each quiver holds 12 arrows - if (inv_quivers == 0) return 0; - return inv_quivers * ARROW_CAPACITY_PER_QUIVER; + int quivers = get_personal_count(ITEM_QUIVERS); + if (quivers == 0) return 0; + return quivers * ARROW_CAPACITY_PER_QUIVER; } string get_equipment_name(int equip_type) { @@ -177,18 +79,18 @@ string get_equipment_name(int equip_type) { } bool equipment_available(int equip_type) { - // Check unruned items first - if (equip_type == EQUIP_SPEAR) return inv_spears > 0 || has_any_runed_version(equip_type); - if (equip_type == EQUIP_AXE) return inv_axes > 0 || has_any_runed_version(equip_type); - if (equip_type == EQUIP_SLING) return inv_slings > 0 || has_any_runed_version(equip_type); - if (equip_type == EQUIP_BOW) return inv_bows > 0 || has_any_runed_version(equip_type); - if (equip_type == EQUIP_HAT) return inv_skin_hats > 0 || has_any_runed_version(equip_type); - if (equip_type == EQUIP_GLOVES) return inv_skin_gloves > 0 || has_any_runed_version(equip_type); - if (equip_type == EQUIP_PANTS) return inv_skin_pants > 0 || has_any_runed_version(equip_type); - if (equip_type == EQUIP_TUNIC) return inv_skin_tunics > 0 || has_any_runed_version(equip_type); - if (equip_type == EQUIP_MOCCASINS) return inv_moccasins > 0 || has_any_runed_version(equip_type); - if (equip_type == EQUIP_POUCH) return inv_skin_pouches > 0 || has_any_runed_version(equip_type); - if (equip_type == EQUIP_BACKPACK) return inv_backpacks > 0 || has_any_runed_version(equip_type); + // Check unruned items first, then runed versions + if (equip_type == EQUIP_SPEAR) return get_personal_count(ITEM_SPEARS) > 0 || has_any_runed_version(equip_type); + if (equip_type == EQUIP_AXE) return get_personal_count(ITEM_AXES) > 0 || has_any_runed_version(equip_type); + if (equip_type == EQUIP_SLING) return get_personal_count(ITEM_SLINGS) > 0 || has_any_runed_version(equip_type); + if (equip_type == EQUIP_BOW) return get_personal_count(ITEM_BOWS) > 0 || has_any_runed_version(equip_type); + if (equip_type == EQUIP_HAT) return get_personal_count(ITEM_SKIN_HATS) > 0 || has_any_runed_version(equip_type); + if (equip_type == EQUIP_GLOVES) return get_personal_count(ITEM_SKIN_GLOVES) > 0 || has_any_runed_version(equip_type); + if (equip_type == EQUIP_PANTS) return get_personal_count(ITEM_SKIN_PANTS) > 0 || has_any_runed_version(equip_type); + if (equip_type == EQUIP_TUNIC) return get_personal_count(ITEM_SKIN_TUNICS) > 0 || has_any_runed_version(equip_type); + if (equip_type == EQUIP_MOCCASINS) return get_personal_count(ITEM_MOCCASINS) > 0 || has_any_runed_version(equip_type); + if (equip_type == EQUIP_POUCH) return get_personal_count(ITEM_SKIN_POUCHES) > 0 || has_any_runed_version(equip_type); + if (equip_type == EQUIP_BACKPACK) return get_personal_count(ITEM_BACKPACKS) > 0 || has_any_runed_version(equip_type); return false; } @@ -329,201 +231,11 @@ int add_to_stack(int current, int amount) { return amount; } -int get_personal_count(int item_type) { - if (item_type == ITEM_STICKS) return inv_sticks; - if (item_type == ITEM_VINES) return inv_vines; - if (item_type == ITEM_REEDS) return inv_reeds; - if (item_type == ITEM_STONES) return inv_stones; - if (item_type == ITEM_LOGS) return inv_logs; - if (item_type == ITEM_CLAY) return inv_clay; - if (item_type == ITEM_SMALL_GAME) return inv_small_game; - if (item_type == ITEM_MEAT) return inv_meat; - if (item_type == ITEM_SKINS) return inv_skins; - if (item_type == ITEM_FEATHERS) return inv_feathers; - if (item_type == ITEM_DOWN) return inv_down; - if (item_type == ITEM_INCENSE) return inv_incense; - if (item_type == ITEM_BOWS) return inv_bows; - if (item_type == ITEM_ARROWS) return inv_arrows; - if (item_type == ITEM_QUIVERS) return inv_quivers; - if (item_type == ITEM_BOWSTRINGS) return inv_bowstrings; - if (item_type == ITEM_SINEW) return inv_sinew; - if (item_type == ITEM_BOAR_CARCASSES) return inv_boar_carcasses; - if (item_type == ITEM_SPEARS) return inv_spears; - if (item_type == ITEM_SLINGS) return inv_slings; - if (item_type == ITEM_AXES) return inv_axes; - if (item_type == ITEM_SNARES) return inv_snares; - if (item_type == ITEM_KNIVES) return inv_knives; - if (item_type == ITEM_FISHING_POLES) return inv_fishing_poles; - if (item_type == ITEM_ROPES) return inv_ropes; - if (item_type == ITEM_REED_BASKETS) return inv_reed_baskets; - if (item_type == ITEM_CLAY_POTS) return inv_clay_pots; - if (item_type == ITEM_SKIN_HATS) return inv_skin_hats; - if (item_type == ITEM_SKIN_GLOVES) return inv_skin_gloves; - if (item_type == ITEM_SKIN_PANTS) return inv_skin_pants; - if (item_type == ITEM_SKIN_TUNICS) return inv_skin_tunics; - if (item_type == ITEM_MOCCASINS) return inv_moccasins; - if (item_type == ITEM_SKIN_POUCHES) return inv_skin_pouches; - if (item_type == ITEM_BACKPACKS) return inv_backpacks; - return 0; -} - -int get_storage_count(int item_type) { - if (item_type == ITEM_STICKS) return storage_sticks; - if (item_type == ITEM_VINES) return storage_vines; - if (item_type == ITEM_REEDS) return storage_reeds; - if (item_type == ITEM_STONES) return storage_stones; - if (item_type == ITEM_LOGS) return storage_logs; - if (item_type == ITEM_CLAY) return storage_clay; - if (item_type == ITEM_SMALL_GAME) return storage_small_game; - if (item_type == ITEM_MEAT) return storage_meat; - if (item_type == ITEM_SKINS) return storage_skins; - if (item_type == ITEM_FEATHERS) return storage_feathers; - if (item_type == ITEM_DOWN) return storage_down; - if (item_type == ITEM_INCENSE) return storage_incense; - if (item_type == ITEM_BOWS) return storage_bows; - if (item_type == ITEM_ARROWS) return storage_arrows; - if (item_type == ITEM_QUIVERS) return storage_quivers; - if (item_type == ITEM_BOWSTRINGS) return storage_bowstrings; - if (item_type == ITEM_SINEW) return storage_sinew; - if (item_type == ITEM_BOAR_CARCASSES) return storage_boar_carcasses; - if (item_type == ITEM_SPEARS) return storage_spears; - if (item_type == ITEM_SLINGS) return storage_slings; - if (item_type == ITEM_AXES) return storage_axes; - if (item_type == ITEM_SNARES) return storage_snares; - if (item_type == ITEM_KNIVES) return storage_knives; - if (item_type == ITEM_FISHING_POLES) return storage_fishing_poles; - if (item_type == ITEM_ROPES) return storage_ropes; - if (item_type == ITEM_REED_BASKETS) return storage_reed_baskets; - if (item_type == ITEM_CLAY_POTS) return storage_clay_pots; - if (item_type == ITEM_SKIN_HATS) return storage_skin_hats; - if (item_type == ITEM_SKIN_GLOVES) return storage_skin_gloves; - if (item_type == ITEM_SKIN_PANTS) return storage_skin_pants; - if (item_type == ITEM_SKIN_TUNICS) return storage_skin_tunics; - if (item_type == ITEM_MOCCASINS) return storage_moccasins; - if (item_type == ITEM_SKIN_POUCHES) return storage_skin_pouches; - if (item_type == ITEM_BACKPACKS) return storage_backpacks; - return 0; -} - -string get_item_label(int item_type) { - if (item_type == ITEM_STICKS) return "sticks"; - if (item_type == ITEM_VINES) return "vines"; - if (item_type == ITEM_REEDS) return "reeds"; - if (item_type == ITEM_STONES) return "stones"; - if (item_type == ITEM_LOGS) return "logs"; - if (item_type == ITEM_CLAY) return "clay"; - if (item_type == ITEM_SMALL_GAME) return "small game"; - if (item_type == ITEM_MEAT) return "meat"; - if (item_type == ITEM_SKINS) return "skins"; - if (item_type == ITEM_FEATHERS) return "feathers"; - if (item_type == ITEM_DOWN) return "down"; - if (item_type == ITEM_INCENSE) return "incense"; - if (item_type == ITEM_BOWS) return "bows"; - if (item_type == ITEM_ARROWS) return "arrows"; - if (item_type == ITEM_QUIVERS) return "quivers"; - if (item_type == ITEM_BOWSTRINGS) return "bowstrings"; - if (item_type == ITEM_SINEW) return "sinew"; - if (item_type == ITEM_BOAR_CARCASSES) return "boar carcasses"; - if (item_type == ITEM_SPEARS) return "spears"; - if (item_type == ITEM_SLINGS) return "slings"; - if (item_type == ITEM_AXES) return "axes"; - if (item_type == ITEM_SNARES) return "snares"; - if (item_type == ITEM_KNIVES) return "knives"; - if (item_type == ITEM_FISHING_POLES) return "fishing poles"; - if (item_type == ITEM_ROPES) return "ropes"; - if (item_type == ITEM_REED_BASKETS) return "reed baskets"; - if (item_type == ITEM_CLAY_POTS) return "clay pots"; - if (item_type == ITEM_SKIN_HATS) return "skin hats"; - if (item_type == ITEM_SKIN_GLOVES) return "skin gloves"; - if (item_type == ITEM_SKIN_PANTS) return "skin pants"; - if (item_type == ITEM_SKIN_TUNICS) return "skin tunics"; - if (item_type == ITEM_MOCCASINS) return "moccasins"; - if (item_type == ITEM_SKIN_POUCHES) return "skin pouches"; - if (item_type == ITEM_BACKPACKS) return "backpacks"; - return "items"; -} - string format_favor(double value) { if (value < 0) value = 0; return "" + int(value); } -string get_item_label_singular(int item_type) { - if (item_type == ITEM_STICKS) return "stick"; - if (item_type == ITEM_VINES) return "vine"; - if (item_type == ITEM_REEDS) return "reed"; - if (item_type == ITEM_STONES) return "stone"; - if (item_type == ITEM_LOGS) return "log"; - if (item_type == ITEM_CLAY) return "clay"; - if (item_type == ITEM_SMALL_GAME) return "small game"; - if (item_type == ITEM_MEAT) return "meat"; - if (item_type == ITEM_SKINS) return "skin"; - if (item_type == ITEM_FEATHERS) return "feather"; - if (item_type == ITEM_DOWN) return "down"; - if (item_type == ITEM_INCENSE) return "incense stick"; - if (item_type == ITEM_BOWS) return "bow"; - if (item_type == ITEM_ARROWS) return "arrow"; - if (item_type == ITEM_QUIVERS) return "quiver"; - if (item_type == ITEM_BOWSTRINGS) return "bowstring"; - if (item_type == ITEM_SINEW) return "piece of sinew"; - if (item_type == ITEM_BOAR_CARCASSES) return "boar carcass"; - if (item_type == ITEM_SPEARS) return "spear"; - if (item_type == ITEM_SLINGS) return "sling"; - if (item_type == ITEM_AXES) return "axe"; - if (item_type == ITEM_SNARES) return "snare"; - if (item_type == ITEM_KNIVES) return "knife"; - if (item_type == ITEM_FISHING_POLES) return "fishing pole"; - if (item_type == ITEM_ROPES) return "rope"; - if (item_type == ITEM_REED_BASKETS) return "reed basket"; - if (item_type == ITEM_CLAY_POTS) return "clay pot"; - if (item_type == ITEM_SKIN_HATS) return "skin hat"; - if (item_type == ITEM_SKIN_GLOVES) return "skin glove"; - if (item_type == ITEM_SKIN_PANTS) return "skin pants"; - if (item_type == ITEM_SKIN_TUNICS) return "skin tunic"; - if (item_type == ITEM_MOCCASINS) return "moccasin"; - if (item_type == ITEM_SKIN_POUCHES) return "skin pouch"; - if (item_type == ITEM_BACKPACKS) return "backpack"; - return "item"; -} - -double get_item_favor_value(int item_type) { - if (item_type == ITEM_STICKS) return 0.01; - if (item_type == ITEM_VINES) return 0.01; - if (item_type == ITEM_REEDS) return 0.01; - if (item_type == ITEM_STONES) return 0.02; - if (item_type == ITEM_LOGS) return 0.05; - if (item_type == ITEM_CLAY) return 0.02; - if (item_type == ITEM_SMALL_GAME) return 0.20; - if (item_type == ITEM_MEAT) return 0.15; - if (item_type == ITEM_SKINS) return 0.15; - if (item_type == ITEM_FEATHERS) return 0.05; - if (item_type == ITEM_DOWN) return 0.05; - if (item_type == ITEM_INCENSE) return 0.10; - if (item_type == ITEM_BOWS) return 2.50; - if (item_type == ITEM_ARROWS) return 0.05; - if (item_type == ITEM_QUIVERS) return 1.50; - if (item_type == ITEM_BOWSTRINGS) return 0.20; - if (item_type == ITEM_SINEW) return 0.10; - if (item_type == ITEM_BOAR_CARCASSES) return 1.50; - if (item_type == ITEM_SPEARS) return 1.00; - if (item_type == ITEM_SLINGS) return 2.00; - if (item_type == ITEM_AXES) return 1.50; - if (item_type == ITEM_SNARES) return 0.50; - if (item_type == ITEM_KNIVES) return 0.80; - if (item_type == ITEM_FISHING_POLES) return 0.80; - if (item_type == ITEM_ROPES) return 0.40; - if (item_type == ITEM_REED_BASKETS) return 0.60; - if (item_type == ITEM_CLAY_POTS) return 0.70; - if (item_type == ITEM_SKIN_HATS) return 0.60; - if (item_type == ITEM_SKIN_GLOVES) return 0.60; - if (item_type == ITEM_SKIN_PANTS) return 1.20; - if (item_type == ITEM_SKIN_TUNICS) return 1.20; - if (item_type == ITEM_MOCCASINS) return 0.80; - if (item_type == ITEM_SKIN_POUCHES) return 0.80; - if (item_type == ITEM_BACKPACKS) return 2.50; - return 0.01; -} - string get_equipped_weapon_name() { if (spear_equipped) return "Spear"; if (axe_equipped) return "Stone Axe"; @@ -551,16 +263,16 @@ string get_speed_status() { } void cleanup_equipment_after_inventory_change() { - if (inv_spears <= 0) spear_equipped = false; - if (inv_axes <= 0) axe_equipped = false; - if (inv_slings <= 0) sling_equipped = false; - if (inv_bows <= 0) bow_equipped = false; - if (inv_skin_hats <= 0) equipped_head = EQUIP_NONE; - if (inv_skin_gloves <= 0) equipped_hands = EQUIP_NONE; - if (inv_skin_pants <= 0) equipped_legs = EQUIP_NONE; - if (inv_skin_tunics <= 0) equipped_torso = EQUIP_NONE; - if (inv_moccasins <= 0) equipped_feet = EQUIP_NONE; - if (inv_skin_pouches <= 0 && equipped_arms == EQUIP_POUCH) equipped_arms = EQUIP_NONE; - if (inv_backpacks <= 0 && equipped_arms == EQUIP_BACKPACK) equipped_arms = EQUIP_NONE; + if (get_personal_count(ITEM_SPEARS) <= 0) spear_equipped = false; + if (get_personal_count(ITEM_AXES) <= 0) axe_equipped = false; + if (get_personal_count(ITEM_SLINGS) <= 0) sling_equipped = false; + if (get_personal_count(ITEM_BOWS) <= 0) bow_equipped = false; + if (get_personal_count(ITEM_SKIN_HATS) <= 0) equipped_head = EQUIP_NONE; + if (get_personal_count(ITEM_SKIN_GLOVES) <= 0) equipped_hands = EQUIP_NONE; + if (get_personal_count(ITEM_SKIN_PANTS) <= 0) equipped_legs = EQUIP_NONE; + if (get_personal_count(ITEM_SKIN_TUNICS) <= 0) equipped_torso = EQUIP_NONE; + if (get_personal_count(ITEM_MOCCASINS) <= 0) equipped_feet = EQUIP_NONE; + if (get_personal_count(ITEM_SKIN_POUCHES) <= 0 && equipped_arms == EQUIP_POUCH) equipped_arms = EQUIP_NONE; + if (get_personal_count(ITEM_BACKPACKS) <= 0 && equipped_arms == EQUIP_BACKPACK) equipped_arms = EQUIP_NONE; update_max_health_from_equipment(); } diff --git a/src/item_registry.nvgt b/src/item_registry.nvgt new file mode 100644 index 0000000..581693c --- /dev/null +++ b/src/item_registry.nvgt @@ -0,0 +1,188 @@ +// Item Registry System +// Centralizes item definitions and inventory management + +// Item type constants +const int ITEM_STICKS = 0; +const int ITEM_VINES = 1; +const int ITEM_REEDS = 2; +const int ITEM_STONES = 3; +const int ITEM_LOGS = 4; +const int ITEM_CLAY = 5; +const int ITEM_SMALL_GAME = 6; +const int ITEM_MEAT = 7; +const int ITEM_SKINS = 8; +const int ITEM_SPEARS = 9; +const int ITEM_SLINGS = 10; +const int ITEM_AXES = 11; +const int ITEM_SNARES = 12; +const int ITEM_KNIVES = 13; +const int ITEM_FISHING_POLES = 14; +const int ITEM_SKIN_HATS = 15; +const int ITEM_SKIN_GLOVES = 16; +const int ITEM_SKIN_PANTS = 17; +const int ITEM_SKIN_TUNICS = 18; +const int ITEM_MOCCASINS = 19; +const int ITEM_SKIN_POUCHES = 20; +const int ITEM_ROPES = 21; +const int ITEM_REED_BASKETS = 22; +const int ITEM_CLAY_POTS = 23; +const int ITEM_FEATHERS = 24; +const int ITEM_DOWN = 25; +const int ITEM_INCENSE = 26; +const int ITEM_BOWS = 27; +const int ITEM_ARROWS = 28; +const int ITEM_QUIVERS = 29; +const int ITEM_BOWSTRINGS = 30; +const int ITEM_SINEW = 31; +const int ITEM_BOAR_CARCASSES = 32; +const int ITEM_BACKPACKS = 33; +const int ITEM_COUNT = 34; // Total number of item types + +// Item definition class +class ItemDefinition { + int type; + string name; // Plural form (e.g., "sticks") + string singular; // Singular form (e.g., "stick") + double favor_value; + + ItemDefinition() { + type = -1; + name = "unknown"; + singular = "unknown"; + favor_value = 0.01; + } + + ItemDefinition(int t, string n, string s, double fv) { + type = t; + name = n; + singular = s; + favor_value = fv; + } +} + +// Global item registry - indexed by item type +ItemDefinition[] item_registry; + +// Inventory arrays - indexed by item type +int[] personal_inventory; +int[] storage_inventory; + +// Special tracking for small game types (what kind of animals) +string[] personal_small_game_types; +string[] storage_small_game_types; + +void init_item_registry() { + // Initialize registry array + item_registry.resize(ITEM_COUNT); + + // Define all items: type, plural name, singular name, favor value + item_registry[ITEM_STICKS] = ItemDefinition(ITEM_STICKS, "sticks", "stick", 0.01); + item_registry[ITEM_VINES] = ItemDefinition(ITEM_VINES, "vines", "vine", 0.01); + item_registry[ITEM_REEDS] = ItemDefinition(ITEM_REEDS, "reeds", "reed", 0.01); + item_registry[ITEM_STONES] = ItemDefinition(ITEM_STONES, "stones", "stone", 0.02); + item_registry[ITEM_LOGS] = ItemDefinition(ITEM_LOGS, "logs", "log", 0.05); + item_registry[ITEM_CLAY] = ItemDefinition(ITEM_CLAY, "clay", "clay", 0.02); + item_registry[ITEM_SMALL_GAME] = ItemDefinition(ITEM_SMALL_GAME, "small game", "small game", 0.20); + item_registry[ITEM_MEAT] = ItemDefinition(ITEM_MEAT, "meat", "meat", 0.15); + item_registry[ITEM_SKINS] = ItemDefinition(ITEM_SKINS, "skins", "skin", 0.15); + item_registry[ITEM_SPEARS] = ItemDefinition(ITEM_SPEARS, "spears", "spear", 1.00); + item_registry[ITEM_SLINGS] = ItemDefinition(ITEM_SLINGS, "slings", "sling", 2.00); + item_registry[ITEM_AXES] = ItemDefinition(ITEM_AXES, "axes", "axe", 1.50); + item_registry[ITEM_SNARES] = ItemDefinition(ITEM_SNARES, "snares", "snare", 0.50); + item_registry[ITEM_KNIVES] = ItemDefinition(ITEM_KNIVES, "knives", "knife", 0.80); + item_registry[ITEM_FISHING_POLES] = ItemDefinition(ITEM_FISHING_POLES, "fishing poles", "fishing pole", 0.80); + item_registry[ITEM_SKIN_HATS] = ItemDefinition(ITEM_SKIN_HATS, "skin hats", "skin hat", 0.60); + item_registry[ITEM_SKIN_GLOVES] = ItemDefinition(ITEM_SKIN_GLOVES, "skin gloves", "skin glove", 0.60); + item_registry[ITEM_SKIN_PANTS] = ItemDefinition(ITEM_SKIN_PANTS, "skin pants", "skin pants", 1.20); + item_registry[ITEM_SKIN_TUNICS] = ItemDefinition(ITEM_SKIN_TUNICS, "skin tunics", "skin tunic", 1.20); + item_registry[ITEM_MOCCASINS] = ItemDefinition(ITEM_MOCCASINS, "moccasins", "moccasin", 0.80); + item_registry[ITEM_SKIN_POUCHES] = ItemDefinition(ITEM_SKIN_POUCHES, "skin pouches", "skin pouch", 0.80); + item_registry[ITEM_ROPES] = ItemDefinition(ITEM_ROPES, "ropes", "rope", 0.40); + item_registry[ITEM_REED_BASKETS] = ItemDefinition(ITEM_REED_BASKETS, "reed baskets", "reed basket", 0.60); + item_registry[ITEM_CLAY_POTS] = ItemDefinition(ITEM_CLAY_POTS, "clay pots", "clay pot", 0.70); + item_registry[ITEM_FEATHERS] = ItemDefinition(ITEM_FEATHERS, "feathers", "feather", 0.05); + item_registry[ITEM_DOWN] = ItemDefinition(ITEM_DOWN, "down", "down", 0.05); + item_registry[ITEM_INCENSE] = ItemDefinition(ITEM_INCENSE, "incense", "incense stick", 0.10); + item_registry[ITEM_BOWS] = ItemDefinition(ITEM_BOWS, "bows", "bow", 2.50); + item_registry[ITEM_ARROWS] = ItemDefinition(ITEM_ARROWS, "arrows", "arrow", 0.05); + item_registry[ITEM_QUIVERS] = ItemDefinition(ITEM_QUIVERS, "quivers", "quiver", 1.50); + item_registry[ITEM_BOWSTRINGS] = ItemDefinition(ITEM_BOWSTRINGS, "bowstrings", "bowstring", 0.20); + item_registry[ITEM_SINEW] = ItemDefinition(ITEM_SINEW, "sinew", "piece of sinew", 0.10); + item_registry[ITEM_BOAR_CARCASSES] = ItemDefinition(ITEM_BOAR_CARCASSES, "boar carcasses", "boar carcass", 1.50); + item_registry[ITEM_BACKPACKS] = ItemDefinition(ITEM_BACKPACKS, "backpacks", "backpack", 2.50); + + // Initialize inventory arrays + personal_inventory.resize(ITEM_COUNT); + storage_inventory.resize(ITEM_COUNT); + for (int i = 0; i < ITEM_COUNT; i++) { + personal_inventory[i] = 0; + storage_inventory[i] = 0; + } +} + +void reset_inventory() { + for (int i = 0; i < ITEM_COUNT; i++) { + personal_inventory[i] = 0; + storage_inventory[i] = 0; + } + personal_small_game_types.resize(0); + storage_small_game_types.resize(0); +} + +// Accessor functions for personal inventory +int get_personal_count(int item_type) { + if (item_type < 0 || item_type >= ITEM_COUNT) return 0; + return personal_inventory[item_type]; +} + +void set_personal_count(int item_type, int count) { + if (item_type < 0 || item_type >= ITEM_COUNT) return; + personal_inventory[item_type] = count; +} + +void add_personal_count(int item_type, int amount) { + if (item_type < 0 || item_type >= ITEM_COUNT) return; + personal_inventory[item_type] += amount; + if (personal_inventory[item_type] < 0) personal_inventory[item_type] = 0; +} + +// Accessor functions for storage inventory +int get_storage_count(int item_type) { + if (item_type < 0 || item_type >= ITEM_COUNT) return 0; + return storage_inventory[item_type]; +} + +void set_storage_count(int item_type, int count) { + if (item_type < 0 || item_type >= ITEM_COUNT) return; + storage_inventory[item_type] = count; +} + +void add_storage_count(int item_type, int amount) { + if (item_type < 0 || item_type >= ITEM_COUNT) return; + storage_inventory[item_type] += amount; + if (storage_inventory[item_type] < 0) storage_inventory[item_type] = 0; +} + +// Item metadata lookups +string get_item_label(int item_type) { + if (item_type < 0 || item_type >= ITEM_COUNT) return "items"; + return item_registry[item_type].name; +} + +string get_item_label_singular(int item_type) { + if (item_type < 0 || item_type >= ITEM_COUNT) return "item"; + return item_registry[item_type].singular; +} + +double get_item_favor_value(int item_type) { + if (item_type < 0 || item_type >= ITEM_COUNT) return 0.01; + return item_registry[item_type].favor_value; +} + +// Helper to get label based on count (singular vs plural) +string get_item_label_for_count(int item_type, int count) { + if (count == 1) { + return get_item_label_singular(item_type); + } + return get_item_label(item_type); +} diff --git a/src/menus/action_menu.nvgt b/src/menus/action_menu.nvgt index 1d23015..ddaa912 100644 --- a/src/menus/action_menu.nvgt +++ b/src/menus/action_menu.nvgt @@ -8,7 +8,7 @@ void check_action_menu(int x) { } void try_place_snare(int x) { - if (inv_snares > 0) { + if (get_personal_count(ITEM_SNARES) > 0) { // Prevent placing in base area if (x <= BASE_END) { speak_with_history("Cannot place snares in the base area.", true); @@ -21,7 +21,7 @@ void try_place_snare(int x) { return; } - inv_snares--; + add_personal_count(ITEM_SNARES, -1); add_world_snare(x); speak_with_history("Snare set.", true); } else { @@ -30,8 +30,8 @@ void try_place_snare(int x) { } void try_feed_fire_stick(WorldFire@ fire) { - if (inv_sticks > 0 && fire != null) { - inv_sticks--; + if (get_personal_count(ITEM_STICKS) > 0 && fire != null) { + add_personal_count(ITEM_STICKS, -1); fire.add_fuel(300000); // 5 minutes speak_with_history("You dump an arm load of sticks into the fire.", true); p.play_stationary("sounds/actions/feed_fire.ogg", false); @@ -39,8 +39,8 @@ void try_feed_fire_stick(WorldFire@ fire) { } void try_feed_fire_vine(WorldFire@ fire) { - if (inv_vines > 0 && fire != null) { - inv_vines--; + if (get_personal_count(ITEM_VINES) > 0 && fire != null) { + add_personal_count(ITEM_VINES, -1); fire.add_fuel(60000); // 1 minute speak_with_history("You toss a fiew vines and leaves into the fire.", true); p.play_stationary("sounds/actions/feed_fire.ogg", false); @@ -48,8 +48,8 @@ void try_feed_fire_vine(WorldFire@ fire) { } void try_feed_fire_log(WorldFire@ fire) { - if (inv_logs > 0 && fire != null) { - inv_logs--; + if (get_personal_count(ITEM_LOGS) > 0 && fire != null) { + add_personal_count(ITEM_LOGS, -1); fire.add_fuel(720000); // 12 minutes speak_with_history("You heave a log into the fire.", true); p.play_stationary("sounds/actions/feed_fire.ogg", false); @@ -61,30 +61,30 @@ void try_burn_incense() { speak_with_history("No altar built.", true); return; } - if (inv_clay_pots <= 0) { + if (get_personal_count(ITEM_CLAY_POTS) <= 0) { speak_with_history("You need a clay pot to burn incense.", true); return; } - if (inv_incense <= 0) { + if (get_personal_count(ITEM_INCENSE) <= 0) { speak_with_history("No incense to burn.", true); return; } - inv_incense--; + add_personal_count(ITEM_INCENSE, -1); incense_hours_remaining += INCENSE_HOURS_PER_STICK; incense_burning = true; speak_with_history("Incense burning. " + incense_hours_remaining + " hours remaining.", true); } void try_feed_fire_stick_max(WorldFire@ fire) { - if (inv_sticks <= 0 || fire == null) { + if (get_personal_count(ITEM_STICKS) <= 0 || fire == null) { speak_with_history("No sticks to feed fire.", true); return; } - int amount = inv_sticks; + int amount = get_personal_count(ITEM_STICKS); int fuel_added = amount * 300000; // 5 minutes per stick - inv_sticks = 0; + set_personal_count(ITEM_STICKS, 0); fire.add_fuel(fuel_added); p.play_stationary("sounds/actions/feed_fire.ogg", false); @@ -92,14 +92,14 @@ void try_feed_fire_stick_max(WorldFire@ fire) { } void try_feed_fire_vine_max(WorldFire@ fire) { - if (inv_vines <= 0 || fire == null) { + if (get_personal_count(ITEM_VINES) <= 0 || fire == null) { speak_with_history("No vines to feed fire.", true); return; } - int amount = inv_vines; + int amount = get_personal_count(ITEM_VINES); int fuel_added = amount * 60000; // 1 minute per vine - inv_vines = 0; + set_personal_count(ITEM_VINES, 0); fire.add_fuel(fuel_added); p.play_stationary("sounds/actions/feed_fire.ogg", false); @@ -107,14 +107,14 @@ void try_feed_fire_vine_max(WorldFire@ fire) { } void try_feed_fire_log_max(WorldFire@ fire) { - if (inv_logs <= 0 || fire == null) { + if (get_personal_count(ITEM_LOGS) <= 0 || fire == null) { speak_with_history("No logs to feed fire.", true); return; } - int amount = inv_logs; + int amount = get_personal_count(ITEM_LOGS); int fuel_added = amount * 720000; // 12 minutes per log - inv_logs = 0; + set_personal_count(ITEM_LOGS, 0); fire.add_fuel(fuel_added); p.play_stationary("sounds/actions/feed_fire.ogg", false); @@ -126,19 +126,19 @@ void try_burn_incense_max() { speak_with_history("No altar built.", true); return; } - if (inv_clay_pots <= 0) { + if (get_personal_count(ITEM_CLAY_POTS) <= 0) { speak_with_history("You need a clay pot to burn incense.", true); return; } - if (inv_incense <= 0) { + if (get_personal_count(ITEM_INCENSE) <= 0) { speak_with_history("No incense to burn.", true); return; } - int amount = inv_incense; + int amount = get_personal_count(ITEM_INCENSE); int total_hours = amount * INCENSE_HOURS_PER_STICK; - inv_incense = 0; - inv_clay_pots--; + set_personal_count(ITEM_INCENSE, 0); + add_personal_count(ITEM_CLAY_POTS, -1); incense_hours_remaining += total_hours; incense_burning = true; @@ -162,21 +162,21 @@ void run_action_menu(int x) { action_types.insert_last(0); if (can_feed_fire) { - if (inv_sticks > 0) { + if (get_personal_count(ITEM_STICKS) > 0) { options.insert_last("Feed fire with stick"); action_types.insert_last(1); } - if (inv_vines > 0) { + if (get_personal_count(ITEM_VINES) > 0) { options.insert_last("Feed fire with vine"); action_types.insert_last(2); } - if (inv_logs > 0) { + if (get_personal_count(ITEM_LOGS) > 0) { options.insert_last("Feed fire with log"); action_types.insert_last(3); } } - if (x <= BASE_END && world_altars.length() > 0 && inv_incense > 0) { + if (x <= BASE_END && world_altars.length() > 0 && get_personal_count(ITEM_INCENSE) > 0) { options.insert_last("Burn incense"); action_types.insert_last(4); } diff --git a/src/menus/altar_menu.nvgt b/src/menus/altar_menu.nvgt index 0303f63..6fe8769 100644 --- a/src/menus/altar_menu.nvgt +++ b/src/menus/altar_menu.nvgt @@ -30,38 +30,38 @@ void sacrifice_item(int item_type) { return; } - if (item_type == ITEM_STICKS) inv_sticks--; - else if (item_type == ITEM_VINES) inv_vines--; - else if (item_type == ITEM_REEDS) inv_reeds--; - else if (item_type == ITEM_STONES) inv_stones--; - else if (item_type == ITEM_LOGS) inv_logs--; - else if (item_type == ITEM_CLAY) inv_clay--; + if (item_type == ITEM_STICKS) add_personal_count(ITEM_STICKS, -1); + else if (item_type == ITEM_VINES) add_personal_count(ITEM_VINES, -1); + else if (item_type == ITEM_REEDS) add_personal_count(ITEM_REEDS, -1); + else if (item_type == ITEM_STONES) add_personal_count(ITEM_STONES, -1); + else if (item_type == ITEM_LOGS) add_personal_count(ITEM_LOGS, -1); + else if (item_type == ITEM_CLAY) add_personal_count(ITEM_CLAY, -1); else if (item_type == ITEM_SMALL_GAME) { - inv_small_game--; - if (inv_small_game_types.length() > 0) { - inv_small_game_types.remove_at(0); + add_personal_count(ITEM_SMALL_GAME, -1); + if (personal_small_game_types.length() > 0) { + personal_small_game_types.remove_at(0); } } - else if (item_type == ITEM_MEAT) inv_meat--; - else if (item_type == ITEM_SKINS) inv_skins--; - else if (item_type == ITEM_FEATHERS) inv_feathers--; - else if (item_type == ITEM_DOWN) inv_down--; - else if (item_type == ITEM_INCENSE) inv_incense--; - else if (item_type == ITEM_SPEARS) inv_spears--; - else if (item_type == ITEM_SLINGS) inv_slings--; - else if (item_type == ITEM_AXES) inv_axes--; - else if (item_type == ITEM_SNARES) inv_snares--; - else if (item_type == ITEM_KNIVES) inv_knives--; - else if (item_type == ITEM_FISHING_POLES) inv_fishing_poles--; - else if (item_type == ITEM_ROPES) inv_ropes--; - else if (item_type == ITEM_REED_BASKETS) inv_reed_baskets--; - else if (item_type == ITEM_CLAY_POTS) inv_clay_pots--; - else if (item_type == ITEM_SKIN_HATS) inv_skin_hats--; - else if (item_type == ITEM_SKIN_GLOVES) inv_skin_gloves--; - else if (item_type == ITEM_SKIN_PANTS) inv_skin_pants--; - else if (item_type == ITEM_SKIN_TUNICS) inv_skin_tunics--; - else if (item_type == ITEM_MOCCASINS) inv_moccasins--; - else if (item_type == ITEM_SKIN_POUCHES) inv_skin_pouches--; + else if (item_type == ITEM_MEAT) add_personal_count(ITEM_MEAT, -1); + else if (item_type == ITEM_SKINS) add_personal_count(ITEM_SKINS, -1); + else if (item_type == ITEM_FEATHERS) add_personal_count(ITEM_FEATHERS, -1); + else if (item_type == ITEM_DOWN) add_personal_count(ITEM_DOWN, -1); + else if (item_type == ITEM_INCENSE) add_personal_count(ITEM_INCENSE, -1); + else if (item_type == ITEM_SPEARS) add_personal_count(ITEM_SPEARS, -1); + else if (item_type == ITEM_SLINGS) add_personal_count(ITEM_SLINGS, -1); + else if (item_type == ITEM_AXES) add_personal_count(ITEM_AXES, -1); + else if (item_type == ITEM_SNARES) add_personal_count(ITEM_SNARES, -1); + else if (item_type == ITEM_KNIVES) add_personal_count(ITEM_KNIVES, -1); + else if (item_type == ITEM_FISHING_POLES) add_personal_count(ITEM_FISHING_POLES, -1); + else if (item_type == ITEM_ROPES) add_personal_count(ITEM_ROPES, -1); + else if (item_type == ITEM_REED_BASKETS) add_personal_count(ITEM_REED_BASKETS, -1); + else if (item_type == ITEM_CLAY_POTS) add_personal_count(ITEM_CLAY_POTS, -1); + else if (item_type == ITEM_SKIN_HATS) add_personal_count(ITEM_SKIN_HATS, -1); + else if (item_type == ITEM_SKIN_GLOVES) add_personal_count(ITEM_SKIN_GLOVES, -1); + else if (item_type == ITEM_SKIN_PANTS) add_personal_count(ITEM_SKIN_PANTS, -1); + else if (item_type == ITEM_SKIN_TUNICS) add_personal_count(ITEM_SKIN_TUNICS, -1); + else if (item_type == ITEM_MOCCASINS) add_personal_count(ITEM_MOCCASINS, -1); + else if (item_type == ITEM_SKIN_POUCHES) add_personal_count(ITEM_SKIN_POUCHES, -1); cleanup_equipment_after_inventory_change(); double favor_gain = get_item_favor_value(item_type); @@ -82,36 +82,36 @@ void sacrifice_item_max(int item_type) { double favor_per_item = get_item_favor_value(item_type); - if (item_type == ITEM_STICKS) { inv_sticks = 0; } - else if (item_type == ITEM_VINES) { inv_vines = 0; } - else if (item_type == ITEM_REEDS) { inv_reeds = 0; } - else if (item_type == ITEM_STONES) { inv_stones = 0; } - else if (item_type == ITEM_LOGS) { inv_logs = 0; } - else if (item_type == ITEM_CLAY) { inv_clay = 0; } + if (item_type == ITEM_STICKS) { set_personal_count(ITEM_STICKS, 0); } + else if (item_type == ITEM_VINES) { set_personal_count(ITEM_VINES, 0); } + else if (item_type == ITEM_REEDS) { set_personal_count(ITEM_REEDS, 0); } + else if (item_type == ITEM_STONES) { set_personal_count(ITEM_STONES, 0); } + else if (item_type == ITEM_LOGS) { set_personal_count(ITEM_LOGS, 0); } + else if (item_type == ITEM_CLAY) { set_personal_count(ITEM_CLAY, 0); } else if (item_type == ITEM_SMALL_GAME) { - inv_small_game = 0; - inv_small_game_types.resize(0); + set_personal_count(ITEM_SMALL_GAME, 0); + personal_small_game_types.resize(0); } - else if (item_type == ITEM_MEAT) { inv_meat = 0; } - else if (item_type == ITEM_SKINS) { inv_skins = 0; } - else if (item_type == ITEM_FEATHERS) { inv_feathers = 0; } - else if (item_type == ITEM_DOWN) { inv_down = 0; } - else if (item_type == ITEM_INCENSE) { inv_incense = 0; } - else if (item_type == ITEM_SPEARS) { inv_spears = 0; } - else if (item_type == ITEM_SLINGS) { inv_slings = 0; } - else if (item_type == ITEM_AXES) { inv_axes = 0; } - else if (item_type == ITEM_SNARES) { inv_snares = 0; } - else if (item_type == ITEM_KNIVES) { inv_knives = 0; } - else if (item_type == ITEM_FISHING_POLES) { inv_fishing_poles = 0; } - else if (item_type == ITEM_ROPES) { inv_ropes = 0; } - else if (item_type == ITEM_REED_BASKETS) { inv_reed_baskets = 0; } - else if (item_type == ITEM_CLAY_POTS) { inv_clay_pots = 0; } - else if (item_type == ITEM_SKIN_HATS) { inv_skin_hats = 0; } - else if (item_type == ITEM_SKIN_GLOVES) { inv_skin_gloves = 0; } - else if (item_type == ITEM_SKIN_PANTS) { inv_skin_pants = 0; } - else if (item_type == ITEM_SKIN_TUNICS) { inv_skin_tunics = 0; } - else if (item_type == ITEM_MOCCASINS) { inv_moccasins = 0; } - else if (item_type == ITEM_SKIN_POUCHES) { inv_skin_pouches = 0; } + else if (item_type == ITEM_MEAT) { set_personal_count(ITEM_MEAT, 0); } + else if (item_type == ITEM_SKINS) { set_personal_count(ITEM_SKINS, 0); } + else if (item_type == ITEM_FEATHERS) { set_personal_count(ITEM_FEATHERS, 0); } + else if (item_type == ITEM_DOWN) { set_personal_count(ITEM_DOWN, 0); } + else if (item_type == ITEM_INCENSE) { set_personal_count(ITEM_INCENSE, 0); } + else if (item_type == ITEM_SPEARS) { set_personal_count(ITEM_SPEARS, 0); } + else if (item_type == ITEM_SLINGS) { set_personal_count(ITEM_SLINGS, 0); } + else if (item_type == ITEM_AXES) { set_personal_count(ITEM_AXES, 0); } + else if (item_type == ITEM_SNARES) { set_personal_count(ITEM_SNARES, 0); } + else if (item_type == ITEM_KNIVES) { set_personal_count(ITEM_KNIVES, 0); } + else if (item_type == ITEM_FISHING_POLES) { set_personal_count(ITEM_FISHING_POLES, 0); } + else if (item_type == ITEM_ROPES) { set_personal_count(ITEM_ROPES, 0); } + else if (item_type == ITEM_REED_BASKETS) { set_personal_count(ITEM_REED_BASKETS, 0); } + else if (item_type == ITEM_CLAY_POTS) { set_personal_count(ITEM_CLAY_POTS, 0); } + else if (item_type == ITEM_SKIN_HATS) { set_personal_count(ITEM_SKIN_HATS, 0); } + else if (item_type == ITEM_SKIN_GLOVES) { set_personal_count(ITEM_SKIN_GLOVES, 0); } + else if (item_type == ITEM_SKIN_PANTS) { set_personal_count(ITEM_SKIN_PANTS, 0); } + else if (item_type == ITEM_SKIN_TUNICS) { set_personal_count(ITEM_SKIN_TUNICS, 0); } + else if (item_type == ITEM_MOCCASINS) { set_personal_count(ITEM_MOCCASINS, 0); } + else if (item_type == ITEM_SKIN_POUCHES) { set_personal_count(ITEM_SKIN_POUCHES, 0); } cleanup_equipment_after_inventory_change(); double total_favor = favor_per_item * available; diff --git a/src/menus/base_info.nvgt b/src/menus/base_info.nvgt index 79cba29..cc7adf5 100644 --- a/src/menus/base_info.nvgt +++ b/src/menus/base_info.nvgt @@ -17,7 +17,7 @@ void run_base_info_menu() { if (world_storages.length() > 0) { options.insert_last("Storage built. Total items " + get_storage_total_items()); int daily_food = get_daily_food_requirement(); - options.insert_last("Food in storage " + storage_meat + " meat. Daily use " + daily_food); + options.insert_last("Food in storage " + get_storage_count(ITEM_MEAT) + " meat. Daily use " + daily_food); } else { options.insert_last("Storage not built"); } diff --git a/src/menus/equipment_menu.nvgt b/src/menus/equipment_menu.nvgt index c09c697..84b5776 100644 --- a/src/menus/equipment_menu.nvgt +++ b/src/menus/equipment_menu.nvgt @@ -4,10 +4,12 @@ // Check if player has any equipment (including runed items) bool has_any_equipment() { // Check unruned items - if (inv_spears > 0 || inv_axes > 0 || inv_slings > 0 || inv_bows > 0 || - inv_skin_hats > 0 || inv_skin_gloves > 0 || inv_skin_pants > 0 || - inv_skin_tunics > 0 || inv_moccasins > 0 || inv_skin_pouches > 0 || - inv_backpacks > 0) { + if (get_personal_count(ITEM_SPEARS) > 0 || get_personal_count(ITEM_AXES) > 0 || + get_personal_count(ITEM_SLINGS) > 0 || get_personal_count(ITEM_BOWS) > 0 || + get_personal_count(ITEM_SKIN_HATS) > 0 || get_personal_count(ITEM_SKIN_GLOVES) > 0 || + get_personal_count(ITEM_SKIN_PANTS) > 0 || get_personal_count(ITEM_SKIN_TUNICS) > 0 || + get_personal_count(ITEM_MOCCASINS) > 0 || get_personal_count(ITEM_SKIN_POUCHES) > 0 || + get_personal_count(ITEM_BACKPACKS) > 0) { return true; } @@ -56,67 +58,67 @@ void run_equipment_menu() { int[] rune_types; // Track which rune is on each option (RUNE_NONE for unruned) // Add unruned items - if (inv_spears > 0) { + if (get_personal_count(ITEM_SPEARS) > 0) { string status = is_runed_item_equipped(EQUIP_SPEAR, RUNE_NONE) ? " (equipped)" : ""; options.insert_last("Spear" + status); equipment_types.insert_last(EQUIP_SPEAR); rune_types.insert_last(RUNE_NONE); } - if (inv_slings > 0) { + if (get_personal_count(ITEM_SLINGS) > 0) { string status = is_runed_item_equipped(EQUIP_SLING, RUNE_NONE) ? " (equipped)" : ""; options.insert_last("Sling" + status); equipment_types.insert_last(EQUIP_SLING); rune_types.insert_last(RUNE_NONE); } - if (inv_axes > 0) { + if (get_personal_count(ITEM_AXES) > 0) { string status = is_runed_item_equipped(EQUIP_AXE, RUNE_NONE) ? " (equipped)" : ""; options.insert_last("Stone Axe" + status); equipment_types.insert_last(EQUIP_AXE); rune_types.insert_last(RUNE_NONE); } - if (inv_bows > 0) { + if (get_personal_count(ITEM_BOWS) > 0) { string status = is_runed_item_equipped(EQUIP_BOW, RUNE_NONE) ? " (equipped)" : ""; options.insert_last("Bow" + status); equipment_types.insert_last(EQUIP_BOW); rune_types.insert_last(RUNE_NONE); } - if (inv_skin_hats > 0) { + if (get_personal_count(ITEM_SKIN_HATS) > 0) { string status = is_runed_item_equipped(EQUIP_HAT, RUNE_NONE) ? " (equipped)" : ""; options.insert_last("Skin Hat" + status); equipment_types.insert_last(EQUIP_HAT); rune_types.insert_last(RUNE_NONE); } - if (inv_skin_gloves > 0) { + if (get_personal_count(ITEM_SKIN_GLOVES) > 0) { string status = is_runed_item_equipped(EQUIP_GLOVES, RUNE_NONE) ? " (equipped)" : ""; options.insert_last("Skin Gloves" + status); equipment_types.insert_last(EQUIP_GLOVES); rune_types.insert_last(RUNE_NONE); } - if (inv_skin_pants > 0) { + if (get_personal_count(ITEM_SKIN_PANTS) > 0) { string status = is_runed_item_equipped(EQUIP_PANTS, RUNE_NONE) ? " (equipped)" : ""; options.insert_last("Skin Pants" + status); equipment_types.insert_last(EQUIP_PANTS); rune_types.insert_last(RUNE_NONE); } - if (inv_skin_tunics > 0) { + if (get_personal_count(ITEM_SKIN_TUNICS) > 0) { string status = is_runed_item_equipped(EQUIP_TUNIC, RUNE_NONE) ? " (equipped)" : ""; options.insert_last("Skin Tunic" + status); equipment_types.insert_last(EQUIP_TUNIC); rune_types.insert_last(RUNE_NONE); } - if (inv_moccasins > 0) { + if (get_personal_count(ITEM_MOCCASINS) > 0) { string status = is_runed_item_equipped(EQUIP_MOCCASINS, RUNE_NONE) ? " (equipped)" : ""; options.insert_last("Moccasins" + status); equipment_types.insert_last(EQUIP_MOCCASINS); rune_types.insert_last(RUNE_NONE); } - if (inv_skin_pouches > 0) { + if (get_personal_count(ITEM_SKIN_POUCHES) > 0) { string status = is_runed_item_equipped(EQUIP_POUCH, RUNE_NONE) ? " (equipped)" : ""; options.insert_last("Skin Pouch" + status); equipment_types.insert_last(EQUIP_POUCH); rune_types.insert_last(RUNE_NONE); } - if (inv_backpacks > 0) { + if (get_personal_count(ITEM_BACKPACKS) > 0) { string status = is_runed_item_equipped(EQUIP_BACKPACK, RUNE_NONE) ? " (equipped)" : ""; options.insert_last("Backpack" + status); equipment_types.insert_last(EQUIP_BACKPACK); diff --git a/src/menus/inventory_core.nvgt b/src/menus/inventory_core.nvgt index 00635e8..b71d574 100644 --- a/src/menus/inventory_core.nvgt +++ b/src/menus/inventory_core.nvgt @@ -4,34 +4,34 @@ void build_personal_inventory_options(string[]@ options, int[]@ item_types) { options.resize(0); item_types.resize(0); - options.insert_last("Sticks: " + inv_sticks); item_types.insert_last(ITEM_STICKS); - options.insert_last("Vines: " + inv_vines); item_types.insert_last(ITEM_VINES); - options.insert_last("Reeds: " + inv_reeds); item_types.insert_last(ITEM_REEDS); - options.insert_last("Stones: " + inv_stones); item_types.insert_last(ITEM_STONES); - options.insert_last("Logs: " + inv_logs); item_types.insert_last(ITEM_LOGS); - options.insert_last("Clay: " + inv_clay); item_types.insert_last(ITEM_CLAY); - options.insert_last("Small Game: " + inv_small_game); item_types.insert_last(ITEM_SMALL_GAME); - options.insert_last("Meat: " + inv_meat); item_types.insert_last(ITEM_MEAT); - options.insert_last("Skins: " + inv_skins); item_types.insert_last(ITEM_SKINS); - options.insert_last("Feathers: " + inv_feathers); item_types.insert_last(ITEM_FEATHERS); - options.insert_last("Down: " + inv_down); item_types.insert_last(ITEM_DOWN); - options.insert_last("Incense: " + inv_incense); item_types.insert_last(ITEM_INCENSE); - options.insert_last("Spears: " + inv_spears); item_types.insert_last(ITEM_SPEARS); - options.insert_last("Slings: " + inv_slings); item_types.insert_last(ITEM_SLINGS); - options.insert_last("Axes: " + inv_axes); item_types.insert_last(ITEM_AXES); - options.insert_last("Snares: " + inv_snares); item_types.insert_last(ITEM_SNARES); - options.insert_last("Knives: " + inv_knives); item_types.insert_last(ITEM_KNIVES); - options.insert_last("Fishing Poles: " + inv_fishing_poles); item_types.insert_last(ITEM_FISHING_POLES); - options.insert_last("Ropes: " + inv_ropes); item_types.insert_last(ITEM_ROPES); - options.insert_last("Reed Baskets: " + inv_reed_baskets); item_types.insert_last(ITEM_REED_BASKETS); - options.insert_last("Clay Pots: " + inv_clay_pots); item_types.insert_last(ITEM_CLAY_POTS); - options.insert_last("Skin Hats: " + inv_skin_hats); item_types.insert_last(ITEM_SKIN_HATS); - options.insert_last("Skin Gloves: " + inv_skin_gloves); item_types.insert_last(ITEM_SKIN_GLOVES); - options.insert_last("Skin Pants: " + inv_skin_pants); item_types.insert_last(ITEM_SKIN_PANTS); - options.insert_last("Skin Tunics: " + inv_skin_tunics); item_types.insert_last(ITEM_SKIN_TUNICS); - options.insert_last("Moccasins: " + inv_moccasins); item_types.insert_last(ITEM_MOCCASINS); - options.insert_last("Skin Pouches: " + inv_skin_pouches); item_types.insert_last(ITEM_SKIN_POUCHES); - options.insert_last("Backpacks: " + inv_backpacks); item_types.insert_last(ITEM_BACKPACKS); + options.insert_last("Sticks: " + get_personal_count(ITEM_STICKS)); item_types.insert_last(ITEM_STICKS); + options.insert_last("Vines: " + get_personal_count(ITEM_VINES)); item_types.insert_last(ITEM_VINES); + options.insert_last("Reeds: " + get_personal_count(ITEM_REEDS)); item_types.insert_last(ITEM_REEDS); + options.insert_last("Stones: " + get_personal_count(ITEM_STONES)); item_types.insert_last(ITEM_STONES); + options.insert_last("Logs: " + get_personal_count(ITEM_LOGS)); item_types.insert_last(ITEM_LOGS); + options.insert_last("Clay: " + get_personal_count(ITEM_CLAY)); item_types.insert_last(ITEM_CLAY); + options.insert_last("Small Game: " + get_personal_count(ITEM_SMALL_GAME)); item_types.insert_last(ITEM_SMALL_GAME); + options.insert_last("Meat: " + get_personal_count(ITEM_MEAT)); item_types.insert_last(ITEM_MEAT); + options.insert_last("Skins: " + get_personal_count(ITEM_SKINS)); item_types.insert_last(ITEM_SKINS); + options.insert_last("Feathers: " + get_personal_count(ITEM_FEATHERS)); item_types.insert_last(ITEM_FEATHERS); + options.insert_last("Down: " + get_personal_count(ITEM_DOWN)); item_types.insert_last(ITEM_DOWN); + options.insert_last("Incense: " + get_personal_count(ITEM_INCENSE)); item_types.insert_last(ITEM_INCENSE); + options.insert_last("Spears: " + get_personal_count(ITEM_SPEARS)); item_types.insert_last(ITEM_SPEARS); + options.insert_last("Slings: " + get_personal_count(ITEM_SLINGS)); item_types.insert_last(ITEM_SLINGS); + options.insert_last("Axes: " + get_personal_count(ITEM_AXES)); item_types.insert_last(ITEM_AXES); + options.insert_last("Snares: " + get_personal_count(ITEM_SNARES)); item_types.insert_last(ITEM_SNARES); + options.insert_last("Knives: " + get_personal_count(ITEM_KNIVES)); item_types.insert_last(ITEM_KNIVES); + options.insert_last("Fishing Poles: " + get_personal_count(ITEM_FISHING_POLES)); item_types.insert_last(ITEM_FISHING_POLES); + options.insert_last("Ropes: " + get_personal_count(ITEM_ROPES)); item_types.insert_last(ITEM_ROPES); + options.insert_last("Reed Baskets: " + get_personal_count(ITEM_REED_BASKETS)); item_types.insert_last(ITEM_REED_BASKETS); + options.insert_last("Clay Pots: " + get_personal_count(ITEM_CLAY_POTS)); item_types.insert_last(ITEM_CLAY_POTS); + options.insert_last("Skin Hats: " + get_personal_count(ITEM_SKIN_HATS)); item_types.insert_last(ITEM_SKIN_HATS); + options.insert_last("Skin Gloves: " + get_personal_count(ITEM_SKIN_GLOVES)); item_types.insert_last(ITEM_SKIN_GLOVES); + options.insert_last("Skin Pants: " + get_personal_count(ITEM_SKIN_PANTS)); item_types.insert_last(ITEM_SKIN_PANTS); + options.insert_last("Skin Tunics: " + get_personal_count(ITEM_SKIN_TUNICS)); item_types.insert_last(ITEM_SKIN_TUNICS); + options.insert_last("Moccasins: " + get_personal_count(ITEM_MOCCASINS)); item_types.insert_last(ITEM_MOCCASINS); + options.insert_last("Skin Pouches: " + get_personal_count(ITEM_SKIN_POUCHES)); item_types.insert_last(ITEM_SKIN_POUCHES); + options.insert_last("Backpacks: " + get_personal_count(ITEM_BACKPACKS)); item_types.insert_last(ITEM_BACKPACKS); // Add runed items int[] runeable = get_runeable_equipment_types(); @@ -49,20 +49,20 @@ void build_personal_inventory_options(string[]@ options, int[]@ item_types) { void show_inventory() { string info = "Inventory: "; - info += inv_sticks + " sticks, "; - info += inv_vines + " vines, "; - info += inv_reeds + " reeds, "; - info += inv_stones + " stones, "; - info += inv_logs + " logs, "; - info += inv_clay + " clay, "; - info += inv_small_game + " small game, "; - info += inv_meat + " meat, "; - info += inv_skins + " skins, "; - info += inv_feathers + " feathers, "; - info += inv_down + " down, "; - info += inv_incense + " incense. "; - info += "Tools: " + inv_spears + " spears, " + inv_slings + " slings, " + inv_axes + " axes, " + inv_snares + " snares, " + inv_knives + " knives, " + inv_fishing_poles + " fishing poles, " + inv_ropes + " ropes, " + inv_reed_baskets + " reed baskets, " + inv_clay_pots + " clay pots. "; - info += "Clothing: " + inv_skin_hats + " hats, " + inv_skin_gloves + " gloves, " + inv_skin_pants + " pants, " + inv_skin_tunics + " tunics, " + inv_moccasins + " moccasins, " + inv_skin_pouches + " skin pouches."; + info += get_personal_count(ITEM_STICKS) + " sticks, "; + info += get_personal_count(ITEM_VINES) + " vines, "; + info += get_personal_count(ITEM_REEDS) + " reeds, "; + info += get_personal_count(ITEM_STONES) + " stones, "; + info += get_personal_count(ITEM_LOGS) + " logs, "; + info += get_personal_count(ITEM_CLAY) + " clay, "; + info += get_personal_count(ITEM_SMALL_GAME) + " small game, "; + info += get_personal_count(ITEM_MEAT) + " meat, "; + info += get_personal_count(ITEM_SKINS) + " skins, "; + info += get_personal_count(ITEM_FEATHERS) + " feathers, "; + info += get_personal_count(ITEM_DOWN) + " down, "; + info += get_personal_count(ITEM_INCENSE) + " incense. "; + info += "Tools: " + get_personal_count(ITEM_SPEARS) + " spears, " + get_personal_count(ITEM_SLINGS) + " slings, " + get_personal_count(ITEM_AXES) + " axes, " + get_personal_count(ITEM_SNARES) + " snares, " + get_personal_count(ITEM_KNIVES) + " knives, " + get_personal_count(ITEM_FISHING_POLES) + " fishing poles, " + get_personal_count(ITEM_ROPES) + " ropes, " + get_personal_count(ITEM_REED_BASKETS) + " reed baskets, " + get_personal_count(ITEM_CLAY_POTS) + " clay pots. "; + info += "Clothing: " + get_personal_count(ITEM_SKIN_HATS) + " hats, " + get_personal_count(ITEM_SKIN_GLOVES) + " gloves, " + get_personal_count(ITEM_SKIN_PANTS) + " pants, " + get_personal_count(ITEM_SKIN_TUNICS) + " tunics, " + get_personal_count(ITEM_MOCCASINS) + " moccasins, " + get_personal_count(ITEM_SKIN_POUCHES) + " skin pouches."; // Add runed items summary string runed_info = ""; diff --git a/src/menus/menu_utils.nvgt b/src/menus/menu_utils.nvgt index e108876..41a220c 100644 --- a/src/menus/menu_utils.nvgt +++ b/src/menus/menu_utils.nvgt @@ -49,30 +49,9 @@ string join_string_list(const string[]@ items) { int get_storage_total_items() { int total = 0; - total += storage_stones; - total += storage_sticks; - total += storage_vines; - total += storage_reeds; - total += storage_logs; - total += storage_clay; - total += storage_small_game; - total += storage_meat; - total += storage_skins; - total += storage_spears; - total += storage_slings; - total += storage_axes; - total += storage_snares; - total += storage_knives; - total += storage_fishing_poles; - total += storage_ropes; - total += storage_reed_baskets; - total += storage_clay_pots; - total += storage_skin_hats; - total += storage_skin_gloves; - total += storage_skin_pants; - total += storage_skin_tunics; - total += storage_moccasins; - total += storage_skin_pouches; + for (int i = 0; i < ITEM_COUNT; i++) { + total += get_storage_count(i); + } return total; } diff --git a/src/menus/storage_menu.nvgt b/src/menus/storage_menu.nvgt index 7e5d0e3..481ca56 100644 --- a/src/menus/storage_menu.nvgt +++ b/src/menus/storage_menu.nvgt @@ -4,9 +4,9 @@ void move_small_game_to_storage(int amount) { for (int i = 0; i < amount; i++) { string game_type = "small game"; - if (inv_small_game_types.length() > 0) { - game_type = inv_small_game_types[0]; - inv_small_game_types.remove_at(0); + if (personal_small_game_types.length() > 0) { + game_type = personal_small_game_types[0]; + personal_small_game_types.remove_at(0); } storage_small_game_types.insert_last(game_type); } @@ -19,7 +19,7 @@ void move_small_game_to_personal(int amount) { game_type = storage_small_game_types[0]; storage_small_game_types.remove_at(0); } - inv_small_game_types.insert_last(game_type); + personal_small_game_types.insert_last(game_type); } } @@ -83,34 +83,14 @@ void deposit_item(int item_type) { int amount = prompt_transfer_amount("Deposit how many?", max_transfer); if (amount <= 0) return; - if (item_type == ITEM_STICKS) { inv_sticks -= amount; storage_sticks += amount; } - else if (item_type == ITEM_VINES) { inv_vines -= amount; storage_vines += amount; } - else if (item_type == ITEM_REEDS) { inv_reeds -= amount; storage_reeds += amount; } - else if (item_type == ITEM_STONES) { inv_stones -= amount; storage_stones += amount; } - else if (item_type == ITEM_LOGS) { inv_logs -= amount; storage_logs += amount; } - else if (item_type == ITEM_CLAY) { inv_clay -= amount; storage_clay += amount; } - else if (item_type == ITEM_SMALL_GAME) { inv_small_game -= amount; storage_small_game += amount; move_small_game_to_storage(amount); } - else if (item_type == ITEM_MEAT) { inv_meat -= amount; storage_meat += amount; } - else if (item_type == ITEM_SKINS) { inv_skins -= amount; storage_skins += amount; } - else if (item_type == ITEM_FEATHERS) { inv_feathers -= amount; storage_feathers += amount; } - else if (item_type == ITEM_DOWN) { inv_down -= amount; storage_down += amount; } - else if (item_type == ITEM_INCENSE) { inv_incense -= amount; storage_incense += amount; } - else if (item_type == ITEM_SPEARS) { inv_spears -= amount; storage_spears += amount; } - else if (item_type == ITEM_SLINGS) { inv_slings -= amount; storage_slings += amount; } - else if (item_type == ITEM_AXES) { inv_axes -= amount; storage_axes += amount; } - else if (item_type == ITEM_SNARES) { inv_snares -= amount; storage_snares += amount; } - else if (item_type == ITEM_KNIVES) { inv_knives -= amount; storage_knives += amount; } - else if (item_type == ITEM_FISHING_POLES) { inv_fishing_poles -= amount; storage_fishing_poles += amount; } - else if (item_type == ITEM_ROPES) { inv_ropes -= amount; storage_ropes += amount; } - else if (item_type == ITEM_REED_BASKETS) { inv_reed_baskets -= amount; storage_reed_baskets += amount; } - else if (item_type == ITEM_CLAY_POTS) { inv_clay_pots -= amount; storage_clay_pots += amount; } - else if (item_type == ITEM_SKIN_HATS) { inv_skin_hats -= amount; storage_skin_hats += amount; } - else if (item_type == ITEM_SKIN_GLOVES) { inv_skin_gloves -= amount; storage_skin_gloves += amount; } - else if (item_type == ITEM_SKIN_PANTS) { inv_skin_pants -= amount; storage_skin_pants += amount; } - else if (item_type == ITEM_SKIN_TUNICS) { inv_skin_tunics -= amount; storage_skin_tunics += amount; } - else if (item_type == ITEM_MOCCASINS) { inv_moccasins -= amount; storage_moccasins += amount; } - else if (item_type == ITEM_SKIN_POUCHES) { inv_skin_pouches -= amount; storage_skin_pouches += amount; } - else if (item_type == ITEM_BACKPACKS) { inv_backpacks -= amount; storage_backpacks += amount; } + // Transfer the items + add_personal_count(item_type, -amount); + add_storage_count(item_type, amount); + + // Special handling for small game types + if (item_type == ITEM_SMALL_GAME) { + move_small_game_to_storage(amount); + } cleanup_equipment_after_inventory_change(); speak_with_history("Deposited " + amount + " " + get_item_label(item_type) + ".", true); @@ -155,34 +135,14 @@ void deposit_item_max(int item_type) { int amount = (available < capacity) ? available : capacity; - if (item_type == ITEM_STICKS) { inv_sticks -= amount; storage_sticks += amount; } - else if (item_type == ITEM_VINES) { inv_vines -= amount; storage_vines += amount; } - else if (item_type == ITEM_REEDS) { inv_reeds -= amount; storage_reeds += amount; } - else if (item_type == ITEM_STONES) { inv_stones -= amount; storage_stones += amount; } - else if (item_type == ITEM_LOGS) { inv_logs -= amount; storage_logs += amount; } - else if (item_type == ITEM_CLAY) { inv_clay -= amount; storage_clay += amount; } - else if (item_type == ITEM_SMALL_GAME) { inv_small_game -= amount; storage_small_game += amount; move_small_game_to_storage(amount); } - else if (item_type == ITEM_MEAT) { inv_meat -= amount; storage_meat += amount; } - else if (item_type == ITEM_SKINS) { inv_skins -= amount; storage_skins += amount; } - else if (item_type == ITEM_FEATHERS) { inv_feathers -= amount; storage_feathers += amount; } - else if (item_type == ITEM_DOWN) { inv_down -= amount; storage_down += amount; } - else if (item_type == ITEM_INCENSE) { inv_incense -= amount; storage_incense += amount; } - else if (item_type == ITEM_SPEARS) { inv_spears -= amount; storage_spears += amount; } - else if (item_type == ITEM_SLINGS) { inv_slings -= amount; storage_slings += amount; } - else if (item_type == ITEM_AXES) { inv_axes -= amount; storage_axes += amount; } - else if (item_type == ITEM_SNARES) { inv_snares -= amount; storage_snares += amount; } - else if (item_type == ITEM_KNIVES) { inv_knives -= amount; storage_knives += amount; } - else if (item_type == ITEM_FISHING_POLES) { inv_fishing_poles -= amount; storage_fishing_poles += amount; } - else if (item_type == ITEM_ROPES) { inv_ropes -= amount; storage_ropes += amount; } - else if (item_type == ITEM_REED_BASKETS) { inv_reed_baskets -= amount; storage_reed_baskets += amount; } - else if (item_type == ITEM_CLAY_POTS) { inv_clay_pots -= amount; storage_clay_pots += amount; } - else if (item_type == ITEM_SKIN_HATS) { inv_skin_hats -= amount; storage_skin_hats += amount; } - else if (item_type == ITEM_SKIN_GLOVES) { inv_skin_gloves -= amount; storage_skin_gloves += amount; } - else if (item_type == ITEM_SKIN_PANTS) { inv_skin_pants -= amount; storage_skin_pants += amount; } - else if (item_type == ITEM_SKIN_TUNICS) { inv_skin_tunics -= amount; storage_skin_tunics += amount; } - else if (item_type == ITEM_MOCCASINS) { inv_moccasins -= amount; storage_moccasins += amount; } - else if (item_type == ITEM_SKIN_POUCHES) { inv_skin_pouches -= amount; storage_skin_pouches += amount; } - else if (item_type == ITEM_BACKPACKS) { inv_backpacks -= amount; storage_backpacks += amount; } + // Transfer the items + add_personal_count(item_type, -amount); + add_storage_count(item_type, amount); + + // Special handling for small game types + if (item_type == ITEM_SMALL_GAME) { + move_small_game_to_storage(amount); + } cleanup_equipment_after_inventory_change(); speak_with_history("Deposited " + amount + " " + get_item_label(item_type) + ".", true); @@ -215,34 +175,14 @@ void withdraw_item(int item_type) { int amount = prompt_transfer_amount("Withdraw how many?", max_transfer); if (amount <= 0) return; - if (item_type == ITEM_STICKS) { storage_sticks -= amount; inv_sticks += amount; } - else if (item_type == ITEM_VINES) { storage_vines -= amount; inv_vines += amount; } - else if (item_type == ITEM_REEDS) { storage_reeds -= amount; inv_reeds += amount; } - else if (item_type == ITEM_STONES) { storage_stones -= amount; inv_stones += amount; } - else if (item_type == ITEM_LOGS) { storage_logs -= amount; inv_logs += amount; } - else if (item_type == ITEM_CLAY) { storage_clay -= amount; inv_clay += amount; } - else if (item_type == ITEM_SMALL_GAME) { storage_small_game -= amount; inv_small_game += amount; move_small_game_to_personal(amount); } - else if (item_type == ITEM_MEAT) { storage_meat -= amount; inv_meat += amount; } - else if (item_type == ITEM_SKINS) { storage_skins -= amount; inv_skins += amount; } - else if (item_type == ITEM_FEATHERS) { storage_feathers -= amount; inv_feathers += amount; } - else if (item_type == ITEM_DOWN) { storage_down -= amount; inv_down += amount; } - else if (item_type == ITEM_INCENSE) { storage_incense -= amount; inv_incense += amount; } - else if (item_type == ITEM_SPEARS) { storage_spears -= amount; inv_spears += amount; } - else if (item_type == ITEM_SLINGS) { storage_slings -= amount; inv_slings += amount; } - else if (item_type == ITEM_AXES) { storage_axes -= amount; inv_axes += amount; } - else if (item_type == ITEM_SNARES) { storage_snares -= amount; inv_snares += amount; } - else if (item_type == ITEM_KNIVES) { storage_knives -= amount; inv_knives += amount; } - else if (item_type == ITEM_FISHING_POLES) { storage_fishing_poles -= amount; inv_fishing_poles += amount; } - else if (item_type == ITEM_ROPES) { storage_ropes -= amount; inv_ropes += amount; } - else if (item_type == ITEM_REED_BASKETS) { storage_reed_baskets -= amount; inv_reed_baskets += amount; } - else if (item_type == ITEM_CLAY_POTS) { storage_clay_pots -= amount; inv_clay_pots += amount; } - else if (item_type == ITEM_SKIN_HATS) { storage_skin_hats -= amount; inv_skin_hats += amount; } - else if (item_type == ITEM_SKIN_GLOVES) { storage_skin_gloves -= amount; inv_skin_gloves += amount; } - else if (item_type == ITEM_SKIN_PANTS) { storage_skin_pants -= amount; inv_skin_pants += amount; } - else if (item_type == ITEM_SKIN_TUNICS) { storage_skin_tunics -= amount; inv_skin_tunics += amount; } - else if (item_type == ITEM_MOCCASINS) { storage_moccasins -= amount; inv_moccasins += amount; } - else if (item_type == ITEM_SKIN_POUCHES) { storage_skin_pouches -= amount; inv_skin_pouches += amount; } - else if (item_type == ITEM_BACKPACKS) { storage_backpacks -= amount; inv_backpacks += amount; } + // Transfer the items + add_storage_count(item_type, -amount); + add_personal_count(item_type, amount); + + // Special handling for small game types + if (item_type == ITEM_SMALL_GAME) { + move_small_game_to_personal(amount); + } speak_with_history("Withdrew " + amount + " " + get_item_label(item_type) + ".", true); } @@ -283,34 +223,14 @@ void withdraw_item_max(int item_type) { int amount = (available < space) ? available : space; - if (item_type == ITEM_STICKS) { storage_sticks -= amount; inv_sticks += amount; } - else if (item_type == ITEM_VINES) { storage_vines -= amount; inv_vines += amount; } - else if (item_type == ITEM_REEDS) { storage_reeds -= amount; inv_reeds += amount; } - else if (item_type == ITEM_STONES) { storage_stones -= amount; inv_stones += amount; } - else if (item_type == ITEM_LOGS) { storage_logs -= amount; inv_logs += amount; } - else if (item_type == ITEM_CLAY) { storage_clay -= amount; inv_clay += amount; } - else if (item_type == ITEM_SMALL_GAME) { storage_small_game -= amount; inv_small_game += amount; move_small_game_to_personal(amount); } - else if (item_type == ITEM_MEAT) { storage_meat -= amount; inv_meat += amount; } - else if (item_type == ITEM_SKINS) { storage_skins -= amount; inv_skins += amount; } - else if (item_type == ITEM_FEATHERS) { storage_feathers -= amount; inv_feathers += amount; } - else if (item_type == ITEM_DOWN) { storage_down -= amount; inv_down += amount; } - else if (item_type == ITEM_INCENSE) { storage_incense -= amount; inv_incense += amount; } - else if (item_type == ITEM_SPEARS) { storage_spears -= amount; inv_spears += amount; } - else if (item_type == ITEM_SLINGS) { storage_slings -= amount; inv_slings += amount; } - else if (item_type == ITEM_AXES) { storage_axes -= amount; inv_axes += amount; } - else if (item_type == ITEM_SNARES) { storage_snares -= amount; inv_snares += amount; } - else if (item_type == ITEM_KNIVES) { storage_knives -= amount; inv_knives += amount; } - else if (item_type == ITEM_FISHING_POLES) { storage_fishing_poles -= amount; inv_fishing_poles += amount; } - else if (item_type == ITEM_ROPES) { storage_ropes -= amount; inv_ropes += amount; } - else if (item_type == ITEM_REED_BASKETS) { storage_reed_baskets -= amount; inv_reed_baskets += amount; } - else if (item_type == ITEM_CLAY_POTS) { storage_clay_pots -= amount; inv_clay_pots += amount; } - else if (item_type == ITEM_SKIN_HATS) { storage_skin_hats -= amount; inv_skin_hats += amount; } - else if (item_type == ITEM_SKIN_GLOVES) { storage_skin_gloves -= amount; inv_skin_gloves += amount; } - else if (item_type == ITEM_SKIN_PANTS) { storage_skin_pants -= amount; inv_skin_pants += amount; } - else if (item_type == ITEM_SKIN_TUNICS) { storage_skin_tunics -= amount; inv_skin_tunics += amount; } - else if (item_type == ITEM_MOCCASINS) { storage_moccasins -= amount; inv_moccasins += amount; } - else if (item_type == ITEM_SKIN_POUCHES) { storage_skin_pouches -= amount; inv_skin_pouches += amount; } - else if (item_type == ITEM_BACKPACKS) { storage_backpacks -= amount; inv_backpacks += amount; } + // Transfer the items + add_storage_count(item_type, -amount); + add_personal_count(item_type, amount); + + // Special handling for small game types + if (item_type == ITEM_SMALL_GAME) { + move_small_game_to_personal(amount); + } speak_with_history("Withdrew " + amount + " " + get_item_label(item_type) + ".", true); } @@ -318,34 +238,34 @@ void withdraw_item_max(int item_type) { void build_storage_inventory_options(string[]@ options, int[]@ item_types) { options.resize(0); item_types.resize(0); - options.insert_last("Sticks: " + storage_sticks); item_types.insert_last(ITEM_STICKS); - options.insert_last("Vines: " + storage_vines); item_types.insert_last(ITEM_VINES); - options.insert_last("Reeds: " + storage_reeds); item_types.insert_last(ITEM_REEDS); - options.insert_last("Stones: " + storage_stones); item_types.insert_last(ITEM_STONES); - options.insert_last("Logs: " + storage_logs); item_types.insert_last(ITEM_LOGS); - options.insert_last("Clay: " + storage_clay); item_types.insert_last(ITEM_CLAY); - options.insert_last("Small Game: " + storage_small_game); item_types.insert_last(ITEM_SMALL_GAME); - options.insert_last("Meat: " + storage_meat); item_types.insert_last(ITEM_MEAT); - options.insert_last("Skins: " + storage_skins); item_types.insert_last(ITEM_SKINS); - options.insert_last("Feathers: " + storage_feathers); item_types.insert_last(ITEM_FEATHERS); - options.insert_last("Down: " + storage_down); item_types.insert_last(ITEM_DOWN); - options.insert_last("Incense: " + storage_incense); item_types.insert_last(ITEM_INCENSE); - options.insert_last("Spears: " + storage_spears); item_types.insert_last(ITEM_SPEARS); - options.insert_last("Slings: " + storage_slings); item_types.insert_last(ITEM_SLINGS); - options.insert_last("Axes: " + storage_axes); item_types.insert_last(ITEM_AXES); - options.insert_last("Snares: " + storage_snares); item_types.insert_last(ITEM_SNARES); - options.insert_last("Knives: " + storage_knives); item_types.insert_last(ITEM_KNIVES); - options.insert_last("Fishing Poles: " + storage_fishing_poles); item_types.insert_last(ITEM_FISHING_POLES); - options.insert_last("Ropes: " + storage_ropes); item_types.insert_last(ITEM_ROPES); - options.insert_last("Reed Baskets: " + storage_reed_baskets); item_types.insert_last(ITEM_REED_BASKETS); - options.insert_last("Clay Pots: " + storage_clay_pots); item_types.insert_last(ITEM_CLAY_POTS); - options.insert_last("Skin Hats: " + storage_skin_hats); item_types.insert_last(ITEM_SKIN_HATS); - options.insert_last("Skin Gloves: " + storage_skin_gloves); item_types.insert_last(ITEM_SKIN_GLOVES); - options.insert_last("Skin Pants: " + storage_skin_pants); item_types.insert_last(ITEM_SKIN_PANTS); - options.insert_last("Skin Tunics: " + storage_skin_tunics); item_types.insert_last(ITEM_SKIN_TUNICS); - options.insert_last("Moccasins: " + storage_moccasins); item_types.insert_last(ITEM_MOCCASINS); - options.insert_last("Skin Pouches: " + storage_skin_pouches); item_types.insert_last(ITEM_SKIN_POUCHES); - options.insert_last("Backpacks: " + storage_backpacks); item_types.insert_last(ITEM_BACKPACKS); + options.insert_last("Sticks: " + get_storage_count(ITEM_STICKS)); item_types.insert_last(ITEM_STICKS); + options.insert_last("Vines: " + get_storage_count(ITEM_VINES)); item_types.insert_last(ITEM_VINES); + options.insert_last("Reeds: " + get_storage_count(ITEM_REEDS)); item_types.insert_last(ITEM_REEDS); + options.insert_last("Stones: " + get_storage_count(ITEM_STONES)); item_types.insert_last(ITEM_STONES); + options.insert_last("Logs: " + get_storage_count(ITEM_LOGS)); item_types.insert_last(ITEM_LOGS); + options.insert_last("Clay: " + get_storage_count(ITEM_CLAY)); item_types.insert_last(ITEM_CLAY); + options.insert_last("Small Game: " + get_storage_count(ITEM_SMALL_GAME)); item_types.insert_last(ITEM_SMALL_GAME); + options.insert_last("Meat: " + get_storage_count(ITEM_MEAT)); item_types.insert_last(ITEM_MEAT); + options.insert_last("Skins: " + get_storage_count(ITEM_SKINS)); item_types.insert_last(ITEM_SKINS); + options.insert_last("Feathers: " + get_storage_count(ITEM_FEATHERS)); item_types.insert_last(ITEM_FEATHERS); + options.insert_last("Down: " + get_storage_count(ITEM_DOWN)); item_types.insert_last(ITEM_DOWN); + options.insert_last("Incense: " + get_storage_count(ITEM_INCENSE)); item_types.insert_last(ITEM_INCENSE); + options.insert_last("Spears: " + get_storage_count(ITEM_SPEARS)); item_types.insert_last(ITEM_SPEARS); + options.insert_last("Slings: " + get_storage_count(ITEM_SLINGS)); item_types.insert_last(ITEM_SLINGS); + options.insert_last("Axes: " + get_storage_count(ITEM_AXES)); item_types.insert_last(ITEM_AXES); + options.insert_last("Snares: " + get_storage_count(ITEM_SNARES)); item_types.insert_last(ITEM_SNARES); + options.insert_last("Knives: " + get_storage_count(ITEM_KNIVES)); item_types.insert_last(ITEM_KNIVES); + options.insert_last("Fishing Poles: " + get_storage_count(ITEM_FISHING_POLES)); item_types.insert_last(ITEM_FISHING_POLES); + options.insert_last("Ropes: " + get_storage_count(ITEM_ROPES)); item_types.insert_last(ITEM_ROPES); + options.insert_last("Reed Baskets: " + get_storage_count(ITEM_REED_BASKETS)); item_types.insert_last(ITEM_REED_BASKETS); + options.insert_last("Clay Pots: " + get_storage_count(ITEM_CLAY_POTS)); item_types.insert_last(ITEM_CLAY_POTS); + options.insert_last("Skin Hats: " + get_storage_count(ITEM_SKIN_HATS)); item_types.insert_last(ITEM_SKIN_HATS); + options.insert_last("Skin Gloves: " + get_storage_count(ITEM_SKIN_GLOVES)); item_types.insert_last(ITEM_SKIN_GLOVES); + options.insert_last("Skin Pants: " + get_storage_count(ITEM_SKIN_PANTS)); item_types.insert_last(ITEM_SKIN_PANTS); + options.insert_last("Skin Tunics: " + get_storage_count(ITEM_SKIN_TUNICS)); item_types.insert_last(ITEM_SKIN_TUNICS); + options.insert_last("Moccasins: " + get_storage_count(ITEM_MOCCASINS)); item_types.insert_last(ITEM_MOCCASINS); + options.insert_last("Skin Pouches: " + get_storage_count(ITEM_SKIN_POUCHES)); item_types.insert_last(ITEM_SKIN_POUCHES); + options.insert_last("Backpacks: " + get_storage_count(ITEM_BACKPACKS)); item_types.insert_last(ITEM_BACKPACKS); // Add stored runed items int[] runeable = get_runeable_equipment_types(); diff --git a/src/quest_system.nvgt b/src/quest_system.nvgt index 5010d2a..32f64f8 100644 --- a/src/quest_system.nvgt +++ b/src/quest_system.nvgt @@ -86,12 +86,12 @@ void apply_quest_reward(int score) { int logs_gain = (score >= QUEST_LOG_SCORE) ? 1 : 0; int skins_gain = (score >= QUEST_SKIN_SCORE) ? 1 : 0; - int stones_added = add_to_stack(inv_stones, stones_gain); - inv_stones += stones_added; - int logs_added = add_to_stack(inv_logs, logs_gain); - inv_logs += logs_added; - int skins_added = add_to_stack(inv_skins, skins_gain); - inv_skins += skins_added; + int stones_added = add_to_stack(get_personal_count(ITEM_STONES), stones_gain); + add_personal_count(ITEM_STONES, stones_added); + int logs_added = add_to_stack(get_personal_count(ITEM_LOGS), logs_gain); + add_personal_count(ITEM_LOGS, logs_added); + int skins_added = add_to_stack(get_personal_count(ITEM_SKINS), skins_gain); + add_personal_count(ITEM_SKINS, skins_added); string message = "Quest Complete!\n\nRewards:\n"; message += "Favor: +" + format_favor(favor_gain) + "\n"; diff --git a/src/quests/bat_invasion_game.nvgt b/src/quests/bat_invasion_game.nvgt index ee3222e..ed14d32 100644 --- a/src/quests/bat_invasion_game.nvgt +++ b/src/quests/bat_invasion_game.nvgt @@ -2,12 +2,20 @@ string[] bat_sounds = {"sounds/quests/bat1.ogg", "sounds/quests/bat2.ogg"}; int run_bat_invasion() { - speak_with_history("Bat Invasion. Bats will fly past from left or right. Press space to throw your spear when the bat is centered. Press enter to continue.", true); - - // Wait for enter - while (!key_pressed(KEY_RETURN)) { - wait(5); - } + // Show instructions in text reader + string[] instructions; + instructions.insert_last("=== Bat Invasion ==="); + instructions.insert_last(""); + instructions.insert_last("Bats are invading! Throw your spear to defend."); + instructions.insert_last(""); + instructions.insert_last("How to play:"); + instructions.insert_last(" - Listen for bats flying past from left or right"); + instructions.insert_last(" - Press SPACE to throw your spear when the bat sounds centered"); + instructions.insert_last(" - Accurate throws earn 2 points each"); + instructions.insert_last(" - You have 10 attempts"); + instructions.insert_last(""); + instructions.insert_last("Close this screen to begin."); + text_reader_lines(instructions, "Quest Instructions", true); speak_with_history("Starting.", true); wait(500); @@ -59,10 +67,7 @@ int run_bat_invasion() { p.play_stationary("sounds/quests/spear_throw.ogg", false); // Check if bat is centered (within tolerance) - int distance_from_center = current_pos; - if (distance_from_center < 0) distance_from_center = -distance_from_center; - - if (distance_from_center <= CENTER_TOLERANCE) { + if (abs(current_pos) <= CENTER_TOLERANCE) { hit = true; // Stop bat sound and play hit if (bat_handle != -1) { diff --git a/src/quests/enchanted_melody_game.nvgt b/src/quests/enchanted_melody_game.nvgt index 214c3a0..5cc57ce 100644 --- a/src/quests/enchanted_melody_game.nvgt +++ b/src/quests/enchanted_melody_game.nvgt @@ -20,7 +20,24 @@ int get_note_from_key() { } void run_practice_mode() { - speak_with_history("Enchanted Melody. Repeat the magical pattern using F D R E or K J I U, from lowest to highest pitch. Practice the notes now, then press enter to begin, or escape to cancel.", true); + // Show instructions in text reader + string[] instructions; + instructions.insert_last("=== Enchanted Melody ==="); + instructions.insert_last(""); + instructions.insert_last("Repeat the magical pattern to earn favor from the gods."); + instructions.insert_last(""); + instructions.insert_last("Controls:"); + instructions.insert_last(" F or K - First note (lowest pitch)"); + instructions.insert_last(" D or J - Second note"); + instructions.insert_last(" R or I - Third note"); + instructions.insert_last(" E or U - Fourth note (highest pitch)"); + instructions.insert_last(""); + instructions.insert_last("After closing this screen, you can practice the notes."); + instructions.insert_last("Press Enter when ready to begin, or Escape to cancel."); + text_reader_lines(instructions, "Quest Instructions", true); + + // Practice mode announcement + speak_with_history("Practice mode. Press Enter to begin, Escape to cancel.", true); while (true) { wait(5); diff --git a/src/quests/escape_from_hel_game.nvgt b/src/quests/escape_from_hel_game.nvgt index 09ea5f9..b0a26f1 100644 --- a/src/quests/escape_from_hel_game.nvgt +++ b/src/quests/escape_from_hel_game.nvgt @@ -1,11 +1,20 @@ // Escape from Hel quest game int run_escape_from_hel() { - speak_with_history("Escape from Hel. You are running from the Draugr, good luck. Press space to jump over open graves as you hear them approach. Press enter to continue.", true); - - // Wait for enter - while (!key_pressed(KEY_RETURN)) { - wait(5); - } + // Show instructions in text reader + string[] instructions; + instructions.insert_last("=== Escape from Hel ==="); + instructions.insert_last(""); + instructions.insert_last("You are fleeing from the realm of the dead!"); + instructions.insert_last(""); + instructions.insert_last("How to play:"); + instructions.insert_last(" - You run automatically, speed increases over time"); + instructions.insert_last(" - Listen for open graves approaching (growing louder)"); + instructions.insert_last(" - Press SPACE to jump over graves"); + instructions.insert_last(" - Each successful jump earns 2 points"); + instructions.insert_last(" - The run ends when you fall into a grave"); + instructions.insert_last(""); + instructions.insert_last("Close this screen to begin."); + text_reader_lines(instructions, "Quest Instructions", true); speak_with_history("Starting.", true); wait(500); diff --git a/src/save_system.nvgt b/src/save_system.nvgt index 10078b3..90309ca 100644 --- a/src/save_system.nvgt +++ b/src/save_system.nvgt @@ -2,7 +2,7 @@ const string SAVE_FILE_PATH = "save.dat"; const string SAVE_ENCRYPTION_KEY = "draugnorak_save_v1"; -const int SAVE_VERSION = 1; +const int SAVE_VERSION = 2; string last_save_error = ""; bool has_save_game() { @@ -183,66 +183,13 @@ void reset_game_state() { incense_burning = false; blessing_speed_active = false; - inv_stones = 0; - inv_sticks = 0; - inv_vines = 0; - inv_reeds = 0; - inv_logs = 0; - inv_clay = 0; - inv_small_game = 0; - inv_small_game_types.resize(0); - inv_meat = 0; - inv_skins = 0; - inv_feathers = 0; - inv_down = 0; - inv_incense = 0; - inv_spears = 0; - inv_snares = 0; - inv_axes = 0; - inv_knives = 0; - inv_fishing_poles = 0; - inv_slings = 0; - inv_ropes = 0; - inv_reed_baskets = 0; - inv_clay_pots = 0; - inv_skin_hats = 0; - inv_skin_gloves = 0; - inv_skin_pants = 0; - inv_skin_tunics = 0; - inv_moccasins = 0; - inv_skin_pouches = 0; - storage_stones = 0; - storage_sticks = 0; - storage_vines = 0; - storage_reeds = 0; - storage_logs = 0; - storage_clay = 0; - storage_small_game = 0; - storage_small_game_types.resize(0); - storage_meat = 0; - storage_skins = 0; - storage_feathers = 0; - storage_down = 0; - storage_incense = 0; - storage_spears = 0; - storage_snares = 0; - storage_axes = 0; - storage_knives = 0; - storage_fishing_poles = 0; - storage_slings = 0; - storage_ropes = 0; - storage_reed_baskets = 0; - storage_clay_pots = 0; - storage_skin_hats = 0; - storage_skin_gloves = 0; - storage_skin_pants = 0; - storage_skin_tunics = 0; - storage_moccasins = 0; - storage_skin_pouches = 0; + // Reset inventory using the registry system + reset_inventory(); spear_equipped = false; axe_equipped = false; sling_equipped = false; + bow_equipped = false; equipped_head = EQUIP_NONE; equipped_torso = EQUIP_NONE; equipped_arms = EQUIP_NONE; @@ -377,192 +324,32 @@ string[] get_string_list_or_split(dictionary@ data, const string&in key) { return result; } -int get_byte_at(const string&in data, int index) { - string single = data.substr(index, 1); - return character_to_ascii(single); -} - -bool find_raw_key(const string&in rawData, const string&in key, int &out pos_after_key) { - int key_len = key.length(); - if (key_len <= 0 || key_len > 65535) return false; - int low = key_len & 0xFF; - int high = (key_len >> 8) & 0xFF; - int limit = rawData.length() - key_len - 2; - for (int i = 0; i <= limit; i++) { - if (get_byte_at(rawData, i) != low) continue; - if (get_byte_at(rawData, i + 1) != high) continue; - if (rawData.substr(i + 2, key_len) == key) { - pos_after_key = i + 2 + key_len; - return true; - } +// Serialize inventory array to comma-separated string +string serialize_inventory_array(const int[]@ arr) { + if (@arr == null || arr.length() == 0) return ""; + string result = "" + arr[0]; + for (uint i = 1; i < arr.length(); i++) { + result += "," + arr[i]; } - return false; + return result; } -bool get_raw_number(const string&in rawData, const string&in key, int &out value) { - int pos; - if (!find_raw_key(rawData, key, pos)) return false; - if (pos >= rawData.length()) return false; - int type = get_byte_at(rawData, pos); - if (type != 2) return false; - if (pos + 1 + 8 > rawData.length()) return false; - double result = 0; - double multiplier = 1; - for (int i = 0; i < 8; i++) { - result += get_byte_at(rawData, pos + 1 + i) * multiplier; - multiplier *= 256; +// Deserialize comma-separated string to inventory array +void deserialize_inventory_array(const string&in data, int[]@ arr, int expected_size) { + arr.resize(expected_size); + for (int i = 0; i < expected_size; i++) { + arr[i] = 0; } - value = int(result); - return true; -} + if (data.length() == 0) return; -bool get_raw_bool(const string&in rawData, const string&in key, bool &out value) { - int pos; - if (!find_raw_key(rawData, key, pos)) return false; - if (pos >= rawData.length()) return false; - int type = get_byte_at(rawData, pos); - if (type != 1) return false; - if (pos + 1 >= rawData.length()) return false; - value = (get_byte_at(rawData, pos + 1) != 0); - return true; -} - -bool load_game_state_from_raw(const string&in rawData) { - reset_game_state(); - - int value; - bool bool_value; - - if (!get_raw_number(rawData, "player_x", value)) return false; - x = value; - if (!get_raw_number(rawData, "player_health", value)) return false; - player_health = value; - if (!get_raw_number(rawData, "time_current_day", value)) return false; - current_day = value; - - if (get_raw_number(rawData, "player_y", value)) y = value; - if (get_raw_number(rawData, "player_facing", value)) facing = value; - if (get_raw_number(rawData, "player_base_health", value)) base_max_health = value; - if (get_raw_number(rawData, "player_max_health", value)) max_health = value; - if (get_raw_number(rawData, "player_favor", value)) favor = value; - if (get_raw_number(rawData, "player_last_adventure_day", value)) last_adventure_day = value; - if (get_raw_number(rawData, "incense_hours_remaining", value)) incense_hours_remaining = value; - if (get_raw_bool(rawData, "incense_burning", bool_value)) incense_burning = bool_value; - if (get_raw_number(rawData, "time_current_hour", value)) current_hour = value; - if (get_raw_number(rawData, "world_map_size", value)) MAP_SIZE = value; - if (get_raw_number(rawData, "world_expanded_area_start", value)) expanded_area_start = value; - if (get_raw_number(rawData, "world_expanded_area_end", value)) expanded_area_end = value; - if (get_raw_number(rawData, "world_barricade_health", value)) barricade_health = value; - if (get_raw_number(rawData, "world_residents_count", value)) residents_count = value; - - if (get_raw_bool(rawData, "world_barricade_initialized", bool_value)) barricade_initialized = bool_value; - if (get_raw_bool(rawData, "time_sun_setting_warned", bool_value)) sun_setting_warned = bool_value; - if (get_raw_bool(rawData, "time_sunrise_warned", bool_value)) sunrise_warned = bool_value; - if (get_raw_bool(rawData, "time_area_expanded_today", bool_value)) area_expanded_today = bool_value; - if (get_raw_bool(rawData, "time_invasion_active", bool_value)) invasion_active = bool_value; - if (get_raw_bool(rawData, "time_invasion_triggered_today", bool_value)) invasion_triggered_today = bool_value; - if (get_raw_bool(rawData, "time_invasion_roll_done_today", bool_value)) invasion_roll_done_today = bool_value; - if (get_raw_bool(rawData, "quest_roll_done_today", bool_value)) quest_roll_done_today = bool_value; - - if (get_raw_number(rawData, "time_invasion_start_hour", value)) invasion_start_hour = value; - if (get_raw_number(rawData, "time_invasion_chance", value)) invasion_chance = value; - if (get_raw_number(rawData, "time_invasion_scheduled_hour", value)) invasion_scheduled_hour = value; - - if (get_raw_number(rawData, "inventory_stones", value)) inv_stones = value; - if (get_raw_number(rawData, "inventory_sticks", value)) inv_sticks = value; - if (get_raw_number(rawData, "inventory_vines", value)) inv_vines = value; - if (get_raw_number(rawData, "inventory_reeds", value)) inv_reeds = value; - if (get_raw_number(rawData, "inventory_logs", value)) inv_logs = value; - if (get_raw_number(rawData, "inventory_clay", value)) inv_clay = value; - if (get_raw_number(rawData, "inventory_small_game", value)) inv_small_game = value; - if (get_raw_number(rawData, "inventory_meat", value)) inv_meat = value; - if (get_raw_number(rawData, "inventory_skins", value)) inv_skins = value; - if (get_raw_number(rawData, "inventory_feathers", value)) inv_feathers = value; - if (get_raw_number(rawData, "inventory_down", value)) inv_down = value; - if (get_raw_number(rawData, "inventory_incense", value)) inv_incense = value; - if (get_raw_number(rawData, "inventory_spears", value)) inv_spears = value; - if (get_raw_number(rawData, "inventory_snares", value)) inv_snares = value; - if (get_raw_number(rawData, "inventory_axes", value)) inv_axes = value; - if (get_raw_number(rawData, "inventory_knives", value)) inv_knives = value; - if (get_raw_number(rawData, "inventory_fishing_poles", value)) inv_fishing_poles = value; - if (get_raw_number(rawData, "inventory_slings", value)) inv_slings = value; - if (get_raw_number(rawData, "inventory_ropes", value)) inv_ropes = value; - if (get_raw_number(rawData, "inventory_reed_baskets", value)) inv_reed_baskets = value; - if (get_raw_number(rawData, "inventory_clay_pots", value)) inv_clay_pots = value; - if (get_raw_number(rawData, "inventory_skin_hats", value)) inv_skin_hats = value; - if (get_raw_number(rawData, "inventory_skin_gloves", value)) inv_skin_gloves = value; - if (get_raw_number(rawData, "inventory_skin_pants", value)) inv_skin_pants = value; - if (get_raw_number(rawData, "inventory_skin_tunics", value)) inv_skin_tunics = value; - if (get_raw_number(rawData, "inventory_moccasins", value)) inv_moccasins = value; - if (get_raw_number(rawData, "inventory_skin_pouches", value)) inv_skin_pouches = value; - if (get_raw_number(rawData, "inventory_backpacks", value)) inv_backpacks = value; - - if (get_raw_number(rawData, "storage_stones", value)) storage_stones = value; - if (get_raw_number(rawData, "storage_sticks", value)) storage_sticks = value; - if (get_raw_number(rawData, "storage_vines", value)) storage_vines = value; - if (get_raw_number(rawData, "storage_reeds", value)) storage_reeds = value; - if (get_raw_number(rawData, "storage_logs", value)) storage_logs = value; - if (get_raw_number(rawData, "storage_clay", value)) storage_clay = value; - if (get_raw_number(rawData, "storage_small_game", value)) storage_small_game = value; - if (get_raw_number(rawData, "storage_meat", value)) storage_meat = value; - if (get_raw_number(rawData, "storage_skins", value)) storage_skins = value; - if (get_raw_number(rawData, "storage_feathers", value)) storage_feathers = value; - if (get_raw_number(rawData, "storage_down", value)) storage_down = value; - if (get_raw_number(rawData, "storage_incense", value)) storage_incense = value; - if (get_raw_number(rawData, "storage_spears", value)) storage_spears = value; - if (get_raw_number(rawData, "storage_snares", value)) storage_snares = value; - if (get_raw_number(rawData, "storage_axes", value)) storage_axes = value; - if (get_raw_number(rawData, "storage_knives", value)) storage_knives = value; - if (get_raw_number(rawData, "storage_fishing_poles", value)) storage_fishing_poles = value; - if (get_raw_number(rawData, "storage_slings", value)) storage_slings = value; - if (get_raw_number(rawData, "storage_ropes", value)) storage_ropes = value; - if (get_raw_number(rawData, "storage_reed_baskets", value)) storage_reed_baskets = value; - if (get_raw_number(rawData, "storage_clay_pots", value)) storage_clay_pots = value; - if (get_raw_number(rawData, "storage_skin_hats", value)) storage_skin_hats = value; - if (get_raw_number(rawData, "storage_skin_gloves", value)) storage_skin_gloves = value; - if (get_raw_number(rawData, "storage_skin_pants", value)) storage_skin_pants = value; - if (get_raw_number(rawData, "storage_skin_tunics", value)) storage_skin_tunics = value; - if (get_raw_number(rawData, "storage_moccasins", value)) storage_moccasins = value; - if (get_raw_number(rawData, "storage_skin_pouches", value)) storage_skin_pouches = value; - if (get_raw_number(rawData, "storage_backpacks", value)) storage_backpacks = value; - - if (get_raw_bool(rawData, "equipment_spear_equipped", bool_value)) spear_equipped = bool_value; - if (get_raw_bool(rawData, "equipment_axe_equipped", bool_value)) axe_equipped = bool_value; - if (get_raw_bool(rawData, "equipment_sling_equipped", bool_value)) sling_equipped = bool_value; - if (get_raw_number(rawData, "equipment_head", value)) equipped_head = value; - if (get_raw_number(rawData, "equipment_torso", value)) equipped_torso = value; - if (get_raw_number(rawData, "equipment_hands", value)) equipped_hands = value; - if (get_raw_number(rawData, "equipment_legs", value)) equipped_legs = value; - if (get_raw_number(rawData, "equipment_feet", value)) equipped_feet = value; - if (get_raw_number(rawData, "equipment_arms", value)) equipped_arms = value; - - if (!equipment_available(equipped_head)) equipped_head = EQUIP_NONE; - if (!equipment_available(equipped_torso)) equipped_torso = EQUIP_NONE; - if (!equipment_available(equipped_hands)) equipped_hands = EQUIP_NONE; - if (!equipment_available(equipped_legs)) equipped_legs = EQUIP_NONE; - if (!equipment_available(equipped_feet)) equipped_feet = EQUIP_NONE; - if (!equipment_available(equipped_arms)) equipped_arms = EQUIP_NONE; - if (incense_hours_remaining > 0) incense_burning = true; - - if (inv_small_game_types.length() == 0 && inv_small_game > 0) { - for (int i = 0; i < inv_small_game; i++) { - inv_small_game_types.insert_last("small game"); - } + string[]@ parts = data.split(","); + uint count = parts.length(); + if (count > uint(expected_size)) count = uint(expected_size); + for (uint i = 0; i < count; i++) { + arr[i] = parse_int(parts[i]); } - - if (!barricade_initialized) { - init_barricade(); - } else { - if (barricade_health < 0) barricade_health = 0; - if (barricade_health > BARRICADE_MAX_HEALTH) barricade_health = BARRICADE_MAX_HEALTH; - } - spawn_trees(5, 19); - - is_daytime = (current_hour >= 6 && current_hour < 19); - hour_timer.restart(); - update_max_health_from_equipment(); - return true; } + bool save_game_state() { dictionary saveData; @@ -578,69 +365,16 @@ bool save_game_state() { saveData.set("incense_hours_remaining", incense_hours_remaining); saveData.set("incense_burning", incense_burning); - saveData.set("inventory_stones", inv_stones); - saveData.set("inventory_sticks", inv_sticks); - saveData.set("inventory_vines", inv_vines); - saveData.set("inventory_reeds", inv_reeds); - saveData.set("inventory_logs", inv_logs); - saveData.set("inventory_clay", inv_clay); - saveData.set("inventory_small_game", inv_small_game); - saveData.set("inventory_meat", inv_meat); - saveData.set("inventory_skins", inv_skins); - saveData.set("inventory_feathers", inv_feathers); - saveData.set("inventory_down", inv_down); - saveData.set("inventory_incense", inv_incense); - saveData.set("inventory_spears", inv_spears); - saveData.set("inventory_snares", inv_snares); - saveData.set("inventory_axes", inv_axes); - saveData.set("inventory_knives", inv_knives); - saveData.set("inventory_fishing_poles", inv_fishing_poles); - saveData.set("inventory_slings", inv_slings); - saveData.set("inventory_ropes", inv_ropes); - saveData.set("inventory_reed_baskets", inv_reed_baskets); - saveData.set("inventory_clay_pots", inv_clay_pots); - saveData.set("inventory_skin_hats", inv_skin_hats); - saveData.set("inventory_skin_gloves", inv_skin_gloves); - saveData.set("inventory_skin_pants", inv_skin_pants); - saveData.set("inventory_skin_tunics", inv_skin_tunics); - saveData.set("inventory_moccasins", inv_moccasins); - saveData.set("inventory_skin_pouches", inv_skin_pouches); - saveData.set("inventory_backpacks", inv_backpacks); - saveData.set("inventory_small_game_types", join_string_array(inv_small_game_types)); - - saveData.set("storage_stones", storage_stones); - saveData.set("storage_sticks", storage_sticks); - saveData.set("storage_vines", storage_vines); - saveData.set("storage_reeds", storage_reeds); - saveData.set("storage_logs", storage_logs); - saveData.set("storage_clay", storage_clay); - saveData.set("storage_small_game", storage_small_game); - saveData.set("storage_meat", storage_meat); - saveData.set("storage_skins", storage_skins); - saveData.set("storage_feathers", storage_feathers); - saveData.set("storage_down", storage_down); - saveData.set("storage_incense", storage_incense); - saveData.set("storage_spears", storage_spears); - saveData.set("storage_snares", storage_snares); - saveData.set("storage_axes", storage_axes); - saveData.set("storage_knives", storage_knives); - saveData.set("storage_fishing_poles", storage_fishing_poles); - saveData.set("storage_slings", storage_slings); - saveData.set("storage_ropes", storage_ropes); - saveData.set("storage_reed_baskets", storage_reed_baskets); - saveData.set("storage_clay_pots", storage_clay_pots); - saveData.set("storage_skin_hats", storage_skin_hats); - saveData.set("storage_skin_gloves", storage_skin_gloves); - saveData.set("storage_skin_pants", storage_skin_pants); - saveData.set("storage_skin_tunics", storage_skin_tunics); - saveData.set("storage_moccasins", storage_moccasins); - saveData.set("storage_skin_pouches", storage_skin_pouches); - saveData.set("storage_backpacks", storage_backpacks); + // Save inventory arrays using new compact format + saveData.set("personal_inventory", serialize_inventory_array(personal_inventory)); + saveData.set("storage_inventory", serialize_inventory_array(storage_inventory)); + saveData.set("personal_small_game_types", join_string_array(personal_small_game_types)); saveData.set("storage_small_game_types", join_string_array(storage_small_game_types)); saveData.set("equipment_spear_equipped", spear_equipped); saveData.set("equipment_axe_equipped", axe_equipped); saveData.set("equipment_sling_equipped", sling_equipped); + saveData.set("equipment_bow_equipped", bow_equipped); saveData.set("equipment_head", equipped_head); saveData.set("equipment_torso", equipped_torso); saveData.set("equipment_arms", equipped_arms); @@ -819,9 +553,6 @@ bool load_game_state() { saveData = deserialize(encryptedData); } if (@saveData == null || !dictionary_has_keys(saveData)) { - if (load_game_state_from_raw(rawData)) { - return true; - } last_save_error = "Save file is corrupted or unreadable."; return false; } @@ -875,94 +606,53 @@ bool load_game_state() { if (y < 0) y = 0; if (facing != 0 && facing != 1) facing = 1; - inv_stones = int(get_number(saveData, "inventory_stones", 0)); - inv_sticks = int(get_number(saveData, "inventory_sticks", 0)); - inv_vines = int(get_number(saveData, "inventory_vines", 0)); - inv_reeds = int(get_number(saveData, "inventory_reeds", 0)); - inv_logs = int(get_number(saveData, "inventory_logs", 0)); - inv_clay = int(get_number(saveData, "inventory_clay", 0)); - inv_small_game = int(get_number(saveData, "inventory_small_game", 0)); - inv_meat = int(get_number(saveData, "inventory_meat", 0)); - inv_skins = int(get_number(saveData, "inventory_skins", 0)); - inv_feathers = int(get_number(saveData, "inventory_feathers", 0)); - inv_down = int(get_number(saveData, "inventory_down", 0)); - inv_incense = int(get_number(saveData, "inventory_incense", 0)); - inv_spears = int(get_number(saveData, "inventory_spears", 0)); - inv_snares = int(get_number(saveData, "inventory_snares", 0)); - inv_axes = int(get_number(saveData, "inventory_axes", 0)); - inv_knives = int(get_number(saveData, "inventory_knives", 0)); - inv_fishing_poles = int(get_number(saveData, "inventory_fishing_poles", 0)); - inv_slings = int(get_number(saveData, "inventory_slings", 0)); - inv_ropes = int(get_number(saveData, "inventory_ropes", 0)); - inv_reed_baskets = int(get_number(saveData, "inventory_reed_baskets", 0)); - inv_clay_pots = int(get_number(saveData, "inventory_clay_pots", 0)); - inv_skin_hats = int(get_number(saveData, "inventory_skin_hats", 0)); - inv_skin_gloves = int(get_number(saveData, "inventory_skin_gloves", 0)); - inv_skin_pants = int(get_number(saveData, "inventory_skin_pants", 0)); - inv_skin_tunics = int(get_number(saveData, "inventory_skin_tunics", 0)); - inv_moccasins = int(get_number(saveData, "inventory_moccasins", 0)); - inv_skin_pouches = int(get_number(saveData, "inventory_skin_pouches", 0)); - inv_backpacks = int(get_number(saveData, "inventory_backpacks", 0)); - - string[] loadedSmallGameTypes = get_string_list_or_split(saveData, "inventory_small_game_types"); - inv_small_game_types.resize(0); - for (uint i = 0; i < loadedSmallGameTypes.length(); i++) { - inv_small_game_types.insert_last(loadedSmallGameTypes[i]); + // Load inventory using new array format + string personal_inv_str; + if (saveData.get("personal_inventory", personal_inv_str)) { + deserialize_inventory_array(personal_inv_str, personal_inventory, ITEM_COUNT); } - if (inv_small_game_types.length() == 0 && inv_small_game > 0) { - for (int i = 0; i < inv_small_game; i++) { - inv_small_game_types.insert_last("small game"); + string storage_inv_str; + if (saveData.get("storage_inventory", storage_inv_str)) { + deserialize_inventory_array(storage_inv_str, storage_inventory, ITEM_COUNT); + } + + // Load small game types + string[] loadedSmallGameTypes = get_string_list_or_split(saveData, "personal_small_game_types"); + personal_small_game_types.resize(0); + for (uint i = 0; i < loadedSmallGameTypes.length(); i++) { + personal_small_game_types.insert_last(loadedSmallGameTypes[i]); + } + + // Sync small game count with types array + int small_game_count = get_personal_count(ITEM_SMALL_GAME); + if (personal_small_game_types.length() == 0 && small_game_count > 0) { + for (int i = 0; i < small_game_count; i++) { + personal_small_game_types.insert_last("small game"); } } else { - inv_small_game = inv_small_game_types.length(); + set_personal_count(ITEM_SMALL_GAME, int(personal_small_game_types.length())); } - storage_stones = int(get_number(saveData, "storage_stones", 0)); - storage_sticks = int(get_number(saveData, "storage_sticks", 0)); - storage_vines = int(get_number(saveData, "storage_vines", 0)); - storage_reeds = int(get_number(saveData, "storage_reeds", 0)); - storage_logs = int(get_number(saveData, "storage_logs", 0)); - storage_clay = int(get_number(saveData, "storage_clay", 0)); - storage_small_game = int(get_number(saveData, "storage_small_game", 0)); - storage_meat = int(get_number(saveData, "storage_meat", 0)); - storage_skins = int(get_number(saveData, "storage_skins", 0)); - storage_feathers = int(get_number(saveData, "storage_feathers", 0)); - storage_down = int(get_number(saveData, "storage_down", 0)); - storage_incense = int(get_number(saveData, "storage_incense", 0)); - storage_spears = int(get_number(saveData, "storage_spears", 0)); - storage_snares = int(get_number(saveData, "storage_snares", 0)); - storage_axes = int(get_number(saveData, "storage_axes", 0)); - storage_knives = int(get_number(saveData, "storage_knives", 0)); - storage_fishing_poles = int(get_number(saveData, "storage_fishing_poles", 0)); - storage_slings = int(get_number(saveData, "storage_slings", 0)); - storage_ropes = int(get_number(saveData, "storage_ropes", 0)); - storage_reed_baskets = int(get_number(saveData, "storage_reed_baskets", 0)); - storage_clay_pots = int(get_number(saveData, "storage_clay_pots", 0)); - storage_skin_hats = int(get_number(saveData, "storage_skin_hats", 0)); - storage_skin_gloves = int(get_number(saveData, "storage_skin_gloves", 0)); - storage_skin_pants = int(get_number(saveData, "storage_skin_pants", 0)); - storage_skin_tunics = int(get_number(saveData, "storage_skin_tunics", 0)); - storage_moccasins = int(get_number(saveData, "storage_moccasins", 0)); - storage_skin_pouches = int(get_number(saveData, "storage_skin_pouches", 0)); - storage_backpacks = int(get_number(saveData, "storage_backpacks", 0)); - string[] loadedStorageSmallGameTypes = get_string_list_or_split(saveData, "storage_small_game_types"); storage_small_game_types.resize(0); for (uint i = 0; i < loadedStorageSmallGameTypes.length(); i++) { storage_small_game_types.insert_last(loadedStorageSmallGameTypes[i]); } - if (storage_small_game_types.length() == 0 && storage_small_game > 0) { - for (int i = 0; i < storage_small_game; i++) { + + int storage_small_game_count = get_storage_count(ITEM_SMALL_GAME); + if (storage_small_game_types.length() == 0 && storage_small_game_count > 0) { + for (int i = 0; i < storage_small_game_count; i++) { storage_small_game_types.insert_last("small game"); } } else { - storage_small_game = storage_small_game_types.length(); + set_storage_count(ITEM_SMALL_GAME, int(storage_small_game_types.length())); } spear_equipped = get_bool(saveData, "equipment_spear_equipped", false); axe_equipped = get_bool(saveData, "equipment_axe_equipped", false); sling_equipped = get_bool(saveData, "equipment_sling_equipped", false); + bow_equipped = get_bool(saveData, "equipment_bow_equipped", false); equipped_head = int(get_number(saveData, "equipment_head", EQUIP_NONE)); equipped_torso = int(get_number(saveData, "equipment_torso", EQUIP_NONE)); equipped_arms = int(get_number(saveData, "equipment_arms", EQUIP_NONE)); @@ -970,8 +660,6 @@ bool load_game_state() { equipped_legs = int(get_number(saveData, "equipment_legs", EQUIP_NONE)); equipped_feet = int(get_number(saveData, "equipment_feet", EQUIP_NONE)); - // Note: Equipment validation moved after runed items are loaded (see below) - reset_quick_slots(); string[] loadedQuickSlots = get_string_list_or_split(saveData, "equipment_quick_slots"); uint slot_count = loadedQuickSlots.length(); diff --git a/src/time_system.nvgt b/src/time_system.nvgt index 579d886..7c74d19 100644 --- a/src/time_system.nvgt +++ b/src/time_system.nvgt @@ -382,7 +382,7 @@ void update_time() { check_ambience_transition(); if (is_daytime && residents_count > 0 && barricade_health < BARRICADE_MAX_HEALTH && current_hour % 4 == 0) { - if (storage_meat > 0) { + if (get_storage_count(ITEM_MEAT) > 0) { int gained = add_barricade_health(residents_count); if (gained > 0 && x <= BASE_END) { speak_with_history("Residents repaired the barricade. +" + gained + " health.", true); @@ -545,14 +545,26 @@ void complete_crossfade() { } void update_ambience(bool force_restart) { - if (is_daytime) { - // Start day ambience + // When force_restart is true, clean up both handles first + if (force_restart) { + if (day_sound_handle != -1) { + p.destroy_sound(day_sound_handle); + day_sound_handle = -1; + } if (night_sound_handle != -1) { p.destroy_sound(night_sound_handle); night_sound_handle = -1; } + } + + if (is_daytime) { + // Stop night ambience if playing + if (night_sound_handle != -1) { + p.destroy_sound(night_sound_handle); + night_sound_handle = -1; + } + // Start day ambience if not already playing if (day_sound_handle == -1 || !p.sound_is_active(day_sound_handle)) { - // Clean up invalid handle if it exists if (day_sound_handle != -1) { p.destroy_sound(day_sound_handle); day_sound_handle = -1; @@ -560,13 +572,13 @@ void update_ambience(bool force_restart) { day_sound_handle = p.play_stationary("sounds/nature/day.ogg", true); } } else { - // Start night ambience + // Stop day ambience if playing if (day_sound_handle != -1) { p.destroy_sound(day_sound_handle); day_sound_handle = -1; } + // Start night ambience if not already playing if (night_sound_handle == -1 || !p.sound_is_active(night_sound_handle)) { - // Clean up invalid handle if it exists if (night_sound_handle != -1) { p.destroy_sound(night_sound_handle); night_sound_handle = -1; diff --git a/src/world/mountains.nvgt b/src/world/mountains.nvgt index 12e82a0..6fbaf4d 100644 --- a/src/world/mountains.nvgt +++ b/src/world/mountains.nvgt @@ -105,9 +105,7 @@ class MountainRange { // Find all steep sections (positions where rope would be needed) int[] steep_positions; for (int i = 1; i < size; i++) { - int diff = elevations[i] - elevations[i-1]; - if (diff < 0) diff = -diff; - if (diff >= MOUNTAIN_STEEP_THRESHOLD) { + if (abs(elevations[i] - elevations[i-1]) >= MOUNTAIN_STEEP_THRESHOLD) { steep_positions.insert_last(i); } } @@ -195,8 +193,7 @@ class MountainRange { // Check if we already have a steep climb (≥7) to/from 10-20 elevation bool has_steep_climb = false; for (int i = 1; i < size; i++) { - int diff = elevations[i] - elevations[i-1]; - if (diff < 0) diff = -diff; + int diff = abs(elevations[i] - elevations[i-1]); if (diff >= MOUNTAIN_STEEP_THRESHOLD) { // Check if either elevation is in 10-20 range @@ -240,9 +237,7 @@ class MountainRange { // Ensure edge transitions aren't too steep (max 20 feet from flat ground) // First transition: tile 0 to tile 1 if (size >= 2) { - int first_diff = elevations[1] - elevations[0]; - if (first_diff < 0) first_diff = -first_diff; - if (first_diff > 20) { + if (abs(elevations[1] - elevations[0]) > 20) { if (elevations[1] > elevations[0]) { elevations[1] = elevations[0] + 20; } else { @@ -253,9 +248,7 @@ class MountainRange { // Last transition: tile size-2 to tile size-1 if (size >= 2) { - int last_diff = elevations[size-1] - elevations[size-2]; - if (last_diff < 0) last_diff = -last_diff; - if (last_diff > 20) { + if (abs(elevations[size-1] - elevations[size-2]) > 20) { if (elevations[size-2] > elevations[size-1]) { elevations[size-2] = elevations[size-1] + 20; } else { @@ -284,9 +277,7 @@ class MountainRange { } bool is_steep_section(int from_x, int to_x) { - int change = get_elevation_change(from_x, to_x); - if (change < 0) change = -change; - return change >= MOUNTAIN_STEEP_THRESHOLD; + return abs(get_elevation_change(from_x, to_x)) >= MOUNTAIN_STEEP_THRESHOLD; } bool contains_position(int world_x) { diff --git a/src/world/world_drops.nvgt b/src/world/world_drops.nvgt index 50288c7..c57a046 100644 --- a/src/world/world_drops.nvgt +++ b/src/world/world_drops.nvgt @@ -81,12 +81,12 @@ void clear_world_drops() { } bool try_pickup_small_game(string game_type) { - if (inv_small_game >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_SMALL_GAME) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more small game.", true); return false; } - inv_small_game++; - inv_small_game_types.insert_last(game_type); + add_personal_count(ITEM_SMALL_GAME, 1); + personal_small_game_types.insert_last(game_type); speak_with_history("Picked up " + game_type + ".", true); return true; } @@ -96,11 +96,11 @@ bool try_pickup_world_drop(WorldDrop@ drop) { return try_pickup_small_game(drop.type); } if (drop.type == "boar carcass") { - if (inv_boar_carcasses >= get_personal_stack_limit()) { + if (get_personal_count(ITEM_BOAR_CARCASSES) >= get_personal_stack_limit()) { speak_with_history("You can't carry any more boar carcasses.", true); return false; } - inv_boar_carcasses++; + add_personal_count(ITEM_BOAR_CARCASSES, 1); speak_with_history("Picked up boar carcass.", true); return true; } diff --git a/src/world/world_fires.nvgt b/src/world/world_fires.nvgt index c2e26ca..1c76006 100644 --- a/src/world/world_fires.nvgt +++ b/src/world/world_fires.nvgt @@ -52,8 +52,7 @@ class WorldFire { // Hard cutoff for fire sound. if (is_burning()) { - int fire_distance = x - position; - if (fire_distance < 0) fire_distance = -fire_distance; + int fire_distance = abs(x - position); if (fire_distance <= FIRE_SOUND_RANGE) { if (sound_handle == -1 || !p.sound_is_active(sound_handle)) { // Clean up invalid handle if it exists diff --git a/src/world/world_snares.nvgt b/src/world/world_snares.nvgt index afac7b9..9e34de5 100644 --- a/src/world/world_snares.nvgt +++ b/src/world/world_snares.nvgt @@ -38,8 +38,7 @@ class WorldSnare { minute_timer.restart(); } - int snare_distance = x - position; - if (snare_distance < 0) snare_distance = -snare_distance; + int snare_distance = abs(x - position); if (snare_distance <= SNARE_SOUND_RANGE) { if (sound_handle == -1 || !p.sound_is_active(sound_handle)) {