Files
draugnorak/src/menus/action_menu.nvgt
2026-01-21 20:01:04 -05:00

231 lines
6.7 KiB
Plaintext

// Action menu system
// Context-sensitive action menu for placing snares, feeding fires, burning incense
void check_action_menu(int x) {
if (key_pressed(KEY_A)) {
run_action_menu(x);
}
}
void try_place_snare(int x) {
if (inv_snares > 0) {
// Prevent placing if one already exists here
if (get_snare_at(x) != null) {
speak_with_history("There is already a snare here.", true);
return;
}
inv_snares--;
add_world_snare(x);
speak_with_history("Snare set.", true);
} else {
speak_with_history("No snares to place.", true);
}
}
void try_feed_fire_stick(WorldFire@ fire) {
if (inv_sticks > 0 && fire != null) {
inv_sticks--;
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);
}
}
void try_feed_fire_vine(WorldFire@ fire) {
if (inv_vines > 0 && fire != null) {
inv_vines--;
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);
}
}
void try_feed_fire_log(WorldFire@ fire) {
if (inv_logs > 0 && fire != null) {
inv_logs--;
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);
}
}
void try_burn_incense() {
if (world_altars.length() == 0) {
speak_with_history("No altar built.", true);
return;
}
if (inv_clay_pots <= 0) {
speak_with_history("You need a clay pot to burn incense.", true);
return;
}
if (inv_incense <= 0) {
speak_with_history("No incense to burn.", true);
return;
}
inv_incense--;
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) {
speak_with_history("No sticks to feed fire.", true);
return;
}
int amount = inv_sticks;
int fuel_added = amount * 300000; // 5 minutes per stick
inv_sticks = 0;
fire.add_fuel(fuel_added);
p.play_stationary("sounds/actions/feed_fire.ogg", false);
speak_with_history("Dumped " + amount + " sticks into the fire.", true);
}
void try_feed_fire_vine_max(WorldFire@ fire) {
if (inv_vines <= 0 || fire == null) {
speak_with_history("No vines to feed fire.", true);
return;
}
int amount = inv_vines;
int fuel_added = amount * 60000; // 1 minute per vine
inv_vines = 0;
fire.add_fuel(fuel_added);
p.play_stationary("sounds/actions/feed_fire.ogg", false);
speak_with_history("Dumped " + amount + " vines into the fire.", true);
}
void try_feed_fire_log_max(WorldFire@ fire) {
if (inv_logs <= 0 || fire == null) {
speak_with_history("No logs to feed fire.", true);
return;
}
int amount = inv_logs;
int fuel_added = amount * 720000; // 12 minutes per log
inv_logs = 0;
fire.add_fuel(fuel_added);
p.play_stationary("sounds/actions/feed_fire.ogg", false);
speak_with_history("Dumped " + amount + " logs into the fire.", true);
}
void try_burn_incense_max() {
if (world_altars.length() == 0) {
speak_with_history("No altar built.", true);
return;
}
if (inv_clay_pots <= 0) {
speak_with_history("You need a clay pot to burn incense.", true);
return;
}
if (inv_incense <= 0) {
speak_with_history("No incense to burn.", true);
return;
}
int amount = inv_incense;
int total_hours = amount * INCENSE_HOURS_PER_STICK;
inv_incense = 0;
inv_clay_pots--;
incense_hours_remaining += total_hours;
incense_burning = true;
speak_with_history("Burned " + amount + " incense. +" + total_hours + " hours.", true);
}
void run_action_menu(int x) {
speak_with_history("Action menu.", true);
int selection = 0;
string[] options;
int[] action_types; // Track what action each option corresponds to
// Check if fire is nearby
WorldFire@ nearby_fire = get_fire_near(x);
bool can_feed_fire = nearby_fire != null;
// Build menu options dynamically
options.insert_last("Place Snare");
action_types.insert_last(0);
if (can_feed_fire) {
if (inv_sticks > 0) {
options.insert_last("Feed fire with stick");
action_types.insert_last(1);
}
if (inv_vines > 0) {
options.insert_last("Feed fire with vine");
action_types.insert_last(2);
}
if (inv_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) {
options.insert_last("Burn incense");
action_types.insert_last(4);
}
while(true) {
wait(5);
menu_background_tick();
if (key_pressed(KEY_ESCAPE)) {
speak_with_history("Closed.", true);
break;
}
if (key_pressed(KEY_DOWN)) {
selection++;
if (selection >= options.length()) selection = 0;
speak_with_history(options[selection], true);
}
if (key_pressed(KEY_UP)) {
selection--;
if (selection < 0) selection = options.length() - 1;
speak_with_history(options[selection], true);
}
if (key_pressed(KEY_RETURN)) {
int action = action_types[selection];
if (action == 0) {
try_place_snare(x);
} else if (action == 1) {
try_feed_fire_stick(nearby_fire);
} else if (action == 2) {
try_feed_fire_vine(nearby_fire);
} else if (action == 3) {
try_feed_fire_log(nearby_fire);
} else if (action == 4) {
try_burn_incense();
}
break;
}
if (key_pressed(KEY_TAB)) {
int action = action_types[selection];
if (action == 0) {
speak_with_history("Can't do that.", true);
} else if (action == 1) {
try_feed_fire_stick_max(nearby_fire);
} else if (action == 2) {
try_feed_fire_vine_max(nearby_fire);
} else if (action == 3) {
try_feed_fire_log_max(nearby_fire);
} else if (action == 4) {
try_burn_incense_max();
}
break;
}
}
}