Formatted document

This commit is contained in:
smallmodel 2023-11-26 19:54:07 +01:00
parent ba1703ebf0
commit 111088b540
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
2 changed files with 112 additions and 121 deletions

View file

@ -29,162 +29,151 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Event EV_Window_Setup
(
"_Windowsetup",
EV_CODEONLY,
NULL,
NULL,
"Does the post spawn setup of the Window"
"_Windowsetup",
EV_CODEONLY,
NULL,
NULL,
"Does the post spawn setup of the Window"
);
Event EV_Window_SetDebris
(
"debristype",
EV_DEFAULT,
"i",
"type",
"Sets the debris type of the Window"
"debristype",
EV_DEFAULT,
"i",
"type",
"Sets the debris type of the Window"
);
CLASS_DECLARATION( Entity, WindowObject, "func_window" )
{
{ &EV_Window_Setup, &WindowObject::WindowSetup },
{ &EV_Damage, &WindowObject::WindowDamaged },
{ &EV_Killed, &WindowObject::WindowKilled },
{ &EV_Window_SetDebris, &WindowObject::WindowDebrisType },
{ NULL, NULL }
CLASS_DECLARATION(Entity, WindowObject, "func_window") {
{&EV_Window_Setup, &WindowObject::WindowSetup },
{&EV_Damage, &WindowObject::WindowDamaged },
{&EV_Killed, &WindowObject::WindowKilled },
{&EV_Window_SetDebris, &WindowObject::WindowDebrisType},
{NULL, NULL }
};
WindowObject::WindowObject()
{
m_iDebrisType = WINDOW_GLASS;
m_iDebrisType = WINDOW_GLASS;
PostEvent( EV_Window_Setup, EV_POSTSPAWN );
PostEvent(EV_Window_Setup, EV_POSTSPAWN);
}
void WindowObject::Archive( Archiver& arc )
void WindowObject::Archive(Archiver& arc)
{
arc.ArchiveInteger( &m_iDebrisType );
arc.ArchiveString( &m_sBrokenModel );
arc.ArchiveInteger(&m_iDebrisType);
arc.ArchiveString(&m_sBrokenModel);
}
void WindowObject::WindowSetup( Event *ev )
void WindowObject::WindowSetup(Event *ev)
{
Entity *pEnt;
Entity *pEnt;
setSolidType( SOLID_BSP );
setSolidType(SOLID_BSP);
if( Target().length() )
{
pEnt = ( Entity * )G_FindTarget( NULL, Target() );
if (Target().length()) {
pEnt = (Entity *)G_FindTarget(NULL, Target());
if( pEnt )
{
// set the broken model to the target model
m_sBrokenModel = pEnt->model;
if (pEnt) {
// set the broken model to the target model
m_sBrokenModel = pEnt->model;
pEnt->PostEvent( EV_Remove, 0 );
}
}
pEnt->PostEvent(EV_Remove, 0);
}
}
takedamage = DAMAGE_YES;
takedamage = DAMAGE_YES;
if( health <= 0.1f ) {
health = 100.0f;
}
if (health <= 0.1f) {
health = 100.0f;
}
}
void WindowObject::WindowDebrisType( Event *ev )
void WindowObject::WindowDebrisType(Event *ev)
{
m_iDebrisType = ev->GetInteger( 1 );
m_iDebrisType = ev->GetInteger(1);
}
void WindowObject::WindowDamaged( Event *ev )
void WindowObject::WindowDamaged(Event *ev)
{
int iMeansOfDeath;
int iDamage;
Vector vRight;
Vector vForward;
Vector vDir;
Event *event;
int iMeansOfDeath;
int iDamage;
Vector vRight;
Vector vForward;
Vector vDir;
Event *event;
if( !takedamage ) {
return;
}
if (!takedamage) {
return;
}
iDamage = ev->GetInteger( 2 );
iMeansOfDeath = ev->GetInteger( 9 );
iDamage = ev->GetInteger(2);
iMeansOfDeath = ev->GetInteger(9);
if( iMeansOfDeath == MOD_BASH )
{
// double damage for bash
iDamage *= 2;
}
else if( iMeansOfDeath == MOD_EXPLOSION )
{
// instant break
iDamage = health;
}
if (iMeansOfDeath == MOD_BASH) {
// double damage for bash
iDamage *= 2;
} else if (iMeansOfDeath == MOD_EXPLOSION) {
// instant break
iDamage = health;
}
health -= iDamage;
health -= iDamage;
if( health <= 0.0f )
{
event = new Event( EV_Killed );
if (health <= 0.0f) {
event = new Event(EV_Killed);
event->AddEntity( ev->GetEntity( 1 ) );
event->AddInteger( ev->GetInteger( 2 ) );
event->AddEntity( ev->GetEntity( 3 ) );
event->AddEntity(ev->GetEntity(1));
event->AddInteger(ev->GetInteger(2));
event->AddEntity(ev->GetEntity(3));
ProcessEvent( event );
}
ProcessEvent(event);
}
}
void WindowObject::WindowKilled( Event *ev )
void WindowObject::WindowKilled(Event *ev)
{
Vector vCenter;
Vector vCenter;
setSolidType( SOLID_NOT );
setSolidType(SOLID_NOT);
hideModel();
takedamage = DAMAGE_NO;
hideModel();
takedamage = DAMAGE_NO;
vCenter = origin + mins + maxs;
vCenter = origin + mins + maxs;
gi.SetBroadcastVisible( vCenter, vCenter );
gi.MSG_StartCGM(BG_MapCGMToProtocol(g_protocol, CGM_MAKE_WINDOW_DEBRIS));
gi.MSG_WriteCoord( vCenter[ 0 ] );
gi.MSG_WriteCoord( vCenter[ 1 ] );
gi.MSG_WriteCoord( vCenter[ 2 ] );
gi.MSG_WriteByte( m_iDebrisType );
gi.MSG_EndCGM();
gi.SetBroadcastVisible(vCenter, vCenter);
gi.MSG_StartCGM(BG_MapCGMToProtocol(g_protocol, CGM_MAKE_WINDOW_DEBRIS));
gi.MSG_WriteCoord(vCenter[0]);
gi.MSG_WriteCoord(vCenter[1]);
gi.MSG_WriteCoord(vCenter[2]);
gi.MSG_WriteByte(m_iDebrisType);
gi.MSG_EndCGM();
if( m_sBrokenModel.length() )
{
Entity *ent = new Entity;
if (m_sBrokenModel.length()) {
Entity *ent = new Entity;
ent->takedamage = DAMAGE_NO;
ent->setModel( m_sBrokenModel );
ent->takedamage = DAMAGE_NO;
ent->setModel(m_sBrokenModel);
ent->setMoveType( MOVETYPE_NONE );
ent->setSolidType( SOLID_BSP );
ent->setMoveType(MOVETYPE_NONE);
ent->setSolidType(SOLID_BSP);
setModel( m_sBrokenModel );
setModel(m_sBrokenModel);
if( spawnflags & WINDOW_BROKEN_BLOCK )
{
ent->setContents( CONTENTS_MONSTERCLIP | CONTENTS_PLAYERCLIP );
}
else
{
ent->setContents( CONTENTS_SHOOTONLY );
}
if (spawnflags & WINDOW_BROKEN_BLOCK) {
ent->setContents(CONTENTS_MONSTERCLIP | CONTENTS_PLAYERCLIP);
} else {
ent->setContents(CONTENTS_SHOOTONLY);
}
ent->setOrigin( origin );
ent->showModel();
}
ent->setOrigin(origin);
ent->showModel();
}
deadflag = DEAD_DEAD;
deadflag = DEAD_DEAD;
// remove the window
PostEvent( EV_Remove, 0 );
// remove the window
PostEvent(EV_Remove, 0);
}

View file

@ -23,29 +23,31 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// windows.h: Window class
//
#pragma once
#include "entity.h"
#define WINDOW_BROKEN_BLOCK 1
#define WINDOW_BROKEN_BLOCK 1
enum
{
WINDOW_GLASS
enum {
WINDOW_GLASS
};
class WindowObject : public Entity {
class WindowObject : public Entity
{
private:
int m_iDebrisType;
str m_sBrokenModel;
int m_iDebrisType;
str m_sBrokenModel;
public:
CLASS_PROTOTYPE( WindowObject );
CLASS_PROTOTYPE(WindowObject);
WindowObject();
WindowObject();
void Archive( Archiver& arc ) override;
void Archive(Archiver& arc) override;
void WindowSetup( Event *ev );
void WindowDebrisType( Event *ev );
void WindowDamaged( Event *ev );
void WindowKilled( Event *ev );
void WindowSetup(Event *ev);
void WindowDebrisType(Event *ev);
void WindowDamaged(Event *ev);
void WindowKilled(Event *ev);
};