Ejemplo n.º 1
0
    static public StaticObject PlaceInstance(StaticObject protoObject, Tile tile)
    {
        if (protoObject.funcPositionValidation(tile) == false)
        {
            return(null);
        }

        StaticObject obj = new StaticObject();

        obj.height           = protoObject.height;
        obj.width            = protoObject.width;
        obj.movementCost     = protoObject.movementCost;
        obj.ObjectType       = protoObject.ObjectType;
        obj.LinksToNeighbour = protoObject.LinksToNeighbour;

        obj.Tile = tile;

        // FIXME
        if (tile.PlaceObject(obj) == false)
        {
            // FOR SOME REASON WE CANT PLACE AN OBJECT THERE
            // already occupied; => return null
            // FIX ME -> GARBAGE PRODUCTION
            return(null);
        }

        if (obj.LinksToNeighbour)
        {
            //this object links to neighbour so change neighbour

            int  x = obj.Tile.X;
            int  y = obj.Tile.Y;
            Tile t;

            t = tile.World.GetTileAt(x, y + 1);
            if (t != null && t.staticObject != null && t.staticObject.cb_OnChanged != null && t.staticObject.ObjectType == obj.ObjectType)
            {
                t.staticObject.cb_OnChanged(t.staticObject);
            }
            t = tile.World.GetTileAt(x + 1, y);
            if (t != null && t.staticObject != null && t.staticObject.cb_OnChanged != null && t.staticObject.ObjectType == obj.ObjectType)
            {
                t.staticObject.cb_OnChanged(t.staticObject);
            }
            t = tile.World.GetTileAt(x, y - 1);
            if (t != null && t.staticObject != null && t.staticObject.cb_OnChanged != null && t.staticObject.ObjectType == obj.ObjectType)
            {
                t.staticObject.cb_OnChanged(t.staticObject);
            }
            t = tile.World.GetTileAt(x - 1, y);
            if (t != null && t.staticObject != null && t.staticObject.cb_OnChanged != null && t.staticObject.ObjectType == obj.ObjectType)
            {
                t.staticObject.cb_OnChanged(t.staticObject);
            }
        }
        return(obj);
    }