From f6d82b6f8a036238f3060f9ca1078f1a9dfb4e1d Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 11 Jan 2016 22:38:42 -0500 Subject: [PATCH] separate t and v argument in create_part, fix LIGH not defaulting to .life of 30 with clones / console --- src/gui/game/Tool.cpp | 2 +- src/lua/LuaScriptInterface.cpp | 9 ++++++++- src/lua/TPTScriptInterface.cpp | 8 +++++++- src/simulation/Simulation.cpp | 33 ++++++++++++++++---------------- src/simulation/Simulation.h | 2 +- src/simulation/elements/ARAY.cpp | 2 +- src/simulation/elements/BCLN.cpp | 4 ++-- src/simulation/elements/CLNE.cpp | 4 ++-- src/simulation/elements/CONV.cpp | 2 +- src/simulation/elements/CRAY.cpp | 2 +- src/simulation/elements/PBCN.cpp | 6 +++--- src/simulation/elements/PCLN.cpp | 6 +++--- src/simulation/elements/STOR.cpp | 2 +- 13 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/gui/game/Tool.cpp b/src/gui/game/Tool.cpp index 3bbbc5855..f65f47a9d 100644 --- a/src/gui/game/Tool.cpp +++ b/src/gui/game/Tool.cpp @@ -163,5 +163,5 @@ void Element_TESC_Tool::DrawFill(Simulation * sim, Brush * brush, ui::Point posi void PlopTool::Click(Simulation * sim, Brush * brush, ui::Point position) { - sim->create_part(-2, position.X, position.Y, toolID); + sim->create_part(-2, position.X, position.Y, toolID&0xFF, toolID>>8); } diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index bcb3c095c..ab2ca6efa 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -895,7 +895,14 @@ int LuaScriptInterface::simulation_partCreate(lua_State * l) lua_pushinteger(l, -1); return 1; } - lua_pushinteger(l, luacon_sim->create_part(newID, lua_tointeger(l, 2), lua_tointeger(l, 3), lua_tointeger(l, 4))); + int type = lua_tointeger(l, 4); + int v = -1; + if (type>>8) + { + v = type>>8; + type = type&0xFF; + } + lua_pushinteger(l, luacon_sim->create_part(newID, lua_tointeger(l, 2), lua_tointeger(l, 3), type, v)); return 1; } diff --git a/src/lua/TPTScriptInterface.cpp b/src/lua/TPTScriptInterface.cpp index 26a38d0df..18fc9c2f3 100644 --- a/src/lua/TPTScriptInterface.cpp +++ b/src/lua/TPTScriptInterface.cpp @@ -452,7 +452,13 @@ AnyType TPTScriptInterface::tptS_create(std::deque * words) if(tempPoint.X<0 || tempPoint.Y<0 || tempPoint.Y >= YRES || tempPoint.X >= XRES) throw GeneralException("Invalid position"); - int returnValue = sim->create_part(-1, tempPoint.X, tempPoint.Y, type); + int v = -1; + if (type>>8) + { + v = type>>8; + type = type&0xFF; + } + int returnValue = sim->create_part(-1, tempPoint.X, tempPoint.Y, type, v); return NumberType(returnValue); } diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 58afff6e8..c79c0c518 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -576,7 +576,7 @@ int Simulation::FloodINST(int x, int y, int fullc, int cm) // fill span for (x=x1; x<=x2; x++) { - if (create_part(-1, x, y, fullc)>=0) + if (create_part(-1, x, y, c, fullc>>8)>=0) created_something = 1; } @@ -1440,12 +1440,12 @@ int Simulation::CreatePartFlags(int x, int y, int c, int flags) { delete_part(x, y); if (c!=0) - create_part(-2, x, y, c); + create_part(-2, x, y, c&0xFF, c>>8); } } //normal draw else - if (create_part(-2, x, y, c) == -1) + if (create_part(-2, x, y, c&0xFF, c>>8) == -1) return 1; return 0; } @@ -1509,6 +1509,8 @@ void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c) bool reverseXY = abs(y2-y1) > abs(x2-x1); int x, y, dx, dy, sy; float e, de; + int v = c>>8; + c = c&0xFF; if (reverseXY) { y = x1; @@ -1539,9 +1541,9 @@ void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c) for (x=x1; x<=x2; x++) { if (reverseXY) - create_part(-1, y, x, c); + create_part(-1, y, x, c, v); else - create_part(-1, x, y, c); + create_part(-1, x, y, c, v); e += de; if (e >= 0.5f) { @@ -1549,9 +1551,9 @@ void Simulation::CreateLine(int x1, int y1, int x2, int y2, int c) if ((y1=y2)) { if (reverseXY) - create_part(-1, y, x, c); + create_part(-1, y, x, c, v); else - create_part(-1, x, y, c); + create_part(-1, x, y, c, v); } e -= 1.0f; } @@ -2763,19 +2765,16 @@ void Simulation::part_change_type(int i, int x, int y, int t)//changes the type //the function for creating a particle, use p=-1 for creating a new particle, -2 is from a brush, or a particle number to replace a particle. //tv = Type (8 bits) + Var (24 bits), var is usually 0 -int Simulation::create_part(int p, int x, int y, int tv) +int Simulation::create_part(int p, int x, int y, int t, int v) { int i; - int t = tv & 0xFF; - int v = (tv >> 8) & 0xFFFFFF; - if (x<0 || y<0 || x>=XRES || y>=YRES) return -1; if (t>=0 && t>8; @@ -2818,10 +2816,11 @@ int Simulation::create_part(int p, int x, int y, int tv) parts[index].temp = parts[index].temp+10.0f; return index; } - if (t==PT_SPAWN&&elementCount[PT_SPAWN]) + else if (t==PT_SPAWN && elementCount[PT_SPAWN]) return -1; - if (t==PT_SPAWN2&&elementCount[PT_SPAWN2]) + else if (t==PT_SPAWN2 && elementCount[PT_SPAWN2]) return -1; + if (p==-1)//creating from anything but brush { // If there is a particle, only allow creation if the new particle can occupy the same space as the existing particle @@ -4701,7 +4700,7 @@ void Simulation::SimulateGoL() } } if (creategol<0xFF) - create_part(-1, nx, ny, PT_LIFE|((creategol-1)<<8)); + create_part(-1, nx, ny, PT_LIFE, creategol-1); } else if (grule[golnum][neighbors-1]==0 || grule[golnum][neighbors-1]==2)//subtract 1 because it counted itself { diff --git a/src/simulation/Simulation.h b/src/simulation/Simulation.h index f6bb76db4..8efcb184b 100644 --- a/src/simulation/Simulation.h +++ b/src/simulation/Simulation.h @@ -150,7 +150,7 @@ public: void part_change_type(int i, int x, int y, int t); //int InCurrentBrush(int i, int j, int rx, int ry); //int get_brush_flags(); - int create_part(int p, int x, int y, int t); + int create_part(int p, int x, int y, int t, int v = -1); void delete_part(int x, int y); void get_sign_pos(int i, int *x0, int *y0, int *w, int *h); int is_wire(int x, int y); diff --git a/src/simulation/elements/ARAY.cpp b/src/simulation/elements/ARAY.cpp index 8e7ee60bb..f881b582a 100644 --- a/src/simulation/elements/ARAY.cpp +++ b/src/simulation/elements/ARAY.cpp @@ -139,7 +139,7 @@ int Element_ARAY::update(UPDATE_FUNC_ARGS) { for (int rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1 - rx1 + 1) { - int np = sim->create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, parts[r].tmp); + int np = sim->create_part(-1, x + nxi + nxx + rx1, y + nyi + nyy + ry1, parts[r].tmp&0xFF); if (np != -1) { parts[np].temp = parts[r].temp; diff --git a/src/simulation/elements/BCLN.cpp b/src/simulation/elements/BCLN.cpp index bcfdc54ba..d5eb2cb46 100644 --- a/src/simulation/elements/BCLN.cpp +++ b/src/simulation/elements/BCLN.cpp @@ -81,10 +81,10 @@ int Element_BCLN::update(UPDATE_FUNC_ARGS) } } else { - if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype|(parts[i].tmp<<8)); + if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_LIFE, parts[i].tmp); else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0) { - int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype); + int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF); if (np>=0) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/CLNE.cpp b/src/simulation/elements/CLNE.cpp index 107d0bbfd..c98fdeef4 100644 --- a/src/simulation/elements/CLNE.cpp +++ b/src/simulation/elements/CLNE.cpp @@ -72,10 +72,10 @@ int Element_CLNE::update(UPDATE_FUNC_ARGS) } } else { - if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype|(parts[i].tmp<<8)); + if (parts[i].ctype==PT_LIFE) sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_LIFE, parts[i].tmp); else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0) { - int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype); + int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF); if (np>=0) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/CONV.cpp b/src/simulation/elements/CONV.cpp index 1f830c4f9..3fbe1493c 100644 --- a/src/simulation/elements/CONV.cpp +++ b/src/simulation/elements/CONV.cpp @@ -85,7 +85,7 @@ int Element_CONV::update(UPDATE_FUNC_ARGS) continue; if((r&0xFF)!=PT_CONV && (r&0xFF)!=PT_DMND && (r&0xFF)!=ctype) { - sim->create_part(r>>8, x+rx, y+ry, parts[i].ctype); + sim->create_part(r>>8, x+rx, y+ry, parts[i].ctype&0xFF, parts[i].ctype>>8); } } } diff --git a/src/simulation/elements/CRAY.cpp b/src/simulation/elements/CRAY.cpp index d9ce079cf..1caca535f 100644 --- a/src/simulation/elements/CRAY.cpp +++ b/src/simulation/elements/CRAY.cpp @@ -93,7 +93,7 @@ int Element_CRAY::update(UPDATE_FUNC_ARGS) } r = pmap[y+nyi+nyy][x+nxi+nxx]; if (!sim->IsWallBlocking(x+nxi+nxx, y+nyi+nyy, parts[i].ctype) && (!sim->pmap[y+nyi+nyy][x+nxi+nxx] || createSpark)) { // create, also set color if it has passed through FILT - int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, parts[i].ctype); + int nr = sim->create_part(-1, x+nxi+nxx, y+nyi+nyy, parts[i].ctype&0xFF, parts[i].ctype>>8); if (nr!=-1) { if (colored) parts[nr].dcolour = colored; diff --git a/src/simulation/elements/PBCN.cpp b/src/simulation/elements/PBCN.cpp index 89b8bbc05..b2a87fed3 100644 --- a/src/simulation/elements/PBCN.cpp +++ b/src/simulation/elements/PBCN.cpp @@ -114,7 +114,7 @@ int Element_PBCN::update(UPDATE_FUNC_ARGS) for (ry = -1; ry < 2; ry++) if (rx || ry) { - int r = sim->create_part(-1, x + rx, y + ry,parts[i].ctype); + int r = sim->create_part(-1, x + rx, y + ry, PT_PHOT); if (r != -1) { parts[r].vx = rx * 3; @@ -130,11 +130,11 @@ int Element_PBCN::update(UPDATE_FUNC_ARGS) else if (parts[i].ctype==PT_LIFE)//create life a different way for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) - sim->create_part(-1, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8)); + sim->create_part(-1, x+rx, y+ry, PT_LIFE, parts[i].tmp); else if (parts[i].ctype!=PT_LIGH || !(rand()%30)) { - int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype); + int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF, parts[i].ctype>>8); if (np>-1) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/PCLN.cpp b/src/simulation/elements/PCLN.cpp index 239a717de..5272d3519 100644 --- a/src/simulation/elements/PCLN.cpp +++ b/src/simulation/elements/PCLN.cpp @@ -105,7 +105,7 @@ int Element_PCLN::update(UPDATE_FUNC_ARGS) for (ry = -1; ry < 2; ry++) if (rx || ry) { - int r = sim->create_part(-1, x + rx, y + ry, parts[i].ctype); + int r = sim->create_part(-1, x + rx, y + ry, PT_PHOT); if (r != -1) { parts[r].vx = rx * 3; @@ -121,11 +121,11 @@ int Element_PCLN::update(UPDATE_FUNC_ARGS) else if (parts[i].ctype==PT_LIFE)//create life a different way for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) - sim->create_part(-1, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8)); + sim->create_part(-1, x+rx, y+ry, PT_LIFE, parts[i].tmp); else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0) { - int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype); + int np = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype&0xFF); if (np>=0) { if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmpelements[parts[i].tmp].HighTemperatureTransition==PT_LAVA) diff --git a/src/simulation/elements/STOR.cpp b/src/simulation/elements/STOR.cpp index 6e45f6d7a..ff07e9398 100644 --- a/src/simulation/elements/STOR.cpp +++ b/src/simulation/elements/STOR.cpp @@ -75,7 +75,7 @@ int Element_STOR::update(UPDATE_FUNC_ARGS) { for(ry1 = 1; ry1 >= -1; ry1--){ for(rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1-rx1+1){ // Oscillate the X starting at 0, 1, -1, 3, -5, etc (Though stop at -1) - np = sim->create_part(-1,x+rx1,y+ry1,parts[i].tmp); + np = sim->create_part(-1,x+rx1,y+ry1,parts[i].tmp&0xFF); if (np!=-1) { parts[np].temp = parts[i].temp;