Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ai: add configurable item drop behaviour #1012

Merged
merged 2 commits into from
Sep 27, 2023

Conversation

lahm86
Copy link
Collaborator

@lahm86 lahm86 commented Sep 26, 2023

Resolves #967.

Checklist

  • I have read the coding conventions
  • I have added a changelog entry about what my pull request accomplishes, or it is an internal change

Description

This follows on from #1000, and allows all but a few enemies to carry and drop items for Lara to collect. The hardcoded drops have been removed and the gameflow is now responsible for the setup. The default gameflow is configured in line with OG behaviour/requirements.

convert_dropped_guns in the gameflow controls whether guns are converted to ammo when dropped and Lara already has that gun. This is false by default to avoid extra ammo pickups when killing Pierre, Cowboy and Kold in the original levels.

Enemies that are not capable of carrying and dropping are:

  • O_CROCODILE O_ALLIGATOR O_RAT O_VOLE - having items spawn in the water would be difficult to track with changing water levels I feel, and having floating pickups would not be in-keeping with normal experience.
  • O_WARRIOR1 O_WARRIOR2 O_WARRIOR3 - these explode in mid-air and don't follow the standard Creature_Animate routine on death. We could manually spawn the items in each object's control, and work out the floor height, but the item would appear out of nowhere if the creature were high above land when killed, so again it feels non-standard.

Pods and centaur statues can be referenced as carriers in the gameflow; the system will give the items to the enemies that actually spawn, provided those are suitable carriers (empty pods are excluded).

The statistics take into account carried items. I have added a function here for common behaviour when testing triggered killable items.

In terms of saving and loading, items will respawn accordingly if Lara hasn't picked them up yet and equally they will not if she has done so. For testing, I used legacy ATI saves, V3 of the TR1X save format (2.16) and the current V4. In each case, I tested Pierre, Cowboy, Skaterboy and Kold in six scenarios - the following with convert_dropped_guns set to false and then again with it set to true.

  • Before killing the enemy
  • After killing the enemy, but before collecting their item(s)
  • After killing the enemy, and after collecting their item(s)

I also used a test level to ensure items allocated to every potential carrier type spawn as expected, and that items allocated to non-carriers are ignored.

I will follow-up this PR with a document update to create a gameflow MD file, so that builders have a go-to reference for this feature in detail, as well as other gameflow aspects.

This replaces all hardcoded enemy item drops with a flexible system
using the gameflow. Specific enemies can carry pickup items, which
spawn on death and are remembered between saves. Dropped guns can also
optionally be converted to ammo if Lara has the gun already.
Support is also included for Pierre, Cowboy, Skaterboy and Kold to
handle their items accordingly when using legacy save files.

Resolves LostArtefacts#967.
@lahm86 lahm86 added the Feature New functionality label Sep 26, 2023
@lahm86 lahm86 added this to the 3.0 milestone Sep 26, 2023
@lahm86 lahm86 self-assigned this Sep 26, 2023
}
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, let's add more comments in the functions what's their purpose.

#include <stdbool.h>
#include <stddef.h>

#define AMMO_OFFSET 4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do without this const?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps an explicit switch statement to convert gun to ammo would be better, or a map even.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that's exactly what I had on my mind.

ITEM_INFO *item = &g_Items[item_num];
if (Carrier_IsObjectType(item->object_number, m_PlaceholderObjects)) {
int16_t child_item_num = *(int16_t *)item->data;
item = &g_Items[child_item_num];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's amazing that you thought of this even.

}
}
return false;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the int16_t throughout this file become GAME_OBJECT_ID?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be much neater I think.

Converted int16_t to GAME_OBJECT_ID in the carrier module; changed the
approach for gun-to-ammo conversion and legacy enemy testing; changed
invalid drop object ID handling - these will no longer invalidate the
entire array for that enemy.
Added comments to carrier functions for clarity.

Part of LostArtefacts#967.
@lahm86 lahm86 marked this pull request as ready for review September 27, 2023 11:01
Copy link
Collaborator

@walkawayy walkawayy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice!

@lahm86 lahm86 merged commit c1bcc82 into LostArtefacts:develop Sep 27, 2023
1 check passed
@lahm86 lahm86 deleted the issue-967-item-drops branch September 27, 2023 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: allow customization of enemy item drops
3 participants