public void HandleBlockEntry(int x, int y, int z)
    {
        Block b = BlockUtilities.GetBlockAt(parentMap, x, y, z);

        if (b != null)
        {
            b.ObjectEnteredBlock(this);
        }

        List <Entity> ce = controller.GetEntitiesAt(x, y, z);

        for (int i = 0; i < ce.Count; i++)
        {
            ce[i].OnEntityCollision(this);
            OnEntityCollision(ce[i]);
        }

        this.x = x;
        this.y = y;
        this.z = z;

        if (automaticallyReservePosition)
        {
            controller.ReserveBlock(entityType, new Vector3(x, y, z));
        }

        OnBlockEntry(x, y, z);
    }
    //Trigger-styled events that will send Block exit / Block entry messages
    public void HandleBlockExit(int x, int y, int z)
    {
        Block b = BlockUtilities.GetBlockAt(parentMap, x, y, z);

        if (b != null)
        {
            b.ObjectExitedBlock(this);
        }

        if (automaticallyReservePosition)
        {
            controller.UnreserveBlock(entityType, new Vector3(x, y, z));
        }

        OnBlockExit(x, y, z);
    }
Beispiel #3
0
    protected bool BlockIsEmpty(int x, int y, int z)
    {
        if (!BlockUtilities.IsWithinMapBounds(parentMap, x, y, z))
        {
            return(false);
        }

        Block b = BlockUtilities.GetBlockAt(parentMap, x, y, z);

        if (b == null || (b.isNullBlock || b.actAsEmptyBlock))
        {
            return(true);
        }

        return(false);
    }
Beispiel #4
0
    void DestroyBlock(Vector3 coords)
    {
        int x = (int)coords.x;
        int y = (int)coords.y;
        int z = (int)coords.z;

        Block         b  = BlockUtilities.GetBlockAt(blockMap, x, y, z);
        OrientedBlock ob = null;

        if (b != null)
        {
            ob = b as OrientedBlock;
        }

        if (ob != null)
        {
            StreamingMapNode n = GetNodeAt(x, y, z);

            if (n != null)
            {
                n.variantIndex = ob.GetCurrentVariant();
            }

            GameObject cio = ob.GetCurrentInstantiatedObject();

            if (cio != null)
            {
                TidyMapBoundObject mbo = cio.GetComponentInChildren <TidyMapBoundObject>();

                if (mbo != null)
                {
                    if (!mbo.DestroyWhenStreaming())
                    {
                        return;
                    }
                }
            }
        }

        BlockUtilities.AddBlockToMap(blockMap, null, false, 0, true, x, y, z, false, false);
    }
Beispiel #5
0
    protected bool CanMoveTo(int x, int y, int z)
    {
        if (!BlockUtilities.IsWithinMapBounds(parentMap, x, y, z))
        {
            return(false);
        }

        if (!controller.CanMoveTo(x, y, z))
        {
            return(false);
        }

        Block b = BlockUtilities.GetBlockAt(parentMap, x, y, z);

        if (b == null || b.isNullBlock || b.actAsEmptyBlock)
        {
            return(true);
        }

        return(false);
    }
Beispiel #6
0
    public bool CanWalkTo(int x, int y, int z)
    {
        if (!BlockUtilities.IsWithinMapBounds(parentMap, x, y, z))
        {
            //Debug.Log("Cannot walk to "+ x + "," + y + "," + z+": bounds");
            return(false);
        }

        if (!controller.CanMoveTo(x, y, z))
        {
            //Debug.Log("Cannot walk to "+ x + "," + y + "," + z+": controller");
            return(false);
        }

        Block b = BlockUtilities.GetBlockAt(parentMap, x, y, z);

        if (b == null || b.isNullBlock || b.actAsEmptyBlock)
        {
            //Debug.Log("Can walk to "+ x + "," + y + "," + z+": not null");
            return(true);
        }

        return(false);
    }
Beispiel #7
0
    //Instantiate our block! Wrap the AssetPool functions nicely
    void InstantiateBlock(Vector3 coords)
    {
        int x = (int)coords.x;
        int y = (int)coords.y;
        int z = (int)coords.z;

        StreamingMapNode n = GetNodeAt(x, y, z);

        Block b  = null;
        int   bv = 0;

        if (n != null)
        {
            b  = n.blockPrefab;
            bv = n.variantIndex;
        }

        Block toAdd = null;

        if (b != null)
        {
            GameObject o = AssetPool.Instantiate(b.gameObject) as GameObject;

#if UNITY_4_0
            o.SetActive(true);
#else
//			o.SetActiveRecursively (true);
#endif

            toAdd = o.GetComponent <Block>();

            OrientedBlock ob = toAdd as OrientedBlock;

            if (ob != null)
            {
                ob.PreRandomiseBlockOrientations();
            }
        }

        if (n != null && n.HasVariant())
        {
            BlockUtilities.AddBlockToMap(blockMap, toAdd, false, bv, true, x, y, z, false, false);
        }
        else
        {
            BlockUtilities.AddBlockToMap(blockMap, toAdd, true, bv, true, x, y, z, false, false);
        }

        if (n != null)
        {
            if (!n.HasVariant())
            {
                Vector3 focus = new Vector3(focus_x, focus_y, focus_z);

                if (!IsOnOuterRim(focus, coords))
                {
                    //Let's save the variant so that we always get a consistent map
                    //It saves the programmer having to randomise this themselves
                    OrientedBlock ob = BlockUtilities.GetBlockAt(blockMap, x, y, z) as OrientedBlock;

                    if (ob != null)
                    {
                        n.variantIndex = ob.GetCurrentVariant();
                    }
                }
            }
        }
    }