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

Introduce character_id type #33344

Merged
merged 2 commits into from
Aug 20, 2019
Merged

Conversation

jbytheway
Copy link
Contributor

Summary

SUMMARY: Infrastructure "Introduce character_id type (rather than just using int)"

Purpose of change

To provide improved type safety and code clarity.

Currently npc and avatar get an integer id stored as an int. This is easy to misuse and unclear to work with.

Describe the solution

Introduce a new type character_id which is a thin wrapper around int. Use it in all the places character ids were being used.

Previously there was a distinction between two types of invalid character id: -1 was "really invalid" and 0 was "should have an id, but you're loading a legacy save game that didn't have them". I think such saves are 0.C-era, so I didn't maintain this distinction. I don't think it was actually an important distinction anyway; I think things should continue to work even if loading an old save, but I haven't tested that.

Describe alternatives you've considered

mission ids should probably be handled similarly. I could pull out the common implementation for both into a base class. Might do that if I add mission_id in a future commit.

Could have tried to leverage the existing int_id infrastructure, but that's closely tied to loading game data from json, so I don't think it's a good fit here.

Additional context

If we ever want to change the internal representation of such ids in the future, we now have fewer places we need to edit.

@jbytheway jbytheway changed the title Character Introduce character_id type Aug 18, 2019
@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style labels Aug 18, 2019
Add a new class character_id, which is just a simple wrapper around int
for type-safety purposes.

No semantic change intended.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants