void CUnitHandler::IdleUnitUpdate(int frame) {
	list<integer2> limboremoveunits;

	for (list<integer2>::iterator i = Limbo.begin(); i != Limbo.end(); i++) {
		if (i->y > 0) {
			i->y--;
		}
		else {
			if (ai->cb->GetUnitDef(i->x) == NULL) {
				// ignore dead unit
			} else {
				IdleUnits[ai->ut->GetCategory(i->x)].push_back(i->x);
			}

			limboremoveunits.push_back(*i);
		}
	}

	if (limboremoveunits.size()) {
		for (list<integer2>::iterator i = limboremoveunits.begin(); i != limboremoveunits.end(); i++) {
			Limbo.remove(*i);
		}
	}

	// make sure that all the builders are in action (hack?)
	if (frame % 15 == 0) {
		for (list<BuilderTracker*>::iterator i = BuilderTrackers.begin(); i != BuilderTrackers.end(); i++) {
			// the new test
			if ((*i)->idleStartFrame != -2) {
				// the brand new builders must be filtered still
				bool ans = VerifyOrder(*i);
				const CCommandQueue* mycommands = ai->cb->GetCurrentUnitCommands((*i)->builderID);
				Command c;

				if (mycommands->size() > 0)
					c = mycommands->front();

				// two sec delay is ok
				if (((*i)->commandOrderPushFrame + LAG_ACCEPTANCE) < frame) {
					if (!ans) {
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i VerifyOrder failed ", (*i)->builderID);

						ClearOrder(*i, false);

						if (!mycommands->empty())
							DecodeOrder(*i, true);
						else
							IdleUnitAdd((*i)->builderID, frame);
					}
				}
			}
		}
	}
}
Beispiel #2
0
void CUnitHandler::IdleUnitUpdate(int frame) {
	std::list<integer2> limboremoveunits;

	for (std::list<integer2>::iterator i = Limbo.begin(); i != Limbo.end(); i++) {
		if (i->y > 0) {
			i->y--;
		} else {
			if (ai->cb->GetUnitDef(i->x) == NULL) {
				// ignore dead unit
			} else {
				IdleUnits[ai->ut->GetCategory(i->x)].push_back(i->x);
			}

			limboremoveunits.push_back(*i);
		}
	}

	if (limboremoveunits.size()) {
		for (std::list<integer2>::iterator i = limboremoveunits.begin(); i != limboremoveunits.end(); i++) {
			Limbo.remove(*i);
		}
	}

	// make sure that all the builders are in action (hack?)
	if (frame % 15 == 0) {
		for (std::list<BuilderTracker*>::iterator i = BuilderTrackers.begin(); i != BuilderTrackers.end(); i++) {
			if ((*i)->idleStartFrame != -2) {
				// the brand new builders must be filtered still
				bool ans = VerifyOrder(*i);
				const int builderID = (*i)->builderID;
				const CCommandQueue* myCommands = ai->cb->GetCurrentUnitCommands(builderID);
				Command c;

				if (myCommands->size() > 0) {
					c = myCommands->front();
				}

				// two sec delay is ok
				if (((*i)->commandOrderPushFrame + LAG_ACCEPTANCE) < frame) {
					if (!ans) {
						float3 pos = ai->cb->GetUnitPos(builderID);

						std::stringstream msg;
							msg << "[CUnitHandler::IdleUnitUpdate()][frame=" << frame << "]\n";
							msg << "\tfailed to verify order for builder " << builderID;
							msg << " with " << (myCommands->size()) << " remaining commands\n";
						ai->GetLogger()->Log(msg.str());

						ClearOrder(*i, false);

						// due to the Legacy AI Wrapper inner workings,
						// the command-queue we fetched above is now invalid,
						// because it got changed in ClearOrder()
						myCommands = ai->cb->GetCurrentUnitCommands(builderID);
						if (!myCommands->empty()) {
							DecodeOrder(*i, true);
						} else {
							IdleUnitAdd(builderID, frame);
						}
					}
				}
			}
		}
	}
}
void CUnitHandler::IdleUnitUpdate() {
//	std::cout << "CUnitHandler::IdleUnitUpdate()" << std::endl;

	list<integer2> limboremoveunits;
	for(list<integer2>::iterator i = Limbo.begin(); i != Limbo.end(); i++){
		if(i->y > 0){
			i->y = i->y - 1;
		}
		else{
			//L("adding unit to idle units: " << i->x);
			if(ai->cb->GetUnitDef(i->x) == NULL)
			{
				//L(" Removeing dead unit... ");
				
			}
			else
				IdleUnits[ai->ut->GetCategory(i->x)]->push_back(i->x);
			if(ai->ut->GetCategory(i->x) == CAT_BUILDER)
			{
				//GetBuilderTracker(i->x)->idleStartFrame = -1; // Its ok now, stop the force idle  (hack)
			}
			
				
			limboremoveunits.push_back(*i);
		}
	}
	if(limboremoveunits.size()){
		for(list<integer2>::iterator i = limboremoveunits.begin(); i != limboremoveunits.end(); i++){
			Limbo.remove(*i);
		}
	}
	// Make shure that all the builders are in action:   (hack ?)
	if(ai->cb->GetCurrentFrame() % 15 == 0)
		for(list<BuilderTracker*>::iterator i = BuilderTrackers.begin(); i != BuilderTrackers.end(); i++){
			
			// The new test:
			if((*i)->idleStartFrame != -2) // The brand new builders must be filtered still
			{
				//L("VerifyOrder");
				bool ans = VerifyOrder(*i);
				const deque<Command>* mycommands = ai->cb->GetCurrentUnitCommands((*i)->builderID);
				Command c;
				if(mycommands->size() > 0)
					c = mycommands->front();
				
				// Two sec delay is ok
				if(( (*i)->commandOrderPushFrame + LAG_ACCEPTANCE) < ai->cb->GetCurrentFrame())
				{
					//assert(ans);
					if(!ans)
					{
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i VerifyOrder failed ", (*i)->builderID);
						AIHCAddMapPoint amp;
						amp.label = text;
						amp.pos = pos;
						////ai->cb->HandleCommand(&amp);
						
						ClearOrder(*i, false);
						if(!mycommands->empty())
							DecodeOrder(*i, true);
						else // Its idle
							IdleUnitAdd((*i)->builderID);
							
					}
				}
			}
			
			/*
			if((*i)->buildTaskId == 0 && (*i)->taskPlanId == 0 && (*i)->factoryId == 0 && (*i)->customOrderId == 0 && (*i)->idleStartFrame != -2)
			{
				// Its without tasks and not in the idle list
				if((*i)->idleStartFrame == -1)
				{
					(*i)->idleStartFrame = ai->cb->GetCurrentFrame();
				}
				else
				{
					if(((*i)->idleStartFrame + 90) < ai->cb->GetCurrentFrame())
					{
						//L("Idle unit command force: " << (*i)->builderID);
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i without tasks and not in the idle list (idle forced)", (*i)->builderID);
						AIHCAddMapPoint amp;
						amp.label = text;
						amp.pos = pos;
						////ai->cb->HandleCommand(&amp);
						IdleUnitAdd((*i)->builderID);
						(*i)->idleStartFrame =  ai->cb->GetCurrentFrame(); // Just to cut down on the spam, if its not idle
					}
				}
			} else if((*i)->idleStartFrame != -2) // This will only be ok if idleStartFrame is changed to -1 on unit UnitFinished
			{
			*/
			/*
				//L("VerifyOrder");
				bool ans = VerifyOrder(*i);
				const deque<Command>* mycommands = ai->cb->GetCurrentUnitCommands((*i)->builderID);
				Command c;
				if(mycommands->size() > 0)
					c = mycommands->front();
				
				// Two sec delay is ok
				if(( (*i)->commandOrderPushFrame + 30 * 2) < ai->cb->GetCurrentFrame())
				{
					//assert(ans);
					if(!ans)
					{
						char text[512];
						float3 pos = ai->cb->GetUnitPos((*i)->builderID);
						sprintf(text, "builder %i VerifyOrder failed ", (*i)->builderID);
						AIHCAddMapPoint amp;
						amp.label = text;
						amp.pos = pos;
						////ai->cb->HandleCommand(&amp);
					}
				}
				* /
			}
			*/
		}
}