[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[bos-dev] StartGathering () in engine/action/action_resource.cpp



	I wonder, why the following fragment is implemented as part of
	the engine?

	Apparently, the code assigns goals to harvesting units that
	already has finished their harvest, but, alas, does it a bit
	unintelligently, by sending, e. g., units formely doing magma
	extraction to cutting down the forests and vice versa.  Also,
	IIUC, there'd be no signal (either to the messages buffer or to
	the Lua code) from the unit that has just finished the harvest
	and is unable to find more.

	Perhaps, having such a piece of code out of the engine itself
	would allow for more smart implementations?  What would be the
	prerequisites for such a refactoring?

	BTW, is there a list of features that are currently implemented
	within the engine, but are supposed to be much more flexible
	when transferred to Lua-space?

$ nl -ba boswars.bos.trunk/engine/action/action_resource.cpp 
    97	static bool StartGathering(CUnit *unit)
    98	{
    99		CUnit *goal = unit->Orders[0]->Goal;
   100	
   101		Assert(!unit->IX && !unit->IY);
   102	
   103		//
   104		// Target is gone, stop getting resources.
   105		//
   106		if (!goal->IsVisibleAsGoal(unit->Player)) {
   107			goal->RefsDecrease();
   108			// Find an alternative, but don't look too far.
   109			unit->Orders[0]->X = unit->Orders[0]->Y = -1;
   110			if ((goal = UnitFindResource(unit, unit->X, unit->Y, 10))) {
   111				unit->SubAction = SUB_START_RESOURCE;
   112				unit->Orders[0]->Goal = goal;
   113				goal->RefsIncrease();
   114			} else {
   115				unit->ClearAction();
   116				unit->Orders[0]->Goal = NoUnitP;
   117			}
   118			return false;
   119		}
$ 

-- 
FSF associate member #7257