Home » MODDING HQ 1.13 » v1.13 General Development Talk » merc assignments enum
merc assignments enum[message #342311] Fri, 04 September 2015 03:12 Go to next message
Franimus

 
Messages:46
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]

Re: merc assignments enum[message #342314 is a reply to message #342311] Fri, 04 September 2015 13:26 Go to previous messageGo to next message
Flugente

 
Messages:3461
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
    IS_PATIENT(assignment)
    , and that wouldn't require the above changes.



You gotta wash your hands before picking up a baby. They can see the bacteria burning into their flesh.

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.


Re: merc assignments enum[message #342316 is a reply to message #342314] Sat, 05 September 2015 00:55 Go to previous messageGo to next message
Franimus

 
Messages:46
Registered:June 2015
Location: USA
Ahh... In my haste, I forgot that I was using 32 bits instead of 8. Derp. Well I had fun with it while it lasted. I'll switch to the other approach you mentioned.
Re: merc assignments enum[message #342342 is a reply to message #342316] Mon, 07 September 2015 07:57 Go to previous messageGo to next message
Franimus

 
Messages:46
Registered:June 2015
Location: USA
Just about there... Now I added three new assignments, FACILITY_DOCTOR, FACILITY_PATIENT, and FACILITY_REPAIR. To preserve savegames, I put a conversion in. Fortunately text strings were just copy/paste and no new translations needed.
I found 3-4 possible existing bugs along the way, too... I'll call them out when I upload a diff/patch file. Doing some testing Monday (happy Labor day!) should hopefully be it.
Re: merc assignments enum[message #342435 is a reply to message #342342] Mon, 14 September 2015 09:03 Go to previous message
RoWa21

 
Messages:2030
Registered:October 2005
Location: Austria
committed to svn development trunk


Previous Topic: Automagical XML Editing/Error Checking via AutoIt
Next Topic: Custom weapons.xml
Goto Forum:
  


Current Time: Sun Sep 22 00:48:30 EEST 2019

Total time taken to generate the page: 0.01471 seconds