示例#1
0
        public bool CheckConditions(TileManager tileManager, Tile tile, TilePosition pos)
        {
            if (condition != null)
                return condition.Validate(tileManager, tile, pos);

            return true;
        }
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            pos += delta;

            if (tileManager.IsValidTile(pos))
                tileManager.EnqueueInvalidatedTile(pos);
        }
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            pos += delta;

            if (tileManager.IsValidTile(pos))
                tileManager.SetTileType(pos, tileType);
        }
示例#4
0
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            pos += delta;

            if (tileManager.IsValidTile(pos))
                tileManager.DamageTile(pos, damage);
        }
示例#5
0
        public override void Execute(TileManager tileManager, Tile tile, TilePosition center)
        {
            for (int d = 1; d <= radius; d++)
            {
	            int rDamage = damage * (radius - d + 1) / radius;
				
				TilePosition[] tiles = Manhattan.GetTilesAtDistance(d);
				
				for(int i = 0; i < tiles.Length; i++)
				{
					TilePosition p = center + tiles[i];
					
	                if (tileManager.IsValidTile(p))
						if (tileManager.DamageTile(p, rDamage) == false)
							if (setOnFire && tileManager.GetTileDefinition(tileManager.GetTileType(p)).burns)
		                        tileManager.SetTileOnFire(p, true);
				}
            }
			
			if (setOnFire)
			{
				TilePosition[] tiles = Manhattan.GetTilesAtDistance(radius + 1);
				
				for(int i = 0; i < tiles.Length; i++)
				{
					TilePosition p = center + tiles[i];
					
	                if (tileManager.IsValidTile(p))
						if (setOnFire && tileManager.GetTileDefinition(tileManager.GetTileType(p)).burns)
	                        tileManager.SetTileOnFire(p, true);
				}
			}
        }
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            pos += delta;

            if (tileManager.IsValidTile(pos))
                tileManager.world.gameplay.CreateItem(itemDefinition, Graphics.TilePositionToVector3(pos));
        }
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            TileDefinition tileDefinition = tileManager.GetTileDefinition(tile.tileType);

            ItemDefinition itemDefinition = tileManager.world.itemManager.GetItemDefinitionById(tileDefinition.id);

            tileManager.world.gameplay.CreateItem(itemDefinition, Graphics.TilePositionToVector3(pos));
        }
        public override bool Validate(TileManager tileManager, Tile tile, TilePosition pos)
        {
            tileManager.world.stats.checkedConditions++;

            pos += delta;

            return tileManager.IsValidTile(pos) && 
				tileManager.GetTileType(pos) == tileType;
        }
示例#9
0
        public CubeWorld(ICWListener cwListener, ICWFxListener fxListener)
        {
			this.cwListener = cwListener;
            this.fxListener = fxListener;
            this.sectorManager = new SectorManager(this);
			this.tileManager = new TileManager(this);
			this.itemManager = new ItemManager(this);
			this.avatarManager = new AvatarManager(this);
			this.dayCycleManager = new DayCycleManager(this);
        }
        public override bool Validate(TileManager tileManager, Tile tile, TilePosition pos)
        {
            tileManager.world.stats.checkedConditions++;

            foreach (TileRuleCondition condition in conditions)
                if (condition.Validate(tileManager, tile, pos))
                    return true;

            return false;
        }
        public override bool Validate(TileManager tileManager, Tile tile, TilePosition pos)
        {
            tileManager.world.stats.checkedConditions++;
            int amount = 0;

            foreach (TilePosition delta in Manhattan.GetTilesAtDistance(1))
                if (tileManager.IsValidTile(pos + delta) && tileManager.GetTileType(pos + delta) == tileType)
                    amount++;

            return amount >= minValue;
        }
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            pos += delta;

            if (tileManager.IsValidTile(pos))
            {
                if (tileManager.GetTileDynamic(pos))
                {
                    DynamicTile dynamicTile = tileManager.GetDynamicTile(pos);
                    tileManager.world.fxListener.PlayEffect(effectId, dynamicTile);
                }
            }
        }
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            int offset = 0;
            
            if (useRandom)
                offset = random.Next(otherRules.Length);

            for (int i = otherRules.Length - 1; i >= 0; i--)
            {
                if (otherRules[(i + offset) % otherRules.Length].CheckConditions(tileManager, tile, pos) == true)
                {
                    otherRules[(i + offset) % otherRules.Length].Execute(tileManager, tile, pos);
                    break;
                }
            }
        }
        static public void InitLuminance(TileManager tileManager)
        {
            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int y = 0; y < tileManager.sizeY; y++)
                {
                    for (int z = 0; z < tileManager.sizeZ; z++)
                    {
                        TilePosition pos = new TilePosition(x, y, z);
                        if (tileManager.GetTileLightSource(pos))
                            pendingUpdateLights.Add(PositionToInt(x, y, z));
                    }
                }
            }

            UpdateLuminanceLightVector(tileManager);
        }
示例#15
0
        static public void InitLuminance(TileManager tileManager)
        {
            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    for (int y = tileManager.sizeY - 1; y >= 0; y--)
                    {
                        TilePosition pos = new TilePosition(x, y, z);

                        tileManager.SetTileAmbientLuminance(pos, Tile.MAX_LUMINANCE);

                        if (tileManager.GetTileCastShadow(pos))
                            break;
                    }
                }
            }

            for (int x = 0; x < tileManager.sizeX; x++)
            {
                for (int z = 0; z < tileManager.sizeZ; z++)
                {
                    for (int y = tileManager.sizeY - 1; y >= 0; y--)
                    {
                        TilePosition pos = new TilePosition(x, y, z);

                        if (tileManager.GetTileAmbientLuminance(pos) == 0)
                            break;

                        if (x > 0 && tileManager.GetTileAmbientLuminance(pos + new TilePosition(-1, 0, 0)) == 0 ||
                            x < tileManager.sizeX - 1 && tileManager.GetTileAmbientLuminance(pos + new TilePosition(1, 0, 0)) == 0 ||
                            z > 0 && tileManager.GetTileAmbientLuminance(pos + new TilePosition(0, 0, -1)) == 0 ||
                            z < tileManager.sizeZ - 1 && tileManager.GetTileAmbientLuminance(pos + new TilePosition(0, 0, 1)) == 0)
                        {
                            pendingUpdateLights.Add(PositionToInt(x, y, z));
                        }
                    }
                }
            }

            UpdateLuminanceLightVector(tileManager);
        }
示例#16
0
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            pos += delta;

            if (tileManager.IsValidTile(pos))
            {
                if (value == true)
                {
                    tileManager.SetTileDynamic(pos, value, gravity, timeout);
                }
                else if (tileManager.GetTileDynamic(pos))
                {
                    //Call DynamicTile.MakeStatic because if the tile is inside it's update cycle
                    //when this rule is executed, then the array of components would become invalid
                    DynamicTile dynamicTile = tileManager.GetDynamicTile(pos);

                    dynamicTile.MakeStatic();
                }
            }
        }
示例#17
0
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            int level = tile.ExtraData;

            if (tileManager.Ticks % spreadSpeed == 0)
            {
                //Update this tile level
                if (level != 0)
                    level = UpdateTileLevel(tileManager, tile, pos, level);

                //Propagate
                if (level <= maxLevel)
                    Propagate(tileManager, tile, pos, level);
                else if (level > maxLevel)
                    tileManager.SetTileType(pos, TileDefinition.EMPTY_TILE_TYPE);
            }
            else
            {
                tileManager.EnqueueInvalidatedTile(pos);
            }
        }
示例#18
0
 public virtual bool Validate(TileManager tileManager, Tile tile, TilePosition pos)
 {
     return true;
 }
        public override bool Validate(TileManager tileManager, Tile tile, TilePosition pos)
        {
            tileManager.world.stats.checkedConditions++;

            return !condition.Validate(tileManager, tile, pos);
        }
示例#20
0
        private int UpdateTileLevel(TileManager tileManager, Tile tile, TilePosition pos, int level)
        {
            TilePosition posAbove = pos + new TilePosition(0, 1, 0);

            bool aboveIsSameLiquid = tileManager.IsValidTile(posAbove) && tileManager.GetTileType(posAbove) == tile.tileType;

            int nearLowestLevel = int.MaxValue;

            if (aboveIsSameLiquid == false)
            {
                nearLowestLevel = GetLowerLevel(new TilePosition(1, 0, 0), tileManager, tile, pos, nearLowestLevel);
                nearLowestLevel = GetLowerLevel(new TilePosition(-1, 0, 0), tileManager, tile, pos, nearLowestLevel);
                nearLowestLevel = GetLowerLevel(new TilePosition(0, 0, 1), tileManager, tile, pos, nearLowestLevel);
                nearLowestLevel = GetLowerLevel(new TilePosition(0, 0, -1), tileManager, tile, pos, nearLowestLevel);
            }
            else
            {
                nearLowestLevel = 0;
            }

            if (nearLowestLevel != int.MaxValue)
            {
                if (nearLowestLevel + 1 != level)
                {
                    if (nearLowestLevel + 1 > level)
                    {
                        level++;
                        tileManager.SetTileExtraData(pos, (byte)level);
                    }
                    else
                    {
                        if (level > 1)
                        {
                            level--;
                            tileManager.SetTileExtraData(pos, (byte)level);
                        }
                    }
                }
            }
            else
            {
                level = maxLevel + 1;
            }

            return level;
        }
        static public void UpdateLuminanceDark(TileManager tileManager, TilePosition from)
		{
            updatedTiles.Clear();

            pendingUpdateLights.Add(PositionToInt(from.x, from.y, from.z));
			
			while(pendingUpdateLights.Count > 0)
			{
				while(pendingUpdateLights.Count > 0)
				{
                    long pos = pendingUpdateLights[pendingUpdateLights.Count - 1];
                    pendingUpdateLights.RemoveAt(pendingUpdateLights.Count - 1);

                    TilePosition tilePos = IntToPosition(pos);
					Tile tile = tileManager.GetTile(tilePos);
					
					if (tile.LightSourceLuminance > 0)
					{
						byte oldLuminance = tile.LightSourceLuminance;
                        tileManager.SetTileLightSourceLuminance(tilePos, 0);
						
						updatedTiles.Add(pos);
						
						for (int i = 0; i < 6; i++)
						{
							switch(i)
							{
								case 0:
									tilePos.x -= 1;
									break;
								case 1:
									tilePos.x += 2;
									break;
								case 2:
									tilePos.x -= 1;
									tilePos.y -= 1;
									break;
								case 3:
									tilePos.y += 2;
									break;
								case 4:
                                    tilePos.y -= 1;
									tilePos.z -= 1;
									break;
								case 5:
									tilePos.z += 2;
									break;
							}

                            long nearPos = PositionToInt(tilePos.x, tilePos.y, tilePos.z);
							
							if (tileManager.IsValidTile(tilePos) && 
								updatedTiles.Contains(nearPos) == false)
							{
								int nearLuminance = tileManager.GetTileLightSourceLuminance(tilePos);
								
								if (nearLuminance < oldLuminance)
									nextPendingUpdateLights.Add(nearPos);
								else if (lightsToRecalculate.Contains(nearPos) == false)
									lightsToRecalculate.Add(nearPos);
							}							
						}
					}
				}

                List<long> old = pendingUpdateLights;
				pendingUpdateLights = nextPendingUpdateLights;
				nextPendingUpdateLights = old;
			}

            pendingUpdateLights.AddRange(lightsToRecalculate);
            lightsToRecalculate.Clear();

            UpdateLuminanceLightVector(tileManager);
		}		
示例#22
0
        static private int GetLowerLevel(TilePosition dir, TileManager tileManager, Tile tile, TilePosition pos, int minLevel)
        {
            TilePosition posNear = pos + dir;
            if (tileManager.IsValidTile(posNear) && tileManager.GetTileType(posNear) == tile.tileType)
            {
                int levelNear = tileManager.GetTileExtraData(posNear);
                if (levelNear < minLevel)
                    minLevel = levelNear;
            }

            return minLevel;
        }
        static private void UpdateLuminanceLightVector(TileManager tileManager)
		{
			while(pendingUpdateLights.Count > 0)
			{
				while(pendingUpdateLights.Count > 0)
				{
					long pos = pendingUpdateLights[pendingUpdateLights.Count - 1];
                    pendingUpdateLights.RemoveAt(pendingUpdateLights.Count - 1);

                    TilePosition tilePos = IntToPosition(pos);
					Tile tile = tileManager.GetTile(tilePos);
					
					if (tile.CastShadow == false)
					{
						byte luminance = tile.LightSourceLuminance;

                        if (luminance > 0)
                        {
                            luminance --;

                            for (int i = 0; i < 6; i++)
                            {
                                switch (i)
                                {
                                    case 0:
                                        tilePos.x -= 1;
                                        break;
                                    case 1:
                                        tilePos.x += 2;
                                        break;
                                    case 2:
                                        tilePos.x -= 1;
                                        tilePos.y -= 1;
                                        break;
                                    case 3:
                                        tilePos.y += 2;
                                        break;
                                    case 4:
                                        tilePos.y -= 1;
                                        tilePos.z -= 1;
                                        break;
                                    case 5:
                                        tilePos.z += 2;
                                        break;
                                }

                                if (tileManager.IsValidTile(tilePos))
                                {
                                    if (tileManager.GetTileLightSourceLuminance(tilePos) < luminance)
                                    {
                                        tileManager.SetTileLightSourceLuminance(tilePos, luminance);
                                        nextPendingUpdateLights.Add(PositionToInt(tilePos.x, tilePos.y, tilePos.z));
                                    }
                                }
                            }
						}
					}
				}

                List<long> old = pendingUpdateLights;
                pendingUpdateLights = nextPendingUpdateLights;
                nextPendingUpdateLights = old;
            }
		}
		static public void UpdateLuminanceLight(TileManager tileManager, TilePosition from, byte luminance)
		{
			pendingUpdateLights.Add(PositionToInt(from.x, from.y, from.z));
			
			tileManager.SetTileLightSourceLuminance(from, luminance);
			
			UpdateLuminanceLightVector(tileManager);
		}
示例#25
0
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            pos += delta;

            tileManager.world.fxListener.PlayEffect(effectId, Graphics.TilePositionToVector3(pos));
        }
示例#26
0
 public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
 {
     foreach (TileRule rule in otherRules)
         if (rule.CheckConditions(tileManager, tile, pos))
             rule.Execute(tileManager, tile, pos);
 }
示例#27
0
        static private void FindFall(TilePosition dir, TileManager tileManager, Tile tile, TilePosition pos, ref TilePosition nearDirection, ref int nearDistance)
        {
            TilePosition posNear = pos;

            for (int d = 1; d < nearDistance; d++)
            {
                posNear += dir;

                if (tileManager.IsValidTile(posNear) && 
                    (tileManager.GetTileType(posNear) == TileDefinition.EMPTY_TILE_TYPE ||
                     tileManager.GetTileType(posNear) == tile.tileType && tileManager.GetTileExtraData(posNear) != 0))
                {
                    TilePosition posNearBelow = posNear + new TilePosition(0, -1, 0);
                    if (tileManager.IsValidTile(posNearBelow) && 
                        (tileManager.GetTileType(posNearBelow) == TileDefinition.EMPTY_TILE_TYPE ||
                         tileManager.GetTileType(posNearBelow) == tile.tileType))
                    {
                        nearDirection = dir;
                        nearDistance = d;
                        break;
                    }
                }
                else
                    break;
            }
        }
示例#28
0
        static public void UpdateLuminanceDark(TileManager tileManager, TilePosition from)
		{
            if (tileManager.GetTileAmbientLuminance(from) == 0)
                return;

            updatedTiles.Clear();

            pendingUpdateLights.Add(PositionToInt(from.x, from.y, from.z));

            for (int y = from.y - 1; y >= 0; y--)
            {
                pendingUpdateLights.Add(PositionToInt(from.x, y, from.z));

                if (tileManager.GetTileCastShadow(new TilePosition(from.x, y, from.z)) == true)
                    break;
            }
			
			while(pendingUpdateLights.Count > 0)
			{
				while(pendingUpdateLights.Count > 0)
				{
                    long pos = pendingUpdateLights[pendingUpdateLights.Count - 1];
                    pendingUpdateLights.RemoveAt(pendingUpdateLights.Count - 1);

                    TilePosition tilePos = IntToPosition(pos);
					Tile tile = tileManager.GetTile(tilePos);
					
					if ((tilePos.x == from.x && tilePos.z == from.z) || (tile.AmbientLuminance != 0 && tile.AmbientLuminance != Tile.MAX_LUMINANCE))
					{
                        byte oldLuminance = tile.AmbientLuminance;

                        tileManager.SetTileAmbientLuminance(tilePos, 0);

                        updatedTiles.Add(pos);
						
						for (int i = 0; i < 6; i++)
						{
							switch(i)
							{
								case 0:
									tilePos.x -= 1;
									break;
								case 1:
									tilePos.x += 2;
									break;
								case 2:
									tilePos.x -= 1;
									tilePos.y -= 1;
									break;
								case 3:
									tilePos.y += 2;
									break;
								case 4:
                                    tilePos.y -= 1;
									tilePos.z -= 1;
									break;
								case 5:
									tilePos.z += 2;
									break;
							}

                            long nearPos = PositionToInt(tilePos.x, tilePos.y, tilePos.z);
							
							if (tileManager.IsValidTile(tilePos) && 
								updatedTiles.Contains(nearPos) == false)
							{
								int nearLuminance = tileManager.GetTileAmbientLuminance(tilePos);

                                if (nearLuminance <= oldLuminance && nearLuminance != Tile.MAX_LUMINANCE)
									nextPendingUpdateLights.Add(nearPos);
								else if (lightsToRecalculate.Contains(nearPos) == false)
									lightsToRecalculate.Add(nearPos);
							}							
						}
					}
				}
				
				List<long> old = pendingUpdateLights;
				pendingUpdateLights = nextPendingUpdateLights;
				nextPendingUpdateLights = old;
			}

            pendingUpdateLights.AddRange(lightsToRecalculate);
            lightsToRecalculate.Clear();
			
			UpdateLuminanceLightVector(tileManager);
		}		
示例#29
0
        private void Propagate(TileManager tileManager, Tile tile, TilePosition pos, int level)
        {
            TilePosition posBelow = pos + new TilePosition(0, -1, 0);
            bool belowIsSameLiquid = tileManager.IsValidTile(posBelow) && tileManager.GetTileType(posBelow) == tile.tileType;

            if (tileManager.IsValidTile(posBelow) && (tileManager.GetTileType(posBelow) == TileDefinition.EMPTY_TILE_TYPE) || belowIsSameLiquid)
            {
                if (belowIsSameLiquid == false)
                {
                    tileManager.SetTileType(posBelow, tile.tileType);
                    tileManager.SetTileExtraData(posBelow, 1);
                }
            }
            else
            {
                if (level < maxLevel)
                {
                    TilePosition[] nearDirection = new TilePosition[4];

                    int[] nearDistance = new int[] { maxLevel, maxLevel, maxLevel, maxLevel };

                    FindFall(new TilePosition(1, 0, 0), tileManager, tile, pos, ref nearDirection[0], ref nearDistance[0]);
                    FindFall(new TilePosition(-1, 0, 0), tileManager, tile, pos, ref nearDirection[1], ref nearDistance[1]);
                    FindFall(new TilePosition(0, 0, 1), tileManager, tile, pos, ref nearDirection[2], ref nearDistance[2]);
                    FindFall(new TilePosition(0, 0, -1), tileManager, tile, pos, ref nearDirection[3], ref nearDistance[3]);

                    int minNearDistance = Math.Min(Math.Min(Math.Min(nearDistance[0], nearDistance[1]), nearDistance[2]), nearDistance[3]);

                    if (minNearDistance != maxLevel)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            if (nearDistance[i] == minNearDistance)
                            {
                                TilePosition posNear = pos + nearDirection[i];

                                if (tileManager.IsValidTile(posNear) && tileManager.GetTileType(posNear) == TileDefinition.EMPTY_TILE_TYPE)
                                {
                                    TilePosition posNearBelow = posNear + new TilePosition(0, -1, 0);
                                    bool nearBelowIsSameLiquid = tileManager.IsValidTile(posNearBelow) && tileManager.GetTileType(posNearBelow) == tile.tileType;

                                    if (nearBelowIsSameLiquid == false || belowIsSameLiquid == false)
                                    {
                                        tileManager.SetTileType(posNear, tile.tileType);
                                        tileManager.SetTileExtraData(posNear, (byte)(level + 1));
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (TilePosition deltaPos in Manhattan.GetTilesAtDistance(1))
                        {
                            if (deltaPos.y == 0)
                            {
                                TilePosition posNear = pos + deltaPos;
                                if (tileManager.IsValidTile(posNear) && tileManager.GetTileType(posNear) == TileDefinition.EMPTY_TILE_TYPE)
                                {
                                    TilePosition posNearBelow = posNear + new TilePosition(0, -1, 0);
                                    bool nearBelowIsSameLiquid = tileManager.IsValidTile(posNearBelow) && tileManager.GetTileType(posNearBelow) == tile.tileType;

                                    if (nearBelowIsSameLiquid == false || belowIsSameLiquid == false)
                                    {
                                        tileManager.SetTileType(posNear, tile.tileType);
                                        tileManager.SetTileExtraData(posNear, (byte)(level + 1));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
示例#30
0
        public virtual void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {

        }