| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** Confidential - Westwood Studios ***
- ***********************************************************************************************
- * *
- * Project Name : Commando *
- * *
- * $Archive:: /Commando/Code/Combat/csdamageevent.cpp $*
- * *
- * $Author:: Tom_s $*
- * *
- * $Modtime:: 11/24/01 10:36a $*
- * *
- * $Revision:: 6 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "csdamageevent.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include "networkobjectfactory.h"
- #include "combat.h"
- #include "networkobjectmgr.h"
- #include "gameobjmanager.h"
- #include "apppackettypes.h"
- #include "damage.h"
- #include "armedgameobj.h"
- #include "debug.h"
- DECLARE_NETWORKOBJECT_FACTORY(cCsDamageEvent, NETCLASSID_CSDAMAGEEVENT);
- //
- // Class statics
- //
- bool cCsDamageEvent::AreClientsTrusted = true;
- //-----------------------------------------------------------------------------
- cCsDamageEvent::cCsDamageEvent(void)
- {
- SenderId = 0;
- DamagerGOID = 0;
- DamageeGOID = 0;
- Damage = 0;
- Warhead = 0;
- Set_App_Packet_Type(APPPACKETTYPE_CSDAMAGEEVENT);
- Set_Unreliable_Override(true);
- }
- //-----------------------------------------------------------------------------
- void
- cCsDamageEvent::Init
- (
- int damager_go_id,
- int damagee_go_id,
- float damage,
- int warhead
- )
- {
- WWASSERT(CombatManager::I_Am_Only_Client());
- WWASSERT(AreClientsTrusted);
- SenderId = CombatManager::Get_My_Id();
- DamagerGOID = damager_go_id;
- DamageeGOID = damagee_go_id;
- Damage = damage;
- Warhead = warhead;
- Set_Network_ID(NetworkObjectMgrClass::Get_New_Client_ID());
- Set_Object_Dirty_Bit(0, BIT_CREATION, true);
- }
- //-----------------------------------------------------------------------------
- void
- cCsDamageEvent::Act
- (
- void
- )
- {
- WWASSERT(CombatManager::I_Am_Server());
- if (AreClientsTrusted)
- {
- // process the member data here. Include sanity checks.
- // Find the gameobj with the damagee id
- PhysicalGameObj * obj = GameObjManager::Find_PhysicalGameObj( DamageeGOID );
- if ( obj ) {
- // Make an offense object
- PhysicalGameObj * damager = GameObjManager::Find_PhysicalGameObj( DamagerGOID );
- if ( damager != NULL && damager->As_ArmedGameObj() != NULL ) {
- OffenseObjectClass offense( Damage, Warhead, damager->As_ArmedGameObj());
- // obj->Get_Defense_Object()->Do_Damage( offense );
- // We need to use apply damage extended in order to allow things to die.
- offense.ForceServerDamage = true;
- #if 0
- // guess at the damage direction
- Vector3 direction;
- Vector3 pos;
- damager->Get_Position( &pos );
- obj->Get_Position( &direction );
- direction -= pos;
- direction.Normalize();
- obj->Apply_Damage_Extended( offense, 1.0f, direction );
- #else
- obj->Apply_Damage_Extended( offense );
- #endif
- // Debug_Say(( "Applying Client damage of %f from %d to %d\n", Damage, DamagerGOID, DamageeGOID ));
- } else {
- // Debug_Say(( "Error: Client damage Damagee %d not found\n", DamageeGOID ));
- }
- } else {
- // Debug_Say(( "Error: Client damage Damagee %d not found\n", DamageeGOID ));
- }
- } else {
- Debug_Say(( "Error: Receiving Client damage when clients are not trusted\n" ));
- }
- Set_Delete_Pending();
- }
- //-----------------------------------------------------------------------------
- void
- cCsDamageEvent::Export_Creation
- (
- BitStreamClass & packet
- )
- {
- WWASSERT(CombatManager::I_Am_Only_Client());
- NetworkObjectClass::Export_Creation(packet);
- WWASSERT(SenderId > 0);
- packet.Add(SenderId);
- packet.Add(DamagerGOID);
- packet.Add(DamageeGOID);
- packet.Add(Damage);
- packet.Add(Warhead);
- Set_Delete_Pending();
- }
- //-----------------------------------------------------------------------------
- void
- cCsDamageEvent::Import_Creation
- (
- BitStreamClass & packet
- )
- {
- WWASSERT(CombatManager::I_Am_Server());
- NetworkObjectClass::Import_Creation(packet);
- packet.Get(SenderId);
- packet.Get(DamagerGOID);
- packet.Get(DamageeGOID);
- packet.Get(Damage);
- packet.Get(Warhead);
- WWASSERT(SenderId > 0);
- Act();
- }
|