Modding Help [SMAPI] Determining if a tile is open

Discussion in 'Mods' started by Consillium, Apr 19, 2016.

  1. Consillium

    Consillium Poptop Tamer

    Hi All,

    I'm working on a mod that has a path finding element, however I'm having some difficulty determining if a tile is "open", meaning that there isn't something that the NPC will collide with on that tile.

    There are multiple methods in GameLocation that, at first glance, look helpful, and I can determine things like:

    - is the tile occupied: includes things like crops/paths/other things that can be walked on
    - passable: false for some expected things like buildings, but returns true for colliding objects like sprinklers
    - placeable

    and some other similar methods, but none of which that really help me determine whether a path can be navigated. If anyone has any thoughts or suggestions I'd appreciate it :)
     
    • Entoarox

      Entoarox Oxygen Tank

      There isnt any specific way to do this, CA hardcoded most NPC pathing into the game, and the NPC's that dont have hardcoded pathing have great trouble getting around obstacles.
       
      • Consillium

        Consillium Poptop Tamer

        I was afraid of that, well in the mean time if anyone is interested I've written an A* pathfinding algorithm that adds a weight to each tile; 0 if passable and 1 otherwise using three things:

        1. GameLocation.isPassable(Location, Viewport), which determines if a point on the map was intended to walk on or not, but unfortunately not whether it is CURRENTLY available to walk on
        2. Determining if an Object exists at the tile and if it is passable
        3. Determining if a TerrainFeature exists at the tile and if it is passable

        This seems to cover most cases, but is far from perfect right now.
         
        • Consillium

          Consillium Poptop Tamer

          I've managed to successfully create A* pathfinding that will return a list of tiles from the start to the goal, avoiding obstacles preventing cutting corners with obstacles as well. A path might look something like:

          {X: 0 Y: 0}
          {X: 0 Y: 1}
          {X: 0 Y: 2}
          {X: 1 Y: 3}
          {X: 2 Y: 4}
          {X: 3 Y: 5}
          {X: 3 Y:6}
          {X: 3 Y:7}
          {X: 3 Y:8}
          {X: 3 Y:9}
          {X:4 Y:9}
          {X:5 Y:9}

          path.png

          My issue is implementing movement for this...getting around obstacles, even though I'm not cutting corners, is proving challenging, when the movement code determines that the npc has "reached the next tile", it doesn't necessarily mean that its bounding box has cleared the point to which it can move on without colliding.

          I'd really appreciate any suggestions at this point...
           
          • BoffoBoy

            BoffoBoy Existential Complex

            I'm not sure this is helpful but weird pathing occurred with my Bus Stop Storage Mod which was entered via a fence post turned into a sign post in the Bus stop map. At the time, the storage proper was hosted by the joshhose map (the pensioners house), Alex and Evelyn had no issue deciding on taking a really major detour past their actual home and went for my so called 'hidden' entrance to their home map via bus stop come 5 pm, getting stuck.

            Whatever that hard coded pathing is, it's pretty capable of choosing other new entances without issue at all, though I fear how it decides.
             
            • Entoarox

              Entoarox Oxygen Tank

              That is because stardew saw the signpost as a second way into that map, even though it wasnt connected.
              And that pathing has great issues with obstacles, hence why early xnb modding was all about removing two impassable tiles from the bus stop, because Pam kept getting stuck on them.

              @Consillium, I do believe there are methods to check if a NPC's bounding box is overlapping with a certain tile, perhaps you can use that?
               

              Share This Page