Example #1
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;
        }
    }
    public void OnJobCreated(EstateJob job)
    {
        if (job.JobType != EstateJobType.BUILD)
        {
            return;
        }

        Debug.Log("Job is being created");
        GameObject job_go = new GameObject();

        //Add data and UI to map
        estateJobGameObjectMap.Add(job, job_go);

        //Set up general info about the GO
        job_go.name = job.Fixture.ObjectType + "_" + job.jobTile.X + "_" + job.jobTile.Y;
        job_go.transform.position = new Vector3(job.jobTile.X + ((job.Fixture.Width - 1) / 2f), job.jobTile.Y + ((job.Fixture.Height - 1) / 2f));
        job_go.transform.SetParent(this.transform, true);

        SpriteRenderer sr = job_go.AddComponent <SpriteRenderer> ();

        sr.sprite           = fsc.GetSpriteForFixture(job.Fixture);
        sr.sortingLayerName = "Fixture";

        sr.color = new Color(0.5f, 1f, 0.5f, 0.3f);

        //TODO: Implement these
        //job.RegisterOnChanged (OnFixtureChanged);
        //job.RegisterOnRemoved (OnFixtureRemoved);
        job.RegisterJobCompletedCallback(OnJobCompleted);
    }
Example #3
0
 void OnJobStopped(EstateJob job)
 {
     job.UnregisterJobStoppedCallback(OnJobStopped);
     if (job != myJob)
     {
         Debug.LogError("Character:: OnJobStopped - char being told about job that isnt theirs. Something wasnt unregistered good and stuff");
         return;
     }
     myJob = null;
 }
 public void OnJobCompleted(EstateJob job)
 {
     if (estateJobGameObjectMap.ContainsKey(job))
     {
         GameObject jobGo = estateJobGameObjectMap[job];
         Destroy(jobGo);
         estateJobGameObjectMap.Remove(job);
     }
     else
     {
         Debug.LogError("EJSC::OnJobCompleted - Trying to remove a jobsprite not in the dictionary");
     }
 }
Example #5
0
    void UnreserveTiles(EstateJob job)
    {
        if (job.Fixture == null)
        {
            reservedTiles.Remove(job.jobTile);
            return;
        }

        for (int xOffset = job.jobTile.X; xOffset < (job.jobTile.X + job.Fixture.Width); xOffset++)
        {
            for (int yOffset = job.jobTile.Y; yOffset < (job.jobTile.Y + job.Fixture.Height); yOffset++)
            {
                reservedTiles.Remove(WorldController.Instance.World.GetTileAt(xOffset, yOffset));
            }
        }
    }
Example #6
0
    protected void RemoveJob(EstateJob job)
    {
        switch (job.JobType)
        {
        case EstateJobType.BUILD:
        case EstateJobType.HAUL:
            if (haulBuildJobList.Contains(job))
            {
                haulBuildJobList.Remove(job);
            }
            else
            {
                Debug.LogError("EstateJobManager::RemoveJob -- Trying to remove a job not in the haulBuildJoblist");
            }
            break;

        case EstateJobType.CLEAN:
            if (cleanJobList.Contains(job))
            {
                cleanJobList.Remove(job);
            }
            else
            {
                Debug.LogError("EstateJobManager::RemoveJob -- Trying to remove a job not in the cleanJobList");
            }
            break;

        case EstateJobType.GARDEN:
            if (gardenJobList.Contains(job))
            {
                gardenJobList.Remove(job);
            }
            else
            {
                Debug.LogError("EstateJobManager::RemoveJob -- Trying to remove a job not in the gardenJobList");
            }
            break;

        default:
            Debug.LogError("EstateJobManager::RemoveJob -- This job has no type or unrecognised type");
            break;
        }

        UnreserveTiles(job);
    }
Example #7
0
    public void AddJob(EstateJob job)
    {
        if (JobTileAlreadyHasJobOfType(job.jobTile, job.JobType))
        {
            Debug.Log("EJM::AddJob - Job is already queued up on this tile");
            return;
        }

        //If this job is instant then dont add to queues. just do it
        if (job.JobTime <= 0)
        {
            job.WorkJob(0);
            return;
        }


        switch (job.JobType)
        {
        case EstateJobType.BUILD:
        case EstateJobType.HAUL:
            haulBuildJobList.Add(job);
            break;

        case EstateJobType.CLEAN:
            cleanJobList.Add(job);
            break;

        case EstateJobType.GARDEN:
            gardenJobList.Add(job);
            break;

        default:
            Debug.LogError("EstateJobManager::AddJob -- This job has no type or unrecognised type");
            break;
        }

        ReserveTiles(job);
        if (onJobCreatedCallback != null)
        {
            onJobCreatedCallback(job);
        }
    }
Example #8
0
    public EstateJob GiveJob(Tile currCharTile, Character character)
    {
        EstateJob jobToGive = null;

        switch (character.CharRole)
        {
        case CharacterRole.BUILDER:
            if (haulBuildJobList.Count > 0)
            {
                jobToGive = FindBestJobForCharRoleAtTile(currCharTile, haulBuildJobList);
            }
            break;

        case CharacterRole.JANITOR:
            if (cleanJobList.Count > 0)
            {
                jobToGive = FindBestJobForCharRoleAtTile(currCharTile, cleanJobList);
            }
            break;

        case CharacterRole.GARDERNER:
            if (gardenJobList.Count > 0)
            {
                jobToGive = FindBestJobForCharRoleAtTile(currCharTile, gardenJobList);
            }
            break;

        default:
            jobToGive = null;     //FIXME instead of null job, we'll give them some idle job
            break;
        }
        if (jobToGive != null)
        {
            RemoveJob(jobToGive);
            jobToGive.character = character;
        }
        return(jobToGive);
    }
Example #9
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();
    }
Example #10
0
 public static void DeliverGoods(EstateJob job)
 {
     job.Fixture.RecieveContents(job.character.item.content.Name, job.character.item.content.CurrentAmount);
     job.character.item = null;
 }
Example #11
0
 public void AbandonJob()
 {
     nextTile = DestTile = CurrTile;
     World.Current.estateJobManager.AddJob(myJob);
     myJob = null;
 }
Example #12
0
 public static void CompleteBuildJob(EstateJob doneJob)
 {
     WorldController.Instance.World.PlaceFixture(doneJob.Fixture.ObjectType, doneJob.jobTile);
 }