Show GameConstants.pas syntax highlighted
//*******************************//
// //
// Strange Game Engine Constants //
// //
//******************//*******************************//*********************//
// //
// This unit is the part of a real time 3d space strategy engine //
// (www.federation.netfirms.com) //
// //
//**************************************************************************//
{
Author : Alexander Federyakov aka Da Stranger
Version : 0.001 ;-]
Date : 02 December '2005
License : You can use this unit ONLY for educational purposes. You cannot use
more than 10% of its code in your own personal projects. It cannot
be used for any commercial products.
Comments: This is the core of a 3d realtime space strategy game engine.
Much is still to be done...
Requirements: GLScene
Known Bugs and limitations: none
Contacts:
Web: http://www.sector-37.com
E-mail: datarget@mail.ru
ICQ: 293-963-070
Odigo: 8077227
}
unit GameConstants;
interface
uses StrangeIniFiles,SysUtils,Dialogs,jpg,
VectorTypes, VectorGeometry, GLTexture, GLThorFX;
const
//Global variable PARAMETERS (can be loaded from ini)
// used for myRandom function
// why don't I use standart Random? Because I use this function to determine
// waypoints and positions of objects, which all MUST be the same, when playing
// on the net with other people. Both players will have the same result, when
// calling this function. And my function is really fast too ;)
RANDOM_ARRAY: array[0..200] of single=(0.52,0.03,0.51,0.97,0,0.8,0.68,0.87,0.51,0.68,0.71,0.44,0.26,0.71,0.04,0.23,0.38,0.05,0.89,0.95,0.43,0.31,
0.22,0.54,0.72,0.83,0.53,0.49,0.82,0.04,0.16,0.13,0.04,0.24,0.6,0.89,0.58,0.44,0.24,0.78,0.83,0.13,0.49,
0.49,0.91,0.05,0.11,0.96,0.41,0.3,0.3,0.33,0.05,0.51,0.84,0.51,0.57,0.77,0.34,0.9,0.14,0.61,0.36,0.94,0.08,
0.18,0.01,0.49,0.78,0.47,0.25,0.3,0.93,0.21,0,0.05,0.55,0.73,0.83,0.61,0.47,0.05,0.76,0.68,0.21,0.84,0.52,
0.82,0.31,0.04,0.29,0.6,0.79,0.41,0.6,0.35,0.04,0.2,0.28,0.75,0.47,0.62,0.2,0.24,0.76,0.99,0.53,0.95,0.29,
0.66,0.63,0.77,0.44,0.02,0.7,0.56,0.61,0.28,0.04,0.72,0.1,0.85,0.33,0.74,0.47,0.37,0.38,0.17,0.76,0.89,0.24,
0.33,0.72,0.63,0.66,0.81,0.2,0.35,0.19,0.2,0.93,0.28,0.55,0.94,0.64,0.17,0.89,0.18,0.18,0.83,0.25,0.88,0.07,
0.18,0.26,0.64,0.61,0.92,0.74,0.06,0.53,0.11,0.09,0.5,0.81,0.25,0.27,0.6,0.11,0.87,0.95,0.9,0,0.53,0.18,0.48,
0.83,0.76,0.43,0.4,0.06,0.49,0.09,0.32,0.28,0.78,0.69,0.75,0.32,0.02,0.34,0.61,0.11,0.98,0.33,0.18,0.22,0.25,
0.74,0.59,0.29);
MAX_PLAYERS = 16;
CRITICAL_MAX_MULT = 2;
CRITICAL_MIN_MULT = 0.2;
MAX_TARGETS = 50;
MAX_RACES = 20;
MOVED_A_LITTLE_CONST = 5;
CURRENT_HEIGHT_MULTIPLIER = 0.1;
CURSOR_SELECTION_RADIUS = 4;
SHOW_UNIT_MOVEMENT_LINES_FOR = 5; //in seconds
EPS = 0.000001;
CURSOR_NORMAL_COLOR = $00FFF0;
UNIT_ATTACK_MOVE_AWAY_MULTIPLYER = 1.1;
UNIT_ENEMY_EVADE_DISTANCE_MULT = 1.5;
UNIT_SAFE_DIST_AFTER_EVADING_MULT = 3;
UNIT_ATTACK_MAX_ANGLE = 90;
UNIT_MAX_EVADE_ANGLE = 150;
UNIT_MAX_EVADE_ANGLE_NUMBER = 90;
UNIT_REGENERATE_TIME_MULT = 1;
UNIT_EXPLOSIONS_FREQUENCY = 6;
UNIT_STOP_ON_EXPLOSION = False;
UTG_SMALL_SIZE = 4;
UTG_BIG_SIZE = 10;
CAMERA_MOVE_MIN2_DIST = 0.03;
FOLLOW_AND_DEFEND_DISTANCE_MULT_MIN = 3;
FOLLOW_AND_DEFEND_DISTANCE_MULT_MAX = 5;
type
{
raFromBeginning - is in the production/research/upgrade tree of that race)
raCanCapture - not in the ../../.. tree, but can be bought/captured
raNone - race can't produce/research/upgrade/buy at all
}
TSingleRaceAvaibility = (raFromBeginning, raCanCapture, raNone);
TRaceAvaibility = array[0..MAX_RACES - 1] of TSingleRaceAvaibility;
//Diplomacy Matrix consists of cells like that
TDiplomacyData = set of (ddAlly, ddEnemy, ddTradePartner);
//each planet will have to choose in which feild it will specialize.
TPlanetSpecialty = (spEconomy, spResearch, spMining, spTrade, spMillitary, spNone);
TGameObjectType = (gotUnit, gotPlanet, gotArtifact, gotAsteroid, gotComet);
const
//Named Constants (use names instead of numbers)
//************************ BlowUpModelQuality *****************************
BLMQ_HIGH = 0;
BLMQ_MEDIUM = 1;
BLMQ_LOW = 2;
//************************ Mesh Quality *****************************
MQ_HIGH = 0;
MQ_MEDIUM = 1;
MQ_LOW = 2;
//*********************** Explosions Quality ***************************
EQ_HIGH = 0;
EQ_MEDIUM = 1;
EQ_LOW = 2;
//************************ Unit Damage Levels *****************************
DL_LOW = 0;
DL_MEDIUM = 1;
DL_HIGH = 2;
//************************** Cursor types *********************************
// MUST BE > 0 !!!
CUR_MENU = 1; //when the game is created
CUR_NORMAL = 2; //after init and always (the default one)
CUR_ATTACK = 3; //when cursor is over an enemy ship
CUR_FOLLOW_AND_DEFEND = 4; //when cursor is over any non-enemy ship
//************************** Game Object types ****************************
GOT_UNIT = 1;
GOT_PLANET = 2;
GOT_ARTIFACT = 3;
GOT_STATIC_ASTEROID = 4;//will be visible on the map at any case
GOT_INVISIBLE_ASTEROID = 5;//will be visible only if it is on the radar
GOT_MISSILE = 6; //also, will be shown anly if unit sees it
GOT_MODULE = 10;
GOT_ENGINE = 11;
GOT_WEAPON = 12;
//************************** Error Types ********************************
MAX_ERROR_TYPE_NUMBER = 20;
{ErrorLevel Constants}
ERR_PLAYER_SENT_UNITS_OUTSIDE_MAP = 1;
ERR_PLAYER_PLACED_WAYPOINT_OUTSIDE_MAP = 2;
// 1 - debug info
//...
// 4 - can proceed with default (safe) settings
//...
// 6 - can proceed with risk of crashing every second...
ERR_BAD_INI = 7; // 7 - Invalid ini settings. Must quit
ERR_NOT_FOUND = 8;
ERR_TEXTURE_NOT_FOUND = 9;
//10 - dangerous to da OS %))
ERR_EXTERNAL_MODULE = 11; //11 - Erro, called from an external module
ERR_INVALID_PLAYER_SETTINGS = 12; //12 - invalid Player Number/Settings
ERR_UNKNOWN = 13;
ERR_UNVALID_POINT_COUNT = 14;
//************************** Unit Operation Constants ***************************
//Player already gave this command to a unit
OP_STAND = 0; //is turned on after unit completes previous command
OP_MOVE = 1;
OP_ATTACK = 2;
OP_PATROL = 3;
OP_SELL = 4;
OP_EXPLODE = 5;
OP_FOLLOW_AND_DEFEND = 6;
OP_STORAGE_BAY = 7;
OP_MOVE_AND_ATTACK = 8;
OP_MOVE_BY_WAYPOINTS = 9;
OP_FACE_DIRECTION = 10;
OP_DRAW_SELECTION_BOX = 100; //not actually a unit command, but a player intention ;)
// 11 - 99 - rerserved for special attacks ;)...
//************************** Control type ********************************
//CT_NONE = 0;
CT_MOUSE = 1;
CT_KEYBOARD = 2;
CT_JOYSTICK = 3;
//************************** Player type ********************************
// 0 = Player(allscreen)
// 1 = Player(left_screen)
// 2 = Player(right_screen)
// 3 = TCP/IP(allscreen)
// 4 = TCP/IP(left_screen)
// 5 = TCP/IP(right_screen)
// 6-8 AI player from 1(stupid) to 3(smartass)
// 9-11 AI neutral race from 1(stupid) to 3(smartass)
//12-14 AI outside-map-area race
PT_ALL_SCREEN = 0 ;
PT_LEFT_SCREEN = 1 ;
PT_RIGHT_SCREEN = 2;
PT_TCP_ALLSCREEN = 3 ;
PT_TCP_LEFT_SCREEN = 4 ;
PT_TCP_RIGHT_SCREEN = 5 ;
PT_CPU_STUPID = 6 ;
PT_CPU_AVERAGE = 7 ;
PT_CPU_SMARTASS = 8 ;
PT_NEUTRAL_STUPID = 9 ;
PT_NEUTRAL_AVERAGE = 10 ;//these 3 probably won't be used...
PT_NEUTRAL_SMARTASS = 11 ;
PT_OUTSIDE_STUPID = 12 ;
PT_OUTSIDE_AVERAGE = 13 ;
PT_OUTSIDE_SMARTASS = 14 ;
{???????????????????????}
//************************** Research groups ********************************
RG_BIOLOGY=1;
RG_SOSIOLOGY=2;
RG_BONUS=10;
{???????????????????????}
//************************** Resource types ********************************
MAX_RESOURSE_TYPES =50;
//General 0-5
RESOURCE_MONEY = 0;
RESOURCE_ENERGY= 1;
RESOURCE_WATER = 2;
//Metals 10-19
RESOURCE_TI = 10;
RESOURCE_AS = 11;
RESOURCE_W = 12;
//Radioactive 20-29
RESOURCE_RA = 20;
//Non-metal 30-39
RESOURCE_CL = 30;
//treasure 40-49
RESOURE_PT = 40;
//**************************Implementation Groups ********************************
//Only New
IG_BUILDING = 1; //ID = base ID
IG_RESEARCH = 2; //ID = Research ID
IG_UPGRADE = 3; //ID = Upgrade ID
IG_UNIT = 9; //Artifact, which was found, turned out to be a Unit!!!
//ID = UnitType ID
//for New AND Old
IG_UNITTYPE = 10; //ID=unittype ID
IG_WEAPON = 11; //the same...
IG_ENGINE = 12;
IG_MODULE = 13;
IG_SHIELD = 14;
//Only for Old
IG_PLANET = 20; //ID is ignored %-)
//**************************OLD Implementation Parameters *****************************
//unit 1-20
IP_UNIT_SPEED = 1;
//weapon 20-40
IP_WEAPON_POWER = 20;
//engine 40-60
IP_ENGINE_MAX_SPEED = 40;
//module 60-80
IP_MODULE_PARAMETER1 = 60;
//shield 80-100
IP_SHIELD_POWER = 80;
//planet 100-120
IP_PLANET_MAX_POPULATION = 100;
IP_PLANET_POPULATION_INCREASE = 101;
IP_PLANET_POLUTION = 105;
//************************** Building Groups *****************************
BG_STANDARD = 0;
BG_FACTORY = 1;
BG_BIOSPHERE = 2;
BG_STARPORT = 3;
//************************** Building Menu Groups *****************************
BMG_POPULATION = 1;
BMG_INDUSTRY = 2;
BMG_MINES = 3;
BMG_RESEARCH = 4;
BMG_DEFENCE = 5;
//I don't like this one, but just in case
BMG_MISC = 6;
//************************** Mine type *****************************
MINE_METAL = 1;
MINE_RADIOACTIVE = 2;
MINE_TREASURE = 3;
MINE_NONMETAL = 4;
const
str_ERROR_READING = 'Error reading "';
str_ERROR_READING_FILE = 'Error reading file "';
str_ERROR_READING_SECTION = 'Error reading section "';
str_FROM_FILE = '" from file "';
str_IN_SECTION = '" in section "';
str_IT_DOES_NOT_EXIST = '": it does not exits!';
str_NOT_FOUND = '" not found!';
str_MENTIONED_IN_FILE = '", mentioned in file "';
str_INVALID_VALUE = '": invalid value!';
str_CONFIG_INI = 'config.ini';
str_DESCRIPTION_DSC = 'description.dsc';
str_MOVEMENT_DSC = 'movement.dsc';
str_ENGINE = 'engine';
str_DSC = '.dsc';
str_ANIMATION = 'animation.aaf';
str_MAIN = 'main'; //animation name
str_DAMAGED = '_damaged';
str_VERY_DAMAGED = '_very_damaged';
str_MESH_NEAR = 'mesh_near';
str_MESH_MEDIUM = 'mesh_medium';
str_MESH_FAR = 'mesh_far';
str_NEAR = 'near';
str_MEDIUM = 'medium';
str_FAR = 'far';
str_HIGH = 'high';
str_LOW = 'low';
str_HQ = '_HQ';
str_MQ = '_MQ';
str_LQ = '_LQ';
str_TEXTURE = 'texture';
str_MAIN_MASK = 'main_mask';
str_SECOND_MASK = 'second_mask';
str_BMP = '.bmp';
str_JPG = '.jpg';
str_GIF = 'gif';
str_CUR = '.cur';
str_ANY = '.*';
str_OBJECTS = 'Objects';
str_PROFILES = 'Profiles';
str_MISSIONS = 'Missions';
str_REAL_NAME = 'RealName';
str_DESCRIPTION = 'Description';
str_RACE_TYPES = 'Race Types';
str_RACE_TYPE = 'RaceType';
str_UNIT_CLASSES ='Unit Classes';
str_UNIT_CLASS = 'UnitClass';
str_DAMAGE_MATRIX_AGAINST = 'DamageMatrixAgainst';
str_RACES = 'Races';
str_WEAPONS = 'Weapons';
str_ENGINES = 'Engines';
str_EQUIPMENT = 'Equipment';
str_SHIELDS = 'Shields';
str_UNITS = 'Units';
str_PLAYERS = 'Players';
str_EXPLOSIONS = 'Explosions';
str_VIEW_DISTANCE = 'ViewDistance';
str_MOVEMENT_SCANNER_DISTANCE = 'MovementScannerDistance';
str_DEFAULT_SHIELD = 'DefaultShield';
str_DEFAULT_ENGINE = 'DefaultEngine';
str_DEFAULT_EQUIPMENT = 'DefaultEquipment';
str_DEFAULT_WEAPON = 'DefaultWeapon';
str_EQUIPMENT_ALLOWED = 'Equipment_Allowed';
str_SHIELDS_ALLOWED = 'Shields_Allowed';
str_ENGINES_ALLOWED = 'Engines_Allowed';
str_WEAPONS_ALLOWED = 'Weapons_Allowed';
str_WEAPON_SETTINGS = 'WeaponSettings';
str_MOVEMENT_SETTINGS = 'MovementSettings';
str_SHIELD_SETTINGS = 'ShieldSettings';
str_NEXT_XP_LEVEL = 'NextXPLevel';
str_MAP_PLAYER_DATA = 'MapPlayerData_';
str_GENERAL_SETTINGS = 'General Settings';
str_VIDEO_SETTINGS = 'Video Settings';
str_AUDIO_SETTINGS = 'Audio Settings';
str_MOUSE_PLAYER_CONTROLS = 'Mouse Player Controls';
str_JOYSTICK_PLAYER_CONTROLS = 'Joystick Player Controls';
str_KEYBOARD_PLAYER_CONTROLS = 'Keyboard Player Controls';
str_GENERAL = 'General';
str_CURRENT_PROFILE = 'CurrentProfile';
str_WEAPON = 'Weapon_';
str_THOR_MANAGER = 'ThorManager';
str_POSITION = 'Position';
str_DIRECTION = 'Direction';
str_UP_VECTOR = 'UpVector';
str_TIP_POSITION = 'TipPosition';
str_MAP_SIZE = 'MapSize';
str_SECTOR_SIZE = 'SectorSize';
str_LOCATION = 'Location';
str_IMAGES_CURSORS = 'Images\Cursors\';
str_MENU_CURSOR = str_IMAGES_CURSORS + 'Menu';
str_NORMAL_CURSOR = str_IMAGES_CURSORS + 'Normal';
str_ATTACK_CURSOR = str_IMAGES_CURSORS + 'Attack';
str_FOLLOW_AND_DEFEND_CURSOR = str_IMAGES_CURSORS + 'FollowAndDefend';
str_CONSOLE_PATH = 'Images\Misc\Console.jpg';
str_ERR_PLAYER_PLACED_WAYPOINT_OUTSIDE_MAP = 'Player wanted to place a waypoint outside the map, stupid bastard ;)';
type
//events
TGameErrorEvent = procedure(Sender: TObject; ErrorMessage: string; ErrorLevel: byte; Number: integer) of object;
TPrimitiveErrorEvent = procedure(Sender: TObject; ErrorMessage: string; ErrorLevel: byte )of object;
TGameErrorHandlerClass = class
private
ErrorArray: array [0..MAX_ERROR_TYPE_NUMBER] of integer;//for holding eror statistics
public
onError: TGameErrorEvent;
procedure MakeError(Msg: String; Level: byte);
end;
TPrimitiveErrorHandlerClass = class
public
onError: TPrimitiveErrorEvent;
procedure MakeError(Msg: String; Level: byte);
end;
TCost = class(TPrimitiveErrorHandlerClass)
public
Time: single;
Money: single;
Ti: single;
U: single;
procedure LoadFromFile(FileName: string; Section: String = 'General');
procedure LoadFromMemory(MemIniFile: TStrangeMemIniFile; Section: String = 'General');
procedure LoadFromIni(ini: TStrangeIniFile; Section: String = 'General');
procedure Add(Cost: TCost);
procedure Multiply(Cost: TCost);
procedure Assign(FromCost: TCost);
end;
TBaseGameObject = class(TPrimitiveErrorHandlerClass)
protected
procedure Assign(From: TBaseGameObject); virtual;
procedure LoadFromIni(ini: TStrangeIniFile; Section: string); virtual;
public
Filename: string;
RealName: string;
Description: string;
procedure LoadFromFile(Filename: String; Section: string);
constructor Create;
destructor Destroy; override;
end;
TBaseGameCostObject = class(TBaseGameObject)
protected
procedure Assign(From: TBaseGameCostObject); reintroduce;
procedure LoadFromIni(ini: TStrangeIniFile; Section: string); override;
public
Cost: TCost;
constructor Create;
destructor Destroy; override;
end;
TBaseGameIconObject = class(TBaseGameObject)
protected
procedure Assign(From: TBaseGameIconObject); reintroduce;
procedure LoadFromIni(ini: TStrangeIniFile; Section: string); override;
public
SmallIcon: TGLMaterial;
BigIcon: TGLMaterial;
constructor Create;
destructor Destroy; override;
end;
TBaseGameIconCostObject = class(TBaseGameIconObject)
protected
procedure Assign(From: TBaseGameIconCostObject); reintroduce;
procedure LoadFromIni(ini: TStrangeIniFile; Section: string); override;
public
Cost: TCost;
constructor Create;
destructor Destroy; override;
end;
TStrangeVector3fList = class
private
function GetItem(index: integer): TVector3f;
procedure SetItem(index: integer; Vector: TVector3f);
public
List: array of TVector3f;// Left public for a good reason :)
function Last: integer;
function LastDot: TVector3f;
function Count: integer;
procedure Add(Vector: TVector3f); overload;
procedure Add(X, Y, Z: single); overload;
procedure Add(Vectors: array of TVector3f); overload;
procedure InsertBefore(Vector : TVector3f; index: integer);
procedure Delete(index: integer); overload;
procedure Delete(Vector: TVector3f); overload;
procedure Clear;
function IndexOf(Vector: TVector3f):integer;
procedure Assign(From: TStrangeVector3fList);
constructor Create;
destructor Destroy; override;
property Item [index: integer]: TVector3f read GetItem write SetItem; default;
end;
//Exported procedures//
function AssignThorFxManager(FromManager, ToManager: TglThorFXManager): TglThorFXManager;
//End of exported procedures
implementation
function AssignThorFxManager(FromManager, ToManager: TglThorFXManager): TglThorFXManager;
begin
Result := nil;
if (FromManager = nil) then exit;
if ToManager = nil then
ToManager := TglThorFXManager.Create(nil);
ToManager.Cadencer := FromManager.Cadencer;
ToManager.Core := FromManager.Core;
ToManager.Glow := FromManager.Glow;
ToManager.GlowSize := FromManager.GlowSize;
ToManager.Maxpoints := FromManager.Maxpoints;
ToManager.Vibrate := FromManager.Vibrate;
ToManager.Wildness := FromManager.Wildness;
ToManager.Outercolor := FromManager.Outercolor;
ToManager.InnerColor := FromManager.InnerColor;
ToManager.CoreColor := FromManager.CoreColor;
ToManager.Disabled := FromManager.Disabled;
Result := ToManager;
end;
{ TBaseGameObject }
procedure TBaseGameObject.Assign(From: TBaseGameObject);
begin
Filename := From.Filename;
RealName := From.RealName;
Description := From.Description;
end;
constructor TBaseGameObject.Create;
begin
inherited;
end;
destructor TBaseGameObject.Destroy;
begin
inherited;
end;
procedure TBaseGameObject.LoadFromFile(Filename: String;Section:string);
var
ini: TStrangeIniFile;
begin
if ExtractFilePath(Filename) = '' then Filename := ExtractFilePath(paramstr(0)) + Filename;
if not FileExists(filename) then MakeError(str_ERROR_READING_FILE + FileName + str_IT_DOES_NOT_EXIST,8);
ini := TStrangeIniFile.Create(Filename);
LoadFromIni(ini,section);
ini.Free;
end;
procedure TBaseGameObject.LoadFromIni(ini: TStrangeIniFile;Section:string);
begin
RealName := ini.ReadString(Section,str_REAL_NAME,RealName);
Description := ini.ReadString(Section,str_DESCRIPTION,Description);
//FileName := ExtcactFileName(ini.FileName); //the name of the file, without extention
//setLength(FileName,Length(FileName)-4);
FileName := ExtractFilePath(ini.FileName); //the name of the folder
setLength(FileName,Length(FileName)-1);
FileName := ExtractFileName(FileName);
end;
{ TBaseGameCostObject }
procedure TBaseGameCostObject.Assign(From: TBaseGameCostObject);
begin
inherited Assign(From);
Cost.Assign(From.Cost);
end;
constructor TBaseGameCostObject.Create;
begin
inherited;
Cost := TCost.Create;
end;
destructor TBaseGameCostObject.Destroy;
begin
Cost.Destroy;
inherited;
end;
procedure TBaseGameCostObject.LoadFromIni(ini: TStrangeIniFile; Section: string);
begin
inherited;
Cost.LoadFromIni(ini, 'Cost');
end;
{ TCost }
procedure TCost.Add(Cost: TCost);
begin
Time := Time + Cost.Time;
Money := Money + Cost.Money;
Ti := Ti + Cost.Ti;
U := U + Cost.U;
end;
procedure TCost.Assign(FromCost: TCost);
begin
Time := FromCost.Time;
Money := FromCost.Money;
Ti := FromCost.Ti;
U := FromCost.U;
end;
procedure TCost.LoadFromFile(FileName, Section: String);
var
ini: TStrangeMemIniFile;
begin
if ExtractFilePath(Filename) = '' then Filename := ExtractFilePath(paramstr(0)) + Filename;
if not FileExists(filename) then MakeError(str_ERROR_READING_FILE + FileName + str_IT_DOES_NOT_EXIST, 8);
ini := TStrangeMemIniFile.Create(Filename);
LoadFromMemory(ini, Section);
ini.Free;
end;
procedure TCost.LoadFromIni(ini: TStrangeIniFile; Section: String);
begin
if ini = nil then exit;
Time := ini.ReadFloat(Section, 'Time', Time);
Money := ini.ReadFloat(Section, 'Money', Money);
Ti := ini.ReadFloat(Section, 'Ti', Ti);
U := ini.ReadFloat(Section, 'U', U);
end;
procedure TCost.LoadFromMemory(MemIniFile: TStrangeMemIniFile; Section: String);
begin
if MemIniFile = nil then exit;
Time := MemIniFile.ReadFloat(Section, 'Time' ,Time);
Money := MemIniFile.ReadFloat(Section, 'Money', Money);
Ti := MemIniFile.ReadFloat(Section, 'Ti', Ti);
U := MemIniFile.ReadFloat(Section, 'U', U);
end;
procedure TCost.Multiply(Cost: TCost);
begin
Time := Time * Cost.Time;
Money := Money * Cost.Money;
Ti := Ti * Cost.Ti;
U := U * Cost.U;
end;
{ TGameErrorHandlerClass }
procedure TGameErrorHandlerClass.MakeError(Msg: String; Level:byte);
begin
inc(ErrorArray[Level]);
if Assigned(onError) then onError(Self, Msg, Level, ErrorArray[Level]);
Beep;
if Level >= 7 then
begin
ShowMessage(Msg);
halt;
end;
end;
{ TPrimitiveErrorHandlerClass }
procedure TPrimitiveErrorHandlerClass.MakeError(Msg: String; Level: byte);
begin
if Assigned(onError) then onError(Self ,Msg, Level);
if Level >= 7 then
begin
ShowMessage(Msg);
halt;
end;
end;
{ TBaseGameIconObject }
procedure TBaseGameIconObject.Assign(From: TBaseGameIconObject);
begin
inherited Assign(From);
SmallIcon.Assign(From.SmallIcon);
BigIcon.Assign(From.BigIcon);
end;
constructor TBaseGameIconObject.Create;
begin
inherited Create;
SmallIcon := TGLMaterial.Create(nil);
BigIcon := TGLMaterial.Create(nil);
end;
destructor TBaseGameIconObject.Destroy;
begin
SmallIcon.Destroy;
BigIcon.Destroy;
inherited;
end;
procedure TBaseGameIconObject.LoadFromIni(ini: TStrangeIniFile; Section: string);
begin
inherited;
SmallIcon.Texture.Image.LoadFromFile(ExtractFilePath(ini.FileName) + 'small_icon.jpg');
BigIcon.Texture.Image.LoadFromFile(ExtractFilePath(ini.FileName) + 'big_icon.jpg');
end;
procedure TBaseGameIconCostObject.Assign(From: TBaseGameIconCostObject);
begin
inherited Assign(From);
Cost.Assign(From.Cost);
end;
constructor TBaseGameIconCostObject.Create;
begin
inherited Create;
Cost := TCost.Create;
end;
destructor TBaseGameIconCostObject.Destroy;
begin
Cost.Destroy;
inherited;
end;
procedure TBaseGameIconCostObject.LoadFromIni(ini: TStrangeIniFile; Section: string);
begin
inherited;
Cost.LoadFromIni(ini,'Cost');
end;
{ TStrangeVector3fList }
procedure TStrangeVector3fList.Add(Vector: TVector3f);
begin
Setlength(List, length(List) + 1);
List[length(List) - 1] := Vector;
end;
procedure TStrangeVector3fList.Add(Vectors: array of TVector3f);
var
i: integer;
prevlength: integer;
begin
if length(Vectors) = 0 then exit;
prevlength := length(List);
Setlength(List, length(Vectors) + prevlength);
for i := prevlength to length(List) - 1 do
List[i] := Vectors[i - prevlength];
end;
procedure TStrangeVector3fList.Add(X, Y, Z: single);
begin
Add(AffineVectorMake(x, y, z));
end;
procedure TStrangeVector3fList.Assign(From: TStrangeVector3fList);
var
i: integer;
begin
if From = nil then exit;
Setlength(List, length(From.List));
if length(From.List) <> 0 then
for i := 0 to length(From.List) - 1 do
List[i] := From.List[i];
end;
procedure TStrangeVector3fList.Clear;
begin
setlength(List, 0);
end;
function TStrangeVector3fList.Count: integer;
begin
Result := length(List);
end;
constructor TStrangeVector3fList.Create;
begin
//
end;
procedure TStrangeVector3fList.Delete(Vector: TVector3f);
var
index: integer;
begin
index := IndexOf(Vector);
if Index <> -1 then
Delete(index);
end;
procedure TStrangeVector3fList.Delete(index: integer);
var
i: integer;
begin
if (index > Last) or (index < 0) then
begin
raise Exception.Create('This sux!');
exit;
end;
if index <> Last then
for i := index to Count - 2 do
List[i] := List[i+1];
setlength(List,Last);
end;
destructor TStrangeVector3fList.Destroy;
begin
setlength(List, 0);
inherited;
end;
function TStrangeVector3fList.GetItem(index: integer): TVector3f;
begin
Result := List[index];
end;
function TStrangeVector3fList.IndexOf(Vector: TVector3f): integer;
var
i: integer;
begin
Result := -1;
if length(List) <> 0 then
for i := 0 to length(List) - 1 do
if VectorEquals(List[i], Vector) then
begin
Result := i;
break;
end;
end;
procedure TStrangeVector3fList.InsertBefore(Vector: TVector3f; index: integer);
var
i:integer;
begin
if (index < 0) or (index > Count) then exit;
if index = Count then
begin
Add(Vector);
exit;
end;
setlength(List,Count + 1);
for i := Last downto index + 1 do
List[i] := List[i-1];
List[index] := Vector;
end;
function TStrangeVector3fList.Last: integer;
begin
Result := length(List) - 1;
end;
function TStrangeVector3fList.LastDot: TVector3f;
begin
Result := List[length(List) - 1];
end;
procedure TStrangeVector3fList.SetItem(index: integer; Vector: TVector3f);
begin
List[index] := Vector;
end;
end.
See more files for this project here