LostArtefacts / TRX

Open source re-implementation of Tomb Raider I and Tomb Raider II, along with additional enhancements and bugfixes
https://lostartefacts.dev/
GNU General Public License v3.0
583 stars 36 forks source link

Feature request: option to remove ammo in gameflow #599

Closed lahm86 closed 2 years ago

lahm86 commented 2 years ago

Similar to the remove_guns gameflow level sequence type, would it be possible to add a remove_ammo option? This would remove all ammo and medipacks from the inventory at the start of the level. It would ideally work alongside remove_guns and give_item, although I imagine the latter would be reliant on the order of definition in the JSON.

The feature is used in TR2 in Home Sweet Home and in TR3 in High Security Compound (OpCode 22 as described in TRosettaStone).

This would be ideal for the Randomizer, as we begin to implement TR1 support. While it's not a feature native to TR1, we were hoping it might be feasible to add it to bring the options in the Randomizer for TR1 into line with TR2 and TR3.

Following is an example usage, where everything would be removed from the inventory at the start of Natla's Mines, but a small medipack would then be added.

"sequence": [
  {"type": "play_fmv", "fmv_path": "fmv\\canyon.avi"},
  {"type": "start_game"},
  {"type": "remove_scions"},
  {"type": "remove_guns"},
  {"type": "remove_ammo"},
  {"type": "give_item", "object_id": 93, "quantity": 1},
  {"type": "loop_game"},
  {"type": "stop_game"},
  {"type": "level_stats", "level_id": 13},
  {"type": "exit_to_cine", "level_id": 18},
]

This option might also be suitable for challenge runs or custom levels where you have to plan your pickups and item usage before starting from scratch at the beginning of the next level.

rr- commented 2 years ago

Sure, I like this idea.

lahm86 commented 2 years ago

Great. I'd be happy to have a go at implementing this.

rr- commented 2 years ago

Thanks, I'd appreciate it. Basically we need to declare a new constant, GFS_REMOVE_AMMO / GFS_REMOVE_MEDPACKS, and handle it in relevant switch cases inside gameflow.c.

lahm86 commented 2 years ago

I have this working but at the same time I think I have unearthed a new issue - I wanted to get your thoughts on the best way to handle it.

I added two new constants (thought it best to keep them separate so there is flexibility) and then added the switch statements to gameflow.c (only GameFlow_InterpretSequence shown here).

case GFS_REMOVE_AMMO:
    if (level_type != GFL_SAVED
        && !(g_GameInfo.bonus_flag & GBF_NGPLUS)) {
        g_GameInfo.current[level_num].shotgun_ammo = 0;
        g_GameInfo.current[level_num].magnum_ammo = 0;
        g_GameInfo.current[level_num].uzi_ammo = 0;
        Lara_InitialiseInventory(level_num);
    }
    break;

case GFS_REMOVE_MEDPACKS:
    if (level_type != GFL_SAVED) {
        g_GameInfo.current[level_num].num_medis = 0;
        g_GameInfo.current[level_num].num_big_medis = 0;
        Lara_InitialiseInventory(level_num);
    }
    break;

This works fine, so if you add remove_ammo / remove_medpacks to a level, Lara's inventory is stripped of all those items when she starts.

The issue is that Lara's gun status is affected by this. So if she ends Caves, for example, with guns holstered, and Vilcabamba is set to remove ammo, she will start that level by drawing her pistols (or whatever her last gun was). Without the new options in the gameflow, she starts Vilcabamba without drawing them.

The case for removing scions also calls Lara_InitialiseInventory so as another test, I added remove_scions to Folly on the current release and the same thing happens; I checked V2.9.1 as well before revert_to_pistols was implemented and it was the same (I didn't think this was the problem, but just wanted to rule it out). It's not normally an issue in Natla's Mines as obviously the guns are removed anyway.

I wondered if anything comes to mind for this. I did think about some sort of guard in Lara_InitialiseInventory in lara.c so that g_Lara.request_gun_type is set only once (I'm guessing that's the issue as I noticed the comment in Game_Start, game.c line 213) or perhaps having a separate function to handle only ammo/medpacks/scions and not touch the gun status.

I can raise a separate issue for this if preferred.

rr- commented 2 years ago

I think this could become a separate follow-up ticket to this one.

lahm86 commented 2 years ago

I'll hold back on the PR for this issue for the time being.

walkawayy commented 2 years ago

@lahm86 if rr doesn't mind the approach I took, it should be really simple to add your ammo removal and medipack removal entries to the gameflow similar to guns and scions. See #612.

walkawayy commented 2 years ago

You should be able to work on this now @lahm86 when you have the time. 😃

lahm86 commented 2 years ago

Brilliant, thank you.