Beispiel #1
0
        public static void JailBreak(int distance, FlowMap ourFlow)
        {
            // note perhaps we could integrate this into the larger flow
            //  system after it's working well?
            // todo change to using FlowTileSet here

            // get list of capture tiles
            FlowTileSet jails = new FlowTileSet();

            foreach (Loc l in Refs.m.pents)
            {
                jails.Add(ourFlow.TileByLoc(l));
            }

            // get list of cubi locations
            FlowTileSet breaker = new FlowTileSet();

            foreach (Cubi c in Refs.h.roster)
            {
                breaker.Add(ourFlow.TileByLoc(c.loc));
            }

            // IntersectWith to get occupied jails
            jails.IntersectWith(breaker);

            // set jails as heads
            foreach (FlowTile fs in jails)
            {
                fs.flow = 0;
            }

            // just flow to them
            ourFlow.RunFlow(maskWalls: true);
        }
Beispiel #2
0
        public FlowTileSet AllFlowSquares()
        {
            var flowList = new FlowTileSet();

            foreach (FlowTile fs in tiles)
            {
                flowList.Add(fs);
            }
            return(flowList);
        }
Beispiel #3
0
        public static void FleeToRing(int distance, FlowMap ourFlow)
        {
            FlowTileSet heads = new FlowTileSet();

            heads.UnionWith(SetUpInitialRing(distance, ourFlow));
            heads.UnionWith(PlayerNectarTiles(ourFlow));
            foreach (FlowTile fs in heads)
            {
                fs.flow = 0;
            }
            ourFlow.RunFlow(maskWalls: true);
        }
Beispiel #4
0
        public void RunFlow(Boolean maskWalls)
        {
            FlowTileSet heads = AllFlowSquares();

            if (maskWalls)
            {
                foreach (FlowTile fs in heads)
                {
                    // mask out walls etc, we don't flow over those
                    MapTile thisTile = Refs.m.TileByLoc(fs.loc);
                    if (!thisTile.clear)
                    {
                        fs.mask = true;
                    }
                }
            }

            // I call them heads because they 'snake' outwards from the initial point(s)
            //    but you get splits into several heads at junctions so it's a bad metaphor...

            // loop till we can't find anything more to do,
            // (or we decide we've messed up)
            bool changes        = true;
            int  failsafe       = 0;
            int  headsProcessed = 0;

            while (changes == true && failsafe < 256)
            {
                changes = false; failsafe++;

                FlowTileSet newHeads = new FlowTileSet();

                // for each active head tile...
                foreach (FlowTile fs in heads)
                {
                    // ...find the tiles next to it...
                    FlowTileSet newTiles = new FlowTileSet()
                    {
                        fs.OneNorth(),
                                  fs.OneEast(),
                                  fs.OneSouth(),
                                  fs.OneWest()
                    };

                    // ... (ignoring any nulls) ...
                    newTiles.RemoveWhere(item => item == null);

                    // ... and for each one found ...
                    foreach (FlowTile newFlowSq in newTiles)
                    {
                        // ... if we can improve the flow rating of it ...
                        double delta = newFlowSq.flow - fs.flow;

                        MapTile targetTile = Refs.m.TileByLoc(fs.loc);
                        if (targetTile.clear && delta > 1.0001)
                        {
                            // ... do so, and then make it a new head ...
                            newFlowSq.flow = fs.flow + 1;
                            newHeads.Add(newFlowSq);
                            changes = true;
                        }
                    }
                    headsProcessed++;
                }
                // ... and next time around, we keep going using those new heads
                heads = newHeads;

                if (failsafe == 255)
                {
                    Console.WriteLine("Hit flow failsafe!");
                }
            }
        }