User Tools

Site Tools


user:loggy:combatsim

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
user:loggy:combatsim [2022/12/02 21:26]
loggy
user:loggy:combatsim [2023/01/16 03:26] (current)
loggy target picking algorithm, mostly done I hope
Line 137: Line 137:
     * If the highest unit ID in the game < 39999, set val1 to (highest unit ID in the game)/2 rounded up     * If the highest unit ID in the game < 39999, set val1 to (highest unit ID in the game)/2 rounded up
     * Otherwise, val1 = 20000     * Otherwise, val1 = 20000
-    * If target type = 7 (magic users) 
-      * FIXME how about I look at a selectable target type first 
     * If target type = 1 (commanders)     * If target type = 1 (commanders)
       * FIXME       * FIXME
     * If target type = 2 (archers)     * If target type = 2 (archers)
-      * Make up to (val1/2) attempts, rounded down. Pick a random unit in the whole game. Continue until all the following are not true:+      * Make up to (val1/2) attempts, rounded down. Pick a random unit ID up to the highest. Continue until all the following are true:
         * It's in the current battle         * It's in the current battle
         * It's alive         * It's alive
         * It's not swallowed by another creature         * It's not swallowed by another creature
         * It's owned by a nation other than the attacker         * It's owned by a nation other than the attacker
-        * Its unit type has any weapon with range > 0 **[Giving bows to commanders that don't inherently have a ranged attack will not be specifically picked out by this]**+        * Its unit type innately has any weapon with range > 0 **[Giving bows to commanders that don't inherently have a ranged attack will not be specifically picked out by this]**
         * And at least one of the following:         * And at least one of the following:
           * The target is mindless, and the weapon we are using has no effect on mindless           * The target is mindless, and the weapon we are using has no effect on mindless
-          *  +          * The target has more of its friends than enemies in a 3x3 box around it 
- +      * If this fails to find something, use fallback 
 +    * If target type = 3 (cavalry) 
 +      * This is identical to archers except it checks for the mounted flag instead of having an innate ranged weapon 
 +    * If target type = 4 (fliers) 
 +      * Same again, except the target needs to be able to fly RIGHT NOW. In cases like perpetual storm, this will therefore go only for storm immune/power creatures 
 +    * If target type = 5 (closest) 
 +      * Check all units in the game, starting at 0 and ascending. 
 +      * In order to be valid, units have to meet all of: 
 +        * Be in the battle province 
 +        * Be on the field 
 +        * Either: 
 +          * The target has more of its friends than enemies in a 3x3 box around it 
 +          * userangedweapons != 1 
 +        * Any one of: 
 +          * there is no ranged weapon being used 
 +          * the ranged weapon being used does not only hit mindless 
 +          * the target is not mindless 
 +        * Calculate a "closeness score": 
 +          * closed d3 - 1 + Abs(difference in front-back coordinate) + Abs(difference in left-right coordinate)/
 +          * Add 50 if the target is routing 
 +        * The final target is the lowest "closeness score". In the event of a tie, the lowest unit ID wins 
 +    * If target type = 6 (horrors) 
 +      * Make up to (val1/2) attempts, rounded down. Pick a random unit ID up to the highest. Accept it if it's in the battle, it's alive, it's not owned by the unit doing the targeting, and it has a nonzero number of horror marks. 
 +      * If the above fails, go through all unit IDs in ascending order, and accept the LAST one found that matches the criteria above. 
 +      * If that fails, use fallback 
 +    * If target type = 7 (magic users) 
 +      * **NOTE**: here for completeness. To the best of my current knowledge I do not believe a player can set this command legitimately. I am not aware of anything in the game that uses this in normal gameplay. 
 +      * Make 3000 attempts... 
 +        * Pick a random commander ID: RandInt(HighestCommanderID + 1) 
 +        * If it is all of the following 
 +          * In the battle province 
 +          * Has current hitpoints > 0 
 +          * is not owned by the nation doing the targeting 
 +          * Has non-holy magic paths 
 +          * Has its Front-back coordinate greater than 0 
 +          * Either not using a ranged weapon, the ranged weapon does not hit mindless only, or the target is not mindless 
 +          * The target has more of its friends than enemies in a 3x3 box around it 
 +            * Accept the first target that matches if one is found 
 +      * If those attempts failed: 
 +        * Make 1500 more attempts, this time include holy levels as well 
 +      * Otherwise, proceed through all commanders in ascending ID order, and accept the one with the highest ID 
 +    * If target type = 8 (large monsters) 
 +      * Make up to (val1/2) attempts, rounded down. Pick a random unit ID up to the highest. Accept it if all of the following: 
 +        * It's in the battle province 
 +        * it's alive 
 +        * it's not owned by the unit doing the targeting 
 +        * Any of: 
 +          * we are not using a ranged weapon 
 +          * our ranged weapon does not affect only mindless 
 +          * the target is not mindless 
 +        * The target has more of its friends than enemies in a 3x3 box around it 
 +        * Either: 
 +          * The target is size 5 or 6 
 +          * The target is size 4-6 inclusive AND (val1/2) < (number of attempts * 2) 
 +      * Otherwise, use fallback 
 +    * If target type = 9 (rear) 
 +      * Proceed in ascending unit ID order, starting at 0. 
 +      * If the unit is in the battle province, owned by someone other than the one doing the targeting, has hp > 0, and is in the battle (coordinate check) 
 +        * Get the to-be-targeted unit's front-back coordinate. 
 +        * If the owner of the targeted unit is on the attacking (left hand side) of the battlefield, consider its front/back coordinate to be negative instead of what it really was. 
 +        * If the owner of the targeted unit is neither the attacking nor defending nation (eg Call Horror etc), its front/back coordinate is considered to be -99999 instead. 
 +        * If the target is retreating, subtract 50 from its front/back coordinate. 
 +        * Its front/back coordinate at this point is now a "rearmost-ness score"
 +        * Accept the unit as the "current best rearmost unit if" all of the following... 
 +          * Either: 
 +            * It is the lowest unit ID to make it here 
 +            * closed d100 - 1 <= (400 / (number of alive units in the province that do not belong to the player doing the targeting/3 + 10) + 15 
 +          * Any of: 
 +            * We are not using a ranged weapon 
 +            * The ranged weapon we are using does not affect only mindless 
 +            * The target is not mindless 
 +          * The target has more of its friends than enemies in a 3x3 box around it 
 +          * The "rearmost-ness score" of this unit is greater than or equal to the best one found so far [ties will therefore favour higher unit IDs] 
 +    * Fallback target type (also used as a "none of the above" option) 
 +      * Make up to val1/2 attempts... 
 +        * Roll RandInt(HighestUnitID + 1) 
 +        * Check that... 
 +          * Unit is in battle province 
 +          * Unit is alive 
 +          * Unit isn't owned by nation doing the targeting 
 +          * Unit is not any of the various kinds of temporary (persists after batle, eg is not PD or battlesummoned or a product of secondtmpshape) 
 +          * Unit's front-back coordinate > 0 
 +          * Either: 
 +            * The ranged weapon we are using doesn't hit only mindless - FIXME this is the only one that doesn't check that the weapon's ID is positive before looking up its spec value - if it's invalid, is this going to result in trying to read weapon -1's "spec" value? 
 +            * The target is not mindless 
 +          * Continuing... 
 +            * If function param5 > 1 and the total number of size points in the target unit's squad is less than param5 and this condition has been met less than three times: 
 +              * multiply param5 by 9, divide by 10 then round down 
 +              * start again as if you failed one of the above checks 
 +            * If userangedweapons > 2: 
 +              * If (your ranged weapon's range squared) < (difference in coord1 squared) + (difference in coord2 squared), start again if you failed one of the above checks 
 +            * If the target has more of its friends than enemies in a 3x3 box around it, start again as if you failed one of the above checks 
 +          * Otherwise, accept this unit 
 +      * If this failed and userangedeweapons < 5: 
 +        * Check all units in ascending unit ID until one is found. 
 +          * Needs to be in the battle province 
 +          * Needs to be alive 
 +          * Needs to be owned by someone other than nation doing the targeting 
 +          * Needs a front-back coordinate on the field 
 +          * Ranged weapon needs to hit non-mindless or the target must be non-mindless 
 +          * If use ranged weapons < 3, accept this unit 
 +          * If (your ranged weapon's range squared) < (difference in coord1 squared) + (difference in coord2 squared), start again if you failed one of the above checks 
 +          * The target must has more of its friends than enemies in a 3x3 box around it 
 +          * If you got here, accept this as the target
  
  
user/loggy/combatsim.1670016404.txt.gz · Last modified: 2022/12/02 21:26 by loggy