public void GetMapPosition(out int x, out int y)
    {
        SimVector3 worldPos = WorldPosition;

        x = ((int)worldPos.x) / SimMap.GRID_SIZE;
        y = ((int)worldPos.z) / SimMap.GRID_SIZE;

        if (x < 0)
        {
            x = 0;
        }
        else if (x >= segment.path.box.gridSizeX)
        {
            x = segment.path.box.gridSizeX - 1;
        }

        if (y < 0)
        {
            y = 0;
        }
        else if (y >= segment.path.box.gridSizeY)
        {
            y = segment.path.box.gridSizeY - 1;
        }
    }
Exemple #2
0
    private void MoveTowardsNextPoint()
    {
        float direction;

        if (nextPoint == currentPosition.segment.point2)
        {
            direction = 1.0f;             //moving from point1 to point2
        }
        else
        {
            direction = -1.0f;             //moving from point2 to point1
        }
        currentPosition.offset += direction * (agentType.speed / Simulation.TICKS_PER_SECOND) / currentPosition.segment.length;
        if (currentPosition.offset < 0.0f)
        {
            currentPosition.offset = 0.0f;

            //Reached point1
            lastPoint = currentPosition.segment.point1;
            nextPoint = null;
        }
        else if (currentPosition.offset > 1.0f)
        {
            currentPosition.offset = 1.0f;

            //Reached point2
            lastPoint = currentPosition.segment.point2;
            nextPoint = null;
        }

        worldPosition = currentPosition.WorldPosition;
    }
Exemple #3
0
    public void Init(SimMap map)
    {
        this.map = map;

        map.mapListener         = this;
        gameObject.name         = map.id;
        transform.localPosition = Vector3.zero;

        mapValues = new Transform[map.sizeX * map.sizeY];

        Material mapMaterial = MaterialsFactory.CreateDiffuseColor(map.mapType.color);

        for (int x = 0; x < map.sizeX; x++)
        {
            for (int y = 0; y < map.sizeY; y++)
            {
                int   val   = map.Get(x, y);
                float scale = ((float)val) / ((float)map.mapType.capacity);

                SimVector3 pos = map.GetWorldPosition(x, y);

                GameObject goCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                goCube.transform.parent        = transform;
                goCube.transform.localScale    = new Vector3(0.5f, scale, 0.5f);
                goCube.transform.localPosition = new Vector3(pos.x, pos.y + scale * 0.5f, pos.z);
                goCube.renderer.sharedMaterial = mapMaterial;
                mapValues[y * map.sizeX + x]   = goCube.transform;
            }
        }
    }
Exemple #4
0
    public void OnMapModified(SimMap map, int x, int y, int val)
    {
        float scale = ((float)val) / ((float)map.mapType.capacity);

        SimVector3 pos = map.GetWorldPosition(x, y);

        mapValues[y * map.sizeX + x].localScale    = new Vector3(0.5f, scale, 0.5f);
        mapValues[y * map.sizeX + x].localPosition = new Vector3(pos.x, pos.y + scale * 0.5f, pos.z);
    }
Exemple #5
0
    public SimPoint AddPoint(SimVector3 worldPosition)
    {
        SimPoint point = new SimPoint();

        point.Init(this, nextPointId++, worldPosition);

        points.Add(point);

        pathListener.OnPointAdded(this, point);

        return(point);
    }
Exemple #6
0
    public void Init(SimAgentType agentType, int id, SimPoint position, SimUnit owner, SimResourceBinCollection resources, string searchTarget)
    {
        this.agentType    = agentType;
        this.id           = id;
        this.owner        = owner;
        this.searchTarget = searchTarget;
        this.resources.AddResources(resources);

        this.worldPosition = position.worldPosition;

        this.lastPoint = position;
    }
Exemple #7
0
    public void Modified()
    {
        transform.localPosition =
            new Vector3(
                segment.point1.worldPosition.x,
                segment.point1.worldPosition.y,
                segment.point1.worldPosition.z);

        SimVector3 delta    = segment.point2.worldPosition - segment.point1.worldPosition;
        SimVector3 midPoint = delta * 0.5f;

        cube.localPosition = new Vector3(midPoint.x, midPoint.y, midPoint.z);
        cube.LookAt(new Vector3(segment.point2.worldPosition.x, segment.point2.worldPosition.y, segment.point2.worldPosition.z));
        cube.localScale = new Vector3(0.2f, 0.2f, delta.Len);
    }
    public void Init(string id, SimVector3 worldPosition, Simulation simulation, int gridSizeX, int gridSizeY)
    {
        this.id            = id;
        this.worldPosition = worldPosition;
        this.simulation    = simulation;
        this.gridSizeX     = gridSizeX;
        this.gridSizeY     = gridSizeY;

        foreach (SimMapType mapType in simulation.simulationDefinition.mapTypes.Values)
        {
            AddMap(mapType);
        }

        foreach (SimPathType pathType in simulation.simulationDefinition.pathTypes.Values)
        {
            AddPath(pathType);
        }
    }
    public SimBox AddBox(string id, SimVector3 center, int gridSizeX, int gridSizeY)
    {
        if (id == null)
        {
            throw new ArgumentNullException("id");
        }

        if (GetBox(id) != null)
        {
            throw new ArgumentException("Duplicated id", "id");
        }

        SimBox box = new SimBox();

        box.Init(id, center, this, gridSizeX, gridSizeY);

        boxes.Add(box);

        simulationListener.OnBoxAdded(box);

        return(box);
    }
 public void Init(SimPath path, int id, SimVector3 worldPosition)
 {
     this.path          = path;
     this.id            = id;
     this.worldPosition = worldPosition;
 }