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

Pickups in map objects #478

Merged
merged 4 commits into from Feb 5, 2017
Merged

Pickups in map objects #478

merged 4 commits into from Feb 5, 2017

Conversation

grimpunch
Copy link
Contributor

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.

@grimpunch
Copy link
Contributor Author

Refactored so just this change is in the PR now.

Copy link
Owner

@cxong cxong left a 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
Copy link
Owner

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

Copy link
Contributor Author

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! 👍

@cxong cxong merged commit aa227fd into cxong:master Feb 5, 2017
@cxong
Copy link
Owner

cxong commented Feb 5, 2017

Thanks! Good change

cxong added a commit that referenced this pull request Feb 28, 2017
Add DestroySpawn array element to map_objects.json; allows spawning
random pickups (Ammo, Health, Gun) at customisable random chance.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants