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
Pickups in map objects #478
Conversation
Refactored so just this change is in the PR now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay in getting back to this, I've taken a closer look now.
The code that adds health/gun pickups should be in ObjRemove and inside an if (!gCampaign.IsClient) block, because:
- ObjDestroy purely destroys objects, so it would be inappropriate for it to do anything else. See how it's also called in a loop in ObjsTerminate, which happens during teardown - don't want to add pickups at the end of the game or anything like that!
- The game supports client/server multiplayer model, so need to be mindful of what things can happen independently or what things need to be server-authoritative. For example, if we independently spawn health pickups on each client, then we could have a health pickup that exists on one client but not another, so the client player can't pick it up because the server doesn't know about the health pickup. Instead only the server should handle things like spawning health pickups; it will then tell all the clients to add the health pickup at the same location so everything's consistent. Unfortunately the server and client code is pretty much the same, because this was hacked into an existing codebase which didn't support client/server model. The gCampaign.IsClient bool is how we can tell whether we are a client or a server. If you search the codebase for this, you can find it in a lot of places. It's very dirty, not architected properly, maybe one day we can redesign the code to make this more elegant... maybe.
src/cdogs/objs.c
Outdated
void ObjDestroy(TObject *o) | ||
{ | ||
// Random chance to add health pickup or gun pickup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in ObjRemove
, and wrapped inside if (!gCampaign.IsClient)
block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the feedback, I'm just getting my dev environment sorted out again after moving distros so I'll get this PR sorted out soon! 👍
Thanks! Good change |
Add DestroySpawn array element to map_objects.json; allows spawning random pickups (Ammo, Health, Gun) at customisable random chance.
Did an implementation of "Pickups in destroyed map objects" in #367
But it does a gun drop with super low chance instead of an ammo drop.