コード例 #1
0
ファイル: CommandAI.cpp プロジェクト: Gepard/spring
int CCommandAI::CancelCommands(const Command &c, CCommandQueue& q,
                               bool& first)
{
	first = false;
	int cancelCount = 0;

	while (true) {
		CCommandQueue::iterator ci = GetCancelQueued(c, q);
		if (ci == q.end()) {
			return cancelCount;
		}
		first = first || (ci == q.begin());
		cancelCount++;

		CCommandQueue::iterator firstErase = ci;
		CCommandQueue::iterator lastErase = ci;

		ci++;
		if ((ci != q.end()) && (ci->id == CMD_SET_WANTED_MAX_SPEED)) {
			lastErase = ci;
			cancelCount++;
			ci++;
		}

		if ((ci != q.end()) && (ci->id == CMD_WAIT)) {
  		waitCommandsAI.RemoveWaitCommand(owner, *ci);
			lastErase = ci;
			cancelCount++;
			ci++;
		}

		lastErase++; // STL: erase the range [first, last)
		q.erase(firstErase, lastErase);

		if (c.id >= 0) {
			return cancelCount; // only delete one non-build order
		}
	}

	return cancelCount;
}
コード例 #2
0
bool CCommandAI::WillCancelQueued(const Command& c)
{
	return (GetCancelQueued(c, commandQue) != commandQue.end());
}
コード例 #3
0
void CFactoryCAI::GiveCommand(Command& c)
{
	map<int,BuildOption>::iterator boi;
	if((boi=buildOptions.find(c.id))==buildOptions.end()){		//not a build order so que it to built units
		if(nonQueingCommands.find(c.id)!=nonQueingCommands.end()){
			CCommandAI::GiveCommand(c);
			return;
		}

		if(!(c.options & SHIFT_KEY)){
			newUnitCommands.clear();
		}
		if(c.id!=CMD_STOP){
			std::deque<Command>::iterator ci = GetCancelQueued(c);
			if(ci == this->newUnitCommands.end()){
				newUnitCommands.push_back(c);
			} else {
				this->newUnitCommands.erase(ci);
			}
		}
		return;
	}
	BuildOption &bo=boi->second;

	int numItems=1;
	if(c.options& SHIFT_KEY)
		numItems*=5;
	if(c.options & CONTROL_KEY)
		numItems*=20;

	if(c.options & RIGHT_MOUSE_KEY){
		bo.numQued-=numItems;
		if(bo.numQued<0)
			bo.numQued=0;

		int numToErase=numItems;
		if(c.options & ALT_KEY){
			for(unsigned int cmdNum=0;cmdNum<commandQue.size() && numToErase;++cmdNum){
				if(commandQue[cmdNum].id==c.id){
					commandQue[cmdNum].id=CMD_STOP;
					numToErase--;
				}
			}
		} else {
			for(int cmdNum=commandQue.size()-1;cmdNum!=-1 && numToErase;--cmdNum){
				if(commandQue[cmdNum].id==c.id){
					commandQue[cmdNum].id=CMD_STOP;
					numToErase--;
				}
			}
		}
		UpdateIconName(c.id,bo);
		SlowUpdate();

	} else {
		if(c.options & ALT_KEY){
			for(int a=0;a<numItems;++a){
				commandQue.push_front(c);
			}
			building=false;
			CFactory* fac=(CFactory*)owner;
			fac->StopBuild();
		} else {
			for(int a=0;a<numItems;++a){
				commandQue.push_back(c);
			}
		}
		bo.numQued+=numItems;
		UpdateIconName(c.id,bo);

		SlowUpdate();
	}
}