コード例 #1
0
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);
					}
				}
			}
		}
	}
}
コード例 #2
0
void CUnitHandler::IdleUnitAdd(int unit)
{	
	//L("IdleUnitAdd: " << unit);
	int category = ai->ut->GetCategory(unit);
	if(category != -1){
		const deque<Command>* mycommands = ai->cb->GetCurrentUnitCommands(unit);
		if(mycommands->empty()){
		
			if(category == CAT_BUILDER)
			{
				BuilderTracker* builderTracker = GetBuilderTracker(unit);
				//L("it was a builder");
				
				// Add clear here
				ClearOrder(builderTracker, true);
				
				if(builderTracker->idleStartFrame == -2)
				{
					// It was in the idle list allready ?
					IdleUnitRemove(builderTracker->builderID);
				}
				builderTracker->idleStartFrame = -2; // Its in the idle list now
				if(builderTracker->commandOrderPushFrame == -2) // Make shure that if the unit was just built it will have some time to leave the factory
				{
					builderTracker->commandOrderPushFrame = ai->cb->GetCurrentFrame() + 30*3;
				}
				//else if(builderTracker->commandOrderPushFrame == -)
				//	builderTracker->commandOrderPushFrame = ;
			}

			integer2 myunit(unit,LIMBOTIME);
			//L("Adding unit : " << myunit.x << " To Limbo " << myunit.y);
			Limbo.remove(myunit);
			//IdleUnitRemove(unit);  // This might be a better idea, but its over the edge (possible assertion)
			Limbo.push_back(myunit);
		}
		else
		{
			// The unit have orders still
			if(category == CAT_BUILDER)
			{
				BuilderTracker* builderTracker = GetBuilderTracker(unit);
				assert(false);
				DecodeOrder(builderTracker, true);
			}
		}
	}
}
コード例 #3
0
void CUnitHandler::IdleUnitAdd(int unit, int frame) {
	int category = ai->ut->GetCategory(unit);

	if (category != -1) {
		const CCommandQueue* mycommands = ai->cb->GetCurrentUnitCommands(unit);

		if (mycommands->empty()) {
			if (category == CAT_BUILDER) {
				BuilderTracker* builderTracker = GetBuilderTracker(unit);
				// add clear here
				ClearOrder(builderTracker, true);

				if (builderTracker->idleStartFrame == -2) {
					// it was in the idle list already?
					IdleUnitRemove(builderTracker->builderID);
				}

				builderTracker->idleStartFrame = -2;

				if (builderTracker->commandOrderPushFrame == -2) {
					// make sure that if the unit was just built
					// it will have some time to leave the factory
					builderTracker->commandOrderPushFrame = frame + 30 * 3;
				}
			}

			integer2 myunit(unit, LIMBOTIME);
			Limbo.remove(myunit);
			Limbo.push_back(myunit);
		}
		else {
			// the unit has orders still
			if (category == CAT_BUILDER) {
				if (false) {
					// KLOOTNOTE: somehow we are now reaching this branch
					// on initialization when USE_CREG is not defined,
					// mycommands->size() returns garbage?
					BuilderTracker* builderTracker = GetBuilderTracker(unit);
					DecodeOrder(builderTracker, true);
				}
			}
		}
	}
}
コード例 #4
0
ファイル: UnitHandler.cpp プロジェクト: BrainDamage/spring
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);
						}
					}
				}
			}
		}
	}
}
コード例 #5
0
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);
					}
				}
				* /
			}
			*/
		}
}