amtep / ck3-tiger

Checks Crusader Kings 3 user mod files for common mistakes and warns about them.
GNU General Public License v3.0
39 stars 13 forks source link

Logical operators trap warnings #143

Open HiddeLekanne opened 1 month ago

HiddeLekanne commented 1 month ago

In vic3 (and I suspect in other games) if you scope inside a logical operate scope (such as OR) it will default back to AND. A somewhat common mistake I see is this:

Where the modder wants to do a scope switch, but tries to do it inside the logical operator instead of the other way around.

In the case of a single object it is clearly a mistake. So that is easy to solve.

OR = {
     c:GER = {
         gdp >= 10000
         total_population >= 800000
         ...
     }
}

However, there are legimate uses of objects inside logical operators, clearly when the scope within has just a single item:

OR = {
     c:GER = {
         gdp >= 10000
     }
     always = yes
}

But unclear when there appears to be a use for the OR.

OR = {
     c:GER = {
         gdp >= 10000
         total_population >= 800000
     }
     always = yes
}

So I don't know if that one is solvable except by forcing the modder to be pendantic and add another AND inside.

OR = {
     c:GER = {
         AND = {
              gdp >= 10000
              total_population >= 800000
         }
     }
     always = yes
}
dragon-archer commented 1 month ago

I suppose this shouldn't generate any warning, as any opening scope under trigger context includes an implicit AND, and all paradox games (not only CK3 or Vic3 but also EU4 and so on) has the same behavior.

And, if you DO want to do a scope switch, you can either swap the scope and logic operate scope, or add another logic operate scope, e.g.

c:GER = {
     OR = {
          gdp >= 10000
          total_population >= 800000
     }
}

or

OR = {
     c:GER = {
          OR = {
               gdp >= 10000
               total_population >= 800000
          }
     }
     c:AUS = { gdp <= 10000 }
}
amtep commented 1 month ago

I think this can be covered under a more general warning about an OR with only one item in it. Your first example would trigger such a warning. I don't think the other example is clear enough to merit a warning; it could easily be the intended code.

An OR (or an AND) with only one item in it is a minor performance issue and might indicate there is a bug there because of an uncompleted thought. Perhaps a warning at untidy level.

HiddeLekanne commented 1 month ago

@amtep I am confused, is there currently a one item rule? If so, the current tool doesn't detect this code from vanilla when we added it to our mod. This should trigger the one item in OR right?

OR = {
        owner = {
        has_law = law_type:law_regulatory_bodies
        has_law = law_type:law_worker_protections
    }
}
amtep commented 1 month ago

Yes I meant we could add one :)