예제 #1
0
파일: XAIGroup.cpp 프로젝트: rrti/ai-libs
// tell ALL units in this group to execute <c>
// (units that cannot comply get a guard order)
int XAIGroup::GiveCommand(const Command& c) const {
	int r = 0;

	if (CanGiveCommand(c.id)) {
		// either all units in this group can execute
		// <c>, or none can... but in the latter case,
		// ::CanGiveCommand() should always have been
		// called before GiveCommand(c) to ensure this
		// does not happen (there should always be >=
		// 1 unit capable of executing the command per
		// group)
		for (std::map<int, XAICUnit*>::const_iterator uit = unitsByID.begin(); uit != unitsByID.end(); uit++) {
			r += (uit->second)->GiveCommand(c);
		}
	} else {
		if (task != 0) {
			// we can end up here when eg. a group of
			// arm_construction_vehicle is added to a
			// a BuildTask for a core_vehicle_plant
			const std::set<XAIGroup*>& groups = task->GetGroupMembers();

			for (std::set<XAIGroup*>::iterator git = groups.begin(); git != groups.end(); git++) {
				if ((*git) != this) {
					if ((*git)->CanGiveCommand(c.id)) {
						// (*git) should already be executing <c>, guard it
						GiveCommand(CMD_GUARD, *git);
						break;
					}
				}
			}
		}
	}

	return r;
}
예제 #2
0
파일: AIUnit.cpp 프로젝트: Error323/MAIM
void AIUnit::Stop() {
	Command c;
		c.id = CMD_STOP;
	GiveCommand(&c);

	idleTime = 0;
}
예제 #3
0
파일: AIUnit.cpp 프로젝트: Error323/MAIM
void AIUnit::Wait(bool w) {
	Command c;
		c.id = CMD_WAIT;
	GiveCommand(&c);

	waiting = w;
}
예제 #4
0
파일: AIUnit.cpp 프로젝트: Error323/MAIM
int AIUnit::TryGiveCommand(pCommand c) const {
	if (CanGiveCommand(c->id)) {
		return (GiveCommand(c));
	}

	return -100;
}
예제 #5
0
파일: AIUnit.cpp 프로젝트: Error323/MAIM
void AIUnit::SetActiveState(cBool wantActive) {
	if (CanGiveCommand(CMD_ONOFF))
	{
		if (active != wantActive) {
			active = !active;

			Command c;
				c.id = CMD_ONOFF;
				c.params.push_back(wantActive);
			GiveCommand(&c);
		}
	}
}