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); } }
public void remove_finished_job(Job.AbstractJob job) { GD.Print("Remove: ", job); var success = jobs.Remove(job); if (success) { EmitSignal(nameof(job_removed), job); } }
private void _AddJob(Job.AbstractJob job) { foreach (var j in jobs) { if (j.equals(job)) { return; } } jobs.Add(job); EmitSignal(nameof(job_added), job); GD.Print("new job added: ", job); }
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]); }