void UVMapView::SelectInverse() { ListIter<Poly> iter = polys; while (++iter) { Poly* p = iter.value(); if (p->material != material) continue; for (int i = 0; i < p->nverts; i++) { WORD p_index = iter.index(); DWORD value = (p_index << 16) | i; bool contains = false; auto svi = selverts.begin(); for (; svi != selverts.end(); ++svi) { if (*svi == value) { contains = true; break; } } if (contains) selverts.erase(svi); else selverts.push_back(value); } } }
bool Screen::Resize(int w, int h) { // scale all root-level windows to new screen size: ListIter<Window> iter = window_list; while (++iter) { Window* win = iter.value(); double w_x = win->GetRect().x / (double) width; double w_y = win->GetRect().y / (double) height; double w_w = win->GetRect().w / (double) width; double w_h = win->GetRect().h / (double) height; Rect r; r.x = (int) (w_x * w); r.y = (int) (w_y * h); r.w = (int) (w_w * w); r.h = (int) (w_h * h); win->MoveTo(r); } width = w; height = h; return true; }
void NetGameClient::ExecFrame() { if (local_player) { if (local_player->GetObjID() == 0) { SendJoinRequest(); } else if (active) { // check health of server: NetPeer* server_peer = link->FindPeer(server_id); if (server_peer && (NetLayer::GetUTC() - server_peer->LastReceiveTime() > 15)) { NetMsg net_disco(0, NET_DISCONNECT, 0, 0, 0); DoDisconnect(&net_disco); } // if server is still there, else if (server_peer) { // check if any old join announcements still need to be processed: ListIter<NetJoinAnnounce> iter = join_backlog; while (++iter) { NetJoinAnnounce* join_ann = iter.value(); if (DoJoinBacklog(join_ann)) { iter.removeItem(); delete join_ann; } } } } } NetGame::ExecFrame(); }
void ModConfig::EnableMod(const char* name) { if (!name || !*name) return; Text* mod_name; ListIter<Text> iter = disabled; while (++iter) { Text* t = iter.value(); if (*t == name) { mod_name = t; iter.removeItem(); break; } } if (mod_name) { enabled.append(mod_name); if (!IsDeployed(*mod_name)) { ModInfo* mod_info = new(__FILE__,__LINE__) ModInfo; if (mod_info->Load(*mod_name) && mod_info->Enable()) { mods.append(mod_info); } } } }
void NetClientConfig::Save() { FILE* f; fopen_s(&f, "client.cfg", "w"); if (f) { fprintf(f, "CLIENT_CONFIG\n\n"); ListIter<NetServerInfo> iter = servers; while (++iter) { NetServerInfo* server = iter.value(); if (server->save) { int port = (int) server->port; fprintf(f, "server: {\n"); fprintf(f, " name: \"%s\",\n", (const char*) server->name); fprintf(f, " addr: \"%s\",\n", (const char*) server->hostname); fprintf(f, " port: %d,\n", port); if (server->password.length()) fprintf(f, " pass: \"%s\",\n", (const char*) server->password); fprintf(f, "}\n\n"); } } fclose(f); } }
System::System(const System& s) : type(s.type), id(s.id), ship(0), subtype(s.subtype), status(s.status), availability(s.availability), safety(s.safety), stability(s.stability), crit_level(s.crit_level), net_avail(-1.0f), mount_rel(s.mount_rel), radius(s.radius), safety_overload(0.0f), hull_factor(s.hull_factor), energy(s.energy), capacity(s.capacity), sink_rate(s.sink_rate), power_level(s.power_level), power_flags(s.power_flags), source_index(s.source_index), power_on(s.power_on), max_value(s.max_value), explosion_type(s.explosion_type), name(s.name), abrv(s.abrv), design(s.design), emcon(s.emcon) { if (design) { // cast-away const ListIter<Component> c = (List<Component>&) s.components; while (++c) { Component* comp = new(__FILE__,__LINE__) Component(*(c.value())); comp->SetSystem(this); components.append(comp); } } emcon_power[0] = s.emcon_power[0]; emcon_power[1] = s.emcon_power[1]; emcon_power[2] = s.emcon_power[2]; }
void WeaponGroup::PowerOn() { ListIter<Weapon> w = weapons; while (++w) w->PowerOn(); }
void WeaponGroup::SetTarget(SimObject* target, System* subtarget) { ListIter<Weapon> w = weapons; while (++w) w->SetTarget(target, subtarget); }
void GroundAI::ExecFrame(double secs) { const int exec_period = 1000; if ((int) Game::GameTime() - exec_time > exec_period) { exec_time = (int) Game::GameTime(); SelectTarget(); } if (ship) { Shield* shield = ship->GetShield(); if (shield) shield->SetPowerLevel(100); ListIter<WeaponGroup> iter = ship->Weapons(); while (++iter) { WeaponGroup* group = (WeaponGroup*) iter.value(); if (group->NumWeapons() > 1 && group->CanTarget(Ship::DROPSHIPS)) group->SetFiringOrders(Weapon::POINT_DEFENSE); else group->SetFiringOrders(Weapon::AUTO); group->SetTarget((Ship*) target, 0); } if (carrier_ai) carrier_ai->ExecFrame(secs); } }
void NetClientDlg::ShowServers() { if (!config || !lst_servers) return; lst_servers->ClearItems(); lst_servers->SetSelectedStyle(ListBox::LIST_ITEM_STYLE_FILLED_BOX); lst_servers->SetLeading(2); int i = 0; ListIter<NetServerInfo> iter = config->GetServerList(); while (++iter) { NetServerInfo* info = iter.value(); lst_servers->AddItemWithData(info->name, (DWORD) i); lst_servers->SetItemText(i, 1, info->type); lst_servers->SetItemText(i, 2, info->password); lst_servers->SetItemText(i, 3, Game::GetText("NetClientDlg.offline")); lst_servers->SetItemText(i, 4, "0"); lst_servers->SetItemText(i, 5, Game::GetText("NetClientDlg.not-avail")); i++; } ping_index = 0; server_index = -1; if (btn_host) btn_host->SetEnabled(false); if (btn_join) btn_join->SetEnabled(false); if (btn_del) btn_del->SetEnabled(false); }
void ModConfig::FindMods() { disabled.destroy(); DataLoader* loader = DataLoader::GetLoader(); if (loader) { loader->UseFileSystem(true); loader->ListFiles("*.dat", disabled, true); loader->UseFileSystem(Starshatter::UseFileSystem()); ListIter<Text> iter = disabled; while (++iter) { Text* name = iter.value(); name->setSensitive(false); if (*name == "shatter.dat" || *name == "beta.dat" || *name == "start.dat" || *name == "irunin.dat" || *name == "vox.dat" || name->contains("uninstall") || enabled.contains(name)) delete iter.removeItem(); } } }
void TacticalAI::FindSupport() { if (!ship_ai->GetThreat()) { ship_ai->SetSupport(0); return; } // pick the biggest friendly contact in the sector: Ship* support = 0; double support_dist = 1e9; ListIter<Contact> contact = ship->ContactList(); while (++contact) { if (contact->GetShip() && contact->GetIFF(ship) == ship->GetIFF()) { Ship* c_ship = contact->GetShip(); if (c_ship != ship && c_ship->Class() >= ship->Class() && !c_ship->InTransition()) { if (!support || c_ship->Class() > support->Class()) support = c_ship; } } } ship_ai->SetSupport(support); }
void CampaignPlanStrategic::PlaceGroup(CombatGroup* g) { if (!g) return; Text rgn = g->GetRegion(); CombatZone* zone = campaign->GetZone(rgn); // if we couldn't find anything suitable, // just pick a zone at random: if (!zone && g->IsMovable()) { int nzones = campaign->GetZones().size(); int n = RandomIndex() % nzones; zone = campaign->GetZones().at(n); Text assigned_rgn; if (!campaign->GetZone(rgn)) { assigned_rgn = *zone->GetRegions().at(0); g->AssignRegion(assigned_rgn); } } if (zone && !zone->HasGroup(g)) zone->AddGroup(g); ListIter<CombatGroup> iter = g->GetComponents(); while (++iter) PlaceGroup(iter.value()); }
void Element::HandleRadioMessage(RadioMessage* msg) { if (!msg) return; static RadioHandler rh; // if this is a message from within the element, // then all ships should report in. Otherwise, // just the leader will acknowledge the message. int full_report = ships.contains(msg->Sender()); int reported = false; ListIter<Ship> s = ships; while (++s) { if (rh.ProcessMessage(msg, s.value())) { if (full_report) { if (s.value() != msg->Sender()) rh.AcknowledgeMessage(msg, s.value()); } else if (!reported) { rh.AcknowledgeMessage(msg, s.value()); reported = true; } } } }
void CampaignPlanStrategic::ScoreTarget(Combatant* c, CombatGroup* g) { if (!g || g->IntelLevel() <= Intel::SECRET) return; if (g->IsTargetable()) { g->SetPlanValue(g->Value() * c->GetTargetStratFactor(g->Type())); c->GetTargetList().append(g); CombatZone* zone = campaign->GetZone(g->GetRegion()); ZoneForce* force = 0; if (zone) force = zone->FindForce(c->GetIFF()); if (force) force->GetTargetList().append(g); } ListIter<CombatGroup> iter = g->GetComponents(); while (++iter) { ScoreTarget(c, iter.value()); } }
void CampaignPlanStrategic::ExecFrame() { if (campaign && campaign->IsActive()) { if (Campaign::Stardate() - exec_time < 300) return; ListIter<CombatZone> zone = campaign->GetZones(); while (++zone) zone->Clear(); ListIter<Combatant> iter = campaign->GetCombatants(); while (++iter) { Combatant* c = iter.value(); CombatGroup* force = c->GetForce(); force->CalcValue(); PlaceGroup(force); ScoreCombatant(c); ScoreNeeds(c); force->ClearUnlockedZones(); AssignZones(c); ResolveZoneMovement(force); } exec_time = Campaign::Stardate(); } }
void CampaignPlanStrategic::ScoreDefend(Combatant* c, CombatGroup* g) { if (!g || g->IsReserve()) return; if (g->IsDefensible()) { g->SetPlanValue(g->Value()); c->GetDefendList().append(g); CombatZone* zone = campaign->GetZone(g->GetRegion()); ZoneForce* force = 0; if (zone) force = zone->FindForce(c->GetIFF()); if (force) force->GetDefendList().append(g); } ListIter<CombatGroup> iter = g->GetComponents(); while (++iter) { ScoreDefend(c, iter.value()); } }
void SimObject::Notify() { if (!notifying) { notifying = true; int nobservers = observers.size(); int nupdate = 0; if (nobservers > 0) { ListIter<SimObserver> iter = observers; while (++iter) { SimObserver* observer = iter.value(); observer->Update(this); nupdate++; } observers.clear(); } if (nobservers != nupdate) { ::Print("WARNING: incomplete notify sim object '%s' - %d of %d notified\n", Name(), nupdate, nobservers); } notifying = false; } else { ::Print("WARNING: double notify on sim object '%s'\n", Name()); } }
void SeekerAI::CheckDecoys(double target_distance) { // if the assigned target has the burner lit, // ignore the decoys: if (orig_target && orig_target->Augmenter()) { SetTarget(orig_target); return; } if (target && target == orig_target && orig_target->GetActiveDecoys().size()) { ListIter<Shot> decoy = orig_target->GetActiveDecoys(); while (++decoy) { double decoy_distance = Point(decoy->Location() - self->Location()).length(); if (decoy_distance < target_distance) { if (rand() < 1600) { SetTarget(decoy.value(), 0); return; } } } } }
void WeaponGroup::DropTarget() { ListIter<Weapon> w = weapons; while (++w) w->SetTarget(0, 0); }
int CombatGroup::CountUnits() const { int n = 0; CombatGroup* g = (CombatGroup*) this; ListIter<CombatUnit> unit = g->units; while (++unit) n += unit->Count() - unit->DeadCount(); CombatGroup* pThis = ((CombatGroup*) this); pThis->live_comp.clear(); ListIter<CombatGroup> iter = g->components; while (++iter) { CombatGroup* comp = iter.value(); if (!comp->IsReserve()) { int unit_count = comp->CountUnits(); if (unit_count > 0) pThis->live_comp.append(comp); n += unit_count; } } return n; }
void Galaxy::ExecFrame() { ListIter<StarSystem> sys = systems; while (++sys) { sys->ExecFrame(); } }
Steer StarshipAI::SeekTarget() { if (navpt) { SimRegion* self_rgn = ship->GetRegion(); SimRegion* nav_rgn = navpt->Region(); QuantumDrive* qdrive = ship->GetQuantumDrive(); if (self_rgn && !nav_rgn) { nav_rgn = self_rgn; navpt->SetRegion(nav_rgn); } bool use_farcaster = self_rgn != nav_rgn && (navpt->Farcast() || !qdrive || !qdrive->IsPowerOn() || qdrive->Status() < System::DEGRADED ); if (use_farcaster) { if (!farcaster) { ListIter<Ship> s = self_rgn->Ships(); while (++s && !farcaster) { if (s->GetFarcaster()) { const Ship* dest = s->GetFarcaster()->GetDest(); if (dest && dest->GetRegion() == nav_rgn) { farcaster = s->GetFarcaster(); } } } } if (farcaster) { if (farcaster->GetShip()->GetRegion() != self_rgn) farcaster = farcaster->GetDest()->GetFarcaster(); obj_w = farcaster->EndPoint(); distance = Point(obj_w - ship->Location()).length(); if (distance < 1000) farcaster = 0; } } else if (self_rgn != nav_rgn) { QuantumDrive* q = ship->GetQuantumDrive(); if (q) { if (q->ActiveState() == QuantumDrive::ACTIVE_READY) { q->SetDestination(navpt->Region(), navpt->Location()); q->Engage(); } } } } return ShipAI::SeekTarget(); }
void MsnWepDlg::OnLoadout(AWEvent* event) { if (!elem) return; ShipDesign* design = (ShipDesign*) elem->GetDesign(); ShipLoad* shipload = 0; if (loadout_list && design) { int index = loadout_list->GetListIndex(); Text loadname = loadout_list->GetItemText(index); ListIter<ShipLoad> sl = (List<ShipLoad>&) design->loadouts; while (++sl) { if (sl->name == loadname) { shipload = sl.value(); } } if (!shipload) return; if (lbl_weight) { char weight[32]; sprintf_s(weight, "%d kg", (int) ((design->mass + shipload->mass) * 1000)); lbl_weight->SetText(weight); } if (elem->Loadouts().size() < 1) { MissionLoad* l = new(__FILE__,__LINE__) MissionLoad(-1, shipload->name); elem->Loadouts().append(l); } else { ListIter<MissionLoad> l = elem->Loadouts(); while (++l) { // if the player chooses a std loadout, // tell the sim loader to use a named // loadout from the ship design: l->SetName(shipload->name); } } int nstations = design->hard_points.size(); int* loadout = shipload->load; for (int i = 0; i < 8; i++) loads[i] = -1; for (int i = 0; i < nstations; i++) loads[i + first_station] = PointIndexToLoad(i, loadout[i]); for (int i = 0; i < 8; i++) { for (int n = 0; n < 8; n++) { btn_load[i][n]->SetPicture(i == loads[n] ? led_on: led_off); } } } }
void CombatGroup::ClearAssignments() { assignments.destroy(); ListIter<CombatGroup> comp = components; while (++comp) comp->ClearAssignments(); }
void WeaponGroup::SetSweep(int s) { sweep = s; ListIter<Weapon> w = weapons; while (++w) w->SetSweep(sweep); }
void WeaponGroup::SetControlMode(int m) { control = m; ListIter<Weapon> w = weapons; while (++w) w->SetControlMode(control); }
void WeaponGroup::SetFiringOrders(int o) { orders = o; ListIter<Weapon> w = weapons; while (++w) w->SetFiringOrders(orders); }
void DisplayView::Refresh() { ListIter<DisplayElement> iter = elements; while (++iter) { DisplayElement* elem = iter.value(); // convert relative rect to window rect: Rect elem_rect = elem->rect; if (elem_rect.x == 0 && elem_rect.y == 0 && elem_rect.w == 0 && elem_rect.h == 0) { // stretch to fit elem_rect.w = width; elem_rect.h = height; } else if (elem_rect.w < 0 && elem_rect.h < 0) { // center image in window elem_rect.w *= -1; elem_rect.h *= -1; elem_rect.x = (width - elem_rect.w)/2; elem_rect.y = (height - elem_rect.h)/2; } else { // offset from right or bottom if (elem_rect.x < 0) elem_rect.x += width; if (elem_rect.y < 0) elem_rect.y += height; } // compute current fade, // assumes fades are 1 second or less: double fade = 0; if (elem->fade_in > 0) fade = 1 - elem->fade_in; else if (elem->hold > 0) fade = 1; else if (elem->fade_out > 0) fade = elem->fade_out; // draw text: if (elem->text.length() && elem->font) { elem->font->SetColor(elem->color); elem->font->SetAlpha(fade); window->SetFont(elem->font); window->DrawText(elem->text, elem->text.length(), elem_rect, DT_WORDBREAK); } // draw image: else if (elem->image) { window->FadeBitmap( elem_rect.x, elem_rect.y, elem_rect.x + elem_rect.w, elem_rect.y + elem_rect.h, elem->image, elem->color * fade, elem->blend ); } } }
void System::ExecFrame(double seconds) { if (seconds < 0.01) seconds = 0.01; STATUS s = DESTROYED; if (availability > 0.99) s = NOMINAL; else if (availability > crit_level) s = DEGRADED; else s = CRITICAL; bool repair = false; if (components.size() > 0) { ListIter<Component> comp = components; while (++comp) { if (comp->Status() > Component::NOMINAL) { repair = true; break; } } } if (repair) { Repair(); } else { if (status != s) { status = s; NetUtil::SendSysStatus(ship, this); } // collateral damage due to unsafe operation: if (power_on && power_level > safety) { safety_overload += (float) seconds; // inflict some damage now: if (safety_overload > 60) { safety_overload -= (float) (rand() / (1000 * (power_level-safety))); ApplyDamage(15); NetUtil::SendSysStatus(ship, this); } } else if (safety_overload > 0) { safety_overload -= (float) seconds; } } }