mirror of
https://github.com/jmarshall23/CnC_Remastered_Collection.git
synced 2026-08-12 08:00:55 +02:00
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:
@@ -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. *
|
||||
* *
|
||||
|
||||
@@ -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
File diff suppressed because it is too large
Load Diff
@@ -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
|
||||
Reference in New Issue
Block a user