Beispiel #1
0
bool CoreScript::RecruitNeutral()
{
	Vector2I sector = ToSector(parentChit->Position());
	Rectangle2I inner = InnerSectorBounds(sector);

	MOBKeyFilter filter;
	filter.value = ISC::denizen;
	CChitArray arr;
	Context()->chitBag->QuerySpatialHash(&arr, ToWorld2F(inner), 0, &filter);

	for (int i = 0; i < arr.Size(); ++i) {
		Chit* chit = arr[i];
		if (Team::Instance()->GetRelationship(chit, parentChit) != ERelate::ENEMY) {
			if (this->IsCitizen(chit)) continue;
			if (!chit->GetItem()) continue;

			if (Team::IsRogue(chit->Team())) {
				// ronin! denizen without a core.
				this->AddCitizen( chit );
				GLASSERT(chit->GetItem()->Significant());

				NewsEvent news(NewsEvent::ROGUE_DENIZEN_JOINS_TEAM, ToWorld2F(chit->Position()), chit->GetItemID(), 0);
				Context()->chitBag->GetNewsHistory()->Add(news);
				return true;
			}
		}
	}
	return false;
}
Beispiel #2
0
Chit* CoreScript::CitizenFilter(int chitID)
{
	Chit* chit = Context()->chitBag->GetChit(chitID);
	if (chit && (chit->Team() == parentChit->Team())) {
		return chit;
	}
	return 0;
}
Beispiel #3
0
void CoreScript::OnChitMsg(Chit* chit, const ChitMsg& msg)
{
	// Logic split between Sim::OnChitMsg and CoreScript::OnChitMsg
	if (msg.ID() == ChitMsg::CHIT_DESTROYED && (chit == parentChit)) {
		while (!citizens.Empty()) {
			int citizenID = citizens.Pop();
			Chit* citizen = Context()->chitBag->GetChit(citizenID);
			if (citizen && citizen->GetItem()) {
				// Set to rogue team.
				citizen->GetItem()->SetRogue();
			}
		}

		Vector2I pos2i = ToWorld2I(chit->Position());
		Vector2I sector = ToSector(pos2i);

		if (Team::Instance()->IsController(chit->Team())) {
			NewsEvent news(NewsEvent::SUPERTEAM_DELETED, ToWorld2F(pos2i), chit->GetItemID(), 0);
			Context()->chitBag->GetNewsHistory()->Add(news);
		}
		int controllerTeam = 0;
		if (Team::Instance()->IsControlled(chit->Team(), &controllerTeam)) {
			CoreScript* controller = CoreScript::GetCoreFromTeam(controllerTeam);
			GLASSERT(controller);
			if (controller) {
				NewsEvent news(NewsEvent::SUBTEAM_DELETED, ToWorld2F(pos2i), chit->GetItemID(), controller->ParentChit()->GetItemID());
				Context()->chitBag->GetNewsHistory()->Add(news);
			}
		}

		int deleterID = chit->GetItemComponent() ? chit->GetItemComponent()->LastDamageID() : 0;
		Chit* deleter = Context()->chitBag->GetChit(deleterID);
		int superTeam = 0;
		if (deleter
			&& (deleter->Team() == Team::Instance()->SuperTeam(deleter->Team()))
			&& Team::IsDenizen(deleter->Team())
			&& Team::IsDenizen(chit->Team()))
		{
			superTeam = deleter->Team();
		}

		if (chit->Team() != TEAM_NEUTRAL) {
			if (superTeam) {
				LumosChitBag::CreateCoreData data = { sector, true, chit->Team(), deleter ? deleter->Team() : 0 };
				Context()->chitBag->coreCreateList.Push(data);
			}
			else {
				LumosChitBag::CreateCoreData data = { sector, false, chit->Team(), deleter ? deleter->Team() : 0 };
				Context()->chitBag->coreCreateList.Push(data);
			}
		}
		else {
			// Neutral cores are taken over by wandering over them
			// with enough friend units to have critical mass.
			LumosChitBag::CreateCoreData data = { sector, false, 0, 0 };
			Context()->chitBag->coreCreateList.Push(data);
		}
		Team::Instance()->CoreDestroyed(parentChit->Team());
	}
}