Project Hospital
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Go down
PanzerKadaver
PanzerKadaver
intern
Posts : 8
Reputation : 0
Join date : 2019-08-31

[MODDING RESOLVED] Default value of PerkType enum is "POSITIVE" Empty [MODDING RESOLVED] Default value of PerkType enum is "POSITIVE"

Wed Jun 30, 2021 7:16 pm
While I was tinkering with the Perk system (in order to update my first mod), I notice some strange behavior in my code. After some research, I finally found that the GameDBPerk's fields, as XmlElement, did not use the highly recommended (but not mandatory) DefaultValueAttribute flag.

Lack of the default attribute flag is 90% time OK, since many type of variable have some sort of "safe default value" (null for string/object, 0 for numbers, false for bool, and so on). But when it come to enum, it's always the first value of the enum that will be used.

In that case, if the GameDBPerk defined in the xml file do not mention the <PerkType> field, the game engine populate this field with the POSITIVE value (from the PerkType enum), which is a problem. "POSITIVE" as a value, have always a strong impact, no matter what game you are playing, and should never been a default value when it come to init a game object.

My recommandations follow :

1) Move the "NEUTRAL" value of PerkType on top of the enum (and specifiy a int value, just to be sure)

Code:
public enum PerkType
{
 NEUTRAL = 0,
 POSITIVE = 1,
 NEGATIVE = 2
}

2) Add a DefaultValueAttribute flag when the game engine should populate an enum value from an xml file.

Code:

using System.ComponentModel;

[XmlRoot]
public class GameDBPerk : DatabaseEntry
{

/**
* Specifying the ElementName is mandatory when you specify a default value. That way, the field will be created first, filled with the default value then the xml reader will try to read the file.
* If the element is absent, the default value will be keeped, otherwise it will be replaced with the value from the file.
* CAUTION : That solution do not handle an empty element (<PerkType></PerkType>), a sanity check may be necessary.
**/


    [DefaultValue(PerkType.NEUTRAL)]
    [XmlElement(ElementName = "PerkType")]
    public PerkType PerkType { get; private set; }
}

Optional : I also notice there is no way for the game engine to know if a Perk is only for an employee (and if yes, for which type of employee) or for a patient. Another flag-type enum could be useful.
jan.oxymoron
jan.oxymoron
developer
Posts : 2309
Reputation : 336
Join date : 2018-03-23

[MODDING RESOLVED] Default value of PerkType enum is "POSITIVE" Empty Re: [MODDING RESOLVED] Default value of PerkType enum is "POSITIVE"

Fri Jul 02, 2021 10:05 am
Hi PanzerKadaver, long time no see!

Good point about the default value, I don't think there was a need for it on our side as the perk type is used mostly for employees in training and in character editor and the values have been filled in for all employee perks. But I should be able to take advantage of the upcoming patch release and set the default value up.

Btw, I actually have a question too - have you had a chance to check the 'official' harmony support that's currently in the game and/or the support for custom procedure scripts (for examinations/treatments)? To be honest I was expecting more interest from the rest of the modding community (same with your original version), but so far no mods using the functionality seem to have been released (as far as I can tell). Smile
https://projecthospital.forumotion.com/t3090-modding-tutorial-setting-up-code-mods
PanzerKadaver
PanzerKadaver
intern
Posts : 8
Reputation : 0
Join date : 2019-08-31

[MODDING RESOLVED] Default value of PerkType enum is "POSITIVE" Empty Re: [MODDING RESOLVED] Default value of PerkType enum is "POSITIVE"

Fri Jul 02, 2021 4:01 pm
Hi Jan,

It's a pleasure to come back here, I'm eager to test the new Heli DLC and, of course, the Infectiology department.

The intent behind the default value is mostly because, the next update of my mod, DoctorModePerks, will add a new Perk (requested by a forum user), "Ace Employee", that will count as all positive perk.

The algortihm override Lopital.PerkSet.HasPerk and check if the perk is positive and if the employee has "Ace Employee" perk. If both assertion are true, the return is override to true.

But, patients' perks do not mention if the perk is positive/negative/neutral or if the perk is exclusive to patients/employee. The workaround I used is to set all patients' perks to NEUTRAL type, meanings the algorithm will not fire.

Without that workaround, all created employees are "gratified" with Pirate perks and such have the "Yarrrr" eye patch. Sure it's fun to look at but not intended noneless.

-------

And yes, I saw the game now officially support Harmony modding and it was an honor for a simple amateur like me to lead the way. I'm very glad to help a studio that deliver a such complete and engaging game.

About the engagement of the modding community, I may have some suggestions to improve it but this thread is maybe not the best place to discuss it. I let you choose how you want me to talk about that subject.
jan.oxymoron
jan.oxymoron
developer
Posts : 2309
Reputation : 336
Join date : 2018-03-23

[MODDING RESOLVED] Default value of PerkType enum is "POSITIVE" Empty Re: [MODDING RESOLVED] Default value of PerkType enum is "POSITIVE"

Mon Jul 12, 2021 5:03 pm
Hi, just a quick update for now - the latest version of the game on beta branch beta-patch-37-test (it should also go live as the official patch later in the week) should have NEUTRAL as the default value of perk type. Regarding the patient perks, yes, setting these to neutral (after copying these to a standalone file under the mod data I assume) should be a good solution, I don't expect many conflicts with other mods there. Smile

Btw - if you'd like to share your thoughts, feel free to drop me a PM here on the forum or an email to info@oxymoron.games. We probably won't have a lot of time for any big mod support changes in the future patches, but this could be really interesting also for future projects. Even with an experienced team, Project Hospital was the first game for most of us with official mod support and we had to build the solutions from scratch in a very limited time frame - it all turned up pretty good, but we should be able to do even better with the lessons learned along the way. Smile
Sponsored content

[MODDING RESOLVED] Default value of PerkType enum is "POSITIVE" Empty Re: [MODDING RESOLVED] Default value of PerkType enum is "POSITIVE"

Back to top
Permissions in this forum:
You cannot reply to topics in this forum