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.

4.4 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 2026 by İlyas Akın for the macOS/Linux port; see NOTICE.md and the git history.

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

// FILE: RadiusDecal.h ///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#ifndef _RadiusDecal_H_
#define _RadiusDecal_H_

#include "Common/GameCommon.h"
#include "Common/GameType.h"
#include "GameClient/Color.h"

#include <memory>

enum ShadowType : int;
class Player;
class Shadow;
class RadiusDecalTemplate;

// ------------------------------------------------------------------------------------------------
/** The decal itself, held where a call queued for after the tick can still reach it once its
	* RadiusDecal is gone.  Logic modules create and clear these inside the tick, which runs beside the
	* render, and adding or releasing a decal edits the decal list the render walks, so both go through
	* LogicThread::callAfterTick and only ever happen on the main thread.  Until the add has run, what
	* the owner sets (a module animates its decal in the tick that created it) waits here and the add
	* puts it on. */
struct RadiusDecalCell
{
	Shadow*	decal;
	Bool		hasPosition;
	Coord3D	position;
	Bool		hasOpacity;
	Int			opacity;
	Bool		hasAngle;
	Real		angle;

	RadiusDecalCell() : decal(NULL), hasPosition(FALSE), hasOpacity(FALSE), opacity(0), hasAngle(FALSE), angle(0.0f)
	{
		position.x = position.y = position.z = 0.0f;
	}

	void setPosition(const Coord3D& pos);
	void setOpacity(Int o);
	void setAngle(Real a);
};

// ------------------------------------------------------------------------------------------------
class RadiusDecal
{
	friend class RadiusDecalTemplate;
private:
	const RadiusDecalTemplate*	m_template;
	std::shared_ptr<RadiusDecalCell>	m_decal;
	Bool												m_empty;
public:
	RadiusDecal();
	RadiusDecal(const RadiusDecal& that);
	RadiusDecal& operator=(const RadiusDecal& that);
	~RadiusDecal();

	void xferRadiusDecal( Xfer *xfer );

	// please note: it is very important, for game/net sync reasons, to ensure that
	// isEmpty() returns the same value, regardless of whether this decal will 
	// be visible to the local player or not.
	Bool isEmpty() const { return m_empty; }
	void clear();
	void update();
	void setPosition(const Coord3D& pos);
	void setOpacity( const Real o );
};

// ------------------------------------------------------------------------------------------------
class RadiusDecalTemplate
{
	friend class RadiusDecal;
private:
	AsciiString		m_name;
	ShadowType		m_shadowType;
	Real					m_minOpacity;
	Real					m_maxOpacity;
	UnsignedInt		m_opacityThrobTime;
	Color					m_color;
	Bool					m_onlyVisibleToOwningPlayer;

public:
	RadiusDecalTemplate();

	Bool valid() const { return m_name.isNotEmpty(); }
	const AsciiString& getTexture() const { return m_name; }
	void xferRadiusDecalTemplate( Xfer *xfer );

	// please note: it is very important, for game/net sync reasons, to ensure that
	// a valid radiusdecal is created, even if will not be visible to the local player,
	// since some logic makes decisions based on this.
	// texture, when given, is drawn in place of the template's own, with the template's style and throb
	void createRadiusDecal(const Coord3D& pos, Real radius, const Player* owningPlayer, RadiusDecal& result, const char* texture = NULL) const;

	static void parseRadiusDecalTemplate(INI* ini, void *instance, void * store, const void* /*userData*/);
};

#endif