示例#1
0
文件: Body.cpp 项目: Gluk-v48/Ares
/**
 * moved the fix for #917 here - check a house's ability to handle base plan before it actually tries to generate a base plan, not at game start
 * (we have no idea what houses at game start are supposed to be able to do base planning, so mission maps f**k up)
 */
bool HouseExt::ExtData::CheckBasePlanSanity() {
	auto House = this->AttachedToObject;
	// this shouldn't happen, but you never know
	if(House->ControlledByHuman() || House->IsNeutral()) {
		return true;
	}

	const char *errorMsg = "AI House of country [%s] cannot build any object in %s. The AI ain't smart enough for that.\n";
	bool AllIsWell(true);

	// if you don't have a base unit buildable, how did you get to base planning?
	// only through crates or map actions, so have to validate base unit in other situations
	auto pArray = &RulesClass::Instance->BaseUnit;
	bool canBuild = false;
	for(int i = 0; i < pArray->Count; ++i) {
		auto Item = pArray->GetItem(i);
		if(House->CanExpectToBuild(Item)) {
			canBuild = true;
			break;
		}
	}
	if(!canBuild) {
		AllIsWell = false;
		Debug::DevLog(Debug::Error, errorMsg, House->Type->ID, "BaseUnit");
	}

	auto CheckList = [House, errorMsg, &AllIsWell]
			(DynamicVectorClass<BuildingTypeClass *> *const List, char * const ListName) -> void {
		if(!House->FirstBuildableFromArray(List)) {
			AllIsWell = false;
			Debug::DevLog(Debug::Error, errorMsg, House->Type->ID, ListName);
		}
	};

	// commented out lists that do not cause a crash, according to testers
//	CheckList(&RulesClass::Instance->Shipyard, "Shipyard");
	CheckList(&RulesClass::Instance->BuildPower, "BuildPower");
	CheckList(&RulesClass::Instance->BuildRefinery, "BuildRefinery");
	CheckList(&RulesClass::Instance->BuildWeapons, "BuildWeapons");

//			CheckList(&RulesClass::Instance->BuildConst, "BuildConst");
//			CheckList(&RulesClass::Instance->BuildBarracks, "BuildBarracks");
//			CheckList(&RulesClass::Instance->BuildTech, "BuildTech");
//			CheckList(&RulesClass::Instance->BuildRadar, "BuildRadar");
//			CheckList(&RulesClass::Instance->ConcreteWalls, "ConcreteWalls");
//			CheckList(&RulesClass::Instance->BuildDummy, "BuildDummy");
//			CheckList(&RulesClass::Instance->BuildNavalYard, "BuildNavalYard");

	auto pCountryData = HouseTypeExt::ExtMap.Find(House->Type);
	auto Powerplants = pCountryData->GetPowerplants();
	DynamicVectorClass<BuildingTypeClass*> Dummy(Powerplants.size(), const_cast<BuildingTypeClass**>(Powerplants.begin()));
	CheckList(&Dummy, "Powerplants");

//			auto pSide = SideClass::Array->GetItem(curHouse->Type->SideIndex);
//			auto pSideData = SideExt::ExtMap.Find(pSide);
//			CheckList(&pSideData->BaseDefenses, "Base Defenses");

	return AllIsWell;
}
示例#2
0
GammaCurvePtr ScaledGammaCurve::GetByEncoding(const GammaCurvePtr& gamma, float factor)
{
    if (IsNeutral(factor))
        return GammaCurvePtr(gamma);
    return GetMatching(GammaCurvePtr(new ScaledGammaCurve(
        GammaCurve::IsNeutral(gamma) ? GammaCurvePtr(NeutralGammaCurve::Get()) : gamma,
        factor)));
}
示例#3
0
void Alliance::Neutral(int32_t allianceid)
{
	if (IsNeutral(allianceid))
		return;
	if (IsAlly(allianceid))
		UnAlly(allianceid);
	if (IsEnemy(allianceid))
		UnEnemy(allianceid);
	m_neutral.push_back(allianceid);
	Alliance * temp = m_main->m_alliances->AllianceById(allianceid);
	temp->SendAllianceMessage("Alliance [" + temp->m_name + "] recognizes Diplomatic Relationship with us as Neutral.", false, false);
}
示例#4
0
void Alliance::Enemy(int32_t allianceid, bool skip /* = false*/)
{
	if (IsEnemy(allianceid))
		return;
	enemyactioncooldown = unixtime() + 1000*60*60*24;
	if (IsNeutral(allianceid))
		UnNeutral(allianceid);
	if (IsAlly(allianceid))
		UnAlly(allianceid);
	m_enemies.push_back(allianceid);
	if (skip)
		return;
	//send global message
	Alliance * temp = m_main->m_alliances->AllianceById(allianceid);
	m_main->MassMessage("Alliance " + this->m_name + " declares war against alliance " + temp->m_name + ". Diplomatic Relationship between each other alters to Hostile automatically.");
	temp->Enemy(m_allianceid, true);
	temp->SendAllianceMessage("Alliance [" + m_name + "] recognizes Diplomatic Relationship with us as Enemy.", false, false);
}
示例#5
0
void ClientObituary (edict_t *self, edict_t *inflictor, edict_t *attacker)
{
	int			mod;
	char		*message;
	char		*message2;
	qboolean	ff;

	if (coop->value && attacker->client)
		meansOfDeath |= MOD_FRIENDLY_FIRE;

	if (deathmatch->value || coop->value)
	{
		ff = meansOfDeath & MOD_FRIENDLY_FIRE;
		mod = meansOfDeath & ~MOD_FRIENDLY_FIRE;
		message = NULL;
		message2 = "";

		switch (mod)
		{
		case MOD_SUICIDE:
			message = "suicides";
			break;
		case MOD_FALLING:
			message = "cratered";
			break;
		case MOD_CRUSH:
			message = "was squished";
			break;
		case MOD_WATER:
			message = "sank like a rock";
			break;
		case MOD_SLIME:
			message = "melted";
			break;
		case MOD_LAVA:
			message = "does a back flip into the lava";
			break;
		case MOD_EXPLOSIVE:
		case MOD_BARREL:
			message = "blew up";
			break;
		case MOD_EXIT:
			message = "found a way out";
			break;
		case MOD_TARGET_LASER:
			message = "saw the light";
			break;
		case MOD_TARGET_BLASTER:
			message = "got blasted";
			break;
		case MOD_BOMB:
		case MOD_SPLASH:
		case MOD_TRIGGER_HURT:
			message = "was in the wrong place";
			break;
		}
		if (attacker == self)
		{
			switch (mod)
			{
			case MOD_HELD_GRENADE:
				message = "tried to put the pin back in";
				break;
			case MOD_HG_SPLASH:
			case MOD_G_SPLASH:
				if (IsNeutral(self))
					message = "tripped on its own grenade";
				else if (IsFemale(self))
					message = "tripped on her own grenade";
				else
					message = "tripped on his own grenade";
				break;
			case MOD_R_SPLASH:
				if (IsNeutral(self))
					message = "blew itself up";
				else if (IsFemale(self))
					message = "blew herself up";
				else
					message = "blew himself up";
				break;
			case MOD_BFG_BLAST:
				message = "should have used a smaller gun";
				break;
			default:
				if (IsNeutral(self))
					message = "killed itself";
				else if (IsFemale(self))
					message = "killed herself";
				else
					message = "killed himself";
				break;
			}
		}
		if (message)
		{
			gi.bprintf (PRINT_MEDIUM, "%s %s.\n", self->client->pers.netname, message);
			if (deathmatch->value)
				self->client->resp.score--;
			self->enemy = NULL;
			return;
		}

		self->enemy = attacker;
		if (attacker && attacker->client)
		{
			switch (mod)
			{
			case MOD_BLASTER:
				message = "was blasted by";
				break;
			case MOD_SHOTGUN:
				message = "was gunned down by";
				break;
			case MOD_SSHOTGUN:
				message = "was blown away by";
				message2 = "'s super shotgun";
				break;
			case MOD_MACHINEGUN:
				message = "was machinegunned by";
				break;
			case MOD_CHAINGUN:
				message = "was cut in half by";
				message2 = "'s chaingun";
				break;
			case MOD_GRENADE:
				message = "was popped by";
				message2 = "'s grenade";
				break;
			case MOD_G_SPLASH:
				message = "was shredded by";
				message2 = "'s shrapnel";
				break;
			case MOD_ROCKET:
				message = "ate";
				message2 = "'s rocket";
				break;
			case MOD_R_SPLASH:
				message = "almost dodged";
				message2 = "'s rocket";
				break;
			case MOD_HYPERBLASTER:
				message = "was melted by";
				message2 = "'s hyperblaster";
				break;
			case MOD_RAILGUN:
				message = "was railed by";
				break;
			case MOD_BFG_LASER:
				message = "saw the pretty lights from";
				message2 = "'s BFG";
				break;
			case MOD_BFG_BLAST:
				message = "was disintegrated by";
				message2 = "'s BFG blast";
				break;
			case MOD_BFG_EFFECT:
				message = "couldn't hide from";
				message2 = "'s BFG";
				break;
			case MOD_HANDGRENADE:
				message = "caught";
				message2 = "'s handgrenade";
				break;
			case MOD_HG_SPLASH:
				message = "didn't see";
				message2 = "'s handgrenade";
				break;
			case MOD_HELD_GRENADE:
				message = "feels";
				message2 = "'s pain";
				break;
			case MOD_TELEFRAG:
				message = "tried to invade";
				message2 = "'s personal space";
				break;
			}
			if (message)
			{
				gi.bprintf (PRINT_MEDIUM,"%s %s %s%s\n", self->client->pers.netname, message, attacker->client->pers.netname, message2);
				if (deathmatch->value)
				{
					if (ff)
						attacker->client->resp.score--;
					else
						attacker->client->resp.score++;
				}
				return;
			}
		}
	}

	gi.bprintf (PRINT_MEDIUM,"%s died.\n", self->client->pers.netname);
	if (deathmatch->value)
		self->client->resp.score--;
}
示例#6
0
bool ScaledGammaCurve::Matches(const GammaCurvePtr& p) const
{
    ScaledGammaCurve* other = dynamic_cast<ScaledGammaCurve*>(p.get());
    if (!other) return false;
    return (this->baseGamma == other->baseGamma) && IsNeutral(this->encFactor / other->encFactor);
}
示例#7
0
bool PowerLawGammaCurve::Matches(const GammaCurvePtr& p) const
{
    PowerLawGammaCurve* other = dynamic_cast<PowerLawGammaCurve*>(p.get());
    if (!other) return false;
    return IsNeutral(this->encGamma / other->encGamma);
}
示例#8
0
SimpleGammaCurvePtr PowerLawGammaCurve::GetByEncodingGamma(float gamma)
{
    if (IsNeutral(gamma))
        return NeutralGammaCurve::Get();
    return std::tr1::dynamic_pointer_cast<SimpleGammaCurve>(GetMatching(GammaCurvePtr(new PowerLawGammaCurve(gamma))));
}
示例#9
0
void Cmd_Partner_f (edict_t * ent)
{
	edict_t *target;
	char *genderstr;

	if (!teamplay->value)
	{
		if (!((int) (dmflags->value) & (DF_MODELTEAMS | DF_SKINTEAMS)))
			return;			// don't allow in a non-team setup...
	}

	if (ent->deadflag == DEAD_DEAD || ent->solid == SOLID_NOT)
		return;

	if (ent->client->resp.radio_partner && !ent->client->resp.radio_partner->inuse)
	{	// just in case RadioThink hasn't caught it yet... avoid any problems
		ent->client->resp.radio_partner = NULL;
	}

	if (ent->client->resp.radio_partner)
	{
		gi.centerprintf (ent, "You already have a partner, %s",
			ent->client->resp.radio_partner->client->pers.netname);
		return;
	}

	target = DetermineViewedTeammate (ent);

	if (target == NULL)
	{
		gi.centerprintf (ent, "No potential partner selected");
		return;
	}

	if (target->client->resp.radio_partner)
	{
		gi.centerprintf (ent, "%s already has a partner", target->client->pers.netname);
		return;
	}

	if (target->client->resp.partner_last_offered_to == ent &&
		ent->client->resp.partner_last_offered_from == target)
	{
		gi.centerprintf (ent, "%s is now your partner", target->client->pers.netname);
		gi.centerprintf (target, "%s is now your partner", ent->client->pers.netname);
		ent->client->resp.radio_partner = target;
		target->client->resp.radio_partner = ent;
		ent->client->resp.partner_last_offered_from = NULL;
		target->client->resp.partner_last_offered_to = NULL;
		return;
	}

	if (target->client->resp.partner_last_denied_from == ent)
	{
		gi.centerprintf (ent, "%s has already denied you", target->client->pers.netname);
		return;
	}

	if (target == ent->client->resp.partner_last_offered_to)
	{
		if (IsFemale (target))
			genderstr = "her";
		else if (IsNeutral (target))
			genderstr = "it";
		else
			genderstr = "him";

		gi.centerprintf (ent, "Already awaiting confirmation from %s", genderstr);
		return;
	}

	if (IsFemale (ent))
		genderstr = "her";
	else if (IsNeutral (ent))
		genderstr = "it";
	else
		genderstr = "him";

	gi.centerprintf (ent, "Awaiting confirmation from %s", target->client->pers.netname);
	gi.centerprintf (target,
		"%s offers to be your partner\n"
		"To accept:\nView %s and use the 'partner' command\n"
		"To deny:\nUse the 'deny' command",
		ent->client->pers.netname, genderstr);

	ent->client->resp.partner_last_offered_to = target;
	target->client->resp.partner_last_offered_from = ent;
}
示例#10
0
/**
 * moved the fix for #917 here - check a house's ability to handle base plan
 * before it actually tries to generate a base plan, not at game start (we have
 * no idea what houses at game start are supposed to be able to do base
 * planning, so mission maps f**k up)
 */
bool HouseExt::ExtData::CheckBasePlanSanity() {
	auto const pThis = this->OwnerObject();
	// this shouldn't happen, but you never know
	if(pThis->ControlledByHuman() || pThis->IsNeutral()) {
		return true;
	}

	auto AllIsWell = true;

	auto const pRules = RulesClass::Instance;
	auto const pType = pThis->Type;

	auto const errorMsg = "AI House of country [%s] cannot build any object in "
		"%s. The AI ain't smart enough for that.\n";

	// if you don't have a base unit buildable, how did you get to base
	// planning? only through crates or map actions, so have to validate base
	// unit in other situations
	auto const idxParent = pType->FindParentCountryIndex();
	auto const canBuild = std::any_of(
		pRules->BaseUnit.begin(), pRules->BaseUnit.end(),
		[pThis, idxParent] (UnitTypeClass const* const pItem)
	{
		return pThis->CanExpectToBuild(pItem, idxParent);
	});

	if(!canBuild) {
		AllIsWell = false;
		Debug::Log(Debug::Severity::Error, errorMsg, pType->ID, "BaseUnit");
	}

	auto CheckList = [pThis, pType, idxParent, errorMsg, &AllIsWell] (
		Iterator<BuildingTypeClass const*> const list,
		const char* const ListName) -> void
	{
		if(!HouseExt::FindBuildable(pThis, idxParent, list)) {
			AllIsWell = false;
			Debug::Log(Debug::Severity::Error, errorMsg, pType->ID, ListName);
		}
	};

	// commented out lists that do not cause a crash, according to testers
	//CheckList(make_iterator(pRules->Shipyard), "Shipyard");
	CheckList(make_iterator(pRules->BuildPower), "BuildPower");
	CheckList(make_iterator(pRules->BuildRefinery), "BuildRefinery");
	CheckList(make_iterator(pRules->BuildWeapons), "BuildWeapons");
	//CheckList(make_iterator(pRules->BuildConst), "BuildConst");
	//CheckList(make_iterator(pRules->BuildBarracks), "BuildBarracks");
	//CheckList(make_iterator(pRules->BuildTech), "BuildTech");
	//CheckList(make_iterator(pRules->BuildRadar), "BuildRadar");
	//CheckList(make_iterator(pRules->ConcreteWalls), "ConcreteWalls");
	//CheckList(make_iterator(pRules->BuildDummy), "BuildDummy");
	//CheckList(make_iterator(pRules->BuildNavalYard), "BuildNavalYard");

	auto const pCountryData = HouseTypeExt::ExtMap.Find(pType);
	auto const Powerplants = pCountryData->GetPowerplants();
	CheckList(Powerplants, "Powerplants");

	//auto const pSide = SideClass::Array->GetItemOrDefault(pType->SideIndex);
	//if(auto const pSideExt = SideExt::ExtMap.Find(pSide)) {
	//	CheckList(make_iterator(pSideExt->BaseDefenses), "Base Defenses");
	//}

	return AllIsWell;
}