Ejemplo n.º 1
0
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            pos += delta;

            if (tileManager.IsValidTile(pos))
                tileManager.SetTileType(pos, tileType);
        }
Ejemplo n.º 2
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);
				}
			}
        }
Ejemplo n.º 3
0
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            pos += delta;

            if (tileManager.IsValidTile(pos))
                tileManager.DamageTile(pos, damage);
        }
Ejemplo n.º 4
0
        public bool CheckConditions(TileManager tileManager, Tile tile, TilePosition pos)
        {
            if (condition != null)
                return condition.Validate(tileManager, tile, pos);

            return true;
        }
Ejemplo n.º 5
0
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            pos += delta;

            if (tileManager.IsValidTile(pos))
                tileManager.EnqueueInvalidatedTile(pos);
        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 11
0
        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;
                }
            }
        }
Ejemplo n.º 13
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();
                }
            }
        }
Ejemplo n.º 14
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);
            }
        }
        public void ClientActionReceived(MultiplayerClient client, MultiplayerAction action)
        {
            switch (action.action)
            {
                case MultiplayerAction.Action.INITIAL_DATA:
                    initializationDataReceived = true;
                    initializationData = action.extraData;
                    break;

                case MultiplayerAction.Action.AVATAR_MOVE:
                {
                    int objectId = Int32.Parse(action.GetParameter(0));
                    Vector3 pos = new Vector3(
                        Single.Parse(action.GetParameter(1)),
                        Single.Parse(action.GetParameter(2)),
                        Single.Parse(action.GetParameter(3)));
                    Vector3 rot = new Vector3(
                        Single.Parse(action.GetParameter(4)),
                        Single.Parse(action.GetParameter(5)),
                        Single.Parse(action.GetParameter(6)));

                    Avatar avatar = world.avatarManager.GetAvatarByObjectId(objectId);
                    avatar.position = pos;
                    avatar.rotation = rot;
                    break;
                }

                case MultiplayerAction.Action.AVATAR_CREATE:
                {
                    int objectId = Int32.Parse(action.GetParameter(0));
                    string avatarDefinitionId = action.GetParameter(1);
                    Vector3 pos = new Vector3(
                        Single.Parse(action.GetParameter(2)),
                        Single.Parse(action.GetParameter(3)),
                        Single.Parse(action.GetParameter(4)));
                    Vector3 rot = new Vector3(
                        Single.Parse(action.GetParameter(5)),
                        Single.Parse(action.GetParameter(6)),
                        Single.Parse(action.GetParameter(7)));

                    Avatar avatar = world.avatarManager.CreateAvatar(world.avatarManager.GetAvatarDefinitionById(avatarDefinitionId), objectId, pos, true);
                    avatar.rotation = rot;
                    break;
                }

                case MultiplayerAction.Action.AVATAR_DESTROY:
                {
                    int objectId = Int32.Parse(action.GetParameter(0));
                    world.avatarManager.DestroyAvatar(world.avatarManager.GetAvatarByObjectId(objectId));
                    break;
                }

                case MultiplayerAction.Action.TILE_INVALIDATED:
                {
                    MemoryStream ms = new MemoryStream(action.extraData);
                    BinaryReader br = new BinaryReader(ms);

                    int n = br.ReadInt32();
                    Tile tile = new Tile();

                    for (int i = 0; i < n; i++)
                    {
                        TilePosition pos = SerializationUtils.ReadTilePosition(br);
                        tile.Deserialize(br.ReadUInt32());

                        if (tile.tileType != world.tileManager.GetTileType(pos))
                            world.tileManager.SetTileType(pos, tile.tileType);
                        if (tile.OnFire != world.tileManager.GetTileOnFire(pos))
                            world.tileManager.SetTileOnFire(pos, tile.OnFire);
                        if (tile.ExtraData != world.tileManager.GetTileExtraData(pos))
                            world.tileManager.SetTileExtraData(pos, tile.ExtraData);
                        if (tile.Energy != world.tileManager.GetTileEnergy(pos))
                            world.tileManager.SetTileEnergy(pos, tile.Energy);
                    }
                    break;
                }
            }
        }
Ejemplo n.º 16
0
        private void ExecuteTileRules(TilePosition pos, Tile tile, TileRule[] rules)
        {
            world.stats.executedRules += rules.Length;

            foreach (TileRule rule in rules)
            {
                if (rule.CheckConditions(this, tile, pos))
                {
                    rule.Execute(this, tile, pos);

                    if (GetTileType(pos) != tile.tileType)
                        break;
                }
            }
        }
Ejemplo n.º 17
0
		public Tile ToTile()
		{
			Tile tile = new Tile();
			
			tile.tileType = this.tileDefinition.tileType;
			tile.OnFire = this.OnFire;
			tile.CastShadow = this.CastShadow;
			tile.LightSource = this.LightSource;
			tile.Enqueued = this.Enqueued;
			tile.AmbientLuminance = this.AmbientLuminance;
			tile.LightSourceLuminance = this.LightSourceLuminance;
			tile.Energy = this.Energy;
			tile.Destroyed = this.Destroyed;
			tile.Dynamic = this.Dynamic;
            tile.ExtraData = this.extraData;
			
			return tile;
		}
Ejemplo n.º 18
0
        public override bool Validate(TileManager tileManager, Tile tile, TilePosition pos)
        {
            tileManager.world.stats.checkedConditions++;

            return !condition.Validate(tileManager, tile, pos);
        }
Ejemplo n.º 19
0
 public virtual bool Validate(TileManager tileManager, Tile tile, TilePosition pos)
 {
     return true;
 }
Ejemplo n.º 20
0
        public virtual bool ProcessTileDamage(TilePosition pos, Tile tile, TileDefinition tileDefinition, int damage)
        {
            if (tileDefinition.energy != Tile.MAX_ENERGY)
            {
                if (tile.Energy > damage)
                {
                    world.tileManager.SetTileEnergy(pos, (byte)(tile.Energy - damage));

                    world.tileManager.TileDamaged(pos);

                    return false;
                }
                else
                {
                    world.tileManager.DestroyTile(pos);

                    return true;
                }
            }
            else
            {
                //world.tileManager.DestroyTile(pos);

                //return true;

                return false;
            }
        }
Ejemplo n.º 21
0
        private void ExecuteTileRule(TilePosition pos, Tile tile, TileRule rule)
        {
            world.stats.executedRules++;

            if (rule.CheckConditions(this, tile, pos))
                rule.Execute(this, tile, pos);
        }
Ejemplo n.º 22
0
        public void Load(System.IO.BinaryReader br)
        {
            //Read tile definition mapper (oldId -> newId)
            byte[] mapTileDefinitionMapper = new byte[byte.MaxValue];
            
            int definitions = br.ReadInt32();
            for (int i = 0; i < definitions; i++)
            {
                byte oldType = br.ReadByte();
                string id = br.ReadString();
                byte newType = 0;

                foreach (TileDefinition td in tileDefinitions)
                {
                    if (td.id == id)
                    {
                        newType = td.tileType;
                        break;
                    }
                }

                mapTileDefinitionMapper[oldType] = newType;
            }

            //Read map size
            //This is read in CubeWorld.Load()
            //int sizeXbits = br.ReadInt32();
            //int sizeYbits = br.ReadInt32();
            //int sizeZbits = br.ReadInt32();
			
            //Create empty world
            //The world is already created in CubeLoad.Load()
            //Create(tileDefinitions, sizeXbits, sizeYbits, sizeZbits);
			
            //Read tiles
			byte[] tileBytes = br.ReadBytes(sizeX * sizeY * sizeZ * 4);
			Tile tile = new Tile();
			
			for (int n = tiles.Length - 1; n >= 0; n--)
			{
				tile.tileType = mapTileDefinitionMapper[tileBytes[(n << 2) | 0]];
				tile.luminance = tileBytes[(n << 2) | 1];
				tile.extra = tileBytes[(n << 2) | 2];
				tile.extra2 = tileBytes[(n << 2) | 3];
				
				tiles[n] = tile;
			}
			
			//Read dynamic tiles
			int nDyanamicTiles = br.ReadInt32();
			for (int n = 0; n < nDyanamicTiles; n++)
			{
                int objectId = br.ReadInt32();
				TilePosition pos = SerializationUtils.ReadTilePosition(br);
				int timeout = br.ReadInt32();
				
                DynamicTile dynamicTile = new DynamicTile(world, pos, true, objectId);

                //TODO: Get gravity attribute from somewhere
                if (true)
                    dynamicTile.AddComponent(new TileComponentGravity());

                dynamicTiles[pos] = dynamicTile;
				
                if (timeout > 0)
                {
                    dynamicTile.timeout = timeout;
                    dynamicTilesTimeout[pos] = dynamicTile;
                }

                world.cwListener.CreateObject(dynamicTile);
			}

            //Read top positions
			topPositions = br.ReadBytes(sizeX * sizeZ);

            if (world.gameplay.useEnqueueTileUpdates)
                EnqueueTilesWithRules();

            enqueueTileUpdates = world.gameplay.useEnqueueTileUpdates;
            updateLighting = true;
            reportTileInvalidated = true;

            if (world.gameplay.useEnqueueTileUpdates)
                UpdateTiles();
			
            //The read tiles already have the light information updated
            //LightModelAmbient.InitLuminance(this);
            //LightModelLightSource.InitLuminance(this);
        }
Ejemplo n.º 23
0
        public override void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {
            pos += delta;

            tileManager.world.fxListener.PlayEffect(effectId, Graphics.TilePositionToVector3(pos));
        }
Ejemplo n.º 24
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);
 }
Ejemplo n.º 25
0
        public virtual void Execute(TileManager tileManager, Tile tile, TilePosition pos)
        {

        }
 public override bool ProcessTileDamage(TilePosition pos, Tile tile, TileDefinition tileDefinition, int damage)
 {
     return baseGameplay.ProcessTileDamage(pos, tile, tileDefinition, damage);
 }
Ejemplo n.º 27
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;
        }
Ejemplo n.º 28
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));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 29
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;
        }
Ejemplo n.º 30
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;
            }
        }