2012-11-26 18:58:24 +00:00
|
|
|
/*
|
|
|
|
===========================================================================
|
|
|
|
|
|
|
|
Doom 3 BFG Edition GPL Source Code
|
2012-11-28 15:47:07 +00:00
|
|
|
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code 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.
|
|
|
|
|
|
|
|
Doom 3 BFG Edition Source Code 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 Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
|
|
|
|
|
|
|
|
If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
|
|
|
|
|
|
|
|
===========================================================================
|
|
|
|
*/
|
|
|
|
#pragma hdrstop
|
|
|
|
#include "../idlib/precompiled.h"
|
|
|
|
|
|
|
|
#include "DeviceContext.h"
|
|
|
|
#include "Window.h"
|
|
|
|
#include "UserInterfaceLocal.h"
|
|
|
|
#include "GameSSDWindow.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define Z_NEAR 100.0f
|
|
|
|
#define Z_FAR 4000.0f
|
|
|
|
#define ENTITY_START_DIST 3000
|
|
|
|
|
|
|
|
#define V_WIDTH 640.0f
|
|
|
|
#define V_HEIGHT 480.0f
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
* SSDCrossHair
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CROSSHAIR_STANDARD_MATERIAL "game/SSD/crosshair_standard"
|
|
|
|
#define CROSSHAIR_SUPER_MATERIAL "game/SSD/crosshair_super"
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDCrossHair::SSDCrossHair()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDCrossHair::~SSDCrossHair()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDCrossHair::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( ¤tCrosshair, sizeof( currentCrosshair ) );
|
|
|
|
savefile->Write( &crosshairWidth, sizeof( crosshairWidth ) );
|
|
|
|
savefile->Write( &crosshairHeight, sizeof( crosshairHeight ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDCrossHair::ReadFromSaveGame( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
InitCrosshairs();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
savefile->Read( ¤tCrosshair, sizeof( currentCrosshair ) );
|
|
|
|
savefile->Read( &crosshairWidth, sizeof( crosshairWidth ) );
|
|
|
|
savefile->Read( &crosshairHeight, sizeof( crosshairHeight ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDCrossHair::InitCrosshairs()
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
crosshairMaterial[CROSSHAIR_STANDARD] = declManager->FindMaterial( CROSSHAIR_STANDARD_MATERIAL );
|
|
|
|
crosshairMaterial[CROSSHAIR_SUPER] = declManager->FindMaterial( CROSSHAIR_SUPER_MATERIAL );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
crosshairWidth = 64;
|
|
|
|
crosshairHeight = 64;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
currentCrosshair = CROSSHAIR_STANDARD;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDCrossHair::Draw( const idVec2& cursor )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
float x, y;
|
|
|
|
x = cursor.x - ( crosshairWidth / 2 );
|
|
|
|
y = cursor.y - ( crosshairHeight / 2 );
|
|
|
|
dc->DrawMaterial( x, y, crosshairWidth, crosshairHeight, crosshairMaterial[currentCrosshair], colorWhite, 1.0f, 1.0f );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
2012-11-28 15:47:07 +00:00
|
|
|
* SSDEntity
|
2012-11-26 18:58:24 +00:00
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDEntity::SSDEntity()
|
|
|
|
{
|
|
|
|
EntityInit();
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDEntity::~SSDEntity()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &type, sizeof( type ) );
|
|
|
|
game->WriteSaveGameString( materialName, savefile );
|
|
|
|
savefile->Write( &position, sizeof( position ) );
|
|
|
|
savefile->Write( &size, sizeof( size ) );
|
|
|
|
savefile->Write( &radius, sizeof( radius ) );
|
|
|
|
savefile->Write( &hitRadius, sizeof( hitRadius ) );
|
|
|
|
savefile->Write( &rotation, sizeof( rotation ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &matColor, sizeof( matColor ) );
|
|
|
|
|
|
|
|
game->WriteSaveGameString( text, savefile );
|
|
|
|
savefile->Write( &textScale, sizeof( textScale ) );
|
|
|
|
savefile->Write( &foreColor, sizeof( foreColor ) );
|
|
|
|
|
|
|
|
savefile->Write( ¤tTime, sizeof( currentTime ) );
|
|
|
|
savefile->Write( &lastUpdate, sizeof( lastUpdate ) );
|
|
|
|
savefile->Write( &elapsed, sizeof( elapsed ) );
|
|
|
|
|
|
|
|
savefile->Write( &destroyed, sizeof( destroyed ) );
|
|
|
|
savefile->Write( &noHit, sizeof( noHit ) );
|
|
|
|
savefile->Write( &noPlayerDamage, sizeof( noPlayerDamage ) );
|
|
|
|
|
|
|
|
savefile->Write( &inUse, sizeof( inUse ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::ReadFromSaveGame( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &type, sizeof( type ) );
|
|
|
|
game->ReadSaveGameString( materialName, savefile );
|
|
|
|
SetMaterial( materialName );
|
|
|
|
savefile->Read( &position, sizeof( position ) );
|
|
|
|
savefile->Read( &size, sizeof( size ) );
|
|
|
|
savefile->Read( &radius, sizeof( radius ) );
|
|
|
|
savefile->Read( &hitRadius, sizeof( hitRadius ) );
|
|
|
|
savefile->Read( &rotation, sizeof( rotation ) );
|
|
|
|
|
|
|
|
savefile->Read( &matColor, sizeof( matColor ) );
|
|
|
|
|
|
|
|
game->ReadSaveGameString( text, savefile );
|
|
|
|
savefile->Read( &textScale, sizeof( textScale ) );
|
|
|
|
savefile->Read( &foreColor, sizeof( foreColor ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
game = _game;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( ¤tTime, sizeof( currentTime ) );
|
|
|
|
savefile->Read( &lastUpdate, sizeof( lastUpdate ) );
|
|
|
|
savefile->Read( &elapsed, sizeof( elapsed ) );
|
|
|
|
|
|
|
|
savefile->Read( &destroyed, sizeof( destroyed ) );
|
|
|
|
savefile->Read( &noHit, sizeof( noHit ) );
|
|
|
|
savefile->Read( &noPlayerDamage, sizeof( noPlayerDamage ) );
|
|
|
|
|
|
|
|
savefile->Read( &inUse, sizeof( inUse ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::EntityInit()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
inUse = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
type = SSD_ENTITY_BASE;
|
|
|
|
|
|
|
|
materialName = "";
|
|
|
|
material = NULL;
|
|
|
|
position.Zero();
|
|
|
|
size.Zero();
|
|
|
|
radius = 0.0f;
|
|
|
|
hitRadius = 0.0f;
|
|
|
|
rotation = 0.0f;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
currentTime = 0;
|
|
|
|
lastUpdate = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
destroyed = false;
|
|
|
|
noHit = false;
|
|
|
|
noPlayerDamage = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
matColor.Set( 1, 1, 1, 1 );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
text = "";
|
|
|
|
textScale = 1.0f;
|
2012-11-28 15:47:07 +00:00
|
|
|
foreColor.Set( 1, 1, 1, 1 );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::SetGame( idGameSSDWindow* _game )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
game = _game;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::SetMaterial( const char* name )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
materialName = name;
|
|
|
|
material = declManager->FindMaterial( name );
|
|
|
|
material->SetSort( SS_GUI );
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::SetPosition( const idVec3& _position )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
position = _position;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::SetSize( const idVec2& _size )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
size = _size;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::SetRadius( float _radius, float _hitFactor )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
radius = _radius;
|
2012-11-28 15:47:07 +00:00
|
|
|
hitRadius = _radius * _hitFactor;
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::SetRotation( float _rotation )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
rotation = _rotation;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::Update()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
currentTime = game->ssdTime;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Is this the first update
|
2012-11-28 15:47:07 +00:00
|
|
|
if( lastUpdate == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
lastUpdate = currentTime;
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
elapsed = currentTime - lastUpdate;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
EntityUpdate();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
lastUpdate = currentTime;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
bool SSDEntity::HitTest( const idVec2& pt )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( noHit )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idVec3 screenPos = WorldToScreen( position );
|
|
|
|
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Scale the radius based on the distance from the player
|
2012-11-28 15:47:07 +00:00
|
|
|
float scale = 1.0f - ( ( screenPos.z - Z_NEAR ) / ( Z_FAR - Z_NEAR ) );
|
|
|
|
float scaledRad = scale * hitRadius;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//So we can compare against the square of the length between two points
|
2012-11-28 15:47:07 +00:00
|
|
|
float scaleRadSqr = scaledRad * scaledRad;
|
|
|
|
|
|
|
|
idVec2 diff = screenPos.ToVec2() - pt;
|
|
|
|
float dist = idMath::Fabs( diff.LengthSqr() );
|
|
|
|
|
|
|
|
if( dist < scaleRadSqr )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::Draw()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
idVec2 persize;
|
2012-11-28 15:47:07 +00:00
|
|
|
float x, y;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idBounds bounds;
|
2012-11-28 15:47:07 +00:00
|
|
|
bounds[0] = idVec3( position.x - ( size.x / 2.0f ), position.y - ( size.y / 2.0f ), position.z );
|
|
|
|
bounds[1] = idVec3( position.x + ( size.x / 2.0f ), position.y + ( size.y / 2.0f ), position.z );
|
|
|
|
|
|
|
|
idBounds screenBounds = WorldToScreen( bounds );
|
|
|
|
persize.x = idMath::Fabs( screenBounds[1].x - screenBounds[0].x );
|
|
|
|
persize.y = idMath::Fabs( screenBounds[1].y - screenBounds[0].y );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 center = screenBounds.GetCenter();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
x = screenBounds[0].x;
|
|
|
|
y = screenBounds[1].y;
|
2012-11-28 15:47:07 +00:00
|
|
|
dc->DrawMaterialRotated( x, y, persize.x, persize.y, material, matColor, 1.0f, 1.0f, DEG2RAD( rotation ) );
|
|
|
|
|
|
|
|
if( text.Length() > 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idRectangle rect( x, y, VIRTUAL_WIDTH, VIRTUAL_HEIGHT );
|
|
|
|
dc->DrawText( text, textScale, 0, foreColor, rect, false );
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDEntity::DestroyEntity()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
inUse = false;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idBounds SSDEntity::WorldToScreen( const idBounds worldBounds )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 screenMin = WorldToScreen( worldBounds[0] );
|
|
|
|
idVec3 screenMax = WorldToScreen( worldBounds[1] );
|
|
|
|
|
|
|
|
idBounds screenBounds( screenMin, screenMax );
|
2012-11-26 18:58:24 +00:00
|
|
|
return screenBounds;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 SSDEntity::WorldToScreen( const idVec3& worldPos )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
float d = 0.5f * V_WIDTH * idMath::Tan( DEG2RAD( 90.0f ) / 2.0f );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//World To Camera Coordinates
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 cameraTrans( 0, 0, d );
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec3 cameraPos;
|
|
|
|
cameraPos = worldPos + cameraTrans;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Camera To Screen Coordinates
|
|
|
|
idVec3 screenPos;
|
2012-11-28 15:47:07 +00:00
|
|
|
screenPos.x = d * cameraPos.x / cameraPos.z + ( 0.5f * V_WIDTH - 0.5f );
|
|
|
|
screenPos.y = -d * cameraPos.y / cameraPos.z + ( 0.5f * V_HEIGHT - 0.5f );
|
2012-11-26 18:58:24 +00:00
|
|
|
screenPos.z = cameraPos.z;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return screenPos;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 SSDEntity::ScreenToWorld( const idVec3& screenPos )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idVec3 worldPos;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
worldPos.x = screenPos.x - 0.5f * V_WIDTH;
|
2012-11-28 15:47:07 +00:00
|
|
|
worldPos.y = -( screenPos.y - 0.5f * V_HEIGHT );
|
2012-11-26 18:58:24 +00:00
|
|
|
worldPos.z = screenPos.z;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return worldPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
2012-11-28 15:47:07 +00:00
|
|
|
* SSDMover
|
2012-11-26 18:58:24 +00:00
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDMover::SSDMover()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDMover::~SSDMover()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDMover::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
SSDEntity::WriteToSaveGame( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &speed, sizeof( speed ) );
|
|
|
|
savefile->Write( &rotationSpeed, sizeof( rotationSpeed ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDMover::ReadFromSaveGame( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
|
|
|
SSDEntity::ReadFromSaveGame( savefile, _game );
|
|
|
|
|
|
|
|
savefile->Read( &speed, sizeof( speed ) );
|
|
|
|
savefile->Read( &rotationSpeed, sizeof( rotationSpeed ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDMover::MoverInit( const idVec3& _speed, float _rotationSpeed )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
speed = _speed;
|
|
|
|
rotationSpeed = _rotationSpeed;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDMover::EntityUpdate()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDEntity::EntityUpdate();
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Move forward based on speed (units per second)
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 moved = ( ( float )elapsed / 1000.0f ) * speed;
|
2012-11-26 18:58:24 +00:00
|
|
|
position += moved;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
float rotated = ( ( float )elapsed / 1000.0f ) * rotationSpeed * 360.0f;
|
2012-11-26 18:58:24 +00:00
|
|
|
rotation += rotated;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( rotation >= 360 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
rotation -= 360.0f;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( rotation < 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
rotation += 360.0f;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
2012-11-28 15:47:07 +00:00
|
|
|
* SSDAsteroid
|
2012-11-26 18:58:24 +00:00
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
SSDAsteroid SSDAsteroid::asteroidPool[MAX_ASTEROIDS];
|
|
|
|
|
|
|
|
#define ASTEROID_MATERIAL "game/SSD/asteroid"
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDAsteroid::SSDAsteroid()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDAsteroid::~SSDAsteroid()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDAsteroid::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
SSDMover::WriteToSaveGame( savefile );
|
|
|
|
|
|
|
|
savefile->Write( &health, sizeof( health ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDAsteroid::ReadFromSaveGame( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
|
|
|
SSDMover::ReadFromSaveGame( savefile, _game );
|
|
|
|
|
|
|
|
savefile->Read( &health, sizeof( health ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDAsteroid::Init( idGameSSDWindow* _game, const idVec3& startPosition, const idVec2& _size, float _speed, float rotate, int _health )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
EntityInit();
|
2012-11-28 15:47:07 +00:00
|
|
|
MoverInit( idVec3( 0, 0, -_speed ), rotate );
|
|
|
|
|
|
|
|
SetGame( _game );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
type = SSD_ENTITY_ASTEROID;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
SetMaterial( ASTEROID_MATERIAL );
|
|
|
|
SetSize( _size );
|
|
|
|
SetRadius( Max( size.x, size.y ), 0.3f );
|
|
|
|
SetRotation( game->random.RandomInt( 360 ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
position = startPosition;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
health = _health;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDAsteroid::EntityUpdate()
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDMover::EntityUpdate();
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDAsteroid* SSDAsteroid::GetNewAsteroid( idGameSSDWindow* _game, const idVec3& startPosition, const idVec2& _size, float _speed, float rotate, int _health )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < MAX_ASTEROIDS; i++ )
|
|
|
|
{
|
|
|
|
if( !asteroidPool[i].inUse )
|
|
|
|
{
|
|
|
|
asteroidPool[i].Init( _game, startPosition, _size, _speed, rotate, _health );
|
2012-11-26 18:58:24 +00:00
|
|
|
asteroidPool[i].inUse = true;
|
|
|
|
asteroidPool[i].id = i;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
return &asteroidPool[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDAsteroid* SSDAsteroid::GetSpecificAsteroid( int id )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &asteroidPool[id];
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDAsteroid::WriteAsteroids( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int count = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < MAX_ASTEROIDS; i++ )
|
|
|
|
{
|
|
|
|
if( asteroidPool[i].inUse )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < MAX_ASTEROIDS; i++ )
|
|
|
|
{
|
|
|
|
if( asteroidPool[i].inUse )
|
|
|
|
{
|
|
|
|
savefile->Write( &( asteroidPool[i].id ), sizeof( asteroidPool[i].id ) );
|
|
|
|
asteroidPool[i].WriteToSaveGame( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDAsteroid::ReadAsteroids( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int count;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < count; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int id;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &id, sizeof( id ) );
|
|
|
|
SSDAsteroid* ent = GetSpecificAsteroid( id );
|
|
|
|
ent->ReadFromSaveGame( savefile, _game );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
* SSDAstronaut
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
SSDAstronaut SSDAstronaut::astronautPool[MAX_ASTRONAUT];
|
|
|
|
|
|
|
|
#define ASTRONAUT_MATERIAL "game/SSD/astronaut"
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDAstronaut::SSDAstronaut()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDAstronaut::~SSDAstronaut()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDAstronaut::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
SSDMover::WriteToSaveGame( savefile );
|
|
|
|
|
|
|
|
savefile->Write( &health, sizeof( health ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDAstronaut::ReadFromSaveGame( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
|
|
|
SSDMover::ReadFromSaveGame( savefile, _game );
|
|
|
|
|
|
|
|
savefile->Read( &health, sizeof( health ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDAstronaut::Init( idGameSSDWindow* _game, const idVec3& startPosition, float _speed, float rotate, int _health )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
EntityInit();
|
2012-11-28 15:47:07 +00:00
|
|
|
MoverInit( idVec3( 0, 0, -_speed ), rotate );
|
|
|
|
|
|
|
|
SetGame( _game );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
type = SSD_ENTITY_ASTRONAUT;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
SetMaterial( ASTRONAUT_MATERIAL );
|
|
|
|
SetSize( idVec2( 256, 256 ) );
|
|
|
|
SetRadius( Max( size.x, size.y ), 0.3f );
|
|
|
|
SetRotation( game->random.RandomInt( 360 ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
position = startPosition;
|
|
|
|
health = _health;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDAstronaut* SSDAstronaut::GetNewAstronaut( idGameSSDWindow* _game, const idVec3& startPosition, float _speed, float rotate, int _health )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < MAX_ASTRONAUT; i++ )
|
|
|
|
{
|
|
|
|
if( !astronautPool[i].inUse )
|
|
|
|
{
|
|
|
|
astronautPool[i].Init( _game, startPosition, _speed, rotate, _health );
|
2012-11-26 18:58:24 +00:00
|
|
|
astronautPool[i].inUse = true;
|
|
|
|
astronautPool[i].id = i;
|
|
|
|
return &astronautPool[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDAstronaut* SSDAstronaut::GetSpecificAstronaut( int id )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &astronautPool[id];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDAstronaut::WriteAstronauts( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int count = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < MAX_ASTRONAUT; i++ )
|
|
|
|
{
|
|
|
|
if( astronautPool[i].inUse )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < MAX_ASTRONAUT; i++ )
|
|
|
|
{
|
|
|
|
if( astronautPool[i].inUse )
|
|
|
|
{
|
|
|
|
savefile->Write( &( astronautPool[i].id ), sizeof( astronautPool[i].id ) );
|
|
|
|
astronautPool[i].WriteToSaveGame( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDAstronaut::ReadAstronauts( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
int count;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < count; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int id;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &id, sizeof( id ) );
|
|
|
|
SSDAstronaut* ent = GetSpecificAstronaut( id );
|
|
|
|
ent->ReadFromSaveGame( savefile, _game );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
2012-11-28 15:47:07 +00:00
|
|
|
* SSDExplosion
|
2012-11-26 18:58:24 +00:00
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
SSDExplosion SSDExplosion::explosionPool[MAX_EXPLOSIONS];
|
|
|
|
|
|
|
|
|
|
|
|
//#define EXPLOSION_MATERIAL "game/SSD/fball"
|
|
|
|
//#define EXPLOSION_TELEPORT "game/SSD/teleport"
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* explosionMaterials[] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"game/SSD/fball",
|
|
|
|
"game/SSD/teleport"
|
|
|
|
};
|
|
|
|
|
|
|
|
#define EXPLOSION_MATERIAL_COUNT 2
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion::SSDExplosion()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
type = SSD_ENTITY_EXPLOSION;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion::~SSDExplosion()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDExplosion::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
SSDEntity::WriteToSaveGame( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &finalSize, sizeof( finalSize ) );
|
|
|
|
savefile->Write( &length, sizeof( length ) );
|
|
|
|
savefile->Write( &beginTime, sizeof( beginTime ) );
|
|
|
|
savefile->Write( &endTime, sizeof( endTime ) );
|
|
|
|
savefile->Write( &explosionType, sizeof( explosionType ) );
|
|
|
|
|
|
|
|
|
|
|
|
savefile->Write( &( buddy->type ), sizeof( buddy->type ) );
|
|
|
|
savefile->Write( &( buddy->id ), sizeof( buddy->id ) );
|
|
|
|
|
|
|
|
savefile->Write( &killBuddy, sizeof( killBuddy ) );
|
|
|
|
savefile->Write( &followBuddy, sizeof( followBuddy ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDExplosion::ReadFromSaveGame( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
|
|
|
SSDEntity::ReadFromSaveGame( savefile, _game );
|
|
|
|
|
|
|
|
savefile->Read( &finalSize, sizeof( finalSize ) );
|
|
|
|
savefile->Read( &length, sizeof( length ) );
|
|
|
|
savefile->Read( &beginTime, sizeof( beginTime ) );
|
|
|
|
savefile->Read( &endTime, sizeof( endTime ) );
|
|
|
|
savefile->Read( &explosionType, sizeof( explosionType ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int type, id;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &type, sizeof( type ) );
|
|
|
|
savefile->Read( &id, sizeof( id ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Get a pointer to my buddy
|
2012-11-28 15:47:07 +00:00
|
|
|
buddy = _game->GetSpecificEntity( type, id );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &killBuddy, sizeof( killBuddy ) );
|
|
|
|
savefile->Read( &followBuddy, sizeof( followBuddy ) );
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDExplosion::Init( idGameSSDWindow* _game, const idVec3& _position, const idVec2& _size, int _length, int _type, SSDEntity* _buddy, bool _killBuddy, bool _followBuddy )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
EntityInit();
|
|
|
|
|
|
|
|
SetGame( _game );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
type = SSD_ENTITY_EXPLOSION;
|
|
|
|
explosionType = _type;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
SetMaterial( explosionMaterials[explosionType] );
|
|
|
|
SetPosition( _position );
|
2012-11-26 18:58:24 +00:00
|
|
|
position.z -= 50;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
finalSize = _size;
|
2012-11-26 18:58:24 +00:00
|
|
|
length = _length;
|
|
|
|
beginTime = game->ssdTime;
|
|
|
|
endTime = beginTime + length;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
buddy = _buddy;
|
|
|
|
killBuddy = _killBuddy;
|
|
|
|
followBuddy = _followBuddy;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Explosion Starts from nothing and will increase in size until it gets to final size
|
|
|
|
size.Zero();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
noPlayerDamage = true;
|
|
|
|
noHit = true;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDExplosion::EntityUpdate()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDEntity::EntityUpdate();
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Always set my position to my buddies position except change z to be on top
|
2012-11-28 15:47:07 +00:00
|
|
|
if( followBuddy )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
position = buddy->position;
|
|
|
|
position.z -= 50;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Only mess with the z if we are not following
|
|
|
|
position.z = buddy->position.z - 50;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Scale the image based on the time
|
2012-11-28 15:47:07 +00:00
|
|
|
size = finalSize * ( ( float )( currentTime - beginTime ) / ( float )length );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Destroy myself after the explosion is done
|
2012-11-28 15:47:07 +00:00
|
|
|
if( currentTime > endTime )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
destroyed = true;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( killBuddy )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Destroy the exploding object
|
|
|
|
buddy->destroyed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion* SSDExplosion::GetNewExplosion( idGameSSDWindow* _game, const idVec3& _position, const idVec2& _size, int _length, int _type, SSDEntity* _buddy, bool _killBuddy, bool _followBuddy )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < MAX_EXPLOSIONS; i++ )
|
|
|
|
{
|
|
|
|
if( !explosionPool[i].inUse )
|
|
|
|
{
|
|
|
|
explosionPool[i].Init( _game, _position, _size, _length, _type, _buddy, _killBuddy, _followBuddy );
|
2012-11-26 18:58:24 +00:00
|
|
|
explosionPool[i].inUse = true;
|
|
|
|
return &explosionPool[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion* SSDExplosion::GetSpecificExplosion( int id )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &explosionPool[id];
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDExplosion::WriteExplosions( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int count = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < MAX_EXPLOSIONS; i++ )
|
|
|
|
{
|
|
|
|
if( explosionPool[i].inUse )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < MAX_EXPLOSIONS; i++ )
|
|
|
|
{
|
|
|
|
if( explosionPool[i].inUse )
|
|
|
|
{
|
|
|
|
savefile->Write( &( explosionPool[i].id ), sizeof( explosionPool[i].id ) );
|
|
|
|
explosionPool[i].WriteToSaveGame( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDExplosion::ReadExplosions( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
int count;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < count; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int id;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &id, sizeof( id ) );
|
|
|
|
SSDExplosion* ent = GetSpecificExplosion( id );
|
|
|
|
ent->ReadFromSaveGame( savefile, _game );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
* SSDPoints
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
SSDPoints SSDPoints::pointsPool[MAX_POINTS];
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDPoints::SSDPoints()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
type = SSD_ENTITY_POINTS;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDPoints::~SSDPoints()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPoints::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
SSDEntity::WriteToSaveGame( savefile );
|
|
|
|
|
|
|
|
savefile->Write( &length, sizeof( length ) );
|
|
|
|
savefile->Write( &distance, sizeof( distance ) );
|
|
|
|
savefile->Write( &beginTime, sizeof( beginTime ) );
|
|
|
|
savefile->Write( &endTime, sizeof( endTime ) );
|
|
|
|
|
|
|
|
savefile->Write( &beginPosition, sizeof( beginPosition ) );
|
|
|
|
savefile->Write( &endPosition, sizeof( endPosition ) );
|
|
|
|
|
|
|
|
savefile->Write( &beginColor, sizeof( beginColor ) );
|
|
|
|
savefile->Write( &endColor, sizeof( endColor ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPoints::ReadFromSaveGame( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
|
|
|
SSDEntity::ReadFromSaveGame( savefile, _game );
|
|
|
|
|
|
|
|
savefile->Read( &length, sizeof( length ) );
|
|
|
|
savefile->Read( &distance, sizeof( distance ) );
|
|
|
|
savefile->Read( &beginTime, sizeof( beginTime ) );
|
|
|
|
savefile->Read( &endTime, sizeof( endTime ) );
|
|
|
|
|
|
|
|
savefile->Read( &beginPosition, sizeof( beginPosition ) );
|
|
|
|
savefile->Read( &endPosition, sizeof( endPosition ) );
|
|
|
|
|
|
|
|
savefile->Read( &beginColor, sizeof( beginColor ) );
|
|
|
|
savefile->Read( &endColor, sizeof( endColor ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPoints::Init( idGameSSDWindow* _game, SSDEntity* _ent, int _points, int _length, int _distance, const idVec4& color )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
EntityInit();
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SetGame( _game );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
length = _length;
|
|
|
|
distance = _distance;
|
|
|
|
beginTime = game->ssdTime;
|
|
|
|
endTime = beginTime + length;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
textScale = 0.4f;
|
2012-11-28 15:47:07 +00:00
|
|
|
text = va( "%d", _points );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
float width = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < text.Length(); i++ )
|
|
|
|
{
|
|
|
|
width += dc->CharWidth( text[i], textScale );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
size.Set( 0, 0 );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Set the start position at the top of the passed in entity
|
2012-11-28 15:47:07 +00:00
|
|
|
position = WorldToScreen( _ent->position );
|
|
|
|
position = ScreenToWorld( position );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
position.z = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
position.x -= ( width / 2.0f );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
beginPosition = position;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
endPosition = beginPosition;
|
|
|
|
endPosition.y += _distance;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//beginColor.Set(0,1,0,1);
|
2012-11-28 15:47:07 +00:00
|
|
|
endColor.Set( 1, 1, 1, 0 );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
beginColor = color;
|
|
|
|
beginColor.w = 1;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
noPlayerDamage = true;
|
|
|
|
noHit = true;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPoints::EntityUpdate()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
float t = ( float )( currentTime - beginTime ) / ( float )length;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Move up from the start position
|
2012-11-28 15:47:07 +00:00
|
|
|
position.Lerp( beginPosition, endPosition, t );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Interpolate the color
|
2012-11-28 15:47:07 +00:00
|
|
|
foreColor.Lerp( beginColor, endColor, t );
|
|
|
|
|
|
|
|
if( currentTime > endTime )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
destroyed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDPoints* SSDPoints::GetNewPoints( idGameSSDWindow* _game, SSDEntity* _ent, int _points, int _length, int _distance, const idVec4& color )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < MAX_POINTS; i++ )
|
|
|
|
{
|
|
|
|
if( !pointsPool[i].inUse )
|
|
|
|
{
|
|
|
|
pointsPool[i].Init( _game, _ent, _points, _length, _distance, color );
|
2012-11-26 18:58:24 +00:00
|
|
|
pointsPool[i].inUse = true;
|
|
|
|
return &pointsPool[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDPoints* SSDPoints::GetSpecificPoints( int id )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &pointsPool[id];
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPoints::WritePoints( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int count = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < MAX_POINTS; i++ )
|
|
|
|
{
|
|
|
|
if( pointsPool[i].inUse )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < MAX_POINTS; i++ )
|
|
|
|
{
|
|
|
|
if( pointsPool[i].inUse )
|
|
|
|
{
|
|
|
|
savefile->Write( &( pointsPool[i].id ), sizeof( pointsPool[i].id ) );
|
|
|
|
pointsPool[i].WriteToSaveGame( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPoints::ReadPoints( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
int count;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < count; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int id;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &id, sizeof( id ) );
|
|
|
|
SSDPoints* ent = GetSpecificPoints( id );
|
|
|
|
ent->ReadFromSaveGame( savefile, _game );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
* SSDProjectile
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
SSDProjectile SSDProjectile::projectilePool[MAX_PROJECTILES];
|
|
|
|
|
|
|
|
#define PROJECTILE_MATERIAL "game/SSD/fball"
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDProjectile::SSDProjectile()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
type = SSD_ENTITY_PROJECTILE;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDProjectile::~SSDProjectile()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDProjectile::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
SSDEntity::WriteToSaveGame( savefile );
|
|
|
|
|
|
|
|
savefile->Write( &dir, sizeof( dir ) );
|
|
|
|
savefile->Write( &speed, sizeof( speed ) );
|
|
|
|
savefile->Write( &beginTime, sizeof( beginTime ) );
|
|
|
|
savefile->Write( &endTime, sizeof( endTime ) );
|
|
|
|
|
|
|
|
savefile->Write( &endPosition, sizeof( endPosition ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDProjectile::ReadFromSaveGame( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
|
|
|
SSDEntity::ReadFromSaveGame( savefile, _game );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &dir, sizeof( dir ) );
|
|
|
|
savefile->Read( &speed, sizeof( speed ) );
|
|
|
|
savefile->Read( &beginTime, sizeof( beginTime ) );
|
|
|
|
savefile->Read( &endTime, sizeof( endTime ) );
|
|
|
|
|
|
|
|
savefile->Read( &endPosition, sizeof( endPosition ) );
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDProjectile::Init( idGameSSDWindow* _game, const idVec3& _beginPosition, const idVec3& _endPosition, float _speed, float _size )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
EntityInit();
|
|
|
|
|
|
|
|
SetGame( _game );
|
|
|
|
|
|
|
|
SetMaterial( PROJECTILE_MATERIAL );
|
|
|
|
size.Set( _size, _size );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
position = _beginPosition;
|
|
|
|
endPosition = _endPosition;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
dir = _endPosition - position;
|
|
|
|
dir.Normalize();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//speed.Zero();
|
|
|
|
speed.x = speed.y = speed.z = _speed;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
noHit = true;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDProjectile::EntityUpdate()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
SSDEntity::EntityUpdate();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Move forward based on speed (units per second)
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 moved = dir * ( ( float )elapsed / 1000.0f ) * speed.z;
|
2012-11-26 18:58:24 +00:00
|
|
|
position += moved;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( position.z > endPosition.z )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//We have reached our position
|
|
|
|
destroyed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDProjectile* SSDProjectile::GetNewProjectile( idGameSSDWindow* _game, const idVec3& _beginPosition, const idVec3& _endPosition, float _speed, float _size )
|
|
|
|
{
|
|
|
|
for( int i = 0; i < MAX_PROJECTILES; i++ )
|
|
|
|
{
|
|
|
|
if( !projectilePool[i].inUse )
|
|
|
|
{
|
|
|
|
projectilePool[i].Init( _game, _beginPosition, _endPosition, _speed, _size );
|
2012-11-26 18:58:24 +00:00
|
|
|
projectilePool[i].inUse = true;
|
|
|
|
return &projectilePool[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDProjectile* SSDProjectile::GetSpecificProjectile( int id )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &projectilePool[id];
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDProjectile::WriteProjectiles( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int count = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < MAX_PROJECTILES; i++ )
|
|
|
|
{
|
|
|
|
if( projectilePool[i].inUse )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < MAX_PROJECTILES; i++ )
|
|
|
|
{
|
|
|
|
if( projectilePool[i].inUse )
|
|
|
|
{
|
|
|
|
savefile->Write( &( projectilePool[i].id ), sizeof( projectilePool[i].id ) );
|
|
|
|
projectilePool[i].WriteToSaveGame( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDProjectile::ReadProjectiles( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
int count;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < count; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int id;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &id, sizeof( id ) );
|
|
|
|
SSDProjectile* ent = GetSpecificProjectile( id );
|
|
|
|
ent->ReadFromSaveGame( savefile, _game );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
* SSDPowerup
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* powerupMaterials[][2] =
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
"game/SSD/powerupHealthClosed", "game/SSD/powerupHealthOpen",
|
|
|
|
"game/SSD/powerupSuperBlasterClosed", "game/SSD/powerupSuperBlasterOpen",
|
|
|
|
"game/SSD/powerupNukeClosed", "game/SSD/powerupNukeOpen",
|
|
|
|
"game/SSD/powerupRescueClosed", "game/SSD/powerupRescueOpen",
|
|
|
|
"game/SSD/powerupBonusPointsClosed", "game/SSD/powerupBonusPointsOpen",
|
|
|
|
"game/SSD/powerupDamageClosed", "game/SSD/powerupDamageOpen",
|
|
|
|
};
|
|
|
|
|
|
|
|
#define POWERUP_MATERIAL_COUNT 6
|
|
|
|
|
|
|
|
SSDPowerup SSDPowerup::powerupPool[MAX_POWERUPS];
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDPowerup::SSDPowerup()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDPowerup::~SSDPowerup()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPowerup::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
SSDMover::WriteToSaveGame( savefile );
|
|
|
|
|
|
|
|
savefile->Write( &powerupState, sizeof( powerupState ) );
|
|
|
|
savefile->Write( &powerupType, sizeof( powerupType ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPowerup::ReadFromSaveGame( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
|
|
|
SSDMover::ReadFromSaveGame( savefile, _game );
|
|
|
|
|
|
|
|
savefile->Read( &powerupState, sizeof( powerupState ) );
|
|
|
|
savefile->Read( &powerupType, sizeof( powerupType ) );
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPowerup::OnHit( int key )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( powerupState == POWERUP_STATE_CLOSED )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Small explosion to indicate it is opened
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion* explosion = SSDExplosion::GetNewExplosion( game, position, size * 2.0f, 300, SSDExplosion::EXPLOSION_NORMAL, this, false, true );
|
|
|
|
game->entities.Append( explosion );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
powerupState = POWERUP_STATE_OPEN;
|
2012-11-28 15:47:07 +00:00
|
|
|
SetMaterial( powerupMaterials[powerupType][powerupState] );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Destory the powerup with a big explosion
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion* explosion = SSDExplosion::GetNewExplosion( game, position, size * 2, 300, SSDExplosion::EXPLOSION_NORMAL, this );
|
|
|
|
game->entities.Append( explosion );
|
|
|
|
game->PlaySound( "arcade_explode" );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
noHit = true;
|
|
|
|
noPlayerDamage = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPowerup::OnStrikePlayer()
|
|
|
|
{
|
|
|
|
|
|
|
|
if( powerupState == POWERUP_STATE_OPEN )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//The powerup was open so activate it
|
|
|
|
OnActivatePowerup();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Just destroy the powerup
|
|
|
|
destroyed = true;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPowerup::OnOpenPowerup()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPowerup::OnActivatePowerup()
|
|
|
|
{
|
|
|
|
switch( powerupType )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
case POWERUP_TYPE_HEALTH:
|
2012-11-28 15:47:07 +00:00
|
|
|
{
|
|
|
|
game->AddHealth( 10 );
|
|
|
|
break;
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
case POWERUP_TYPE_SUPER_BLASTER:
|
2012-11-28 15:47:07 +00:00
|
|
|
{
|
|
|
|
game->OnSuperBlaster();
|
|
|
|
break;
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
case POWERUP_TYPE_ASTEROID_NUKE:
|
2012-11-28 15:47:07 +00:00
|
|
|
{
|
|
|
|
game->OnNuke();
|
|
|
|
break;
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
case POWERUP_TYPE_RESCUE_ALL:
|
2012-11-28 15:47:07 +00:00
|
|
|
{
|
|
|
|
game->OnRescueAll();
|
|
|
|
break;
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
case POWERUP_TYPE_BONUS_POINTS:
|
2012-11-28 15:47:07 +00:00
|
|
|
{
|
|
|
|
int points = ( game->random.RandomInt( 5 ) + 1 ) * 100;
|
|
|
|
game->AddScore( this, points );
|
|
|
|
break;
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
case POWERUP_TYPE_DAMAGE:
|
2012-11-28 15:47:07 +00:00
|
|
|
{
|
|
|
|
game->AddDamage( 10 );
|
|
|
|
game->PlaySound( "arcade_explode" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPowerup::Init( idGameSSDWindow* _game, float _speed, float _rotation )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
EntityInit();
|
2012-11-28 15:47:07 +00:00
|
|
|
MoverInit( idVec3( 0, 0, -_speed ), _rotation );
|
|
|
|
|
|
|
|
SetGame( _game );
|
|
|
|
SetSize( idVec2( 200, 200 ) );
|
|
|
|
SetRadius( Max( size.x, size.y ), 0.3f );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
type = SSD_ENTITY_POWERUP;
|
|
|
|
|
|
|
|
idVec3 startPosition;
|
2012-11-28 15:47:07 +00:00
|
|
|
startPosition.x = game->random.RandomInt( V_WIDTH ) - ( V_WIDTH / 2.0f );
|
|
|
|
startPosition.y = game->random.RandomInt( V_HEIGHT ) - ( V_HEIGHT / 2.0f );
|
2012-11-26 18:58:24 +00:00
|
|
|
startPosition.z = ENTITY_START_DIST;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
position = startPosition;
|
|
|
|
//SetPosition(startPosition);
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
powerupState = POWERUP_STATE_CLOSED;
|
2012-11-28 15:47:07 +00:00
|
|
|
powerupType = game->random.RandomInt( POWERUP_TYPE_MAX + 1 );
|
|
|
|
if( powerupType >= POWERUP_TYPE_MAX )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
powerupType = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
/*OutputDebugString(va("Powerup: %d\n", powerupType));
|
|
|
|
if(powerupType == 0) {
|
|
|
|
int x = 0;
|
|
|
|
}*/
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
SetMaterial( powerupMaterials[powerupType][powerupState] );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDPowerup* SSDPowerup::GetNewPowerup( idGameSSDWindow* _game, float _speed, float _rotation )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < MAX_POWERUPS; i++ )
|
|
|
|
{
|
|
|
|
if( !powerupPool[i].inUse )
|
|
|
|
{
|
|
|
|
powerupPool[i].Init( _game, _speed, _rotation );
|
2012-11-26 18:58:24 +00:00
|
|
|
powerupPool[i].inUse = true;
|
|
|
|
return &powerupPool[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDPowerup* SSDPowerup::GetSpecificPowerup( int id )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return &powerupPool[id];
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPowerup::WritePowerups( idFile* savefile )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int count = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < MAX_POWERUPS; i++ )
|
|
|
|
{
|
|
|
|
if( powerupPool[i].inUse )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < MAX_POWERUPS; i++ )
|
|
|
|
{
|
|
|
|
if( powerupPool[i].inUse )
|
|
|
|
{
|
|
|
|
savefile->Write( &( powerupPool[i].id ), sizeof( powerupPool[i].id ) );
|
|
|
|
powerupPool[i].WriteToSaveGame( savefile );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void SSDPowerup::ReadPowerups( idFile* savefile, idGameSSDWindow* _game )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
int count;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &count, sizeof( count ) );
|
|
|
|
for( int i = 0; i < count; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int id;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &id, sizeof( id ) );
|
|
|
|
SSDPowerup* ent = GetSpecificPowerup( id );
|
|
|
|
ent->ReadFromSaveGame( savefile, _game );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*****************************************************************************
|
|
|
|
* idGameSSDWindow
|
|
|
|
****************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
idRandom idGameSSDWindow::random;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idGameSSDWindow::idGameSSDWindow( idUserInterfaceLocal* g ) : idWindow( g )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gui = g;
|
|
|
|
CommonInit();
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idGameSSDWindow::~idGameSSDWindow()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
ResetGameStats();
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::WriteToSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
idWindow::WriteToSaveGame( savefile );
|
|
|
|
|
|
|
|
savefile->Write( &ssdTime, sizeof( ssdTime ) );
|
|
|
|
|
|
|
|
beginLevel.WriteToSaveGame( savefile );
|
|
|
|
resetGame.WriteToSaveGame( savefile );
|
|
|
|
continueGame.WriteToSaveGame( savefile );
|
|
|
|
refreshGuiData.WriteToSaveGame( savefile );
|
|
|
|
|
|
|
|
crosshair.WriteToSaveGame( savefile );
|
|
|
|
savefile->Write( &screenBounds, sizeof( screenBounds ) );
|
|
|
|
|
|
|
|
savefile->Write( &levelCount, sizeof( levelCount ) );
|
|
|
|
for( int i = 0; i < levelCount; i++ )
|
|
|
|
{
|
|
|
|
savefile->Write( &( levelData[i] ), sizeof( SSDLevelData_t ) );
|
|
|
|
savefile->Write( &( asteroidData[i] ), sizeof( SSDAsteroidData_t ) );
|
|
|
|
savefile->Write( &( astronautData[i] ), sizeof( SSDAstronautData_t ) );
|
|
|
|
savefile->Write( &( powerupData[i] ), sizeof( SSDPowerupData_t ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
savefile->Write( &weaponCount, sizeof( weaponCount ) );
|
|
|
|
for( int i = 0; i < weaponCount; i++ )
|
|
|
|
{
|
|
|
|
savefile->Write( &( weaponData[i] ), sizeof( SSDWeaponData_t ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
savefile->Write( &superBlasterTimeout, sizeof( superBlasterTimeout ) );
|
|
|
|
savefile->Write( &gameStats, sizeof( SSDGameStats_t ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Write All Static Entities
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDAsteroid::WriteAsteroids( savefile );
|
|
|
|
SSDAstronaut::WriteAstronauts( savefile );
|
|
|
|
SSDExplosion::WriteExplosions( savefile );
|
|
|
|
SSDPoints::WritePoints( savefile );
|
|
|
|
SSDProjectile::WriteProjectiles( savefile );
|
|
|
|
SSDPowerup::WritePowerups( savefile );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int entCount = entities.Num();
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Write( &entCount, sizeof( entCount ) );
|
|
|
|
for( int i = 0; i < entCount; i++ )
|
|
|
|
{
|
|
|
|
savefile->Write( &( entities[i]->type ), sizeof( entities[i]->type ) );
|
|
|
|
savefile->Write( &( entities[i]->id ), sizeof( entities[i]->id ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::ReadFromSaveGame( idFile* savefile )
|
|
|
|
{
|
|
|
|
idWindow::ReadFromSaveGame( savefile );
|
|
|
|
|
|
|
|
|
|
|
|
savefile->Read( &ssdTime, sizeof( ssdTime ) );
|
|
|
|
|
|
|
|
beginLevel.ReadFromSaveGame( savefile );
|
|
|
|
resetGame.ReadFromSaveGame( savefile );
|
|
|
|
continueGame.ReadFromSaveGame( savefile );
|
|
|
|
refreshGuiData.ReadFromSaveGame( savefile );
|
|
|
|
|
|
|
|
crosshair.ReadFromSaveGame( savefile );
|
|
|
|
savefile->Read( &screenBounds, sizeof( screenBounds ) );
|
|
|
|
|
|
|
|
savefile->Read( &levelCount, sizeof( levelCount ) );
|
|
|
|
for( int i = 0; i < levelCount; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDLevelData_t newLevel;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &newLevel, sizeof( SSDLevelData_t ) );
|
|
|
|
levelData.Append( newLevel );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDAsteroidData_t newAsteroid;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &newAsteroid, sizeof( SSDAsteroidData_t ) );
|
|
|
|
asteroidData.Append( newAsteroid );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDAstronautData_t newAstronaut;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &newAstronaut, sizeof( SSDAstronautData_t ) );
|
|
|
|
astronautData.Append( newAstronaut );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
SSDPowerupData_t newPowerup;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &newPowerup, sizeof( SSDPowerupData_t ) );
|
|
|
|
powerupData.Append( newPowerup );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
savefile->Read( &weaponCount, sizeof( weaponCount ) );
|
|
|
|
for( int i = 0; i < weaponCount; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDWeaponData_t newWeapon;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &newWeapon, sizeof( SSDWeaponData_t ) );
|
|
|
|
weaponData.Append( newWeapon );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &superBlasterTimeout, sizeof( superBlasterTimeout ) );
|
|
|
|
|
|
|
|
savefile->Read( &gameStats, sizeof( SSDGameStats_t ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
//Reset this because it is no longer valid
|
|
|
|
gameStats.levelStats.targetEnt = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
SSDAsteroid::ReadAsteroids( savefile, this );
|
|
|
|
SSDAstronaut::ReadAstronauts( savefile, this );
|
|
|
|
SSDExplosion::ReadExplosions( savefile, this );
|
|
|
|
SSDPoints::ReadPoints( savefile, this );
|
|
|
|
SSDProjectile::ReadProjectiles( savefile, this );
|
|
|
|
SSDPowerup::ReadPowerups( savefile, this );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int entCount;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &entCount, sizeof( entCount ) );
|
|
|
|
|
|
|
|
for( int i = 0; i < entCount; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
int type, id;
|
2012-11-28 15:47:07 +00:00
|
|
|
savefile->Read( &type, sizeof( type ) );
|
|
|
|
savefile->Read( &id, sizeof( id ) );
|
|
|
|
|
|
|
|
SSDEntity* ent = GetSpecificEntity( type, id );
|
|
|
|
if( ent )
|
|
|
|
{
|
|
|
|
entities.Append( ent );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
const char* idGameSSDWindow::HandleEvent( const sysEvent_t* event, bool* updateVisuals )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
// need to call this to allow proper focus and capturing on embedded children
|
|
|
|
const char* ret = idWindow::HandleEvent( event, updateVisuals );
|
|
|
|
|
|
|
|
if( !gameStats.gameRunning )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int key = event->evValue;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( event->evType == SE_KEY )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !event->evValue2 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_MOUSE1 || key == K_MOUSE2 )
|
|
|
|
{
|
|
|
|
FireWeapon( key );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idWinVar* idGameSSDWindow::GetWinVarByName( const char* _name, bool winLookup, drawWin_t** owner )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idWinVar* retVar = NULL;
|
|
|
|
|
|
|
|
if( idStr::Icmp( _name, "beginLevel" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
retVar = &beginLevel;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( idStr::Icmp( _name, "resetGame" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
retVar = &resetGame;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( idStr::Icmp( _name, "continueGame" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
retVar = &continueGame;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "refreshGuiData" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
retVar = &refreshGuiData;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( retVar )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return retVar;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
return idWindow::GetWinVarByName( _name, winLookup, owner );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::Draw( int time, float x, float y )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
//Update the game every frame before drawing
|
|
|
|
UpdateGame();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
RefreshGuiData();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameStats.gameRunning )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ZOrderEntities();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Draw from back to front
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = entities.Num() - 1; i >= 0; i-- )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
entities[i]->Draw();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//The last thing to draw is the crosshair
|
|
|
|
idVec2 cursor;
|
|
|
|
//GetCursor(cursor);
|
|
|
|
cursor.x = gui->CursorX();
|
|
|
|
cursor.y = gui->CursorY();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
crosshair.Draw( cursor );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
bool idGameSSDWindow::ParseInternalVar( const char* _name, idTokenParser* src )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "beginLevel" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
beginLevel = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "resetGame" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
resetGame = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "continueGame" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continueGame = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "refreshGuiData" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
refreshGuiData = src->ParseBool();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "levelcount" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
levelCount = src->ParseInt();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < levelCount; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDLevelData_t newLevel;
|
2012-11-28 15:47:07 +00:00
|
|
|
memset( &newLevel, 0, sizeof( SSDLevelData_t ) );
|
|
|
|
levelData.Append( newLevel );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDAsteroidData_t newAsteroid;
|
2012-11-28 15:47:07 +00:00
|
|
|
memset( &newAsteroid, 0, sizeof( SSDAsteroidData_t ) );
|
|
|
|
asteroidData.Append( newAsteroid );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDAstronautData_t newAstronaut;
|
2012-11-28 15:47:07 +00:00
|
|
|
memset( &newAstronaut, 0, sizeof( SSDAstronautData_t ) );
|
|
|
|
astronautData.Append( newAstronaut );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDPowerupData_t newPowerup;
|
2012-11-28 15:47:07 +00:00
|
|
|
memset( &newPowerup, 0, sizeof( SSDPowerupData_t ) );
|
|
|
|
powerupData.Append( newPowerup );
|
|
|
|
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( idStr::Icmp( _name, "weaponCount" ) == 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
weaponCount = src->ParseInt();
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < weaponCount; i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDWeaponData_t newWeapon;
|
2012-11-28 15:47:07 +00:00
|
|
|
memset( &newWeapon, 0, sizeof( SSDWeaponData_t ) );
|
|
|
|
weaponData.Append( newWeapon );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( idStr::FindText( _name, "leveldata", false ) >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr tempName = _name;
|
2012-11-28 15:47:07 +00:00
|
|
|
int level = atoi( tempName.Right( 2 ) ) - 1;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr levelData;
|
2012-11-28 15:47:07 +00:00
|
|
|
ParseString( src, levelData );
|
|
|
|
ParseLevelData( level, levelData );
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( idStr::FindText( _name, "asteroiddata", false ) >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr tempName = _name;
|
2012-11-28 15:47:07 +00:00
|
|
|
int level = atoi( tempName.Right( 2 ) ) - 1;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr asteroidData;
|
2012-11-28 15:47:07 +00:00
|
|
|
ParseString( src, asteroidData );
|
|
|
|
ParseAsteroidData( level, asteroidData );
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( idStr::FindText( _name, "weapondata", false ) >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr tempName = _name;
|
2012-11-28 15:47:07 +00:00
|
|
|
int weapon = atoi( tempName.Right( 2 ) ) - 1;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr weaponData;
|
2012-11-28 15:47:07 +00:00
|
|
|
ParseString( src, weaponData );
|
|
|
|
ParseWeaponData( weapon, weaponData );
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( idStr::FindText( _name, "astronautdata", false ) >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr tempName = _name;
|
2012-11-28 15:47:07 +00:00
|
|
|
int level = atoi( tempName.Right( 2 ) ) - 1;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr astronautData;
|
2012-11-28 15:47:07 +00:00
|
|
|
ParseString( src, astronautData );
|
|
|
|
ParseAstronautData( level, astronautData );
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( idStr::FindText( _name, "powerupdata", false ) >= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr tempName = _name;
|
2012-11-28 15:47:07 +00:00
|
|
|
int level = atoi( tempName.Right( 2 ) ) - 1;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idStr powerupData;
|
2012-11-28 15:47:07 +00:00
|
|
|
ParseString( src, powerupData );
|
|
|
|
ParsePowerupData( level, powerupData );
|
2012-11-26 18:58:24 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
return idWindow::ParseInternalVar( _name, src );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::ParseLevelData( int level, const idStr& levelDataString )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idParser parser;
|
|
|
|
idToken token;
|
2012-11-28 15:47:07 +00:00
|
|
|
parser.LoadMemory( levelDataString.c_str(), levelDataString.Length(), "LevelData" );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
levelData[level].spawnBuffer = parser.ParseFloat();
|
|
|
|
levelData[level].needToWin = parser.ParseInt(); //Required Destroyed
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::ParseAsteroidData( int level, const idStr& asteroidDataString )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idParser parser;
|
|
|
|
idToken token;
|
2012-11-28 15:47:07 +00:00
|
|
|
parser.LoadMemory( asteroidDataString.c_str(), asteroidDataString.Length(), "AsteroidData" );
|
|
|
|
|
|
|
|
asteroidData[level].speedMin = parser.ParseFloat(); //Speed Min
|
2012-11-26 18:58:24 +00:00
|
|
|
asteroidData[level].speedMax = parser.ParseFloat(); //Speed Max
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
asteroidData[level].sizeMin = parser.ParseFloat(); //Size Min
|
2012-11-26 18:58:24 +00:00
|
|
|
asteroidData[level].sizeMax = parser.ParseFloat(); //Size Max
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
asteroidData[level].rotateMin = parser.ParseFloat(); //Rotate Min (rotations per second)
|
2012-11-26 18:58:24 +00:00
|
|
|
asteroidData[level].rotateMax = parser.ParseFloat(); //Rotate Max (rotations per second)
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
asteroidData[level].spawnMin = parser.ParseInt(); //Spawn Min
|
|
|
|
asteroidData[level].spawnMax = parser.ParseInt(); //Spawn Max
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
asteroidData[level].asteroidHealth = parser.ParseInt(); //Health of the asteroid
|
|
|
|
asteroidData[level].asteroidDamage = parser.ParseInt(); //Asteroid Damage
|
|
|
|
asteroidData[level].asteroidPoints = parser.ParseInt(); //Points awarded for destruction
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::ParsePowerupData( int level, const idStr& powerupDataString )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idParser parser;
|
|
|
|
idToken token;
|
2012-11-28 15:47:07 +00:00
|
|
|
parser.LoadMemory( powerupDataString.c_str(), powerupDataString.Length(), "PowerupData" );
|
|
|
|
|
|
|
|
powerupData[level].speedMin = parser.ParseFloat(); //Speed Min
|
2012-11-26 18:58:24 +00:00
|
|
|
powerupData[level].speedMax = parser.ParseFloat(); //Speed Max
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
powerupData[level].rotateMin = parser.ParseFloat(); //Rotate Min (rotations per second)
|
2012-11-26 18:58:24 +00:00
|
|
|
powerupData[level].rotateMax = parser.ParseFloat(); //Rotate Max (rotations per second)
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
powerupData[level].spawnMin = parser.ParseInt(); //Spawn Min
|
|
|
|
powerupData[level].spawnMax = parser.ParseInt(); //Spawn Max
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::ParseWeaponData( int weapon, const idStr& weaponDataString )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idParser parser;
|
|
|
|
idToken token;
|
2012-11-28 15:47:07 +00:00
|
|
|
parser.LoadMemory( weaponDataString.c_str(), weaponDataString.Length(), "WeaponData" );
|
|
|
|
|
|
|
|
weaponData[weapon].speed = parser.ParseFloat();
|
2012-11-26 18:58:24 +00:00
|
|
|
weaponData[weapon].damage = parser.ParseFloat();
|
|
|
|
weaponData[weapon].size = parser.ParseFloat();
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::ParseAstronautData( int level, const idStr& astronautDataString )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idParser parser;
|
|
|
|
idToken token;
|
2012-11-28 15:47:07 +00:00
|
|
|
parser.LoadMemory( astronautDataString.c_str(), astronautDataString.Length(), "AstronautData" );
|
|
|
|
|
|
|
|
astronautData[level].speedMin = parser.ParseFloat(); //Speed Min
|
2012-11-26 18:58:24 +00:00
|
|
|
astronautData[level].speedMax = parser.ParseFloat(); //Speed Max
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
astronautData[level].rotateMin = parser.ParseFloat(); //Rotate Min (rotations per second)
|
2012-11-26 18:58:24 +00:00
|
|
|
astronautData[level].rotateMax = parser.ParseFloat(); //Rotate Max (rotations per second)
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
astronautData[level].spawnMin = parser.ParseInt(); //Spawn Min
|
|
|
|
astronautData[level].spawnMax = parser.ParseInt(); //Spawn Max
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
astronautData[level].health = parser.ParseInt(); //Health of the asteroid
|
|
|
|
astronautData[level].points = parser.ParseInt(); //Asteroid Damage
|
|
|
|
astronautData[level].penalty = parser.ParseInt(); //Points awarded for destruction
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::CommonInit()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
crosshair.InitCrosshairs();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
beginLevel = false;
|
|
|
|
resetGame = false;
|
|
|
|
continueGame = false;
|
|
|
|
refreshGuiData = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ssdTime = 0;
|
|
|
|
levelCount = 0;
|
|
|
|
weaponCount = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
screenBounds = idBounds( idVec3( -320, -240, 0 ), idVec3( 320, 240, 0 ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
superBlasterTimeout = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
currentSound = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Precahce all assets that are loaded dynamically
|
2012-11-28 15:47:07 +00:00
|
|
|
declManager->FindMaterial( ASTEROID_MATERIAL );
|
|
|
|
declManager->FindMaterial( ASTRONAUT_MATERIAL );
|
|
|
|
|
|
|
|
for( int i = 0; i < EXPLOSION_MATERIAL_COUNT; i++ )
|
|
|
|
{
|
|
|
|
declManager->FindMaterial( explosionMaterials[i] );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
declManager->FindMaterial( PROJECTILE_MATERIAL );
|
|
|
|
for( int i = 0; i < POWERUP_MATERIAL_COUNT; i++ )
|
|
|
|
{
|
|
|
|
declManager->FindMaterial( powerupMaterials[i][0] );
|
|
|
|
declManager->FindMaterial( powerupMaterials[i][1] );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Precache sounds
|
|
|
|
declManager->FindSound( "arcade_blaster" );
|
|
|
|
declManager->FindSound( "arcade_capture" );
|
|
|
|
declManager->FindSound( "arcade_explode" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ResetGameStats();
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::ResetGameStats()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
ResetEntities();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Reset the gamestats structure
|
2012-11-28 15:47:07 +00:00
|
|
|
memset( &gameStats, 0, sizeof( gameStats ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.health = 100;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::ResetLevelStats()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
ResetEntities();
|
|
|
|
|
|
|
|
//Reset the level statistics structure
|
2012-11-28 15:47:07 +00:00
|
|
|
memset( &gameStats.levelStats, 0, sizeof( gameStats.levelStats ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::ResetEntities()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Destroy all of the entities
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < entities.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
entities[i]->DestroyEntity();
|
|
|
|
}
|
|
|
|
entities.Clear();
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::StartGame()
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.gameRunning = true;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::StopGame()
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.gameRunning = false;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::GameOver()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
StopGame();
|
|
|
|
|
|
|
|
gui->HandleNamedEvent( "gameOver" );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::BeginLevel( int level )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
ResetLevelStats();
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.currentLevel = level;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
StartGame();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Continue game resets the players health
|
|
|
|
*/
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::ContinueGame()
|
|
|
|
{
|
|
|
|
gameStats.health = 100;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
StartGame();
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::LevelComplete()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
gameStats.prebonusscore = gameStats.score;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
// Add the bonuses
|
|
|
|
int accuracy;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !gameStats.levelStats.shotCount )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
accuracy = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
accuracy = ( int )( ( ( float )gameStats.levelStats.hitCount / ( float )gameStats.levelStats.shotCount ) * 100.0f );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
int accuracyPoints = Max( 0, accuracy - 50 ) * 20;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
gui->SetStateString( "player_accuracy_score", va( "%i", accuracyPoints ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.score += accuracyPoints;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
int saveAccuracy;
|
|
|
|
int totalAst = gameStats.levelStats.savedAstronauts + gameStats.levelStats.killedAstronauts;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !totalAst )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
saveAccuracy = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
saveAccuracy = ( int )( ( ( float )gameStats.levelStats.savedAstronauts / ( float )totalAst ) * 100.0f );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
accuracyPoints = Max( 0, saveAccuracy - 50 ) * 20;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
gui->SetStateString( "save_accuracy_score", va( "%i", accuracyPoints ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.score += accuracyPoints;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
StopSuperBlaster();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.nextLevel++;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameStats.nextLevel >= levelCount )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Have they beaten the game
|
|
|
|
GameComplete();
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Make sure we don't go above the levelcount
|
|
|
|
//min(gameStats.nextLevel, levelCount-1);
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
StopGame();
|
2012-11-28 15:47:07 +00:00
|
|
|
gui->HandleNamedEvent( "levelComplete" );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::GameComplete()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
StopGame();
|
2012-11-28 15:47:07 +00:00
|
|
|
gui->HandleNamedEvent( "gameComplete" );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::UpdateGame()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
//Check to see if and functions where called by the gui
|
2012-11-28 15:47:07 +00:00
|
|
|
if( beginLevel == true )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
beginLevel = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
BeginLevel( gameStats.nextLevel );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( resetGame == true )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
resetGame = false;
|
|
|
|
ResetGameStats();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( continueGame == true )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
continueGame = false;
|
|
|
|
ContinueGame();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
if( refreshGuiData == true )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
refreshGuiData = false;
|
|
|
|
RefreshGuiData();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameStats.gameRunning )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//We assume an upate every 16 milliseconds
|
|
|
|
ssdTime += 16;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( superBlasterTimeout && ssdTime > superBlasterTimeout )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
StopSuperBlaster();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Find if we are targeting and enemy
|
|
|
|
idVec2 cursor;
|
|
|
|
//GetCursor(cursor);
|
|
|
|
cursor.x = gui->CursorX();
|
|
|
|
cursor.y = gui->CursorY();
|
2012-11-28 15:47:07 +00:00
|
|
|
gameStats.levelStats.targetEnt = EntityHitTest( cursor );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Update from back to front
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = entities.Num() - 1; i >= 0; i-- )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
entities[i]->Update();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
CheckForHits();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Delete entities that need to be deleted
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = entities.Num() - 1; i >= 0; i-- )
|
|
|
|
{
|
|
|
|
if( entities[i]->destroyed )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDEntity* ent = entities[i];
|
|
|
|
ent->DestroyEntity();
|
2012-11-28 15:47:07 +00:00
|
|
|
entities.RemoveIndex( i );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Check if we can spawn an asteroid
|
|
|
|
SpawnAsteroid();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Check if we should spawn an astronaut
|
|
|
|
SpawnAstronaut();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Check if we should spawn an asteroid
|
|
|
|
SpawnPowerup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::CheckForHits()
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//See if the entity has gotten close enough
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < entities.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDEntity* ent = entities[i];
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ent->position.z <= Z_NEAR )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( !ent->noPlayerDamage )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Is the object still in the screen
|
|
|
|
idVec3 entPos = ent->position;
|
|
|
|
entPos.z = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
idBounds entBounds( entPos );
|
|
|
|
entBounds.ExpandSelf( ent->hitRadius );
|
|
|
|
|
|
|
|
if( screenBounds.IntersectsBounds( entBounds ) )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
ent->OnStrikePlayer();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//The entity hit the player figure out what is was and act appropriately
|
2012-11-28 15:47:07 +00:00
|
|
|
if( ent->type == SSD_ENTITY_ASTEROID )
|
|
|
|
{
|
|
|
|
AsteroidStruckPlayer( static_cast<SSDAsteroid*>( ent ) );
|
|
|
|
}
|
|
|
|
else if( ent->type == SSD_ENTITY_ASTRONAUT )
|
|
|
|
{
|
|
|
|
AstronautStruckPlayer( static_cast<SSDAstronaut*>( ent ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Tag for removal later in the frame
|
|
|
|
ent->destroyed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::ZOrderEntities()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Z-Order the entities
|
|
|
|
//Using a simple sorting method
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = entities.Num() - 1; i >= 0; i-- )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
bool flipped = false;
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int j = 0; j < i ; j++ )
|
|
|
|
{
|
|
|
|
if( entities[j]->position.z > entities[j + 1]->position.z )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDEntity* ent = entities[j];
|
2012-11-28 15:47:07 +00:00
|
|
|
entities[j] = entities[j + 1];
|
|
|
|
entities[j + 1] = ent;
|
|
|
|
flipped = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( !flipped )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Jump out because it is sorted
|
2012-11-28 15:47:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::SpawnAsteroid()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
int currentTime = ssdTime;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( currentTime < gameStats.levelStats.nextAsteroidSpawnTime )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Not time yet
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Lets spawn it
|
|
|
|
idVec3 startPosition;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
float spawnBuffer = levelData[gameStats.currentLevel].spawnBuffer * 2.0f;
|
|
|
|
startPosition.x = random.RandomInt( V_WIDTH + spawnBuffer ) - ( ( V_WIDTH / 2.0f ) + spawnBuffer );
|
|
|
|
startPosition.y = random.RandomInt( V_HEIGHT + spawnBuffer ) - ( ( V_HEIGHT / 2.0f ) + spawnBuffer );
|
2012-11-26 18:58:24 +00:00
|
|
|
startPosition.z = ENTITY_START_DIST;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
float speed = random.RandomInt( asteroidData[gameStats.currentLevel].speedMax - asteroidData[gameStats.currentLevel].speedMin ) + asteroidData[gameStats.currentLevel].speedMin;
|
|
|
|
float size = random.RandomInt( asteroidData[gameStats.currentLevel].sizeMax - asteroidData[gameStats.currentLevel].sizeMin ) + asteroidData[gameStats.currentLevel].sizeMin;
|
|
|
|
float rotate = ( random.RandomFloat() * ( asteroidData[gameStats.currentLevel].rotateMax - asteroidData[gameStats.currentLevel].rotateMin ) ) + asteroidData[gameStats.currentLevel].rotateMin;
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDAsteroid* asteroid = SSDAsteroid::GetNewAsteroid( this, startPosition, idVec2( size, size ), speed, rotate, asteroidData[gameStats.currentLevel].asteroidHealth );
|
|
|
|
entities.Append( asteroid );
|
|
|
|
|
|
|
|
gameStats.levelStats.nextAsteroidSpawnTime = currentTime + random.RandomInt( asteroidData[gameStats.currentLevel].spawnMax - asteroidData[gameStats.currentLevel].spawnMin ) + asteroidData[gameStats.currentLevel].spawnMin;
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::FireWeapon( int key )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
idVec2 cursorWorld = GetCursorWorld();
|
|
|
|
idVec2 cursor;
|
|
|
|
//GetCursor(cursor);
|
|
|
|
cursor.x = gui->CursorX();
|
|
|
|
cursor.y = gui->CursorY();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( key == K_MOUSE1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
gameStats.levelStats.shotCount++;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( gameStats.levelStats.targetEnt )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Aim the projectile from the bottom of the screen directly at the ent
|
|
|
|
//SSDProjectile* newProj = new (TAG_OLD_UI) SSDProjectile(this, idVec3(320,0,0), gameStats.levelStats.targetEnt->position, weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size);
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDProjectile* newProj = SSDProjectile::GetNewProjectile( this, idVec3( 0, -180, 0 ), gameStats.levelStats.targetEnt->position, weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size );
|
|
|
|
entities.Append( newProj );
|
2012-11-26 18:58:24 +00:00
|
|
|
//newProj = SSDProjectile::GetNewProjectile(this, idVec3(-320,-0,0), gameStats.levelStats.targetEnt->position, weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size);
|
|
|
|
//entities.Append(newProj);
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//We hit something
|
|
|
|
gameStats.levelStats.hitCount++;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
gameStats.levelStats.targetEnt->OnHit( key );
|
|
|
|
|
|
|
|
if( gameStats.levelStats.targetEnt->type == SSD_ENTITY_ASTEROID )
|
|
|
|
{
|
|
|
|
HitAsteroid( static_cast<SSDAsteroid*>( gameStats.levelStats.targetEnt ), key );
|
|
|
|
}
|
|
|
|
else if( gameStats.levelStats.targetEnt->type == SSD_ENTITY_ASTRONAUT )
|
|
|
|
{
|
|
|
|
HitAstronaut( static_cast<SSDAstronaut*>( gameStats.levelStats.targetEnt ), key );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
////Aim the projectile at the cursor position all the way to the far clipping
|
|
|
|
//SSDProjectile* newProj = SSDProjectile::GetNewProjectile(this, idVec3(0,-180,0), idVec3(cursorWorld.x, cursorWorld.y, (Z_FAR-Z_NEAR)/2.0f), weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size);
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Aim the projectile so it crosses the cursor 1/4 of screen
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec3 vec = idVec3( cursorWorld.x, cursorWorld.y, ( Z_FAR - Z_NEAR ) / 8.0f );
|
2012-11-26 18:58:24 +00:00
|
|
|
vec *= 8;
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDProjectile* newProj = SSDProjectile::GetNewProjectile( this, idVec3( 0, -180, 0 ), vec, weaponData[gameStats.currentWeapon].speed, weaponData[gameStats.currentWeapon].size );
|
|
|
|
entities.Append( newProj );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Play the blaster sound
|
2012-11-28 15:47:07 +00:00
|
|
|
PlaySound( "arcade_blaster" );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
} /*else if (key == K_MOUSE2) {
|
|
|
|
if(gameStats.levelStats.targetEnt) {
|
|
|
|
if(gameStats.levelStats.targetEnt->type == SSD_ENTITY_ASTRONAUT) {
|
|
|
|
HitAstronaut(static_cast<SSDAstronaut*>(gameStats.levelStats.targetEnt), key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDEntity* idGameSSDWindow::EntityHitTest( const idVec2& pt )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0; i < entities.Num(); i++ )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Since we ZOrder the entities every frame we can stop at the first entity we hit.
|
|
|
|
//ToDo: Make sure this assumption is true
|
2012-11-28 15:47:07 +00:00
|
|
|
if( entities[i]->HitTest( pt ) )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
return entities[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::HitAsteroid( SSDAsteroid* asteroid, int key )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
asteroid->health -= weaponData[gameStats.currentWeapon].damage;
|
|
|
|
|
|
|
|
if( asteroid->health <= 0 )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//The asteroid has been destroyed
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion* explosion = SSDExplosion::GetNewExplosion( this, asteroid->position, asteroid->size * 2, 300, SSDExplosion::EXPLOSION_NORMAL, asteroid );
|
|
|
|
entities.Append( explosion );
|
|
|
|
PlaySound( "arcade_explode" );
|
|
|
|
|
|
|
|
AddScore( asteroid, asteroidData[gameStats.currentLevel].asteroidPoints );
|
|
|
|
|
|
|
|
//Don't let the player hit it anymore because
|
2012-11-26 18:58:24 +00:00
|
|
|
asteroid->noHit = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.levelStats.destroyedAsteroids++;
|
|
|
|
//if(gameStats.levelStats.destroyedAsteroids >= levelData[gameStats.currentLevel].needToWin) {
|
|
|
|
// LevelComplete();
|
|
|
|
//}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//This was a damage hit so create a real small quick explosion
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion* explosion = SSDExplosion::GetNewExplosion( this, asteroid->position, asteroid->size / 2.0f, 200, SSDExplosion::EXPLOSION_NORMAL, asteroid, false, false );
|
|
|
|
entities.Append( explosion );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::AsteroidStruckPlayer( SSDAsteroid* asteroid )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
asteroid->noPlayerDamage = true;
|
|
|
|
asteroid->noHit = true;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
AddDamage( asteroidData[gameStats.currentLevel].asteroidDamage );
|
|
|
|
|
|
|
|
SSDExplosion* explosion = SSDExplosion::GetNewExplosion( this, asteroid->position, asteroid->size * 2, 300, SSDExplosion::EXPLOSION_NORMAL, asteroid );
|
|
|
|
entities.Append( explosion );
|
|
|
|
PlaySound( "arcade_explode" );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::AddScore( SSDEntity* ent, int points )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
SSDPoints* pointsEnt;
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( points > 0 )
|
|
|
|
{
|
|
|
|
pointsEnt = SSDPoints::GetNewPoints( this, ent, points, 1000, 50, idVec4( 0, 1, 0, 1 ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
pointsEnt = SSDPoints::GetNewPoints( this, ent, points, 1000, 50, idVec4( 1, 0, 0, 1 ) );
|
|
|
|
}
|
|
|
|
entities.Append( pointsEnt );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.score += points;
|
2012-11-28 15:47:07 +00:00
|
|
|
gui->SetStateString( "player_score", va( "%i", gameStats.score ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::AddDamage( int damage )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.health -= damage;
|
2012-11-28 15:47:07 +00:00
|
|
|
gui->SetStateString( "player_health", va( "%i", gameStats.health ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gui->HandleNamedEvent( "playerDamage" );
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( gameStats.health <= 0 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//The player is dead
|
|
|
|
GameOver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::AddHealth( int health )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.health += health;
|
|
|
|
gameStats.health = Min( 100, gameStats.health );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::OnNuke()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
gui->HandleNamedEvent( "nuke" );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Destory All Asteroids
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0 ; i < entities.Num(); i++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( entities[i]->type == SSD_ENTITY_ASTEROID )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//The asteroid has been destroyed
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion* explosion = SSDExplosion::GetNewExplosion( this, entities[i]->position, entities[i]->size * 2, 300, SSDExplosion::EXPLOSION_NORMAL, entities[i] );
|
|
|
|
entities.Append( explosion );
|
|
|
|
|
|
|
|
AddScore( entities[i], asteroidData[gameStats.currentLevel].asteroidPoints );
|
|
|
|
|
|
|
|
//Don't let the player hit it anymore because
|
2012-11-26 18:58:24 +00:00
|
|
|
entities[i]->noHit = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.levelStats.destroyedAsteroids++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
PlaySound( "arcade_explode" );
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
//Check to see if a nuke ends the level
|
|
|
|
/*if(gameStats.levelStats.destroyedAsteroids >= levelData[gameStats.currentLevel].needToWin) {
|
|
|
|
LevelComplete();
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::OnRescueAll()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
gui->HandleNamedEvent( "rescueAll" );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Rescue All Astronauts
|
2012-11-28 15:47:07 +00:00
|
|
|
for( int i = 0 ; i < entities.Num(); i++ )
|
|
|
|
{
|
|
|
|
|
|
|
|
if( entities[i]->type == SSD_ENTITY_ASTRONAUT )
|
|
|
|
{
|
|
|
|
|
|
|
|
AstronautStruckPlayer( ( SSDAstronaut* )entities[i] );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::OnSuperBlaster()
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
StartSuperBlaster();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::RefreshGuiData()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
gui->SetStateString( "nextLevel", va( "%i", gameStats.nextLevel + 1 ) );
|
|
|
|
gui->SetStateString( "currentLevel", va( "%i", gameStats.currentLevel + 1 ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
float accuracy;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( !gameStats.levelStats.shotCount )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
accuracy = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
accuracy = ( ( float )gameStats.levelStats.hitCount / ( float )gameStats.levelStats.shotCount ) * 100.0f;
|
|
|
|
}
|
|
|
|
gui->SetStateString( "player_accuracy", va( "%d%%", ( int )accuracy ) );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
float saveAccuracy;
|
|
|
|
int totalAst = gameStats.levelStats.savedAstronauts + gameStats.levelStats.killedAstronauts;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( !totalAst )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
saveAccuracy = 0;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
saveAccuracy = ( ( float )gameStats.levelStats.savedAstronauts / ( float )totalAst ) * 100.0f;
|
|
|
|
}
|
|
|
|
gui->SetStateString( "save_accuracy", va( "%d%%", ( int )saveAccuracy ) );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( gameStats.levelStats.targetEnt )
|
|
|
|
{
|
|
|
|
int dist = ( gameStats.levelStats.targetEnt->position.z / 100.0f );
|
2012-11-26 18:58:24 +00:00
|
|
|
dist *= 100;
|
2012-11-28 15:47:07 +00:00
|
|
|
gui->SetStateString( "target_info", va( "%i meters", dist ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
gui->SetStateString( "target_info", "No Target" );
|
|
|
|
}
|
|
|
|
|
|
|
|
gui->SetStateString( "player_health", va( "%i", gameStats.health ) );
|
|
|
|
gui->SetStateString( "player_score", va( "%i", gameStats.score ) );
|
|
|
|
gui->SetStateString( "player_prebonusscore", va( "%i", gameStats.prebonusscore ) );
|
|
|
|
gui->SetStateString( "level_complete", va( "%i/%i", gameStats.levelStats.savedAstronauts, levelData[gameStats.currentLevel].needToWin ) );
|
|
|
|
|
|
|
|
|
|
|
|
if( superBlasterTimeout )
|
|
|
|
{
|
|
|
|
float timeRemaining = ( superBlasterTimeout - ssdTime ) / 1000.0f;
|
|
|
|
gui->SetStateString( "super_blaster_time", va( "%.2f", timeRemaining ) );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
idVec2 idGameSSDWindow::GetCursorWorld()
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
idVec2 cursor;
|
|
|
|
//GetCursor(cursor);
|
|
|
|
cursor.x = gui->CursorX();
|
|
|
|
cursor.y = gui->CursorY();
|
|
|
|
cursor.x = cursor.x - 0.5f * V_WIDTH;
|
2012-11-28 15:47:07 +00:00
|
|
|
cursor.y = -( cursor.y - 0.5f * V_HEIGHT );
|
2012-11-26 18:58:24 +00:00
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::SpawnAstronaut()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
int currentTime = ssdTime;
|
|
|
|
|
|
|
|
if( currentTime < gameStats.levelStats.nextAstronautSpawnTime )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Not time yet
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Lets spawn it
|
|
|
|
idVec3 startPosition;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
startPosition.x = random.RandomInt( V_WIDTH ) - ( V_WIDTH / 2.0f );
|
|
|
|
startPosition.y = random.RandomInt( V_HEIGHT ) - ( V_HEIGHT / 2.0f );
|
2012-11-26 18:58:24 +00:00
|
|
|
startPosition.z = ENTITY_START_DIST;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
float speed = random.RandomInt( astronautData[gameStats.currentLevel].speedMax - astronautData[gameStats.currentLevel].speedMin ) + astronautData[gameStats.currentLevel].speedMin;
|
|
|
|
float rotate = ( random.RandomFloat() * ( astronautData[gameStats.currentLevel].rotateMax - astronautData[gameStats.currentLevel].rotateMin ) ) + astronautData[gameStats.currentLevel].rotateMin;
|
|
|
|
|
|
|
|
SSDAstronaut* astronaut = SSDAstronaut::GetNewAstronaut( this, startPosition, speed, rotate, astronautData[gameStats.currentLevel].health );
|
|
|
|
entities.Append( astronaut );
|
|
|
|
|
|
|
|
gameStats.levelStats.nextAstronautSpawnTime = currentTime + random.RandomInt( astronautData[gameStats.currentLevel].spawnMax - astronautData[gameStats.currentLevel].spawnMin ) + astronautData[gameStats.currentLevel].spawnMin;
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::HitAstronaut( SSDAstronaut* astronaut, int key )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
if( key == K_MOUSE1 )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
astronaut->health -= weaponData[gameStats.currentWeapon].damage;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( astronaut->health <= 0 )
|
|
|
|
{
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.levelStats.killedAstronauts++;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//The astronaut has been destroyed
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion* explosion = SSDExplosion::GetNewExplosion( this, astronaut->position, astronaut->size * 2, 300, SSDExplosion::EXPLOSION_NORMAL, astronaut );
|
|
|
|
entities.Append( explosion );
|
|
|
|
PlaySound( "arcade_explode" );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Add the penalty for killing the astronaut
|
2012-11-28 15:47:07 +00:00
|
|
|
AddScore( astronaut, astronautData[gameStats.currentLevel].penalty );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Don't let the player hit it anymore
|
|
|
|
astronaut->noHit = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//This was a damage hit so create a real small quick explosion
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion* explosion = SSDExplosion::GetNewExplosion( this, astronaut->position, astronaut->size / 2.0f, 200, SSDExplosion::EXPLOSION_NORMAL, astronaut, false, false );
|
|
|
|
entities.Append( explosion );
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::AstronautStruckPlayer( SSDAstronaut* astronaut )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
gameStats.levelStats.savedAstronauts++;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
astronaut->noPlayerDamage = true;
|
|
|
|
astronaut->noHit = true;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//We are saving an astronaut
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDExplosion* explosion = SSDExplosion::GetNewExplosion( this, astronaut->position, astronaut->size * 2, 300, SSDExplosion::EXPLOSION_TELEPORT, astronaut );
|
|
|
|
entities.Append( explosion );
|
|
|
|
PlaySound( "arcade_capture" );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
//Give the player points for saving the astronaut
|
2012-11-28 15:47:07 +00:00
|
|
|
AddScore( astronaut, astronautData[gameStats.currentLevel].points );
|
|
|
|
|
|
|
|
if( gameStats.levelStats.savedAstronauts >= levelData[gameStats.currentLevel].needToWin )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
LevelComplete();
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::SpawnPowerup()
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
|
|
|
int currentTime = ssdTime;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
if( currentTime < gameStats.levelStats.nextPowerupSpawnTime )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
//Not time yet
|
|
|
|
return;
|
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
|
|
|
|
float speed = random.RandomInt( powerupData[gameStats.currentLevel].speedMax - powerupData[gameStats.currentLevel].speedMin ) + powerupData[gameStats.currentLevel].speedMin;
|
|
|
|
float rotate = ( random.RandomFloat() * ( powerupData[gameStats.currentLevel].rotateMax - powerupData[gameStats.currentLevel].rotateMin ) ) + powerupData[gameStats.currentLevel].rotateMin;
|
|
|
|
|
|
|
|
SSDPowerup* powerup = SSDPowerup::GetNewPowerup( this, speed, rotate );
|
|
|
|
entities.Append( powerup );
|
|
|
|
|
|
|
|
gameStats.levelStats.nextPowerupSpawnTime = currentTime + random.RandomInt( powerupData[gameStats.currentLevel].spawnMax - powerupData[gameStats.currentLevel].spawnMin ) + powerupData[gameStats.currentLevel].spawnMin;
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::StartSuperBlaster()
|
|
|
|
{
|
|
|
|
|
|
|
|
gui->HandleNamedEvent( "startSuperBlaster" );
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.currentWeapon = 1;
|
|
|
|
superBlasterTimeout = ssdTime + 10000;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::StopSuperBlaster()
|
|
|
|
{
|
|
|
|
gui->HandleNamedEvent( "stopSuperBlaster" );
|
2012-11-26 18:58:24 +00:00
|
|
|
gameStats.currentWeapon = 0;
|
|
|
|
superBlasterTimeout = 0;
|
2012-11-28 15:47:07 +00:00
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
SSDEntity* idGameSSDWindow::GetSpecificEntity( int type, int id )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
SSDEntity* ent = NULL;
|
2012-11-28 15:47:07 +00:00
|
|
|
switch( type )
|
|
|
|
{
|
|
|
|
case SSD_ENTITY_ASTEROID:
|
|
|
|
ent = SSDAsteroid::GetSpecificAsteroid( id );
|
|
|
|
break;
|
|
|
|
case SSD_ENTITY_ASTRONAUT:
|
|
|
|
ent = SSDAstronaut::GetSpecificAstronaut( id );
|
|
|
|
break;
|
|
|
|
case SSD_ENTITY_EXPLOSION:
|
|
|
|
ent = SSDExplosion::GetSpecificExplosion( id );
|
|
|
|
break;
|
|
|
|
case SSD_ENTITY_POINTS:
|
|
|
|
ent = SSDPoints::GetSpecificPoints( id );
|
|
|
|
break;
|
|
|
|
case SSD_ENTITY_PROJECTILE:
|
|
|
|
ent = SSDProjectile::GetSpecificProjectile( id );
|
|
|
|
break;
|
|
|
|
case SSD_ENTITY_POWERUP:
|
|
|
|
ent = SSDPowerup::GetSpecificPowerup( id );
|
|
|
|
break;
|
2012-11-26 18:58:24 +00:00
|
|
|
}
|
|
|
|
return ent;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_SOUND_CHANNEL 8
|
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
void idGameSSDWindow::PlaySound( const char* sound )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
|
2012-11-28 15:47:07 +00:00
|
|
|
common->SW()->PlayShaderDirectly( sound, currentSound );
|
|
|
|
|
2012-11-26 18:58:24 +00:00
|
|
|
currentSound++;
|
2012-11-28 15:47:07 +00:00
|
|
|
if( currentSound >= MAX_SOUND_CHANNEL )
|
|
|
|
{
|
2012-11-26 18:58:24 +00:00
|
|
|
currentSound = 0;
|
|
|
|
}
|
|
|
|
}
|