Пример #1
0
 public override void map_input_event(Camera camera, InputEvent _event, Vector3 click_position, Vector3 click_normal, int shape_idx, Vector2 chunk, AStar navigation, Node meshMapCtrl, Info info)
 {
     if (_event is InputEventMouseButton)
     {
         var tmpInput = (InputEventMouseButton)_event;
         if (tmpInput.ButtonIndex == (int)ButtonList.Right && tmpInput.ButtonMask == (int)ButtonList.MaskRight)
         {
             var             x   = Mathf.Round(click_position.x / 2);
             var             y   = Mathf.Round(click_position.y / 2);
             Job.AbstractJob job = ((singleton.InGameState)ctrl).get_job_system().get_tunnel_job_on_cell(new Vector2(x, y));
             if (job != null)
             {
                 GD.Print(constant.JobNames.BUILD_TUNNEL, job);
             }
             else
             {
                 var dwarfs = ((SceneTree)ctrl.Call("get_tree")).GetNodesInGroup(constant.GroupNames.SELECTED_DWARFS);
                 foreach (entities.Dwarf d in dwarfs)
                 {
                     Job.AbstractJob walkJob = new Job.WalkJob(navigation, click_position);
                     walkJob.Personal = true;
                     walkJob.Owner    = d;
                     Job.AbstractJob[] jobsToAdd = { walkJob };
                     ((singleton.InGameState)ctrl).get_job_system().submit_jobs(jobsToAdd, walkJob.Owner);
                 }
             }
         }
         ((singleton.InGameState)ctrl).request_new_state(constant.StateNames.NONE);
     }
 }
Пример #2
0
        private Job.WalkJob getWalkToJob(Job.BuildTunnelJob job, entities.Dwarf caller)
        {
            var walk = new Job.WalkJob(job.navigation, new Vector3(job.get_cell_pos().x * 2, job.get_cell_pos().y * 2, 0));

            walk.Personal = true;
            walk.Owner    = caller;
            return(walk);
        }
Пример #3
0
        public Job.AbstractJob[] request_jobs(Vector2 pos, entities.Dwarf caller)
        {
            GD.Print("Request jobs, ", pos, " -> ", caller);
            // Vector2 pos = new Vector2(x, y);
            // KinematicBody caller = null;
            Job.AbstractJob nearest = null;
            int             lastPos = 500;

            foreach (var j in jobs)
            {
                if (j.distance_from_cell(pos).Length < lastPos && j.distance_from_cell(pos).Length > 0 && j.Owner == null)
                {
                    lastPos = j.distance_from_cell(pos).Length;
                    nearest = j;
                }
            }

            if (nearest != null)
            {
                GD.Print(pos, " -> ", lastPos, " ", nearest, " ", nearest.get_cell_pos(), " ", GD.Str(nearest.Owner), " ", caller);
                nearest.Owner = caller;

                var path = nearest.distance_from_cell(pos);
                if (path.Length > 0)
                {
                    var walk = new Job.WalkJob(((Job.BuildTunnelJob)nearest).navigation, path[path.Length - 1]);
                    walk.Personal = true;
                    walk.Owner    = caller;

                    var jobs = new List <Job.AbstractJob>();
                    jobs.Add(walk);

                    foreach (var item in _GetArrayOfConnectedTunnelJobs((Job.BuildTunnelJob)nearest, caller))
                    {
                        jobs.Add(item);
                    }

                    return(jobs.ToArray()); //new Job.AbstractJob[] { walk, nearest };
                }
                else
                {
                    return(_GetArrayOfConnectedTunnelJobs((Job.BuildTunnelJob)nearest, caller));//new Job.AbstractJob[] { nearest };
                }
            }
            else
            {
                // GD.Print(pos, " -> ", lastPos);
            }
            return(new Job.AbstractJob[0]);
        }