Esempio n. 1
0
    public void RandomMigration()
    {
        Tile  fromTile      = GetRandomOccupiedTile();
        Tile  toTile        = fromTile.cell.GetRandomNeighborCellAboveWater().tile;
        int   creatureCount = fromTile.creatureCounts[name];
        float percent       = Mathf.Round(Random.value * 4);
        int   moveCount     = (int)(creatureCount * (percent / 4f));

        fromTile.RemoveCreature(this, moveCount);
        toTile.AddCreature(this, moveCount);
    }
Esempio n. 2
0
    public void IncreaseGeneration(Tile tile)
    {
        int tilePop = tile.GetCreatureCount(name);

        if (tilePop > 0)
        {
            int newBornCount = tilePop * stats.Fert;
            tile.AddCreature(this, newBornCount);
            population += newBornCount;
        }


        //int deathToll = deathQueue.Count == stats.lSpn ? deathQueue.Dequeue() : 0;
        //deathQueue.Enqueue(newBornCount);
        //population = population + newBornCount - deathToll;

        // TODO: implement lifespan ^
    }
Esempio n. 3
0
        public static bool PlaceCreature(Position centerPosition, Creature creature, bool extendedPos = false, bool forceLogin = false)
        {
            bool foundTile;
            bool placeInPZ;

            Tile tile = GetTile(centerPosition.X, centerPosition.Y, centerPosition.Z);

            if (tile != null)
            {
                placeInPZ = tile.Flags.HasFlag(TileFlags.ProtectionZone);
                ReturnTypes ret = tile.QueryAdd(0, creature, 1, CylinderFlags.IgnoreBlockItem);
                foundTile = forceLogin || ret == ReturnTypes.NoError;
            }
            else
            {
                placeInPZ = false;
                foundTile = false;
            }

            if (!foundTile)
            {
                List <Tuple <int, int> > relList = (extendedPos ? ExtendedRelList : NormalRelList);

                if (extendedPos)
                {
                    relList.Shuffle(0, 5);
                    relList.Shuffle(5, 6);
                }
                else
                {
                    relList.Shuffle();
                }

                foreach (Tuple <int, int> pos in relList)
                {
                    Position tryPos = new Position((ushort)(centerPosition.X + pos.Item1), (ushort)(centerPosition.Y + pos.Item2), centerPosition.Z);

                    tile = GetTile(tryPos.X, tryPos.Y, tryPos.Z);
                    if (tile == null || (placeInPZ && !tile.Flags.HasFlag(TileFlags.ProtectionZone)))
                    {
                        continue;
                    }

                    if (tile.QueryAdd(0, creature, 1, CylinderFlags.None) == ReturnTypes.NoError)
                    {
                        if (!extendedPos || IsSightClear(centerPosition, tryPos, false))
                        {
                            foundTile = true;
                            break;
                        }
                    }
                }

                if (!foundTile)
                {
                    return(false);
                }
            }

            int  index  = 0;
            uint flags  = 0;
            Item toItem = null;

            //Cylinder* toCylinder = tile->queryDestination(index, *creature, &toItem, flags); //TODO
            //toCylinder->internalAddThing(creature);
            tile.InternalAddThing(creature);
            tile.AddCreature(creature);
            return(true);
        }
Esempio n. 4
0
 public void AddCreature(Creature creature, int amount)
 {
     tile.AddCreature(creature, amount);
     RefreshSelfOnly();
 }