Code: Select all
float3 patrolpos = *xyz you want*;
TCommand t(CMD_PATROL);
t.push(unit_id);// push in the units ID
t.push(patrolpos); // push in the position
boolean result = G->OrderRouter(t,false);// queue for execution(false means any previously queued commands for this unit arent deleted)
That would be the code to set a simple patrol, or at very least something that looks like that.
I would add a simple keyword, and a new task class that issued that order in the initialize function, and registered itself for unitdeath events. Then on RecieveMessage function it would check for the unitdeath and if the unit that the task belongs to has died it would end the task. This way the unit will carry on the patrol indefinately till death. Then you would modify CUnit.cpp so that the LoadTaskList() function loads the task.
The final step is modifying include.h(to add the new keyword to the enum), and CManufacturer(to register the enum, along with its canonical name so it can be printed out in the logs).
To generate the task position of the patrol route (float3 patrolpos) I would use a function in the CMap class or one of the other help classes that generates a random position based upon a distance and an origin point. For the distance I would use the builder distance of the unit.
As a side note, the value returned by result is most likely true but its not a 100% check. If the command passes initial checks itll return true, but that command may then get passed to the engine and an error value gets returned so the order router class will issue a UnitIdle command on that unit.
Using the above you can adapt it to make whatever task you want. You could even implement a custom rule based system for a builder that behaves like AAI or KAI, or a custom attack handler. If your looking to help make general improvements, most of the keywords from the previous task management system were simply copy pasted into one keyword task class, with a big list of if else statements.
Perhaps it would have been best if this were in the NTai thread. When v0.75 is released, I intend to allow NTai to interface with the mod based lua so that config makers cna implement their own task keywords so say there'll be a t_sell command that sells a unit or a superweapon_arty keyword that fires the artillery superweapon, or implements a superweapon AI for an artillery superweapon building, or perhaps a task to make a transporter couple up with artillery and go around as requested by the s44 people.