void NetGameClient::DoJoinAnnounce(NetMsg* msg) { if (!msg) return; Sim* sim = Sim::GetSim(); if (!sim) return; NetJoinAnnounce* join_ann = new(__FILE__,__LINE__) NetJoinAnnounce; bool saved = false; if (join_ann->Unpack(msg->Data())) { DWORD nid = msg->NetID(); DWORD oid = join_ann->GetObjID(); Text name = join_ann->GetName(); Text elem_name = join_ann->GetElement(); Text region = join_ann->GetRegion(); Point loc = join_ann->GetLocation(); Point velocity = join_ann->GetVelocity(); int index = join_ann->GetIndex(); int shld_lvl = join_ann->GetShield(); join_ann->SetNetID(nid); Ship* ship = 0; char ship_name[128]; strcpy_s(ship_name, Game::GetText("NetGameClient.no-ship").data()); if (local_player && player_name == name) { HUDView::Message(Game::GetText("NetGameClient.local-accept"), name.data(), local_player->Name()); objid = oid; netid = nid; local_player->SetObjID(oid); local_player->SetNetObserver(false); Observe(local_player); SimRegion* rgn = local_player->GetRegion(); if (rgn && region != rgn->Name()) { SimRegion* dst = sim->FindRegion(region); if (dst) dst->InsertObject(local_player); } local_player->MoveTo(loc); local_player->SetVelocity(velocity); Shield* shield = local_player->GetShield(); if (shield) shield->SetNetShieldLevel(shld_lvl); } else { NetPlayer* remote_player = FindPlayerByObjID(oid); if (remote_player) { remote_player->SetName(name); remote_player->SetObjID(oid); if (index > 0) sprintf_s(ship_name, "%s %d", elem_name.data(), index); else sprintf_s(ship_name, "%s", elem_name.data()); } else { Element* element = sim->FindElement(elem_name); if (element) { ship = element->GetShip(index); } else { Print("NetGameClient::DoJoinAnnounce() could not find elem %s for player '%s' objid %d\n", elem_name.data(), name.data(), oid); NetUtil::SendElemRequest(elem_name.data()); } if (!ship) { // save it for later: join_backlog.append(join_ann); saved = true; } else { strcpy_s(ship_name, ship->Name()); SimRegion* rgn = ship->GetRegion(); if (rgn && region != rgn->Name()) { SimRegion* dst = sim->FindRegion(region); if (dst) dst->InsertObject(ship); } ship->MoveTo(loc); ship->SetVelocity(velocity); Shield* shield = ship->GetShield(); if (shield) shield->SetNetShieldLevel(shld_lvl); NetPlayer* remote_player = new(__FILE__,__LINE__) NetPlayer(nid); remote_player->SetName(name); remote_player->SetObjID(oid); remote_player->SetShip(ship); players.append(remote_player); if (name == "Server A.I. Ship") { Print("Remote Player '%s' has joined as '%s' with ID %d\n", name.data(), ship_name, oid); } else { HUDView::Message(Game::GetText("NetGameClient.remote-join").data(), name.data(), ship_name); } } } } } if (!saved) delete join_ann; }
bool NetGameClient::DoJoinBacklog(NetJoinAnnounce* join_ann) { bool finished = false; if (!join_ann) return finished; Sim* sim = Sim::GetSim(); if (!sim) return finished; DWORD nid = join_ann->GetNetID(); DWORD oid = join_ann->GetObjID(); Text name = join_ann->GetName(); Text elem_name = join_ann->GetElement(); Text region = join_ann->GetRegion(); Point loc = join_ann->GetLocation(); Point velocity = join_ann->GetVelocity(); int index = join_ann->GetIndex(); int shld_lvl = join_ann->GetShield(); Ship* ship = 0; char ship_name[128]; strcpy_s(ship_name, Game::GetText("NetGameClient.no-ship").data()); if (nid && oid) { NetPlayer* remote_player = FindPlayerByObjID(oid); if (remote_player) { remote_player->SetName(name); remote_player->SetObjID(oid); if (index > 0) sprintf_s(ship_name, "%s %d", elem_name.data(), index); else sprintf_s(ship_name, "%s", elem_name.data()); } else { Element* element = sim->FindElement(elem_name); if (element) { ship = element->GetShip(index); } if (ship) { strcpy_s(ship_name, ship->Name()); SimRegion* rgn = ship->GetRegion(); if (rgn && region != rgn->Name()) { SimRegion* dst = sim->FindRegion(region); if (dst) dst->InsertObject(ship); } ship->MoveTo(loc); ship->SetVelocity(velocity); Shield* shield = ship->GetShield(); if (shield) shield->SetNetShieldLevel(shld_lvl); NetPlayer* remote_player = new(__FILE__,__LINE__) NetPlayer(nid); remote_player->SetName(name); remote_player->SetObjID(oid); remote_player->SetShip(ship); players.append(remote_player); finished = true; if (name == "Server A.I. Ship") { Print("NetGameClient::DoJoinBacklog() Remote Player '%s' has joined as '%s' with ID %d\n", name.data(), ship_name, oid); } else { HUDView::Message(Game::GetText("NetGameClient.remote-join").data(), name.data(), ship_name); } } } } return finished; }
void FltDlg::OnPackage(AWEvent* event) { if (!filter_list || !hangar_list || !ship) return; int code = Mission::PATROL; switch (mission_type) { case 0: code = Mission::PATROL; break; case 1: code = Mission::INTERCEPT; break; case 2: code = Mission::ASSAULT; break; case 3: code = Mission::STRIKE; break; case 4: code = Mission::ESCORT; break; case 5: code = Mission::INTEL; break; } int squad = filter_list->GetSelectedIndex(); Hangar* hangar = ship->GetHangar(); Sim* sim = Sim::GetSim(); const char* call = sim->FindAvailCallsign(ship->GetIFF()); Element* elem = sim->CreateElement(call, ship->GetIFF(), code); Element* tgt = 0; FlightDeck* deck = 0; int queue = 1000; int* load = 0; elem->SetSquadron(hangar->SquadronName(squad)); elem->SetCarrier(ship); if (objective_list) { int index = objective_list->GetListIndex(); Text target = objective_list->GetItemText(index); Instruction* objective = new(__FILE__,__LINE__) Instruction(code, target.data()); elem->AddObjective(objective); tgt = sim->FindElement(target.data()); } if (loadout_list && design) { int index = loadout_list->GetListIndex(); Text loadname = loadout_list->GetItemText(index); ListIter<ShipLoad> sl = (List<ShipLoad>&) design->loadouts; while (++sl && !load) { if (sl->name == loadname) { load = sl->load; elem->SetLoadout(load); } } } for (int i = 0; i < ship->NumFlightDecks(); i++) { FlightDeck* d = ship->GetFlightDeck(i); if (d && d->IsLaunchDeck()) { int dq = hangar->PreflightQueue(d); if (dq < queue) { queue = dq; deck = d; } } } int npackage = 0; int slots[6]; for (int i = 0; i < 6; i++) slots[i] = -1; for (int i = 0; i < hangar_list->NumItems(); i++) { if (hangar_list->IsSelected(i)) { int nslot = hangar_list->GetItemData(i); hangar->GotoAlert(squad, nslot, deck, elem, load, true); slots[npackage] = nslot; hangar_list->SetSelected(i, false); npackage++; if (npackage >= 6) break; } } NetUtil::SendElemCreate(elem, squad, slots, false); if (flight_planner) { switch (mission_type) { case 0: default: flight_planner->CreatePatrolRoute(elem, patrol_pattern++); break; case 1: case 2: case 3: if (tgt) flight_planner->CreateStrikeRoute(elem, tgt); else flight_planner->CreatePatrolRoute(elem, patrol_pattern++); break; case 4: if (tgt) flight_planner->CreateEscortRoute(elem, tgt); else flight_planner->CreatePatrolRoute(elem, patrol_pattern++); break; } if (patrol_pattern < 0 || patrol_pattern > 3) patrol_pattern = 0; } }