Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

5.1 KB
Raw Blame
/*
**	Command & Conquer Generals Zero Hour(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/>.
*/
// Modified 2025-2026 by Olcay Seygan for Zero Hour Reforged; see the git history.
// Modified 2026 by İlyas Akın for the macOS/Linux port; see NOTICE.md and the git history.

////////////////////////////////////////////////////////////////////////////////
//																																						//
//  (c) 2001-2003 Electronic Arts Inc.																				//
//																																						//
////////////////////////////////////////////////////////////////////////////////

// FILE: LaserUpdate.h //////////////////////////////////////////////////////////////////////////
// Author: Kris Morness, July 2002
// Desc:   Handles laser update processing for render purposes and game control.
// Modifications: Kris Morness - Oct 2002 -- moved to Client update (will rename later)
///////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#ifndef __LASER_UPDATE_H
#define __LASER_UPDATE_H

// INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
#include "Common/ClientUpdateModule.h"

// FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
class Thing;
class Vector3;
enum ParticleSystemID : Int;

//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
class LaserUpdateModuleData : public ClientUpdateModuleData
{
public:
	AsciiString m_particleSystemName;  ///< Used for the muzzle flare while laser active.

	AsciiString m_targetParticleSystemName;  ///< Used for the target effect while laser active.
	
	Real m_punchThroughScalar;	///< If non-zero, length modifier when we used to have a target object and now don't

	LaserUpdateModuleData();
	static void buildFieldParse(MultiIniFieldParse& p);

private: 

};


//-------------------------------------------------------------------------------------------------
/** The default	update module */
//-------------------------------------------------------------------------------------------------
class LaserUpdate : public ClientUpdateModule
{

	MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE( LaserUpdate, "LaserUpdate" )
	MAKE_STANDARD_MODULE_MACRO_WITH_MODULE_DATA( LaserUpdate, LaserUpdateModuleData );

public:

	LaserUpdate( Thing *thing, const ModuleData* moduleData );
	// virtual destructor prototype provided by memory pool declaration

	//Actually puts the laser in the world.
	void initLaser( const Object *parent, const Object *target, const Coord3D *startPos, const Coord3D *endPos, AsciiString parentBoneName, Int sizeDeltaFrames = 0 );
	void setDecayFrames( UnsignedInt decayFrames );
	void moveEnds( const Coord3D *startPos, const Coord3D *endPos ) { m_startPos = *startPos; m_endPos = *endPos; m_dirty = TRUE; }

	const Coord3D* getStartPos() { return &m_startPos; }
	const Coord3D* getEndPos() { return &m_endPos; }

	void setDirty( Bool dirty ) { m_dirty = dirty; }
	Bool isDirty() { return m_dirty; }

	Real getWidthScale() const { return m_currentWidthScalar; }

	// for W3DLaserDraw's travel: who fired at whom (the target as initLaser found it, kept after a kill
	// clears m_targetID), and the target effect it holds back until the beam's head lands
	DrawableID getParentID() const { return m_parentID; }
	DrawableID getFiredAtID() const { return m_firedAtID; }
	ParticleSystemID getTargetParticleSystemID() const { return m_targetParticleSystemID; }

	virtual void clientUpdate();

protected:

	void updateStartPos( const Drawable *parentDrawable = NULL ); ///< figures out and sets startPos; NULL looks the parent up by m_parentID
	void updateEndPos(); ///< figures out and sets endPos
	Real computeWidthScalar( UnsignedInt frame ) const; ///< the width on that logic frame, from the frames alone

	//If the master dies, so will this laser (although if it has a fade delay, it'll just skip to the fade)
	Coord3D m_startPos;
	Coord3D m_endPos;

	DrawableID m_parentID;
	DrawableID m_targetID;
	DrawableID m_firedAtID;	///< client only, not saved: the drawing reads it in the first passes of a beam

	Bool m_dirty;
	ParticleSystemID m_particleSystemID;
	ParticleSystemID m_targetParticleSystemID;
	Bool m_widening;
	Bool m_decaying;
	UnsignedInt m_widenStartFrame;
	UnsignedInt m_widenFinishFrame;
	Real m_currentWidthScalar;
	UnsignedInt m_decayStartFrame;
	UnsignedInt m_decayFinishFrame;
	AsciiString m_parentBoneName;
};


#endif