LCOV - code coverage report
Current view: top level - simulation/ai/common-api - filters.js (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 65 0.0 %
Date: 2023-04-02 12:52:40 Functions: 0 54 0.0 %

          Line data    Source code
       1           0 : var API3 = function(m)
       2             : {
       3             : 
       4           0 : m.Filters = {
       5           0 :         "byType": type => ({
       6           0 :                 "func": ent => ent.templateName() == type,
       7             :                 "dynamicProperties": []
       8             :         }),
       9             : 
      10           0 :         "byClass": cls => ({
      11           0 :                 "func": ent => ent.hasClass(cls),
      12             :                 "dynamicProperties": []
      13             :         }),
      14             : 
      15           0 :         "byClasses": clsList => ({
      16           0 :                 "func": ent => ent.hasClasses(clsList),
      17             :                 "dynamicProperties": []
      18             :         }),
      19             : 
      20           0 :         "byMetadata": (player, key, value) => ({
      21           0 :                 "func": ent => ent.getMetadata(player, key) == value,
      22             :                 "dynamicProperties": ['metadata.' + key]
      23             :         }),
      24             : 
      25           0 :         "byHasMetadata": (player, key) => ({
      26           0 :                 "func": ent => ent.getMetadata(player, key) !== undefined,
      27             :                 "dynamicProperties": ['metadata.' + key]
      28             :         }),
      29             : 
      30           0 :         "and": (filter1, filter2) => ({
      31           0 :                 "func": ent => filter1.func(ent) && filter2.func(ent),
      32             :                 "dynamicProperties": filter1.dynamicProperties.concat(filter2.dynamicProperties)
      33             :         }),
      34             : 
      35           0 :         "or": (filter1, filter2) => ({
      36           0 :                 "func": ent => filter1.func(ent) || filter2.func(ent),
      37             :                 "dynamicProperties": filter1.dynamicProperties.concat(filter2.dynamicProperties)
      38             :         }),
      39             : 
      40           0 :         "not": (filter) => ({
      41           0 :                 "func": ent => !filter.func(ent),
      42             :                 "dynamicProperties": filter.dynamicProperties
      43             :         }),
      44             : 
      45           0 :         "byOwner": owner => ({
      46           0 :                 "func": ent => ent.owner() == owner,
      47             :                 "dynamicProperties": ['owner']
      48             :         }),
      49             : 
      50           0 :         "byNotOwner": owner => ({
      51           0 :                 "func": ent => ent.owner() != owner,
      52             :                 "dynamicProperties": ['owner']
      53             :         }),
      54             : 
      55           0 :         "byOwners": owners => ({
      56           0 :                 "func": ent => owners.some(owner => owner == ent.owner()),
      57             :                 "dynamicProperties": ['owner']
      58             :         }),
      59             : 
      60           0 :         "byCanGarrison": () => ({
      61           0 :                 "func": ent => ent.garrisonMax() > 0,
      62             :                 "dynamicProperties": []
      63             :         }),
      64             : 
      65           0 :         "byTrainingQueue": () => ({
      66           0 :                 "func": ent => ent.trainingQueue(),
      67             :                 "dynamicProperties": ['trainingQueue']
      68             :         }),
      69             : 
      70           0 :         "byResearchAvailable": (gameState, civ) => ({
      71           0 :                 "func": ent => ent.researchableTechs(gameState, civ) !== undefined,
      72             :                 "dynamicProperties": []
      73             :         }),
      74             : 
      75           0 :         "byCanAttackClass": aClass => ({
      76           0 :                 "func": ent => ent.canAttackClass(aClass),
      77             :                 "dynamicProperties": []
      78             :         }),
      79             : 
      80           0 :         "byCanAttackTarget": target => ({
      81           0 :                 "func": ent => ent.canAttackTarget(target),
      82             :                 "dynamicProperties": []
      83             :         }),
      84             : 
      85           0 :         "isGarrisoned": () => ({
      86           0 :                 "func": ent => ent.position() === undefined,
      87             :                 "dynamicProperties": []
      88             :         }),
      89             : 
      90           0 :         "isIdle": () => ({
      91           0 :                 "func": ent => ent.isIdle(),
      92             :                 "dynamicProperties": ['idle']
      93             :         }),
      94             : 
      95           0 :         "isFoundation": () => ({
      96           0 :                 "func": ent => ent.foundationProgress() !== undefined,
      97             :                 "dynamicProperties": []
      98             :         }),
      99             : 
     100           0 :         "isBuilt": () => ({
     101           0 :                 "func": ent => ent.foundationProgress() === undefined,
     102             :                 "dynamicProperties": []
     103             :         }),
     104             : 
     105           0 :         "hasDefensiveFire": () => ({
     106           0 :                 "func": ent => ent.hasDefensiveFire(),
     107             :                 "dynamicProperties": []
     108             :         }),
     109             : 
     110           0 :         "isDropsite": resourceType => ({
     111           0 :                 "func": ent => ent.isResourceDropsite(resourceType),
     112             :                 "dynamicProperties": []
     113             :         }),
     114             : 
     115           0 :         "isTreasure": () => ({
     116             :                 "func": ent => {
     117           0 :                         if (!ent.isTreasure())
     118           0 :                                 return false;
     119             : 
     120             :                         // Don't go for floating treasures since we might not be able
     121             :                         // to reach them and that kills the pathfinder.
     122           0 :                         let template = ent.templateName();
     123           0 :                         return template != "gaia/treasure/shipwreck_debris" &&
     124             :                             template != "gaia/treasure/shipwreck";
     125             :                 },
     126             :                 "dynamicProperties": []
     127             :         }),
     128             : 
     129           0 :         "byResource": resourceType => ({
     130             :                 "func": ent => {
     131           0 :                         if (!ent.resourceSupplyMax())
     132           0 :                                 return false;
     133             : 
     134           0 :                         let type = ent.resourceSupplyType();
     135           0 :                         if (!type)
     136           0 :                                 return false;
     137             : 
     138             :                         // Skip targets that are too hard to hunt
     139           0 :                         if (!ent.isHuntable() || ent.hasClass("SeaCreature"))
     140           0 :                                 return false;
     141             : 
     142           0 :                         return resourceType == type.generic;
     143             :                 },
     144             :                 "dynamicProperties": []
     145             :         }),
     146             : 
     147           0 :         "isHuntable": () => ({
     148             :                 // Skip targets that are too hard to hunt and don't go for the fish! TODO: better accessibility checks
     149           0 :                 "func": ent => ent.hasClass("Animal") && ent.resourceSupplyMax() &&
     150             :                                ent.isHuntable() && !ent.hasClass("SeaCreature"),
     151             :                 "dynamicProperties": []
     152             :         }),
     153             : 
     154           0 :         "isFishable": () => ({
     155             :                 // temporarily do not fish moving fish (i.e. whales)
     156           0 :                 "func": ent => !ent.get("UnitMotion") && ent.hasClass("SeaCreature") && ent.resourceSupplyMax(),
     157             :                 "dynamicProperties": []
     158             :         })
     159             : };
     160             : 
     161           0 : return m;
     162             : 
     163             : }(API3);
     164             : 

Generated by: LCOV version 1.14