Exemplo n.º 1
0
    public void Update(float deltaTime)
    {
        //Debug.Log(fixtParameters["contents"] + " " + fixtParameters["contentCurrAmount"] + " " + fixtParameters["contentMaxAmount"]);
        if (jobCreateCooldown <= 0f)
        {
            if (content != null && content.CurrentAmount < content.MaxAmount)
            {
                if (!world.estateJobManager.IsTileReserved(this.tile))
                {
                    PathAstar pathToItem = new PathAstar(world, this.tile, null, "books");
                    Debug.Log("pathToItem is long: " + pathToItem.Length());
                    if (pathToItem != null && pathToItem.Length() > 0)
                    {
                        Debug.Log("Fixture::Update -- we've got a path to an item");
                        Tile tile = pathToItem.EndTile();
                        world.estateJobManager.AddJob(new EstateJob(this.tile, EstateJobType.HAUL, 1, Character.DeliverGoods, new Vector2(0, -1), this, tile));
                    }
                    else
                    {
                        Debug.LogError("We cant find an item for this job, aborting"); //TODO: Implement some sort of goods ordering.
                    }
                    jobCreateCooldown = 5f;
                }
            }
        }

        jobCreateCooldown -= deltaTime;
    }
Exemplo n.º 2
0
    void GetNewJob()
    {
        switch (CharRole)
        {
        case CharacterRole.BUILDER:
        case CharacterRole.GARDERNER:
        case CharacterRole.JANITOR:
            myJob = World.Current.estateJobManager.GiveJob(CurrTile, this);
            break;

        case CharacterRole.ACADEMIC:
            break;
        }

        if (myJob == null)
        {
            return;
        }

        DestTile = myJob.jobTile;
        myJob.RegisterJobStoppedCallback(OnJobStopped);

        pathAstar = new PathAstar(World.Current, CurrTile, DestTile);
        if (pathAstar.Length() == 0 || pathAstar == null)
        {
            Debug.LogError("Character::GetNewJob - PathAstar couldnt find a path to job site!");
            AbandonJob();
            DestTile = CurrTile;
        }
    }
Exemplo n.º 3
0
    void UpdateDoMovement(float deltaTime)
    {
        if (CurrTile == DestTile)
        {
            pathAstar = null;
            return;
        }

        if (nextTile == null || nextTile == CurrTile)
        {
            if (pathAstar == null || pathAstar.Length() == 0)
            {
                Debug.Log("Creating new path");
                pathAstar = new PathAstar(World.Current, CurrTile, DestTile);
                if (pathAstar.Length() == 0)
                {
                    Debug.LogError("Character::UpdateDoMovement - PathAstar couldnt find a path to job site!");
                    AbandonJob();
                    DestTile = CurrTile;
                    return;
                }

                nextTile = pathAstar.Dequeue();
            }
            nextTile = pathAstar.Dequeue();
            if (nextTile == CurrTile)
            {
                //Debug.LogError("Character::UpdateDoMovement - nextTIle is CurrTile?");
                return;
            }
        }

        float distToTravel = Mathf.Sqrt(Mathf.Pow(CurrTile.X - nextTile.X, 2) + Mathf.Pow(CurrTile.Y - nextTile.Y, 2));


        float distThisFrame = speed / nextTile.movementCost * deltaTime;

        float percThisFrame = distThisFrame / distToTravel;

        movementPercentage += percThisFrame;

        if (movementPercentage >= 1)
        {
            CurrTile           = nextTile;
            movementPercentage = movementPercentage - 1;
        }
    }
Exemplo n.º 4
0
    protected EstateJob FindBestJobForCharRoleAtTile(Tile currTile, List <EstateJob> jobList)
    {
        EstateJob bestJob = jobList.First();

        Debug.LogError("bestJob is at: " + bestJob.jobTile.X + ":" + bestJob.jobTile.Y);
        int   distanceToJob  = new PathAstar(WorldController.Instance.World, currTile, bestJob.jobTile).Length();        //FIXME somePathfindingThing(currTile, job);
        float maxJobPriority = (bestJob.JobAge * jobAgeWeighting) + (distanceToJob * jobDistanceWeighting);

        foreach (EstateJob job in jobList)
        {
            //TODO: All the pf stuff
            distanceToJob = new PathAstar(WorldController.Instance.World, currTile, job.jobTile).Length();
            float thisJobPriority = (job.JobAge * jobAgeWeighting) + (distanceToJob * jobDistanceWeighting);
            if (thisJobPriority > maxJobPriority)
            {
                bestJob        = job;
                maxJobPriority = thisJobPriority;
            }
        }

        return(bestJob);
        //return jobList.First();
    }