diff --git a/generator.py b/generator.py index 16407b4f6..35c4d2c13 100644 --- a/generator.py +++ b/generator.py @@ -2,8 +2,8 @@ import re, os, shutil, string, sys def generateElements(elementFiles, outputCpp, outputH): - elementClasses = dict() - baseClasses = dict() + elementClasses = {} + baseClasses = {} elementHeader = """#ifndef ELEMENTCLASSES_H #define ELEMENTCLASSES_H @@ -120,6 +120,8 @@ std::vector GetElements() } """; + if not os.path.exists(outputH.split("/")[1]): + os.makedirs(outputH.split("/")[1]) f = open(outputH, "w") f.write(elementHeader) f.close() @@ -129,7 +131,7 @@ std::vector GetElements() f.close() def generateTools(toolFiles, outputCpp, outputH): - toolClasses = dict() + toolClasses = {} toolHeader = """#ifndef TOOLCLASSES_H #define TOOLCLASSES_H @@ -193,7 +195,9 @@ def generateTools(toolFiles, outputCpp, outputH): toolContent += """ return tools; } """; - + + if not os.path.exists(outputH.split("/")[1]): + os.makedirs(outputH.split("/")[1]) f = open(outputH, "w") f.write(toolHeader) f.close() diff --git a/src/Config.h b/src/Config.h index 50444cd50..0e6673771 100644 --- a/src/Config.h +++ b/src/Config.h @@ -23,11 +23,11 @@ #endif #ifndef MINOR_VERSION -#define MINOR_VERSION 0 +#define MINOR_VERSION 1 #endif #ifndef BUILD_NUM -#define BUILD_NUM 261 +#define BUILD_NUM 262 #endif #ifndef SNAPSHOT_ID diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp index cb46ca4e9..ef0c1f6a3 100644 --- a/src/cat/LuaScriptInterface.cpp +++ b/src/cat/LuaScriptInterface.cpp @@ -423,6 +423,9 @@ int LuaScriptInterface::interface_closeWindow(lua_State * l) //// Begin Simulation API +StructProperty * LuaScriptInterface::particleProperties; +int LuaScriptInterface::particlePropertiesCount; + void LuaScriptInterface::initSimulationAPI() { //Methods @@ -430,6 +433,9 @@ void LuaScriptInterface::initSimulationAPI() {"partNeighbours", simulation_partNeighbours}, {"partChangeType", simulation_partChangeType}, {"partCreate", simulation_partCreate}, + {"partProperty", simulation_partProperty}, + {"partPosition", simulation_partPosition}, + {"partID", simulation_partID}, {"partKill", simulation_partKill}, {"pressure", simulation_pressure}, {"ambientHeat", simulation_ambientHeat}, @@ -454,6 +460,18 @@ void LuaScriptInterface::initSimulationAPI() lua_pushinteger(l, MAX_TEMP); lua_setfield(l, simulationAPI, "MAX_TEMP"); lua_pushinteger(l, MIN_TEMP); lua_setfield(l, simulationAPI, "MIN_TEMP"); + //Declare FIELD_BLAH constants + std::vector particlePropertiesV = Particle::GetProperties(); + particlePropertiesCount = 0; + particleProperties = new StructProperty[particlePropertiesV.size()]; + for(std::vector::iterator iter = particlePropertiesV.begin(), end = particlePropertiesV.end(); iter != end; ++iter) + { + std::string propertyName = (*iter).Name; + std::transform(propertyName.begin(), propertyName.end(), propertyName.begin(), ::toupper); + lua_pushinteger(l, particlePropertiesCount); + lua_setfield(l, simulationAPI, ("FIELD_"+propertyName).c_str()); + particleProperties[particlePropertiesCount++] = *iter; + } } void LuaScriptInterface::set_map(int x, int y, int width, int height, float value, int map) // A function so this won't need to be repeated many times later @@ -541,6 +559,166 @@ int LuaScriptInterface::simulation_partCreate(lua_State * l) return 1; } +int LuaScriptInterface::simulation_partID(lua_State * l) +{ + int x = lua_tointeger(l, 1); + int y = lua_tointeger(l, 2); + + if(x < 0 || x >= XRES || y < 0 || y >= YRES) + { + lua_pushnil(l); + return 1; + } + + int amalgam = luacon_sim->pmap[y][x]; + if(!amalgam) + amalgam = luacon_sim->photons[y][x]; + lua_pushinteger(l, amalgam >> 8); + return 1; +} + +int LuaScriptInterface::simulation_partPosition(lua_State * l) +{ + int particleID = lua_tointeger(l, 1); + int argCount = lua_gettop(l); + if(particleID < 0 || particleID >= NPART || !luacon_sim->parts[particleID].type) + { + if(argCount == 1) + { + lua_pushnil(l); + lua_pushnil(l); + return 2; + } else { + return 0; + } + } + + if(argCount == 3) + { + luacon_sim->parts[particleID].x = lua_tonumber(l, 2); + luacon_sim->parts[particleID].y = lua_tonumber(l, 3); + return 0; + } + else + { + lua_pushnumber(l, luacon_sim->parts[particleID].x); + lua_pushnumber(l, luacon_sim->parts[particleID].y); + return 2; + } +} + +int LuaScriptInterface::simulation_partProperty(lua_State * l) +{ + int argCount = lua_gettop(l); + int particleID = lua_tointeger(l, 1); + StructProperty * property = NULL; + + if(particleID < 0 || particleID >= NPART || !luacon_sim->parts[particleID].type) + { + if(argCount == 3) + { + lua_pushnil(l); + return 1; + } else { + return 0; + } + } + + //Get field + if(lua_type(l, 2) == LUA_TNUMBER) + { + int fieldID = lua_tointeger(l, 2); + if(fieldID < 0 || fieldID >= particlePropertiesCount) + return luaL_error(l, "Invalid field ID (%d)", fieldID); + property = &particleProperties[fieldID]; + } else if(lua_type(l, 2) == LUA_TSTRING) { + std::string fieldName = lua_tostring(l, 2); + for(int i = particlePropertiesCount-1; i >= 0; i--) + { + if(particleProperties[i].Name == fieldName) + property = &particleProperties[i]; + } + if(!property) + return luaL_error(l, "Unknown field (%s)", fieldName.c_str()); + } else { + return luaL_error(l, "Field ID must be an name (string) or identifier (integer)"); + } + + //Calculate memory address of property + intptr_t propertyAddress = (intptr_t)(((unsigned char*)&luacon_sim->parts[particleID])+property->Offset); + + if(argCount == 3) + { + //Set + switch(property->Type) + { + case StructProperty::ParticleType: + case StructProperty::Integer: + *((int*)propertyAddress) = lua_tointeger(l, 3); + break; + case StructProperty::UInteger: + *((unsigned int*)propertyAddress) = lua_tointeger(l, 3); + break; + case StructProperty::Float: + *((float*)propertyAddress) = lua_tonumber(l, 3); + break; + case StructProperty::Char: + *((char*)propertyAddress) = lua_tointeger(l, 3); + break; + case StructProperty::UChar: + *((unsigned char*)propertyAddress) = lua_tointeger(l, 3); + break; + case StructProperty::String: + *((char**)propertyAddress) = strdup(lua_tostring(l, 3)); + break; + case StructProperty::Colour: + #if PIXELSIZE == 4 + *((unsigned int*)propertyAddress) = lua_tointeger(l, 3); + #else + *((unsigned short*)propertyAddress) = lua_tointeger(l, 3); + #endif + break; + } + return 0; + } + else + { + //Get + switch(property->Type) + { + case StructProperty::ParticleType: + case StructProperty::Integer: + lua_pushinteger(l, *((int*)propertyAddress)); + break; + case StructProperty::UInteger: + lua_pushinteger(l, *((unsigned int*)propertyAddress)); + break; + case StructProperty::Float: + lua_pushnumber(l, *((float*)propertyAddress)); + break; + case StructProperty::Char: + lua_pushinteger(l, *((char*)propertyAddress)); + break; + case StructProperty::UChar: + lua_pushinteger(l, *((unsigned char*)propertyAddress)); + break; + case StructProperty::String: + lua_pushstring(l, *((char**)propertyAddress)); + break; + case StructProperty::Colour: + #if PIXELSIZE == 4 + lua_pushinteger(l, *((unsigned int*)propertyAddress)); + #else + lua_pushinteger(l, *((unsigned short*)propertyAddress)); + #endif + break; + default: + lua_pushnil(l); + } + return 1; + } +} + int LuaScriptInterface::simulation_partKill(lua_State * l) { if(lua_gettop(l)==2) diff --git a/src/cat/LuaScriptInterface.h b/src/cat/LuaScriptInterface.h index d925bbe9e..20dada176 100644 --- a/src/cat/LuaScriptInterface.h +++ b/src/cat/LuaScriptInterface.h @@ -54,11 +54,17 @@ class LuaScriptInterface: public CommandInterface TPTScriptInterface * legacy; //Simulation + static StructProperty * particleProperties; + static int particlePropertiesCount; + // void initSimulationAPI(); static void set_map(int x, int y, int width, int height, float value, int mapType); static int simulation_partNeighbours(lua_State * l); static int simulation_partChangeType(lua_State * l); static int simulation_partCreate(lua_State * l); + static int simulation_partProperty(lua_State * l); + static int simulation_partPosition(lua_State * l); + static int simulation_partID(lua_State * l); static int simulation_partKill(lua_State * l); static int simulation_pressure(lua_State * l); static int simulation_velocityX(lua_State * l); diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 53736cace..d3ada65e5 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -1942,6 +1942,17 @@ char * GameSave::serialiseOPS(int & dataLength) } bson_init(&b); + bson_append_start_object(&b, "origin"); + bson_append_int(&b, "majorVersion", SAVE_VERSION); + bson_append_int(&b, "minorVersion", MINOR_VERSION); + bson_append_int(&b, "buildNum", MINOR_VERSION); + bson_append_int(&b, "snapshotId", MINOR_VERSION); + bson_append_string(&b, "releaseType", IDENT_RELTYPE); + bson_append_string(&b, "platform", IDENT_PLATFORM); + bson_append_string(&b, "builtType", IDENT_BUILD); + bson_append_finish_object(&b); + + bson_append_bool(&b, "waterEEnabled", waterEEnabled); bson_append_bool(&b, "legacyEnable", legacyEnable); bson_append_bool(&b, "gravityEnable", gravityEnable);