Пример #1
0
int CAICheats::HandleCommand(int commandId, void* data)
{
	int ret = 0; // handling failed

	switch (commandId) {
		case AIHCQuerySubVersionId: {
			ret = 1; // current version of Handle Command interface
		} break;

		case AIHCTraceRayId: {
			AIHCTraceRay* cmdData = static_cast<AIHCTraceRay*>(data);

			if (CHECK_UNITID(cmdData->srcUID)) {
				const CUnit* srcUnit = unitHandler->GetUnit(cmdData->srcUID);

				CUnit* hitUnit = nullptr;
				CFeature* hitFeature = nullptr;

				if (srcUnit != nullptr) {
					//FIXME ignore features?
					cmdData->rayLen = TraceRay::TraceRay(cmdData->rayPos, cmdData->rayDir, cmdData->rayLen, cmdData->flags, srcUnit, hitUnit, hitFeature);
					cmdData->hitUID = (hitUnit != nullptr)? hitUnit->id: -1;
				}
			}

			ret = 1;
		} break;

		case AIHCFeatureTraceRayId: {
			AIHCFeatureTraceRay* cmdData = static_cast<AIHCFeatureTraceRay*>(data);

			if (CHECK_UNITID(cmdData->srcUID)) {
				const CUnit* srcUnit = unitHandler->GetUnit(cmdData->srcUID);

				CUnit* hitUnit = nullptr;
				CFeature* hitFeature = nullptr;

				if (srcUnit != nullptr) {
					//FIXME ignore units?
					cmdData->rayLen = TraceRay::TraceRay(cmdData->rayPos, cmdData->rayDir, cmdData->rayLen, cmdData->flags, srcUnit, hitUnit, hitFeature);
					cmdData->hitFID = (hitFeature != nullptr)? hitFeature->id: -1;
				}
			}

			ret = 1;
		} break;

		default: {
			ret = 0; // handling failed
		}
	}

	return ret;
}
Пример #2
0
const UnitDef* CAICallback::GetUnitDef(int unitId)
{
	const UnitDef* def = nullptr;

	verify();
	if (CHECK_UNITID(unitId)) {
		const CUnit* unit = unitHandler->GetUnit(unitId);

		if (unit == nullptr)
			return def;

		const UnitDef* unitDef = unit->unitDef;
		const int allyTeam = teamHandler->AllyTeam(team);
		if (teamHandler->Ally(unit->allyteam, allyTeam)) {
			def = unitDef;
		} else {
			const unsigned short losStatus = unit->losStatus[allyTeam];
			const unsigned short prevMask = (LOS_PREVLOS | LOS_CONTRADAR);
			if (((losStatus & LOS_INLOS) != 0) ||
					((losStatus & prevMask) == prevMask)) {
				const UnitDef* decoyDef = unitDef->decoyDef;
				if (decoyDef == NULL) {
					def = unitDef;
				} else {
					def = decoyDef;
				}
			}
		}
	}

	return def;
}
Пример #3
0
const UnitDef* CAICallback::GetUnitDef(int unitId)
{
	verify ();
	if (CHECK_UNITID(unitId)) {
		CUnit* unit = uh->units[unitId];
		if (unit) {
			const UnitDef* unitDef = unit->unitDef;
			const int allyTeam = gs->AllyTeam(team);
			if (gs->Ally(unit->allyteam, allyTeam)) {
				return unitDef;
			}
			const unsigned short losStatus = unit->losStatus[allyTeam];
			const unsigned short prevMask = (LOS_PREVLOS | LOS_CONTRADAR);
			if (((losStatus & LOS_INLOS) != 0) ||
					((losStatus & prevMask) == prevMask)) {
				const UnitDef* decoyDef = unitDef->decoyDef;
				if (decoyDef == NULL) {
					return unitDef;
				} else {
					return decoyDef;
				}
			}
		}
	}
	return 0;
}
Пример #4
0
float CAICallback::GetUnitPower(int unitId)
{
	float power = -1;

	verify();
	if (CHECK_UNITID(unitId)) {
		const CUnit* unit = unitHandler->units[unitId];
		if (unit) {
			const int allyTeam = teamHandler->AllyTeam(team);
			if (teamHandler->Ally(unit->allyteam, allyTeam)) {
				power = unit->power;
			} else if (unit->losStatus[allyTeam] & LOS_INLOS) {
				const UnitDef* unitDef = unit->unitDef;
				const UnitDef* decoyDef = unitDef->decoyDef;
				if (decoyDef == NULL) {
					power = unit->power;
				} else {
					const float scale = (decoyDef->power / unitDef->power);
					power = unit->power * scale;
				}
			}
		}
	}

	return power;
}
Пример #5
0
float CAICallback::GetUnitMaxRange(int unitId)
{
	float maxRange = -1;

	verify();
	if (CHECK_UNITID(unitId)) {
		const CUnit* unit = unitHandler->units[unitId];
		if (unit) {
			const int allyTeam = teamHandler->AllyTeam(team);
			if (teamHandler->Ally(unit->allyteam, allyTeam)) {
				maxRange = unit->maxRange;
			} else if (unit->losStatus[allyTeam] & LOS_INLOS) {
				const UnitDef* unitDef = unit->unitDef;
				const UnitDef* decoyDef = unitDef->decoyDef;
				if (decoyDef == NULL) {
					maxRange = unit->maxRange;
				} else {
					maxRange = decoyDef->maxWeaponRange;
				}
			}
		}
	}

	return maxRange;
}
Пример #6
0
float CAICallback::GetUnitSpeed(int unitId)
{
	float speed = 0;

	verify();
	if (CHECK_UNITID(unitId)) {
		const CUnit* unit = unitHandler->units[unitId];
		if (unit) {
			const int allyTeam = teamHandler->AllyTeam(team);
			if (teamHandler->Ally(unit->allyteam, allyTeam)) {
				speed = unit->moveType->GetMaxSpeed();
			} else if (unit->losStatus[allyTeam] & LOS_INLOS) {
				const UnitDef* unitDef = unit->unitDef;
				const UnitDef* decoyDef = unitDef->decoyDef;
				if (decoyDef == NULL) {
					speed = unitDef->speed;
				} else {
					speed = decoyDef->speed;
				}
			}
		}
	}

	return speed;
}
Пример #7
0
float CAICallback::GetUnitMaxHealth(int unitId)
{
	float maxHealth = -1;

	verify();
	if (CHECK_UNITID(unitId)) {
		const CUnit* unit = unitHandler->units[unitId];
		if (unit) {
			const int allyTeam = teamHandler->AllyTeam(team);
			if (teamHandler->Ally(unit->allyteam, allyTeam)) {
				maxHealth = unit->maxHealth;
			} else if (unit->losStatus[allyTeam] & LOS_INLOS) {
				const UnitDef* unitDef = unit->unitDef;
				const UnitDef* decoyDef = unitDef->decoyDef;
				if (decoyDef == NULL) {
					maxHealth = unit->maxHealth;
				} else {
					const float scale = (decoyDef->health / unitDef->health);
					maxHealth = unit->maxHealth * scale;
				}
			}
		}
	}

	return maxHealth;
}
Пример #8
0
int CAICallback::GiveOrder(int unitId, Command* c)
{
	verify();

	if (!CHECK_UNITID(unitId) || c == NULL) {
		return -1;
	}

	if (noMessages) {
		return -2;
	}

	const CUnit * unit = unitHandler->units[unitId];

	if (!unit) {
		return -3;
	}

	if (unit->team != team) {
		return -5;
	}

	net->Send(CBaseNetProtocol::Get().SendAICommand(gu->myPlayerNum, skirmishAIHandler.GetCurrentAIID(), unitId, c->GetID(), c->aiCommandId, c->options, c->params));

	return 0;
}
Пример #9
0
CUnit* CAICheats::GetUnit(int unitId) const
{
	if (CHECK_UNITID(unitId))
		return unitHandler->GetUnit(unitId);

	return nullptr;
}
Пример #10
0
int CAICallback::GiveOrder(int unitid, Command* c)
{
	verify ();

	if (!CHECK_UNITID(unitid) || c == NULL)
		return -1;

	if (noMessages)
		return -1;

	CUnit *unit = uh->units[unitid];

	if (!unit)
		return -1;

	if (group && unit->group != group)
		return -1;

	if (unit->team != team)
		return -1;

	net->SendSTLData<unsigned char, short, int, unsigned char, std::vector<float> >(
			NETMSG_AICOMMAND, gu->myPlayerNum, unitid, c->id, c->options, c->params);
	return 0;
}
Пример #11
0
int CAICheats::HandleCommand(int commandId, void *data)
{
	switch (commandId) {
		case AIHCQuerySubVersionId:
			return 1; // current version of Handle Command interface

		case AIHCTraceRayId: {
			AIHCTraceRay* cmdData = (AIHCTraceRay*) data;

			if (CHECK_UNITID(cmdData->srcUID)) {
				const CUnit* srcUnit = uh->units[cmdData->srcUID];
				const CUnit* hitUnit = NULL;

				if (srcUnit != NULL) {
					cmdData->rayLen = helper->TraceRay(cmdData->rayPos, cmdData->rayDir, cmdData->rayLen, 0.0f, srcUnit, hitUnit, cmdData->flags);
					cmdData->hitUID = (hitUnit != NULL)? hitUnit->id: -1;
				}
			}

			return 1;
		}

		default:
			return 0;
	}
}
Пример #12
0
float CAICallback::GetUnitHealth(int unitId)
{
	float health = -1.0f;

	verify();
	if (CHECK_UNITID(unitId)) {
		const CUnit* unit = unitHandler->GetUnit(unitId);

		if (unit == nullptr)
			return health;

		const int allyTeam = teamHandler->AllyTeam(team);

		if (teamHandler->Ally(unit->allyteam, allyTeam)) {
			health = unit->health;
		} else if (unit->losStatus[allyTeam] & LOS_INLOS) {
			const UnitDef* unitDef = unit->unitDef;
			const UnitDef* decoyDef = unitDef->decoyDef;

			if (decoyDef == nullptr) {
				health = unit->health;
			} else {
				health = unit->health * (decoyDef->health / unitDef->health);
			}
		}
	}

	return health;
}
Пример #13
0
float CAICallback::GetUnitHealth(int unitId)
{
	verify();
	if (CHECK_UNITID(unitId)) {
		CUnit* unit = uh->units[unitId];

		if (unit) {
			const int allyTeam = gs->AllyTeam(team);

			if (gs->Ally(unit->allyteam, allyTeam)) {
				return unit->health;
			}
			else if (unit->losStatus[allyTeam] & LOS_INLOS) {
				const UnitDef* unitDef = unit->unitDef;
				const UnitDef* decoyDef = unitDef->decoyDef;

				if (decoyDef == NULL) {
					return unit->health;
				} else {
					const float scale = (decoyDef->health / unitDef->health);
					return (unit->health * scale);
				}
			}
		}
	}

	return 0;
}
Пример #14
0
bool CAICheats::IsUnitCloaked(int unitid) {
	if (!CHECK_UNITID(unitid)) return false;
	CUnit* unit = uh->units[unitid];
	if (unit) {
		return unit->isCloaked;
	}
	return false;
}
Пример #15
0
int CAICheats::GetBuildingFacing(int unitid) {
	if (!CHECK_UNITID(unitid)) return 0;
	CUnit* unit = uh->units[unitid];
	if (unit) {
		return unit->buildFacing;
	}
	return 0;
}
Пример #16
0
const CCommandQueue* CAICheats::GetCurrentUnitCommands(int unitid)
{
	if (!CHECK_UNITID(unitid)) return 0;
	CUnit* unit = uh->units[unitid];
	if (unit) {
		return &unit->commandAI->commandQue;
	}
	return 0;
}
Пример #17
0
bool CAICheats::UnitBeingBuilt(int unitid)
{
	if (!CHECK_UNITID(unitid)) return false;
	CUnit* unit = uh->units[unitid];
	if (unit) {
		return unit->beingBuilt;
	}
	return false;
}
Пример #18
0
float CAICheats::GetUnitExperience(int unitid)	//how experienced the unit is (0.0-1.0)
{
	if (!CHECK_UNITID(unitid)) return 0;
	CUnit* unit = uh->units[unitid];
	if (unit) {
		return unit->experience;
	}
	return 0;
}
Пример #19
0
float CAICheats::GetUnitMaxHealth(int unitid)		//the units max health
{
	if (!CHECK_UNITID(unitid)) return 0;
	CUnit* unit = uh->units[unitid];
	if (unit) {
		return unit->maxHealth;
	}
	return 0;
}
Пример #20
0
float3 CAICheats::GetUnitVelocity(int unitid)
{
	if (!CHECK_UNITID(unitid)) return ZeroVector;
	const CUnit* unit = uh->units[unitid];
	if (unit != NULL) {
		return unit->speed;
	}
	return ZeroVector;
}
Пример #21
0
const deque<Command>* CAICallback::GetCurrentUnitCommands(int unitid)
{
	if (CHECK_UNITID(unitid)) {
		CUnit *unit = uh->units[unitid];
		if (unit && unit->team == team)
			return &unit->commandAI->commandQue;
	}
	return 0;
}
Пример #22
0
int CAICheats::GetUnitAllyTeam(int unitid)
{
	if (!CHECK_UNITID(unitid)) return 0;
	CUnit* unit = uh->units[unitid];
	if (unit) {
		return unit->allyteam;
	}
	return 0;
}
Пример #23
0
CUnit* CAICallback::GetUnit(int unitId) const
{
	CUnit* unit = nullptr;

	if (CHECK_UNITID(unitId))
		unit = unitHandler->GetUnit(unitId);

	return unit;
}
Пример #24
0
const vector<CommandDescription>* CAICallback::GetUnitCommands(int unitid)
{
	if (CHECK_UNITID(unitid)) {
		CUnit *unit = uh->units[unitid];
		if (unit && unit->team == team)
			return &unit->commandAI->possibleCommands;
	}
	return 0;
}
Пример #25
0
float CAICheats::GetUnitPower(int unitid)				//sort of the measure of the units overall power
{
	if (!CHECK_UNITID(unitid)) return 0;
	CUnit* unit = uh->units[unitid];
	if (unit) {
		return unit->power;
	}
	return 0;
}
Пример #26
0
bool CAICallback::GetProperty(int unitId, int property, void* data)
{
	verify();
	if (CHECK_UNITID(unitId)) {
		const CUnit* unit = unitHandler->GetUnit(unitId);
		const int allyTeam = teamHandler->AllyTeam(team);

		myAllyTeamId = allyTeam;

		// the unit does not exist or can not be seen
		if (unit == nullptr || !unit_IsInLos(unit))
			return false;

		switch (property) {
			case AIVAL_UNITDEF: {
				if (teamHandler->Ally(unit->allyteam, allyTeam)) {
					(*(const UnitDef**)data) = unit->unitDef;
				} else {
					const UnitDef* unitDef = unit->unitDef;
					const UnitDef* decoyDef = unitDef->decoyDef;
					if (decoyDef == NULL) {
						(*(const UnitDef**)data) = unitDef;
					} else {
						(*(const UnitDef**)data) = decoyDef;
					}
				}
				return true;
			}
			case AIVAL_CURRENT_FUEL: { //Deprecated
				(*(float*)data) = 0;
				return true;
			}
			case AIVAL_STOCKPILED: {
				if (!unit->stockpileWeapon || !teamHandler->Ally(unit->allyteam, allyTeam)) {
					return false;
				}
				(*(int*)data) = unit->stockpileWeapon->numStockpiled;
				return true;
			}
			case AIVAL_STOCKPILE_QUED: {
				if (!unit->stockpileWeapon || !teamHandler->Ally(unit->allyteam, allyTeam)) {
					return false;
				}
				(*(int*)data) = unit->stockpileWeapon->numStockpileQued;
				return true;
			}
			case AIVAL_UNIT_MAXSPEED: {
				(*(float*) data) = unit->moveType->GetMaxSpeed();
				return true;
			}
			default:
				return false;
		}
	}
	return false;
}
Пример #27
0
bool CAICallback::UnitBeingBuilt (int unitid)
{
	verify ();
	if (CHECK_UNITID(unitid)) {
		CUnit* unit=uh->units[unitid];
		if(unit && (unit->losStatus[gs->AllyTeam(team)] & LOS_INLOS))
			return unit->beingBuilt;
	}
	return false;
}
Пример #28
0
bool CAICallback::IsUnitCloaked(int unitId) {
	verify ();
	if (CHECK_UNITID(unitId)) {
		CUnit* unit=uh->units[unitId];
		if(unit && (unit->losStatus[gs->AllyTeam(team)] & LOS_INLOS)){
			return unit->isCloaked;
		}
	}
	return false;
}
Пример #29
0
bool CAICallback::IsUnitActivated (int unitid)
{
	verify ();
	if (CHECK_UNITID(unitid)) {
		CUnit* unit=uh->units[unitid];
		if(unit && (unit->losStatus[gs->AllyTeam(team)] & LOS_INLOS))
			return unit->activated;
	}
	return false;
}
Пример #30
0
bool CAICallback::AddUnitToGroup(int unitid,int groupid)
{
	if (CHECK_UNITID(unitid) && CHECK_GROUPID(groupid)) {
		CUnit* u=uh->units[unitid];
		if(u && u->team==team && gh->groups[groupid]){
			return u->SetGroup(gh->groups[groupid]);
		}
	}
	return false;
}