void CoreScript::RemoveFlag(const Vector2I& pos) { Flag f = { pos, 0 }; int i = flags.Find(f); if (i >= 0) { if (flags[i].chitID) { Chit* chit = Context()->chitBag->GetChit(flags[i].chitID); if (chit) { chit->QueueDelete(); } flags[i].chitID = 0; } flags.Remove(i); } }
void FluidTestScene::Tap3D(const grinliz::Vector2F& view, const grinliz::Ray& world) { Vector3F at = { 0, 0, 0 }; float t = 0; int result = IntersectRayAAPlane(world.origin, world.direction, 1, 0, &at, &t); if (result == INTERSECT) { Vector2I pos2i = ToWorld2I(at); Vector2I sector = { 0, 0 }; CircuitSim* circuitSim = context.physicsSims->GetCircuitSim(sector); if (context.worldMap->Bounds().Contains(pos2i)) { bool trigger = false; if (!buildButton[BUTTON_DELETE].Down() && !buildButton[BUTTON_ROTATE].Down()) { Chit* building = context.chitBag->QueryPorch(pos2i); if (!building) { building = context.chitBag->QueryBuilding(IString(), pos2i, 0); } if (building) { if (building->GetItem()->IName() == ISC::detector) { circuitSim->TriggerDetector(pos2i); trigger = true; } else if (building->GetItem()->IName() == ISC::switchOn || building->GetItem()->IName() == ISC::switchOff) { circuitSim->TriggerSwitch(pos2i); trigger = true; } } } int id = -1; if (!trigger) { for (int i = 0; i < NUM_BUTTONS; ++i) { if (buildButton[i].Down()) { id = i; break; } } } if (id >= 0) { Chit* chit = 0; switch (id) { case BUTTON_ROCK0: case BUTTON_ROCK1: case BUTTON_ROCK2: case BUTTON_ROCK3: context.worldMap->SetRock(pos2i.x, pos2i.y, id - BUTTON_ROCK0, false, WorldGrid::ROCK); break; case BUTTON_SWITCH_ON: chit = context.chitBag->NewBuilding(pos2i, "switchOn", TEAM_HOUSE); break; case BUTTON_SWITCH_OFF: chit = context.chitBag->NewBuilding(pos2i, "switchOff", TEAM_HOUSE); break; case BUTTON_TEMPLE: chit = context.chitBag->NewBuilding(pos2i, "temple", TEAM_HOUSE); break; case BUTTON_GATE: chit = context.chitBag->NewBuilding(pos2i, "gate", TEAM_HOUSE); break; case BUTTON_TIMED_GATE: chit = context.chitBag->NewBuilding(pos2i, "timedGate", TEAM_HOUSE); break; case BUTTON_DETECTOR: chit = context.chitBag->NewBuilding(pos2i, "detector", TEAM_HOUSE); break; case BUTTON_TURRET: chit = context.chitBag->NewBuilding(pos2i, "turret", TEAM_HOUSE); break; case BUTTON_DELETE: { Chit* building = context.chitBag->QueryBuilding(IString(), pos2i, 0); if (building) { building->QueueDelete(); } } break; case BUTTON_ROTATE: { Chit* building = context.chitBag->QueryBuilding(IString(), pos2i, 0); if (building) { Matrix4 m; building->Rotation().ToMatrix(&m); float r = m.CalcRotationAroundAxis(1); r = NormalizeAngleDegrees(r + 90.0f); building->SetRotation(Quaternion::MakeYRotation(r)); } } break; } if (chit) { MapSpatialComponent* msc = GET_SUB_COMPONENT(chit, SpatialComponent, MapSpatialComponent); if (msc) msc->SetNeedsCorePower(false); } } } } }