Added To_Float to fixed point class. This is to help with certain house values to/from Lua but may have other uses.

Added ability to create objects out of thin air, and force factories to produce units.

Added ability to issue movement commands to units.

Updated object cache system to use an incremental UID for retrieval / passing ID back to the script, as ID collisions were occuring.
This commit is contained in:
nev6502
2020-06-28 15:35:10 -06:00
parent 19569faf2b
commit 678d784004
5 changed files with 2302 additions and 355 deletions
+29
View File
@@ -32,6 +32,7 @@
* Functions: *
* fixed::As_ASCII -- Returns a pointer (static) of this number as an ASCII string. *
* fixed::To_ASCII -- Convert a fixed point number into an ASCII string. *
* fixed::To_Float -- Convert a fixed point number into a float value *
* fixed::fixed -- Constructor for fixed integral from ASCII initializer. *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
@@ -40,6 +41,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
/*
@@ -148,6 +150,33 @@ fixed::fixed(char const * ascii)
}
/***********************************************************************************************
* fixed::To_Float -- Convert a fixed point number into a float *
* *
* Use this routine to convert this fixed point number into a float. This can be lossy for *
* fine values. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the float value of this fixed point number *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/27/2020 JJ : Created. *
*=============================================================================================*/
float fixed::To_Float() const
{
unsigned int whole = Data.Composite.Whole;
unsigned int frac = ((unsigned int)Data.Composite.Fraction * 1000U) / PRECISION;
float this_raw_value = (whole + (frac * .001));
return floor(this_raw_value * 100.0 + 0.5) / 100.0;
}
/***********************************************************************************************
* fixed::To_ASCII -- Convert a fixed point number into an ASCII string. *
* *
+5
View File
@@ -206,6 +206,11 @@ class fixed
int To_ASCII(char * buffer, int maxlen=-1) const;
char const * As_ASCII(void) const;
/*
** Helper function to convert fixed point number to float (JJ)
*/
float To_Float() const;
/*
** Helper constants that provide some convenient fixed point values.
*/
+2150 -343
View File
File diff suppressed because it is too large Load Diff
+57 -9
View File
@@ -15,27 +15,30 @@ extern "C" {
// Object Cache Item
// Stores an id lookup table
struct MapScriptObject {
int UID; // The UID of the object (to prevent ID collisions)
int ID=-1; // The object's "Global ID"
int classIndex=-1; // The object's "Global ID"
RTTIType RTTI; // The type of object
};
// Stores defaults of rules from before
// variables were changed within
struct MapScriptDefaultAttribute {
// Stores defaults of object attributes whenever they are changed for the first time (for later restoration)
struct MapScriptDefaultObjectAttribute {
RTTIType RTTI; // The type of object
int ID=-1; // The index of the object in its heap
int attribute;
int value;
};
//
// MapScript Class
//
class MapScript {
public:
int cUID = 0;
~MapScript() { Deinit(); };
@@ -43,11 +46,13 @@ public:
bool Init(const char* mapName);
void Deinit();
MapScriptObject* CreateCacheObject();
void CallFunction(const char* functionName);
void SetLuaPath(const char* input_path);
std::vector<MapScriptObject*> ObjectCache;
std::vector<MapScriptDefaultAttribute*> DefaultTypeAttributeCache;
std::vector<MapScriptDefaultObjectAttribute*> DefaultObjectTypeAttributeCache;
private:
lua_State* L;
@@ -56,7 +61,7 @@ private:
// Enums
typedef enum MapScriptAttributeType : char {
typedef enum MapScriptObjectAttributeType : char {
// Techno types
ATTRIBUTE_TYPE=0,
@@ -105,7 +110,49 @@ typedef enum MapScriptAttributeType : char {
ATTRIBUTE_DOG
} MapScriptAttributeType;
} MapScriptObjectAttributeType;
// Enums
typedef enum MapScriptHouseAttributeType : char {
// Techno types
HOUSE_ATTRIBUTE_IQ = 0,
HOUSE_ATTRIBUTE_TECH_LEVEL,
HOUSE_ATTRIBUTE_IS_HUMAN,
HOUSE_ATTRIBUTE_FIREPOWER_BIAS,
HOUSE_ATTRIBUTE_GROUNDSPEED_BIAS,
HOUSE_ATTRIBUTE_ARMOR_BIAS,
HOUSE_ATTRIBUTE_ROF_BIAS,
HOUSE_ATTRIBUTE_COST_BIAS,
HOUSE_ATTRIBUTE_REPAIR_DELAY,
HOUSE_ATTRIBUTE_BUILD_DELAY,
HOUSE_ATTRIBUTE_STARTED,
HOUSE_ATTRIBUTE_ALERTED,
HOUSE_ATTRIBUTE_BASE_BUILDING,
HOUSE_ATTRIBUTE_DISCOVERED,
HOUSE_ATTRIBUTE_CAPACITY,
HOUSE_ATTRIBUTE_TIBERIUM,
HOUSE_ATTRIBUTE_CREDITS,
HOUSE_ATTRIBUTE_ALERT_TIMER,
HOUSE_ATTRIBUTE_REPAIR_TIMER,
HOUSE_ATTRIBUTE_POINTS,
HOUSE_ATTRIBUTE_DESTROYED_BUILDINGS,
HOUSE_ATTRIBUTE_DESTROYED_VEHICLES,
HOUSE_ATTRIBUTE_DESTROYED_INFANTRY,
HOUSE_ATTRIBUTE_DESTROYED_AIRCRAFT,
HOUSE_ATTRIBUTE_DESTROYED_VESSELS,
HOUSE_ATTRIBUTE_CAPTURED_BUILDINGS,
HOUSE_ATTRIBUTE_CRATES,
HOUSE_ATTRIBUTE_BUILDING_FACTORIES,
HOUSE_ATTRIBUTE_UNIT_FACTORIES,
HOUSE_ATTRIBUTE_INFANTRY_FACTORIES,
HOUSE_ATTRIBUTE_AIRCRAFT_FACTORIES,
HOUSE_ATTRIBUTE_VESSEL_FACTORIES,
HOUSE_ATTRIBUTE_POWER,
HOUSE_ATTRIBUTE_DRAIN,
HOUSE_ATTRIBUTE_LAST_ATTACKER
} MapScriptHouseAttributeType;
// Non-Class-Functions
bool Script_SetObjectTrigger(int input_object_id, TriggerClass* input_trigger);
@@ -117,8 +164,9 @@ int Script_AircraftIndexFromID(int input_object_id);
int Script_InfantryIndexFromID(int input_object_id);
int Script_VesselIndexFromID(int input_object_id);
static int Script_SetObjectTypeAttribute(lua_State* L, TechnoTypeClass* this_type_class, MapScriptAttributeType attribute_type);
static int Script_SetObjectTypeAttribute(lua_State* L, TechnoTypeClass* this_type_class, MapScriptObjectAttributeType attribute_type);
static int Script_GetObjectTypeAttribute(lua_State* L, TechnoTypeClass* this_type_class, MapScriptObjectAttributeType attribute_type);
void Script_CacheDefaultAttribute(RTTIType input_rtti, int input_id, MapScriptAttributeType input_attribute, int input_value);
void Script_CacheDefaultObjectTypeAttribute(RTTIType input_rtti, int input_id, MapScriptObjectAttributeType input_attribute, int input_value);
#endif
+61 -3
View File
@@ -160,7 +160,21 @@
MIG=3, -- MIG Attack Plane
YAK=4, -- Yak Attack Plane
HELI=5, -- Longbow Helicopter
HIND=6, -- Hind Helicopter
HIND=6 -- Hind Helicopter
}
-- *********************************************************
-- * *
-- * Vessels *
-- * *
-- *********************************************************
VesselTypes={
SS=0, -- Submarine
DD=1, -- Destroyer
CA=2, -- Cruiser
LST=3, -- Land Sea Tank (transport)
PT=4 -- Gun Boat
}
-- *********************************************************
@@ -270,10 +284,10 @@
-- *********************************************************
-- * *
-- * Attribite Types *
-- * Obejct Attributes *
-- * *
-- *********************************************************
Attributes = {
ObjectAttributes = {
Type=0,
Strength=1, -- Object attribute
MaxStrength=2, -- Definition attribute
@@ -320,6 +334,50 @@
IsDog=37
}
-- *********************************************************
-- * *
-- * House Attributes *
-- * *
-- *********************************************************
HouseAttributes = {
IQ = 0,
TechLevel =1,
IsHuman=2,
FirepowerBias=3,
GroundspeedBias=4,
ArmorBias=5,
ROFBias=6,
CostBias=7,
RepairDelay=8,
BuildDelay=9,
Started=10,
Alerted=11,
BaseBuilding=12,
Discovered=13,
Capacity=14,
Tiberium=15,
Credits=16,
AlertTimer=17,
RepairTimer=18,
Points=19,
DestroyedBuildings=20,
DestroyedVehicles=21,
DestroyedInfantry=22,
DestroyedAircraft=23,
DestroyedVessels=24,
CapturedBuildings=25,
Crates=26,
BuildingFactories=27,
VehicleFactories=28,
InfantryFactories=29,
AircraftFactories=30,
VesselFactories=31,
Power=32,
Drain=33,
LastAttacker=34
}
-- *********************************************************
-- * *