Home » MODDING HQ 1.13 » v1.13 General Development Talk » merc assignments enum
merc assignments enum[message #342311]
|
Fri, 04 September 2015 03:12
|
|
Franimus |
|
Messages:55
Registered:June 2015 Location: USA |
|
|
TL;DR - I'm working on a patch to change the merc assignments enum to a bitmask. This will simplify many areas of the code where it makes checks like "assignment == PATIENT || assignment == DOCTOR || assignment == HOSPITAL" to something like "assignment & HEAL".
So I managed to get my mercs to the hospital, but now they are so disease-ridden that they're still bleeding to death, losing 3-4 health per hour. I don't have enough loyalty yet to actually put them in the hospital vanilla-style, so I'm using the facility assignment. For some reason, whenever the disease knocks them below 15, they become completely unbandaged. This means I'd have to sit in tactical view for every single hour change and autobandage, because they'll bleed out before I can stop time compression. Stepping through the code a few times looking for how to make them keep their bandages while on a healing-related assignment, I noticed that the facility bonus for hospital patients isn't being applied. I think the problem is that the code sets assignment = PATIENT in what appears to be an attempt to ensure the merc gets some of those bonuses, but that causes it to always fail the check later where it sets the facility bonus. So rather than search through for every instance of PATIENT and add yet another "|| assignment == FAC_PATIENT" and take out the case FAC_PATIENT: set(assigment, PATIENT) line, and hope there aren't other similar problems, I decided a bitmask would suit the assignments much better. Looking at the existing enum, there is ample opportunity to make good use of this since the addition of facilities, snitches, and propaganda, to name a few.
Since I've got a busy weekend, I'll probably get it done next week. The switch cases are the hardest to translate, but I think it's worth it. I defined a few macros to make the bitwise comparisons much easier.
[Updated on: Fri, 04 September 2015 05:23] Report message to a moderator
|
Corporal
|
|
|
Re: merc assignments enum[message #342314 is a reply to message #342311]
|
Fri, 04 September 2015 13:26
|
|
Flugente |
|
Messages:3509
Registered:April 2009 Location: Germany |
|
|
I see a few issues with that:
- A merc can only ever be on one assignment at any given moment. Thus your bitmask will only ever have one value set. Thus storing the assignment via enum is much, much more effectively - a UINT8 enum can thus be used for 256 assignments, while a UINT8 bitmask only works for 8 assignments.
- We have way more assignments than can fit into a UINT32 bitmask ( I think we've already passed 64 too). Thus you need a very big bitmask to store it.
- This change would require a new variable, and thus modifications to saving/loading SOLDIERTYPE from savegames. Not that much of an issue, but be sure to do that.
- The way I understand you, the only gain is that you can define
#define FLAG_PATIENT_ASSIGNMENT_ALL (FLAG_PATIENT|FLAG_FAC_PATIENT) and then do assignmentflag & FLAG_PATIENT_ASSIGNMENT_ALL .
It would be about the same effort to do, say, #define IS_PATIENT(x) (x == PATIENT || x = FAC_PATIENT) and then , and that wouldn't require the above changes.
I know now that it could never work between us, as much as we wanted to, it could never be! Not because you're a rabbit, but because you're black.
If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.Report message to a moderator
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri Mar 29 08:52:07 GMT+2 2024
Total time taken to generate the page: 0.00941 seconds
|