From 69209c38968c6f4066a772e0a51a2928749217de Mon Sep 17 00:00:00 2001 From: "FWoltermann@gmail.com" Date: Fri, 9 Dec 2011 19:00:23 +0000 Subject: Re-indenting the code to use standard tabs. Yes, I know this is pretty pointless, but who cares? --- Stars45/NetUtil.cpp | 476 ++++++++++++++++++++++++++-------------------------- 1 file changed, 238 insertions(+), 238 deletions(-) (limited to 'Stars45/NetUtil.cpp') diff --git a/Stars45/NetUtil.cpp b/Stars45/NetUtil.cpp index d0360f7..1a0142b 100644 --- a/Stars45/NetUtil.cpp +++ b/Stars45/NetUtil.cpp @@ -1,15 +1,15 @@ /* Project Starshatter 4.5 - Destroyer Studios LLC - Copyright © 1997-2004. All Rights Reserved. + Destroyer Studios LLC + Copyright © 1997-2004. All Rights Reserved. - SUBSYSTEM: Stars.exe - FILE: NetUtil.cpp - AUTHOR: John DiCamillo + SUBSYSTEM: Stars.exe + FILE: NetUtil.cpp + AUTHOR: John DiCamillo - OVERVIEW - ======== - Utility class to simplify sending NetData messages. + OVERVIEW + ======== + Utility class to simplify sending NetData messages. */ @@ -32,19 +32,19 @@ void NetUtil::SendObjDamage(SimObject* obj, double dmg, Shot* shot) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !obj) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !obj) return; - if (net_game->IsServer() && obj->GetObjID()) { - NetObjDamage damage; - damage.SetObjID(obj->GetObjID()); - damage.SetDamage((float) dmg); + if (net_game->IsServer() && obj->GetObjID()) { + NetObjDamage damage; + damage.SetObjID(obj->GetObjID()); + damage.SetDamage((float) dmg); - if (shot) - damage.SetShotID(shot->GetObjID()); + if (shot) + damage.SetShotID(shot->GetObjID()); - net_game->SendData(&damage); - } + net_game->SendData(&damage); + } } // +-------------------------------------------------------------------+ @@ -52,17 +52,17 @@ NetUtil::SendObjDamage(SimObject* obj, double dmg, Shot* shot) void NetUtil::SendSysDamage(Ship* obj, System* sys, double dmg) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !obj || !sys) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !obj || !sys) return; - if (net_game->IsServer() && obj->GetObjID()) { - NetSysDamage damage; - damage.SetObjID(obj->GetObjID()); - damage.SetDamage(dmg); - damage.SetSystem(sys->GetID()); + if (net_game->IsServer() && obj->GetObjID()) { + NetSysDamage damage; + damage.SetObjID(obj->GetObjID()); + damage.SetDamage(dmg); + damage.SetSystem(sys->GetID()); - net_game->SendData(&damage); - } + net_game->SendData(&damage); + } } // +-------------------------------------------------------------------+ @@ -70,20 +70,20 @@ NetUtil::SendSysDamage(Ship* obj, System* sys, double dmg) void NetUtil::SendSysStatus(Ship* obj, System* sys) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !obj || !sys) return; - - if (obj->GetObjID()) { - NetSysStatus status; - status.SetObjID(obj->GetObjID()); - status.SetSystem( (int) sys->GetID()); - status.SetStatus( (int) sys->Status()); - status.SetPower( (int) sys->GetPowerLevel()); - status.SetReactor((int) sys->GetSourceIndex()); - status.SetAvailablility(sys->Availability()); - - net_game->SendData(&status); - } + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !obj || !sys) return; + + if (obj->GetObjID()) { + NetSysStatus status; + status.SetObjID(obj->GetObjID()); + status.SetSystem( (int) sys->GetID()); + status.SetStatus( (int) sys->Status()); + status.SetPower( (int) sys->GetPowerLevel()); + status.SetReactor((int) sys->GetSourceIndex()); + status.SetAvailablility(sys->Availability()); + + net_game->SendData(&status); + } } // +-------------------------------------------------------------------+ @@ -91,59 +91,59 @@ NetUtil::SendSysStatus(Ship* obj, System* sys) void NetUtil::SendObjKill(Ship* obj, const Ship* killer, int type, int deck) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !obj) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !obj) return; - if (type == NetObjKill::KILL_DOCK || (net_game->IsServer() && obj->GetObjID())) { - NetObjKill kill; - kill.SetObjID(obj->GetObjID()); - kill.SetFlightDeck(deck); + if (type == NetObjKill::KILL_DOCK || (net_game->IsServer() && obj->GetObjID())) { + NetObjKill kill; + kill.SetObjID(obj->GetObjID()); + kill.SetFlightDeck(deck); - if (killer) - kill.SetKillerID(killer->GetObjID()); + if (killer) + kill.SetKillerID(killer->GetObjID()); - kill.SetKillType(type); + kill.SetKillType(type); - if (type != NetObjKill::KILL_DOCK && obj->RespawnCount() > 0) { - Print("NetObjKill preparing respawn for %s\n", obj->Name()); + if (type != NetObjKill::KILL_DOCK && obj->RespawnCount() > 0) { + Print("NetObjKill preparing respawn for %s\n", obj->Name()); - Point respawn_loc = RandomPoint() * 1.75; - kill.SetRespawn(true); - kill.SetRespawnLoc(respawn_loc); - obj->SetRespawnLoc(respawn_loc); - } - else { - Print("NetObjKill no respawn for %s\n", obj->Name()); - } + Point respawn_loc = RandomPoint() * 1.75; + kill.SetRespawn(true); + kill.SetRespawnLoc(respawn_loc); + obj->SetRespawnLoc(respawn_loc); + } + else { + Print("NetObjKill no respawn for %s\n", obj->Name()); + } - net_game->SendData(&kill); - } + net_game->SendData(&kill); + } } // +-------------------------------------------------------------------+ void NetUtil::SendObjHyper(Ship* obj, const char* rgn, const Point& loc, - const Ship* fc1, const Ship* fc2, int transtype) +const Ship* fc1, const Ship* fc2, int transtype) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !obj) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !obj) return; - if (obj->GetObjID()) { - NetObjHyper obj_hyper; - obj_hyper.SetObjID(obj->GetObjID()); - obj_hyper.SetRegion(rgn); - obj_hyper.SetLocation(loc); - obj_hyper.SetTransitionType(transtype); + if (obj->GetObjID()) { + NetObjHyper obj_hyper; + obj_hyper.SetObjID(obj->GetObjID()); + obj_hyper.SetRegion(rgn); + obj_hyper.SetLocation(loc); + obj_hyper.SetTransitionType(transtype); - if (fc1) - obj_hyper.SetFarcaster1(fc1->GetObjID()); + if (fc1) + obj_hyper.SetFarcaster1(fc1->GetObjID()); - if (fc2) - obj_hyper.SetFarcaster2(fc2->GetObjID()); + if (fc2) + obj_hyper.SetFarcaster2(fc2->GetObjID()); - net_game->SendData(&obj_hyper); - } + net_game->SendData(&obj_hyper); + } } // +-------------------------------------------------------------------+ @@ -151,27 +151,27 @@ NetUtil::SendObjHyper(Ship* obj, const char* rgn, const Point& loc, void NetUtil::SendObjTarget(Ship* obj) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !obj) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !obj) return; - if (obj->GetObjID()) { - NetObjTarget obj_target; - obj_target.SetObjID(obj->GetObjID()); + if (obj->GetObjID()) { + NetObjTarget obj_target; + obj_target.SetObjID(obj->GetObjID()); - SimObject* target = obj->GetTarget(); - if (target) { - obj_target.SetTgtID(target->GetObjID()); + SimObject* target = obj->GetTarget(); + if (target) { + obj_target.SetTgtID(target->GetObjID()); - System* subtarget = obj->GetSubTarget(); + System* subtarget = obj->GetSubTarget(); - if (subtarget) { - Ship* s = (Ship*) target; - obj_target.SetSubtarget(subtarget->GetID()); - } - } + if (subtarget) { + Ship* s = (Ship*) target; + obj_target.SetSubtarget(subtarget->GetID()); + } + } - net_game->SendData(&obj_target); - } + net_game->SendData(&obj_target); + } } // +-------------------------------------------------------------------+ @@ -179,15 +179,15 @@ NetUtil::SendObjTarget(Ship* obj) void NetUtil::SendObjEmcon(Ship* obj) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !obj) return; - - if (obj->GetObjID()) { - NetObjEmcon obj_emcon; - obj_emcon.SetObjID(obj->GetObjID()); - obj_emcon.SetEMCON(obj->GetEMCON()); - net_game->SendData(&obj_emcon); - } + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !obj) return; + + if (obj->GetObjID()) { + NetObjEmcon obj_emcon; + obj_emcon.SetObjID(obj->GetObjID()); + obj_emcon.SetEMCON(obj->GetEMCON()); + net_game->SendData(&obj_emcon); + } } // +-------------------------------------------------------------------+ @@ -195,32 +195,32 @@ NetUtil::SendObjEmcon(Ship* obj) void NetUtil::SendWepTrigger(Weapon* wep, int count) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !wep) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !wep) return; - if (wep->IsPrimary() || net_game->IsClient()) { - NetWepTrigger trigger; - trigger.SetObjID(wep->Owner()->GetObjID()); + if (wep->IsPrimary() || net_game->IsClient()) { + NetWepTrigger trigger; + trigger.SetObjID(wep->Owner()->GetObjID()); - SimObject* target = wep->GetTarget(); - if (target) { - trigger.SetTgtID(target->GetObjID()); + SimObject* target = wep->GetTarget(); + if (target) { + trigger.SetTgtID(target->GetObjID()); - System* subtarget = wep->GetSubTarget(); + System* subtarget = wep->GetSubTarget(); - if (subtarget) { - Ship* s = (Ship*) target; - trigger.SetSubtarget(subtarget->GetID()); - } - } + if (subtarget) { + Ship* s = (Ship*) target; + trigger.SetSubtarget(subtarget->GetID()); + } + } - trigger.SetIndex(wep->GetIndex()); - trigger.SetCount(count); - trigger.SetDecoy(wep->IsDecoy()); - trigger.SetProbe(wep->IsProbe()); + trigger.SetIndex(wep->GetIndex()); + trigger.SetCount(count); + trigger.SetDecoy(wep->IsDecoy()); + trigger.SetProbe(wep->IsProbe()); - net_game->SendData(&trigger); - } + net_game->SendData(&trigger); + } } // +-------------------------------------------------------------------+ @@ -228,33 +228,33 @@ NetUtil::SendWepTrigger(Weapon* wep, int count) void NetUtil::SendWepRelease(Weapon* wep, Shot* shot) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !wep || !shot) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !wep || !shot) return; - if (net_game->IsServer() && wep->IsMissile()) { - DWORD wepid = NetGame::GetNextObjID(NetGame::SHOT); - shot->SetObjID(wepid); + if (net_game->IsServer() && wep->IsMissile()) { + DWORD wepid = NetGame::GetNextObjID(NetGame::SHOT); + shot->SetObjID(wepid); - NetWepRelease release; - release.SetObjID(wep->Owner()->GetObjID()); + NetWepRelease release; + release.SetObjID(wep->Owner()->GetObjID()); - SimObject* target = wep->GetTarget(); - if (target) - release.SetTgtID(target->GetObjID()); + SimObject* target = wep->GetTarget(); + if (target) + release.SetTgtID(target->GetObjID()); - System* subtarget = wep->GetSubTarget(); - if (target && subtarget && target->Type() == SimObject::SIM_SHIP) { - Ship* tgt = (Ship*) target; - release.SetSubtarget(subtarget->GetID()); - } + System* subtarget = wep->GetSubTarget(); + if (target && subtarget && target->Type() == SimObject::SIM_SHIP) { + Ship* tgt = (Ship*) target; + release.SetSubtarget(subtarget->GetID()); + } - release.SetWepID(wepid); - release.SetIndex(wep->GetIndex()); - release.SetDecoy(shot->IsDecoy()); - release.SetProbe(shot->IsProbe()); + release.SetWepID(wepid); + release.SetIndex(wep->GetIndex()); + release.SetDecoy(shot->IsDecoy()); + release.SetProbe(shot->IsProbe()); - net_game->SendData(&release); - } + net_game->SendData(&release); + } } // +-------------------------------------------------------------------+ @@ -262,16 +262,16 @@ NetUtil::SendWepRelease(Weapon* wep, Shot* shot) void NetUtil::SendWepDestroy(Shot* shot) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !shot) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !shot) return; - if (net_game->IsServer() && shot->GetObjID()) { - NetWepDestroy destroy; + if (net_game->IsServer() && shot->GetObjID()) { + NetWepDestroy destroy; - destroy.SetObjID(shot->GetObjID()); + destroy.SetObjID(shot->GetObjID()); - net_game->SendData(&destroy); - } + net_game->SendData(&destroy); + } } // +-------------------------------------------------------------------+ @@ -279,22 +279,22 @@ NetUtil::SendWepDestroy(Shot* shot) void NetUtil::SendChat(DWORD dst, const char* name, const char* text) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !name || !*name || !text || !*text) return; - - NetChatMsg chat_msg; - chat_msg.SetDstID(dst); - chat_msg.SetName(name); - chat_msg.SetText(text); - - if (net_game->IsClient()) { - net_game->SendData(&chat_msg); - } - - else { - NetGameServer* net_game_server = (NetGameServer*) net_game; - net_game_server->RouteChatMsg(chat_msg); - } + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !name || !*name || !text || !*text) return; + + NetChatMsg chat_msg; + chat_msg.SetDstID(dst); + chat_msg.SetName(name); + chat_msg.SetText(text); + + if (net_game->IsClient()) { + net_game->SendData(&chat_msg); + } + + else { + NetGameServer* net_game_server = (NetGameServer*) net_game; + net_game_server->RouteChatMsg(chat_msg); + } } // +-------------------------------------------------------------------+ @@ -302,14 +302,14 @@ NetUtil::SendChat(DWORD dst, const char* name, const char* text) void NetUtil::SendElemRequest(const char* name) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !name) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !name) return; - NetElemRequest elem_request; - elem_request.SetName(name); + NetElemRequest elem_request; + elem_request.SetName(name); - ::Print("NetUtil::SendElemRequest name: '%s'\n", name); - net_game->SendData(&elem_request); + ::Print("NetUtil::SendElemRequest name: '%s'\n", name); + net_game->SendData(&elem_request); } // +-------------------------------------------------------------------+ @@ -317,37 +317,37 @@ NetUtil::SendElemRequest(const char* name) void NetUtil::SendElemCreate(Element* elem, int squadron, int* slots, bool alert, bool in_flight) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !elem) return; - - NetElemCreate elem_create; - elem_create.SetName(elem->Name()); - elem_create.SetType(elem->Type()); - elem_create.SetIFF(elem->GetIFF()); - elem_create.SetIntel(elem->IntelLevel()); - elem_create.SetLoadout(elem->Loadout()); - elem_create.SetSquadron(squadron); - elem_create.SetSlots(slots); - elem_create.SetAlert(alert); - elem_create.SetInFlight(in_flight); - - if (elem->NumObjectives() > 0) { - Instruction* obj = elem->GetObjective(0); - - if (obj) { - elem_create.SetObjCode(obj->Action()); - elem_create.SetObjective(obj->TargetName()); - } - } - - if (elem->GetCarrier()) - elem_create.SetCarrier(elem->GetCarrier()->Name()); - - if (elem->GetCommander()) - elem_create.SetCommander(elem->GetCommander()->Name()); - - ::Print("NetUtil::SendElemCreate iff: %d name: '%s'\n", elem->GetIFF(), elem->Name().data()); - net_game->SendData(&elem_create); + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !elem) return; + + NetElemCreate elem_create; + elem_create.SetName(elem->Name()); + elem_create.SetType(elem->Type()); + elem_create.SetIFF(elem->GetIFF()); + elem_create.SetIntel(elem->IntelLevel()); + elem_create.SetLoadout(elem->Loadout()); + elem_create.SetSquadron(squadron); + elem_create.SetSlots(slots); + elem_create.SetAlert(alert); + elem_create.SetInFlight(in_flight); + + if (elem->NumObjectives() > 0) { + Instruction* obj = elem->GetObjective(0); + + if (obj) { + elem_create.SetObjCode(obj->Action()); + elem_create.SetObjective(obj->TargetName()); + } + } + + if (elem->GetCarrier()) + elem_create.SetCarrier(elem->GetCarrier()->Name()); + + if (elem->GetCommander()) + elem_create.SetCommander(elem->GetCommander()->Name()); + + ::Print("NetUtil::SendElemCreate iff: %d name: '%s'\n", elem->GetIFF(), elem->Name().data()); + net_game->SendData(&elem_create); } // +-------------------------------------------------------------------+ @@ -355,18 +355,18 @@ NetUtil::SendElemCreate(Element* elem, int squadron, int* slots, bool alert, boo void NetUtil::SendShipLaunch(Ship* carrier, int squadron, int slot) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !carrier) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !carrier) return; - if (carrier->GetObjID()) { - NetShipLaunch ship_launch; + if (carrier->GetObjID()) { + NetShipLaunch ship_launch; - ship_launch.SetObjID(carrier->GetObjID()); - ship_launch.SetSquadron(squadron); - ship_launch.SetSlot(slot); + ship_launch.SetObjID(carrier->GetObjID()); + ship_launch.SetSquadron(squadron); + ship_launch.SetSlot(slot); - net_game->SendData(&ship_launch); - } + net_game->SendData(&ship_launch); + } } // +-------------------------------------------------------------------+ @@ -374,20 +374,20 @@ NetUtil::SendShipLaunch(Ship* carrier, int squadron, int slot) void NetUtil::SendNavData(bool add, Element* elem, int index, Instruction* navpt) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !elem || !navpt) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !elem || !navpt) return; - // resolve rloc before copying the navpoint into the net nav data structure: - Point loc = navpt->Location(); + // resolve rloc before copying the navpoint into the net nav data structure: + Point loc = navpt->Location(); - NetNavData nav_data; - nav_data.SetObjID(net_game->GetObjID()); - nav_data.SetAdd(add); - nav_data.SetElem(elem->Name()); - nav_data.SetIndex(index); - nav_data.SetNavPoint(navpt); + NetNavData nav_data; + nav_data.SetObjID(net_game->GetObjID()); + nav_data.SetAdd(add); + nav_data.SetElem(elem->Name()); + nav_data.SetIndex(index); + nav_data.SetNavPoint(navpt); - net_game->SendData(&nav_data); + net_game->SendData(&nav_data); } // +-------------------------------------------------------------------+ @@ -395,15 +395,15 @@ NetUtil::SendNavData(bool add, Element* elem, int index, Instruction* navpt) void NetUtil::SendNavDelete(Element* elem, int index) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !elem) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !elem) return; - NetNavDelete nav_delete; - nav_delete.SetObjID(net_game->GetObjID()); - nav_delete.SetElem(elem->Name()); - nav_delete.SetIndex(index); + NetNavDelete nav_delete; + nav_delete.SetObjID(net_game->GetObjID()); + nav_delete.SetElem(elem->Name()); + nav_delete.SetIndex(index); - net_game->SendData(&nav_delete); + net_game->SendData(&nav_delete); } // +-------------------------------------------------------------------+ @@ -411,14 +411,14 @@ NetUtil::SendNavDelete(Element* elem, int index) void NetUtil::SendSelfDestruct(Ship* obj, double dmg) { - NetGame* net_game = NetGame::GetInstance(); - if (!net_game || !obj) return; + NetGame* net_game = NetGame::GetInstance(); + if (!net_game || !obj) return; - if (obj->GetObjID()) { - NetSelfDestruct sd; - sd.SetObjID(obj->GetObjID()); - sd.SetDamage((float) dmg); + if (obj->GetObjID()) { + NetSelfDestruct sd; + sd.SetObjID(obj->GetObjID()); + sd.SetDamage((float) dmg); - net_game->SendData(&sd); - } + net_game->SendData(&sd); + } } -- cgit v1.1