Example #1
0
void CoreScript::AddFlag(const Vector2I& _pos)
{
	Vector2I pos = _pos;
	// A little UI fixup: set the flag to a porch
	// if we click on the switch.
	Chit* building = Context()->chitBag->QueryBuilding(IString(), pos, 0);
	if (building && (building->GetItem()->IName() == ISC::switchOn || building->GetItem()->IName() == ISC::switchOff)) {
		MapSpatialComponent* msc = GET_SUB_COMPONENT(building, SpatialComponent, MapSpatialComponent);
		if (msc) {
			pos = msc->PorchPos().min;
		}
	}

	Flag f = { pos, 0 };
	if (flags.Find(f) < 0) {
		Chit* chit = Context()->chitBag->NewChit();
		RenderComponent* rc = new RenderComponent("flag");
		chit->Add(rc);
		ProcRenderInfo info;
		AssignProcedural(ISC::team,
							false,
							ParentChit()->GetItem()->ID(),
							ParentChit()->Team(),
							false,
							0,
							0,
							&info);
		rc->SetProcedural(0, info);
		chit->SetPosition(ToWorld3F(pos));
		f.chitID = chit->ID();
		flags.Push(f);
	}
}
int MapSpatialComponent::DoTick(U32 delta)
{
	if (slowTick.Delta(delta)) {
		CoreScript* cs = CoreScript::GetCore(ToSector(parentChit->Position()));
		glowTarget = 0;

		if (needsCorePower) {
			if (cs && cs->InUse()) {
				Rectangle2I porch = this->PorchPos();
				if (porch.min.IsZero()) {
					// No porch. Just need core.
					glowTarget = 1;
				}
				else {
					Vector2F start = ToWorld2F(porch.min);
					Vector2F end = ToWorld2F(cs->ParentChit()->Position());
					if (Context()->worldMap->CalcPath(start, end, 0, 0, false)) {
						glowTarget = 1;
					}
				}
			}
		}
		else {
			glowTarget = 1;
			glow = 1;
		}
	}

	if (glow != glowTarget) {
		glow = TravelTo(0.7f, delta, glow, glowTarget);
	}
	if (parentChit->GetItem() && parentChit->GetItem()->IName() == ISC::core) {
		glow = glowTarget = 1;
	}

	RenderComponent* rc = parentChit->GetRenderComponent();
	if (rc) {
		const GameItem* gameItem = parentChit->GetItem();
		if (gameItem && gameItem->keyValues.GetIString(ISC::procedural) == ISC::team) {
//			int team = parentChit->Team();
			ProcRenderInfo info;
			AssignProcedural(parentChit->GetItem(), &info);
			info.color.X(Matrix4::M41) *= glow;
			info.color.X(Matrix4::M42) *= glow;
			info.color.X(Matrix4::M43) *= glow;
			rc->SetProcedural(0, info);
			rc->SetSaturation(0.5f + 0.5f*glow);
		}
	}
	return VERY_LONG_TICK;
}