Beispiel #1
0
        public DynamicTile(CubeWorld.World.CubeWorld world, TilePosition tilePosition, bool proxy, int objectId)
            : base(objectId)
        {
            this.world        = world;
            this.tilePosition = tilePosition;
            this.position     = Utils.Graphics.TilePositionToVector3(tilePosition);
            this.proxy        = proxy;

            Tile tile = world.tileManager.GetTile(tilePosition);

            this.tileDefinition = world.tileManager.GetTileDefinition(tile.tileType);
            this.definition     = this.tileDefinition;

            if (proxy == false)
            {
                this.onFire               = tile.OnFire;
                this.castShadow           = tile.CastShadow;
                this.lightSource          = tile.LightSource;
                this.enqueued             = tile.Enqueued;
                this.ambientLuminance     = tile.AmbientLuminance;
                this.lightSourceLuminance = tile.LightSourceLuminance;
                this.energy               = tile.Energy;
                this.destroyed            = tile.Destroyed;
                this.dynamic              = tile.Dynamic;
                this.extraData            = tile.ExtraData;
            }
        }
Beispiel #2
0
        private void UpdateTile(TilePosition pos)
        {
            Tile tile = GetTile(pos);

            TileDefinition tileDefinition = GetTileDefinition(tile.tileType);

            if (tileDefinition.tileUpdateRules != null)
            {
                world.stats.updatedTiles++;

                ExecuteTileRules(pos, tile, tileDefinition.tileUpdateRules.rules);
            }
        }
Beispiel #3
0
        public bool DamageTile(TilePosition pos, int damage)
        {
            Tile tile = GetTile(pos);

            if (tile.tileType != TileDefinition.EMPTY_TILE_TYPE)
            {
                TileDefinition tileDefinition = GetTileDefinition(tile.tileType);

                return(world.gameplay.ProcessTileDamage(pos, tile, tileDefinition, damage));
            }

            return(false);
        }
Beispiel #4
0
        private bool ExecuteTileActions(TilePosition pos, TileActionRule.ActionType actionType)
        {
            TileDefinition tileDefinition = GetTileDefinition(GetTileType(pos));

            if (tileDefinition.tileActionRules != null && tileDefinition.tileActionRules.GetRulesForAction(actionType) != null)
            {
                TileActionRule actionRules = tileDefinition.tileActionRules.GetRulesForAction(actionType);

                ExecuteTileRules(pos, GetTile(pos), actionRules.rules);

                return(true);
            }

            return(false);
        }
Beispiel #5
0
        public DynamicTile(CubeWorld.World.CubeWorld world, TileDefinition tileDefinition, int objectId)
            : base(objectId)
        {
            this.world          = world;
            this.definition     = tileDefinition;
            this.tileDefinition = tileDefinition;

            this.onFire               = false;
            this.castShadow           = tileDefinition.castShadow;
            this.lightSource          = tileDefinition.lightSourceIntensity > 0;
            this.enqueued             = false;
            this.ambientLuminance     = 0;
            this.lightSourceLuminance = tileDefinition.lightSourceIntensity;
            this.energy               = (byte)tileDefinition.energy;
            this.destroyed            = false;
            this.dynamic              = true;
            this.extraData            = 0;
        }
Beispiel #6
0
        public void Create(TileDefinition[] tileDefinitions, int sizeXbits, int sizeYbits, int sizeZbits)
        {
            this.sizeXbits = sizeXbits;
            this.sizeYbits = sizeYbits;
            this.sizeZbits = sizeZbits;

            sizeXBitsYBits = sizeXbits + sizeYbits;

            sizeX = 1 << sizeXbits;
            sizeY = 1 << sizeYbits;
            sizeZ = 1 << sizeZbits;

            tiles = new Tile[1 << (sizeXbits + sizeYbits + sizeZbits)];
            topPositions = new byte[1 << (sizeXbits + sizeZbits)];

            this.tileDefinitions = tileDefinitions;

            this.ticks = (uint) new Random().Next(0, 100);
        }
Beispiel #7
0
        public DynamicTile(CubeWorld.World.CubeWorld world, TilePosition tilePosition, bool proxy, int objectId)
            : base(objectId)
		{
			this.world = world;
			this.tilePosition = tilePosition;
			this.position = Utils.Graphics.TilePositionToVector3(tilePosition);
			this.proxy = proxy;
			
			Tile tile = world.tileManager.GetTile(tilePosition);
			
			this.tileDefinition = world.tileManager.GetTileDefinition(tile.tileType);
			this.definition = this.tileDefinition;
			
			if (proxy == false)
			{
				this.onFire = tile.OnFire;
				this.castShadow = tile.CastShadow;
				this.lightSource = tile.LightSource;
				this.enqueued = tile.Enqueued;
				this.ambientLuminance = tile.AmbientLuminance;
				this.lightSourceLuminance = tile.LightSourceLuminance;
				this.energy = tile.Energy;
				this.destroyed = tile.Destroyed;
				this.dynamic = tile.Dynamic;
                this.extraData = tile.ExtraData;
			}
		}
Beispiel #8
0
        public DynamicTile(CubeWorld.World.CubeWorld world, TileDefinition tileDefinition, int objectId)
            : base(objectId)
		{
			this.world = world;
			this.definition = tileDefinition;
			this.tileDefinition = tileDefinition;
			
			this.onFire = false;
			this.castShadow = tileDefinition.castShadow;
			this.lightSource = tileDefinition.lightSourceIntensity > 0;
			this.enqueued = false;
			this.ambientLuminance = 0;
			this.lightSourceLuminance = tileDefinition.lightSourceIntensity;
			this.energy = (byte) tileDefinition.energy;
			this.destroyed = false;
			this.dynamic = true;
            this.extraData = 0;
		}
Beispiel #9
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;
            }
        }
Beispiel #10
0
        public bool HasTileActions(TilePosition pos, TileActionRule.ActionType actionType)
        {
            TileDefinition tileDefinition = GetTileDefinition(GetTileType(pos));

            return(tileDefinition.tileActionRules != null && tileDefinition.tileActionRules.GetRulesForAction(actionType) != null);
        }
Beispiel #11
0
        public void SetTileOnFire(TilePosition pos, bool onFire)
        {
            if (GetTileType(pos) != TileDefinition.EMPTY_TILE_TYPE)
            {
                if (tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)].OnFire != onFire)
                {
                    tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)].OnFire = onFire;

                    if (onFire)
                    {
                        ExecuteTileActions(pos, TileActionRule.ActionType.ONFIRE);

                        if (tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)].LightSource == false)
                        {
                            tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)].LightSource = true;

                            if (tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)].CastShadow)
                            {
                                tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)].CastShadow = false;
                                if (updateLighting)
                                {
                                    LightModelAmbient.UpdateLuminanceDark(this, pos);
                                }
                            }

                            if (updateLighting)
                            {
                                LightModelLightSource.UpdateLuminanceLight(this, pos, (byte)(Tile.MAX_LUMINANCE - 1));
                            }
                            else
                            {
                                SetTileLightSourceLuminance(pos, (byte)(Tile.MAX_LUMINANCE - 1));
                            }
                        }
                    }
                    else
                    {
                        TileDefinition def = GetTileDefinition(GetTileType(pos));

                        if (tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)].LightSource != (def.lightSourceIntensity > 0))
                        {
                            if (updateLighting)
                            {
                                LightModelLightSource.UpdateLuminanceDark(this, pos);
                            }

                            tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)].LightSource = false;

                            if (def.castShadow != tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)].CastShadow != def.castShadow)
                            {
                                tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)].CastShadow = false;

                                if (updateLighting)
                                {
                                    LightModelAmbient.UpdateLuminanceLight(this, pos, GetTileAmbientLuminance(pos));
                                }
                            }
                        }
                    }

                    if (enqueueTileUpdates)
                    {
                        EnqueueInvalidatedTileAndNearTiles(pos);
                    }

                    if (reportTileInvalidated)
                    {
                        ReportTileInvalidated(pos);
                    }
                }
            }
        }
Beispiel #12
0
        public void SetTileType(TilePosition pos, byte type)
        {
            Tile oldTile = tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)];

            if (oldTile.Dynamic)
            {
                SetTileDynamic(pos, false, false, 0);
                oldTile.Dynamic = false;
            }

            if (oldTile.LightSource)
            {
                if (updateLighting)
                {
                    LightModelLightSource.UpdateLuminanceDark(this, pos);
                    oldTile.LightSourceLuminance = GetTileLightSourceLuminance(pos);
                }
                else
                {
                    oldTile.LightSourceLuminance = 0;
                }
            }

            Tile           newTile        = oldTile;
            TileDefinition tileDefinition = GetTileDefinition(type);

            newTile.tileType    = type;
            newTile.Energy      = (byte)tileDefinition.energy;
            newTile.Destroyed   = false;
            newTile.OnFire      = false;
            newTile.CastShadow  = tileDefinition.castShadow;
            newTile.LightSource = (tileDefinition.lightSourceIntensity > 0);
            newTile.ExtraData   = 0;

            tiles[pos.x | (pos.y << sizeXbits) | (pos.z << sizeXBitsYBits)] = newTile;

            if (updateLighting)
            {
                if (newTile.CastShadow != oldTile.CastShadow)
                {
                    if (newTile.CastShadow)
                    {
                        LightModelAmbient.UpdateLuminanceDark(this, pos);
                        LightModelLightSource.UpdateLuminanceDark(this, pos);
                    }
                    else
                    {
                        LightModelAmbient.UpdateLuminanceLight(this, pos, newTile.AmbientLuminance);
                        LightModelLightSource.UpdateLuminanceLight(this, pos, newTile.LightSourceLuminance);
                    }
                }

                if (tileDefinition.lightSourceIntensity > 0)
                {
                    LightModelLightSource.UpdateLuminanceLight(this, pos, tileDefinition.lightSourceIntensity);
                }
            }
            else
            {
                if (newTile.LightSource)
                {
                    SetTileLightSourceLuminance(pos, tileDefinition.lightSourceIntensity);
                }
            }

            ExecuteTileActions(pos, TileActionRule.ActionType.CREATED);

            if (enqueueTileUpdates)
            {
                EnqueueInvalidatedTileAndNearTiles(pos);
            }

            UpdateTopPosition(pos, type);

            if (reportTileInvalidated)
            {
                ReportTileInvalidated(pos);
            }
        }
 public override bool ProcessTileDamage(TilePosition pos, Tile tile, TileDefinition tileDefinition, int damage)
 {
     return baseGameplay.ProcessTileDamage(pos, tile, tileDefinition, damage);
 }
        private TileDefinition ParseTileDefinition(byte type, XmlElement tileDefinitionXML)
        {
            TileDefinition tile = new TileDefinition();

            tile.tileType = type;
            tile.id = GetAttributeStringValue(tileDefinitionXML, "id");
            tile.solid = GetAttributeBoolValue(tileDefinitionXML, "solid", true);
            tile.liquid = GetAttributeBoolValue(tileDefinitionXML, "liquid", false);
            tile.burns = GetAttributeBoolValue(tileDefinitionXML, "burns", false);
            tile.animated = GetAttributeBoolValue(tileDefinitionXML, "animated", false);
            tile.energy = (byte)GetAttributeIntValue(tileDefinitionXML, "energy", Tile.MAX_ENERGY);
            tile.description = GetAttributeStringValue(tileDefinitionXML, "description");
            tile.drawMode = (TileDefinition.DrawMode)System.Enum.Parse(typeof(TileDefinition.DrawMode),
                                                                            GetAttributeStringValue(tileDefinitionXML, "drawMode"),
                                                                            true);

            tile.castShadow = GetAttributeBoolValue(tileDefinitionXML, "castShadow", true);
            tile.lightSourceIntensity = (byte)GetAttributeIntValue(tileDefinitionXML, "lightSourceIntensity", 0);

            string[] materials = GetAttributeStringValue(tileDefinitionXML, "materials").Split(',');
            tile.materials = new int[6];

            if (materials.Length == 1)
            {
                for (int i = 0; i < 6; i++)
                    tile.materials[i] = int.Parse(materials[0]);
            }
            else if (materials.Length == 6)
            {
                for (int i = 0; i < materials.Length; i++)
                    tile.materials[i] = int.Parse(materials[i]);
            }
            else
            {
                throw new System.Exception("Invalid number of materials in tile " + tile.id);
            }

            return tile;
        }
        private TileDefinition[] ParseTileDefinitions(XmlElement tilesDefinitionsXML)
        {
            List<TileDefinition> tiles = new List<TileDefinition>();

            TileDefinition emptyTile = new TileDefinition();
            emptyTile.tileType = TileDefinition.EMPTY_TILE_TYPE;
            emptyTile.castShadow = false;
            emptyTile.description = "Empty";
            emptyTile.drawMode = TileDefinition.DrawMode.NONE;
            emptyTile.energy = 0;
            emptyTile.id = "empty";
            //emptyTile.liquid = false;
            emptyTile.materials = null;
            emptyTile.solid = false;

            tiles.Add(emptyTile);

            byte tileId = 1;

            foreach (XmlElement tileDefinitionXML in GetChildElements(tilesDefinitionsXML))
                tiles.Add(ParseTileDefinition(tileId++, tileDefinitionXML));

            return tiles.ToArray();
        }