Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » C++ Help request
C++ Help request [message #420409] Sat, 20 February 2010 10:21 Go to previous message
Raptor RSF is currently offline  Raptor RSF
Messages: 210
Registered: July 2007
Location: Netherlands
Karma:
Recruit
Can anybody help me with creating this function. I failed and wasted much hours on this Huh

What the function needs to do:

Showing health number for 5 seconds and after that showing shield number for 5 seconds. The function needs to repeat itself over and over again.

healthinfo.h

/*	HealthInfoItemClass
	Copyright 2009 Mark Sararu

	This code file is made by: Raptor*[RSF]

	This file is part of the Renegade scripts.dll
	The Renegade scripts.dll 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 2, or (at your option) any later
	version. See the file COPYING for more details.
	In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module 
	that does not contain code covered by this licence.
	Only the source code to the module(s) containing the licenced code has to be released.
*/

#ifndef SHADERS_HEALTHINFO_H_
#define SHADERS_HEALTHINFO_H_

class HealthInfoItemClass
{
protected:
	bool Enabled;
	bool Enabled2;

	Render2DClass*		Render2D;
	Render2DTextClass*	Render2DText;

	int					NextPrint;

	Vector2				TextPosition;
	char *				TextFontFile;

	unsigned int		StopTime;

public:
	HealthInfoItemClass();
	~HealthInfoItemClass();
	void Load(INIClass* ini);
	void Render();
};

extern HealthInfoItemClass HealthInfo;

#endif



healthinfo.cpp

/*	HealthInfoItemClass
	Copyright 2009 Mark Sararu

	This code file is made by: Raptor*[RSF]

	This file is part of the Renegade scripts.dll
	The Renegade scripts.dll 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 2, or (at your option) any later
	version. See the file COPYING for more details.
	In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module 
	that does not contain code covered by this licence.
	Only the source code to the module(s) containing the licenced code has to be released.
*/

#include "scripts.h"
#include "shadereng.h"
#include "healthinfo.h"

SimpleDynVecClass<unsigned int> *Colors9;
unsigned long HealthInfoColor = 0;

HealthInfoItemClass::HealthInfoItemClass():
	Enabled(false),
	Enabled2(false),
	Render2D(NULL), 
	Render2DText(NULL),
	NextPrint(1),
	StopTime(0),
	TextPosition(0, 0),
	TextFontFile(NULL)
{
};

HealthInfoItemClass::~HealthInfoItemClass()
{
	SAFE_DELETE(Render2D);
	SAFE_DELETE(Render2DText);
	SAFE_DELETE(TextFontFile);
};

void HealthInfoItemClass::Load(INIClass *ini)
{
	if (!ini) return; // if you don't have an ini, something is horribly wrong!

	const char* section_name = "HealthInfo";

	Enabled = ini->Get_Bool(section_name, "HealthInfoEnabled", false);
	Enabled2 = ini->Get_Bool("General", "HealthInfoEnabled", false);
	if ((!Enabled) && (!Enabled2)) return;



	// Gathers the colors from hud.ini
	Colors9 = new SimpleDynVecClass<unsigned int>;

	unsigned int color = RGB(255,255,255)+0xFF000000;
	Colors9->Add(color);
	unsigned int colors9 = ini->Get_Int("General","ColorCount",0);
	for (unsigned int i = 0;i < colors9;i++)
	{
		char section[10];
		sprintf(section,"Color%d",i+1);
		unsigned int Red = ini->Get_Int(section,"Red",255);
		unsigned int Green = ini->Get_Int(section,"Green",255);
		unsigned int Blue = ini->Get_Int(section,"Blue",255);
		unsigned int Alpha = (ini->Get_Int(section,"Alpha",255) << 24);
		color = RGB(Blue,Green,Red)+Alpha;
		Colors9->Add(color);
	}
	unsigned int HealthInfoCol = ini->Get_Int(section_name,"HealthInfoColor",0);
	HealthInfoColor = (*Colors9)[HealthInfoCol];

	Render2D = CreateRender2DClass();

	Vector2 screen_center;
	screen_center.X = (ScreenResolution->Right - ScreenResolution->Left) / 2.0f;
	screen_center.Y = (ScreenResolution->Bottom - ScreenResolution->Top) / 2.0f;

	char temp[512];
	ini->Get_String(section_name, "Text.Font.File", "DEFAULT_FONT", temp, 512);
	Render2DText = CreateRender2DTextClass(temp);
	TextFontFile = newstr(temp);

	float average_height = ini->Get_Float(section_name, "Text.Font.AverageCharacterHeight", 16);

	bool text_centered = ini->Get_Bool(section_name, "Text.Position.Centered", true);
	TextPosition.X = ini->Get_Float(section_name, "Text.Position.X", 0.0f);
	TextPosition.Y = ini->Get_Float(section_name, "Text.Position.Y", 0.0f);
	if (TextPosition.X < 0)
	{
		TextPosition.X += ScreenResolution->Right;
	}
	if (TextPosition.Y < 0)
	{
		TextPosition.Y += ScreenResolution->Bottom;
	}

	if (text_centered)
	{
		TextPosition = TextPosition + screen_center;
		TextPosition.Y -= average_height / 2.0f;
	}
};



void HealthInfoItemClass::Render()
{
	if ((!Enabled) && (!Enabled2)) return;

	GameObject *obj = Get_Vehicle_Return((GameObject *)(*TheStar)->obj);
	float health = Commands->Get_Health(obj);
	float shield = Commands->Get_Shield_Strength(obj);
	unsigned int current_time = *SyncTime;
	StopTime = current_time + 10000;

	unsigned int color = 0;
	color = HealthInfoColor;

	// needs to render the health number for 5 sec while not showing shield number.
	if // something
	{
		Render2DText->Reset();
		RectClass *r = (RectClass *)((char *)Render2DText+0x5B8);
		r->Top = TextPosition.Y;
		r->Left = TextPosition.X;
		r->Bottom = TextPosition.Y;
		r->Right = TextPosition.X;
		char temp[64];
		unsigned int h = (unsigned int)(health + 0.5f);
		char icon_health[8] = "+_";
		sprintf(temp,"%s%03d" ,icon_health,h);
		Render2DText->Draw_Text(temp, color);
		Render2DText->Render();
	}
	// needs to render the Shield number for 5 sec while not showing health number.
	else if // something
	{
		Render2DText->Reset();
		RectClass *r = (RectClass *)((char *)Render2DText+0x5B8);
		r->Top = TextPosition.Y; 
		r->Left = TextPosition.X; 
		r->Bottom = TextPosition.Y; 
		r->Right = TextPosition.X;
		char temp[64];
		unsigned int s = (unsigned int)(shield + 0.5f);
		char icon_shield[8] = "*_";
		sprintf(temp,"%s%03d" ,icon_shield,s);
		Render2DText->Draw_Text(temp, color);
		Render2DText->Render();
	}
};

//--------------------------------------------------------------------------------
// globals
//--------------------------------------------------------------------------------
HealthInfoItemClass HealthInfo;



shaderhud.cpp

#include "healthinfo.h" // HealthInfo

HealthInfo.Load(hudini); // HealthInfo

HealthInfo.Render(); // HealthInfo



HUD.ini

[HealthInfo]
HealthInfoEnabled=true
Text.Font.File=font12x16.tga
Text.Font.AverageCharacterHeight=0
Text.Position.Centered=false
Text.Position.X=185.0
Text.Position.Y=-130.0
HealthInfoColor=1



Anybody please help Dont Get It


Rencom server Fan - Marathon#1

http://bfbc2.statsverse.com/sig/clean1/pc/Raptor_RSF.png
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Help installing LUA 5?
Next Topic: C&C Volcano
Goto Forum:
  


Current Time: Fri Aug 23 21:32:58 MST 2024

Total time taken to generate the page: 0.00738 seconds