Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upFix spawned monster upgrading #12147
Conversation
i2amroy
added some commits
Apr 24, 2015
i2amroy
reviewed
Apr 24, 2015
| add_zombie(mon); | ||
|
|
||
| // Return the non-local copy of the monster | ||
| return &zombie(critter_tracker.mon_at(p)); |
This comment has been minimized.
This comment has been minimized.
i2amroy
Apr 24, 2015
Author
Member
Anyone know of a better way to do this than searching through the critter_tracker again to find the monster we just added? I couldn't think of any better way to get a permanent pointer to the monster.
This comment has been minimized.
This comment has been minimized.
BevapDin
Apr 24, 2015
Contributor
You could make add_zombie return the new monster, than return add_zombie(...). add_zombie already returns a bool, but is only used in catalua.cpp
But you want to check the result of add_zombie anyway, there are several situations when it wont have add a zombie, calling critter_tracker.mon_at(p) will fail then:
- the monster id was mon_null,
- the monsters location is outside the map
- (most likely) the monster is blacklisted
Edit: I suggest you make the function return the bool from add_zombie directly and let the caller get the monster reference themself, the caller often doesn't need it anyway.
i2amroy commentedApr 24, 2015
Fixes #12106 permanently.
This turns the "spawn a new monster" block of 4 lines or so into a single function that takes a monster id and a tripoint and then returns a pointer to the newly made monster. This function updates the summoned monster's last update check to the current date, instead of leaving it at the default value of 0.