diff --git a/src/simulation/ElementDefs.h b/src/simulation/ElementDefs.h index e6d77b8b8..b16aaceb5 100644 --- a/src/simulation/ElementDefs.h +++ b/src/simulation/ElementDefs.h @@ -45,6 +45,8 @@ #define GRAPHICS_FUNC_ARGS Renderer * ren, Particle *cpart, int nx, int ny, int *pixel_mode, int* cola, int *colr, int *colg, int *colb, int *firea, int *firer, int *fireg, int *fireb #define GRAPHICS_FUNC_SUBCALL_ARGS ren, cpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb +#define ELEMENT_CREATE_FUNC_ARGS Simulation *sim, int i, int x, int y, int t, int v + #define CTYPEDRAW_FUNC_ARGS Simulation *sim, int i, int t, int v #define CTYPEDRAW_FUNC_SUBCALL_ARGS sim, i, t, v diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 5841a8c43..ff4c777a1 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -3285,54 +3285,9 @@ int Simulation::create_part(int p, int x, int y, int t, int v) parts[i].type = t; parts[i].x = (float)x; parts[i].y = (float)y; - if (t == PT_GLAS || t == PT_QRTZ || t == PT_TUNG) - { - parts[i].pavg[0] = 0.0f; - parts[i].pavg[1] = pv[y/CELL][x/CELL]; - } switch (t) { - case PT_WARP: - parts[i].life = RNG::Ref().between(70, 164); - break; - case PT_LIFE: - if (v < NGOL) - { - parts[i].tmp = grule[v+1][9] - 1; - parts[i].ctype = v; - } - break; - case PT_SING: - parts[i].life = RNG::Ref().between(60, 109); - break; - case PT_QRTZ: - case PT_PQRT: - parts[i].tmp2 = RNG::Ref().between(0, 10); - break; - case PT_CLST: - parts[i].tmp = RNG::Ref().between(0, 6); - break; - case PT_FIRE: - parts[i].life = RNG::Ref().between(120, 169); - break; - case PT_PLSM: - parts[i].life = RNG::Ref().between(50, 199); - break; - case PT_CFLM: - parts[i].life = RNG::Ref().between(50, 199); - break; - case PT_LAVA: - parts[i].life = RNG::Ref().between(240, 359); - break; - case PT_TESC: - parts[i].tmp = v; - if (parts[i].tmp > 300) - parts[i].tmp=300; - break; - case PT_CRMC: - parts[i].tmp2 = RNG::Ref().between(0, 4); - break; case PT_ETRD: etrd_life0_count++; break; @@ -3340,7 +3295,6 @@ int Simulation::create_part(int p, int x, int y, int t, int v) { if (player.spwn == 0) { - parts[i].life = 100; Element_STKM::STKM_init_legs(this, &player, i); player.spwn = 1; player.rocketBoots = false; @@ -3350,16 +3304,12 @@ int Simulation::create_part(int p, int x, int y, int t, int v) parts[i].type = 0; return -1; } - int spawnID = create_part(-3, x, y, PT_SPAWN); - if (spawnID >= 0) - player.spawnID = spawnID; break; } case PT_STKM2: { if (player2.spwn == 0) { - parts[i].life = 100; Element_STKM::STKM_init_legs(this, &player2, i); player2.spwn = 1; player2.rocketBoots = false; @@ -3369,9 +3319,6 @@ int Simulation::create_part(int p, int x, int y, int t, int v) parts[i].type = 0; return -1; } - int spawnID = create_part(-3, x, y, PT_SPAWN2); - if (spawnID >= 0) - player2.spawnID = spawnID; break; } case PT_FIGH: @@ -3380,7 +3327,6 @@ int Simulation::create_part(int p, int x, int y, int t, int v) while (fcount < MAX_FIGHTERS && fighters[fcount].spwn==1) fcount++; if (fcount < MAX_FIGHTERS && fighters[fcount].spwn == 0) { - parts[i].life = 100; parts[i].tmp = fcount; Element_STKM::STKM_init_legs(this, &fighters[fcount], i); fighters[fcount].spwn = 1; @@ -3392,90 +3338,6 @@ int Simulation::create_part(int p, int x, int y, int t, int v) parts[i].type=0; return -1; } - case PT_PHOT: - { - float a = RNG::Ref().between(0, 7) * 0.78540f; - parts[i].life = 680; - parts[i].ctype = 0x3FFFFFFF; - parts[i].vx = 3.0f*cosf(a); - parts[i].vy = 3.0f*sinf(a); - if (TYP(pmap[y][x]) == PT_FILT) - parts[i].ctype = Element_FILT::interactWavelengths(&parts[ID(pmap[y][x])], parts[i].ctype); - break; - } - case PT_ELEC: - { - float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; - parts[i].life = 680; - parts[i].vx = 2.0f*cosf(a); - parts[i].vy = 2.0f*sinf(a); - break; - } - case PT_NEUT: - { - float r = RNG::Ref().between(128, 255) / 127.0f; - float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; - parts[i].life = RNG::Ref().between(480, 959); - parts[i].vx = r*cosf(a); - parts[i].vy = r*sinf(a); - break; - } - case PT_PROT: - { - float a = RNG::Ref().between(0, 35) * 0.17453f; - parts[i].life = 680; - parts[i].vx = 2.0f*cosf(a); - parts[i].vy = 2.0f*sinf(a); - break; - } - case PT_GRVT: - { - float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; - parts[i].life = RNG::Ref().between(250, 449); - parts[i].vx = 2.0f*cosf(a); - parts[i].vy = 2.0f*sinf(a); - parts[i].tmp = 7; - break; - } - case PT_TRON: - { - int randhue = RNG::Ref().between(0, 359); - int randomdir = RNG::Ref().between(0, 3); - parts[i].tmp = 1|(randomdir<<5)|(randhue<<7);//set as a head and a direction - parts[i].tmp2 = 4;//tail - parts[i].life = 5; - break; - } - case PT_LIGH: - { - float gx, gy, gsize; - - if (v >= 0) - { - if (v > 55) - v = 55; - parts[i].life = v; - } - else - parts[i].life = 30; - parts[i].temp = parts[i].life*150.0f; // temperature of the lightning shows the power of the lightning - GetGravityField(x, y, 1.0f, 1.0f, gx, gy); - gsize = gx*gx+gy*gy; - if (gsize<0.0016f) - { - float angle = RNG::Ref().between(0, 6283) * 0.001f;//(in radians, between 0 and 2*pi) - gsize = sqrtf(gsize); - // randomness in weak gravity fields (more randomness with weaker fields) - gx += cosf(angle)*(0.04f-gsize); - gy += sinf(angle)*(0.04f-gsize); - } - parts[i].tmp = (((int)(atan2f(-gy, gx)*(180.0f/M_PI))) + RNG::Ref().between(340, 380)) % 360; - parts[i].tmp2 = 4; - break; - } - case PT_FILT: - parts[i].tmp = v; - break; default: break; } @@ -3497,6 +3359,13 @@ int Simulation::create_part(int p, int x, int y, int t, int v) colb = colb>255 ? 255 : (colb<0 ? 0 : colb); parts[i].dcolour = (RNG::Ref().between(0, 149)<<24) | (colr<<16) | (colg<<8) | colb; } + + // Set non-static properties (such as randomly generated ones) + if (elements[t].Create) + { + (*(elements[t].Create))(this, i, x, y, t, v); + } + elementCount[t]++; return i; } diff --git a/src/simulation/elements/CFLM.cpp b/src/simulation/elements/CFLM.cpp index f56f76c4f..f90448b69 100644 --- a/src/simulation/elements/CFLM.cpp +++ b/src/simulation/elements/CFLM.cpp @@ -45,6 +45,7 @@ Element_CFLM::Element_CFLM() Update = NULL; Graphics = &Element_CFLM::graphics; + Create = &Element_CFLM::create; } //#TPT-Directive ElementHeader Element_CFLM static int graphics(GRAPHICS_FUNC_ARGS) @@ -67,5 +68,10 @@ int Element_CFLM::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_CFLM static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_CFLM::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].life = RNG::Ref().between(50, 199); +} Element_CFLM::~Element_CFLM() {} diff --git a/src/simulation/elements/CLST.cpp b/src/simulation/elements/CLST.cpp index e86148501..b5344d163 100644 --- a/src/simulation/elements/CLST.cpp +++ b/src/simulation/elements/CLST.cpp @@ -42,6 +42,7 @@ Element_CLST::Element_CLST() Update = &Element_CLST::update; Graphics = &Element_CLST::graphics; + Create = &Element_CLST::create; } //#TPT-Directive ElementHeader Element_CLST static int update(UPDATE_FUNC_ARGS) @@ -98,5 +99,10 @@ int Element_CLST::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_CLST static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_CLST::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].tmp = RNG::Ref().between(0, 6); +} Element_CLST::~Element_CLST() {} diff --git a/src/simulation/elements/CRMC.cpp b/src/simulation/elements/CRMC.cpp index 4a0ac3558..5f90f7a9f 100644 --- a/src/simulation/elements/CRMC.cpp +++ b/src/simulation/elements/CRMC.cpp @@ -42,6 +42,7 @@ Element_CRMC::Element_CRMC() Update = &Element_CRMC::update; Graphics = &Element_CRMC::graphics; + Create = &Element_CRMC::create; } //#TPT-Directive ElementHeader Element_CRMC static int update(UPDATE_FUNC_ARGS) @@ -62,5 +63,11 @@ int Element_CRMC::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_CRMC static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_CRMC::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].tmp2 = RNG::Ref().between(0, 4); +} + Element_CRMC::~Element_CRMC() {} diff --git a/src/simulation/elements/ELEC.cpp b/src/simulation/elements/ELEC.cpp index ec50cf8fb..a384d3f72 100644 --- a/src/simulation/elements/ELEC.cpp +++ b/src/simulation/elements/ELEC.cpp @@ -43,6 +43,7 @@ Element_ELEC::Element_ELEC() Update = &Element_ELEC::update; Graphics = &Element_ELEC::graphics; + Create = &Element_ELEC::create; } //#TPT-Directive ElementHeader Element_ELEC static int update(UPDATE_FUNC_ARGS) @@ -135,5 +136,13 @@ int Element_ELEC::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_ELEC static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_ELEC::create(ELEMENT_CREATE_FUNC_ARGS) +{ + float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; + sim->parts[i].life = 680; + sim->parts[i].vx = 2.0f * cosf(a); + sim->parts[i].vy = 2.0f * sinf(a); +} Element_ELEC::~Element_ELEC() {} diff --git a/src/simulation/elements/Element.h b/src/simulation/elements/Element.h index 09be83bbe..dd6a099d5 100644 --- a/src/simulation/elements/Element.h +++ b/src/simulation/elements/Element.h @@ -52,6 +52,9 @@ public: int (*Update) (UPDATE_FUNC_ARGS); int (*Graphics) (GRAPHICS_FUNC_ARGS); + + void (*Create)(ELEMENT_CREATE_FUNC_ARGS) = nullptr; + bool (*CtypeDraw) (CTYPEDRAW_FUNC_ARGS); VideoBuffer * (*IconGenerator)(int, int, int); diff --git a/src/simulation/elements/FILT.cpp b/src/simulation/elements/FILT.cpp index 36e8f2c13..7cc1c57a1 100644 --- a/src/simulation/elements/FILT.cpp +++ b/src/simulation/elements/FILT.cpp @@ -42,6 +42,7 @@ Element_FILT::Element_FILT() Update = NULL; Graphics = &Element_FILT::graphics; + Create = &Element_FILT::create; } //#TPT-Directive ElementHeader Element_FILT static int graphics(GRAPHICS_FUNC_ARGS) @@ -70,6 +71,12 @@ int Element_FILT::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_FILT static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_FILT::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].tmp = v; +} + //#TPT-Directive ElementHeader Element_FILT static int interactWavelengths(Particle* cpart, int origWl) // Returns the wavelengths in a particle after FILT interacts with it (e.g. a photon) // cpart is the FILT particle, origWl the original wavelengths in the interacting particle diff --git a/src/simulation/elements/FIRE.cpp b/src/simulation/elements/FIRE.cpp index 04c1e172c..1dade6908 100644 --- a/src/simulation/elements/FIRE.cpp +++ b/src/simulation/elements/FIRE.cpp @@ -45,6 +45,7 @@ Element_FIRE::Element_FIRE() Update = &Element_FIRE::update; Graphics = &Element_FIRE::graphics; + Create = &Element_FIRE::create; } //#TPT-Directive ElementHeader Element_FIRE static int update(UPDATE_FUNC_ARGS) @@ -265,4 +266,10 @@ int Element_FIRE::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_FIRE static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_FIRE::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].life = RNG::Ref().between(120, 169); +} + Element_FIRE::~Element_FIRE() {} diff --git a/src/simulation/elements/GLAS.cpp b/src/simulation/elements/GLAS.cpp index 3466e0d1f..b430276c8 100644 --- a/src/simulation/elements/GLAS.cpp +++ b/src/simulation/elements/GLAS.cpp @@ -41,6 +41,7 @@ Element_GLAS::Element_GLAS() HighTemperatureTransition = PT_LAVA; Update = &Element_GLAS::update; + Create = &Element_GLAS::create; } //#TPT-Directive ElementHeader Element_GLAS static int update(UPDATE_FUNC_ARGS) @@ -56,5 +57,10 @@ int Element_GLAS::update(UPDATE_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_GLAS static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_GLAS::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].pavg[1] = sim->pv[y/CELL][x/CELL]; +} Element_GLAS::~Element_GLAS() {} diff --git a/src/simulation/elements/GRVT.cpp b/src/simulation/elements/GRVT.cpp index 8e4e5dc83..64799463d 100644 --- a/src/simulation/elements/GRVT.cpp +++ b/src/simulation/elements/GRVT.cpp @@ -44,6 +44,7 @@ Element_GRVT::Element_GRVT() Update = &Element_GRVT::update; Graphics = &Element_GRVT::graphics; + Create = &Element_GRVT::create; } //#TPT-Directive ElementHeader Element_GRVT static int update(UPDATE_FUNC_ARGS) @@ -71,4 +72,13 @@ int Element_GRVT::graphics(GRAPHICS_FUNC_ARGS) return 1; } +//#TPT-Directive ElementHeader Element_GRVT static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_GRVT::create(ELEMENT_CREATE_FUNC_ARGS) +{ + float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; + sim->parts[i].life = 250 + RNG::Ref().between(0, 199); + sim->parts[i].vx = 2.0f*cosf(a); + sim->parts[i].vy = 2.0f*sinf(a); +} + Element_GRVT::~Element_GRVT() {} diff --git a/src/simulation/elements/LAVA.cpp b/src/simulation/elements/LAVA.cpp index c9d92ab7d..296ca974d 100644 --- a/src/simulation/elements/LAVA.cpp +++ b/src/simulation/elements/LAVA.cpp @@ -44,6 +44,7 @@ Element_LAVA::Element_LAVA() Update = &Element_FIRE::update; Graphics = &Element_LAVA::graphics; + Create = &Element_LAVA::create; } @@ -67,5 +68,10 @@ int Element_LAVA::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_LAVA static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_LAVA::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].life = RNG::Ref().between(240, 359); +} Element_LAVA::~Element_LAVA() {} diff --git a/src/simulation/elements/LIFE.cpp b/src/simulation/elements/LIFE.cpp index dd404c92f..4b543b3a6 100644 --- a/src/simulation/elements/LIFE.cpp +++ b/src/simulation/elements/LIFE.cpp @@ -47,8 +47,9 @@ Element_LIFE::Element_LIFE() Update = NULL; Graphics = &Element_LIFE::graphics; + Create = &Element_LIFE::create; - if(!Element_GOL_colourInit) + if (!Element_GOL_colourInit) { Element_GOL_colourInit = true; @@ -120,5 +121,14 @@ int Element_LIFE::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_LIFE static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_LIFE::create(ELEMENT_CREATE_FUNC_ARGS) +{ + if (v >= 0 && v < NGOL) + { + sim->parts[i].tmp = sim->grule[v+1][9] - 1; + sim->parts[i].ctype = v; + } +} Element_LIFE::~Element_LIFE() {} diff --git a/src/simulation/elements/LIGH.cpp b/src/simulation/elements/LIGH.cpp index 287ee3e77..ab512fcc2 100644 --- a/src/simulation/elements/LIGH.cpp +++ b/src/simulation/elements/LIGH.cpp @@ -43,6 +43,7 @@ Element_LIGH::Element_LIGH() Update = &Element_LIGH::update; Graphics = &Element_LIGH::graphics; + Create = &Element_LIGH::create; } #define LIGHTING_POWER 0.65 @@ -376,5 +377,31 @@ int Element_LIGH::graphics(GRAPHICS_FUNC_ARGS) return 1; } +//#TPT-Directive ElementHeader Element_LIGH static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_LIGH::create(ELEMENT_CREATE_FUNC_ARGS) +{ + float gx, gy, gsize; + if (v >= 0) + { + if (v > 55) + v = 55; + sim->parts[i].life = v; + } + else + sim->parts[i].life = 30; + sim->parts[i].temp = sim->parts[i].life * 150.0f; // temperature of the lightning shows the power of the lightning + sim->GetGravityField(x, y, 1.0f, 1.0f, gx, gy); + gsize = gx * gx + gy * gy; + if (gsize < 0.0016f) + { + float angle = RNG::Ref().between(0, 6283) * 0.001f; //(in radians, between 0 and 2*pi) + gsize = sqrtf(gsize); + // randomness in weak gravity fields (more randomness with weaker fields) + gx += cosf(angle) * (0.04f - gsize); + gy += sinf(angle) * (0.04f - gsize); + } + sim->parts[i].tmp = (static_cast(atan2f(-gy, gx) * (180.0f / M_PI)) + RNG::Ref().between(-20, 20) + 360) % 360; + sim->parts[i].tmp2 = 4; +} Element_LIGH::~Element_LIGH() {} diff --git a/src/simulation/elements/NEUT.cpp b/src/simulation/elements/NEUT.cpp index 1e43a6706..3677e030d 100644 --- a/src/simulation/elements/NEUT.cpp +++ b/src/simulation/elements/NEUT.cpp @@ -43,6 +43,7 @@ Element_NEUT::Element_NEUT() Update = &Element_NEUT::update; Graphics = &Element_NEUT::graphics; + Create = &Element_NEUT::create; } //#TPT-Directive ElementHeader Element_NEUT static int update(UPDATE_FUNC_ARGS) @@ -196,6 +197,16 @@ int Element_NEUT::graphics(GRAPHICS_FUNC_ARGS) return 1; } +//#TPT-Directive ElementHeader Element_NEUT static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_NEUT::create(ELEMENT_CREATE_FUNC_ARGS) +{ + float r = RNG::Ref().between(128, 255) / 127.0f; + float a = RNG::Ref().between(0, 359) * 3.14159f / 180.0f; + sim->parts[i].life = RNG::Ref().between(480, 959); + sim->parts[i].vx = r * cosf(a); + sim->parts[i].vy = r * sinf(a); +} + //#TPT-Directive ElementHeader Element_NEUT static int DeutExplosion(Simulation * sim, int n, int x, int y, float temp, int t) int Element_NEUT::DeutExplosion(Simulation * sim, int n, int x, int y, float temp, int t)//testing a new deut create part { diff --git a/src/simulation/elements/PHOT.cpp b/src/simulation/elements/PHOT.cpp index 5d0b44706..a7de41cc1 100644 --- a/src/simulation/elements/PHOT.cpp +++ b/src/simulation/elements/PHOT.cpp @@ -46,6 +46,7 @@ Element_PHOT::Element_PHOT() Update = &Element_PHOT::update; Graphics = &Element_PHOT::graphics; + Create = &Element_PHOT::create; } //#TPT-Directive ElementHeader Element_PHOT static int update(UPDATE_FUNC_ARGS) @@ -144,5 +145,14 @@ int Element_PHOT::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_PHOT static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_PHOT::create(ELEMENT_CREATE_FUNC_ARGS) +{ + float a = RNG::Ref().between(0, 7) * 0.78540f; + sim->parts[i].vx = 3.0f * cosf(a); + sim->parts[i].vy = 3.0f * sinf(a); + if (TYP(sim->pmap[y][x]) == PT_FILT) + sim->parts[i].ctype = Element_FILT::interactWavelengths(&sim->parts[ID(sim->pmap[y][x])], sim->parts[i].ctype); +} Element_PHOT::~Element_PHOT() {} diff --git a/src/simulation/elements/PLSM.cpp b/src/simulation/elements/PLSM.cpp index af81b5d74..397c3e8a6 100644 --- a/src/simulation/elements/PLSM.cpp +++ b/src/simulation/elements/PLSM.cpp @@ -43,6 +43,7 @@ Element_PLSM::Element_PLSM() Update = &Element_FIRE::update; Graphics = &Element_PLSM::graphics; + Create = &Element_PLSM::create; } //#TPT-Directive ElementHeader Element_PLSM static int graphics(GRAPHICS_FUNC_ARGS) @@ -65,5 +66,10 @@ int Element_PLSM::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_PLSM static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_PLSM::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].life = RNG::Ref().between(50, 199); +} Element_PLSM::~Element_PLSM() {} diff --git a/src/simulation/elements/PQRT.cpp b/src/simulation/elements/PQRT.cpp index 8f29bf200..242375d57 100644 --- a/src/simulation/elements/PQRT.cpp +++ b/src/simulation/elements/PQRT.cpp @@ -42,6 +42,13 @@ Element_PQRT::Element_PQRT() Update = &Element_QRTZ::update; Graphics = &Element_QRTZ::graphics; + Create = &Element_PQRT::create; +} + +//#TPT-Directive ElementHeader Element_PQRT static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_PQRT::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].tmp2 = RNG::Ref().between(0, 10); } Element_PQRT::~Element_PQRT() {} diff --git a/src/simulation/elements/PROT.cpp b/src/simulation/elements/PROT.cpp index 78074d862..24613828b 100644 --- a/src/simulation/elements/PROT.cpp +++ b/src/simulation/elements/PROT.cpp @@ -44,6 +44,7 @@ Element_PROT::Element_PROT() Update = &Element_PROT::update; Graphics = &Element_PROT::graphics; + Create = &Element_PROT::create; } //#TPT-Directive ElementHeader Element_PROT static int update(UPDATE_FUNC_ARGS) @@ -204,4 +205,13 @@ int Element_PROT::graphics(GRAPHICS_FUNC_ARGS) return 1; } +//#TPT-Directive ElementHeader Element_PROT static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_PROT::create(ELEMENT_CREATE_FUNC_ARGS) +{ + float a = RNG::Ref().between(0, 35) * 0.17453f; + sim->parts[i].life = 680; + sim->parts[i].vx = 2.0f * cosf(a); + sim->parts[i].vy = 2.0f * sinf(a); +} + Element_PROT::~Element_PROT() {} diff --git a/src/simulation/elements/QRTZ.cpp b/src/simulation/elements/QRTZ.cpp index 55c312e92..4e7281fce 100644 --- a/src/simulation/elements/QRTZ.cpp +++ b/src/simulation/elements/QRTZ.cpp @@ -42,6 +42,7 @@ Element_QRTZ::Element_QRTZ() Update = &Element_QRTZ::update; Graphics = &Element_QRTZ::graphics; + Create = &Element_QRTZ::create; } //#TPT-Directive ElementHeader Element_QRTZ static int update(UPDATE_FUNC_ARGS) @@ -155,5 +156,11 @@ int Element_QRTZ::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_QRTZ static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_QRTZ::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].tmp2 = RNG::Ref().between(0, 10); + sim->parts[i].pavg[1] = sim->pv[y/CELL][x/CELL]; +} Element_QRTZ::~Element_QRTZ() {} diff --git a/src/simulation/elements/SING.cpp b/src/simulation/elements/SING.cpp index 532d40347..26a2b56d5 100644 --- a/src/simulation/elements/SING.cpp +++ b/src/simulation/elements/SING.cpp @@ -41,6 +41,7 @@ Element_SING::Element_SING() HighTemperatureTransition = NT; Update = &Element_SING::update; + Create = &Element_SING::create; } //#TPT-Directive ElementHeader Element_SING static int update(UPDATE_FUNC_ARGS) @@ -140,5 +141,10 @@ int Element_SING::update(UPDATE_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_SING static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_SING::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].life = RNG::Ref().between(60, 109); +} Element_SING::~Element_SING() {} diff --git a/src/simulation/elements/STKM.cpp b/src/simulation/elements/STKM.cpp index 080a3734b..69c802fd3 100644 --- a/src/simulation/elements/STKM.cpp +++ b/src/simulation/elements/STKM.cpp @@ -46,11 +46,11 @@ Element_STKM::Element_STKM() Update = &Element_STKM::update; Graphics = &Element_STKM::graphics; + Create = &Element_STKM::create; } //#TPT-Directive ElementHeader Element_STKM static int update(UPDATE_FUNC_ARGS) int Element_STKM::update(UPDATE_FUNC_ARGS) - { run_stickman(&sim->player, UPDATE_FUNC_SUBCALL_ARGS); return 0; @@ -66,6 +66,14 @@ int Element_STKM::graphics(GRAPHICS_FUNC_ARGS) return 1; } +//#TPT-Directive ElementHeader Element_STKM static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_STKM::create(ELEMENT_CREATE_FUNC_ARGS) +{ + int spawnID = sim->create_part(-3, x, y, PT_SPAWN); + if (spawnID >= 0) + sim->player.spawnID = spawnID; +} + #define INBOND(x, y) ((x)>=0 && (y)>=0 && (x)create_part(-3, x, y, PT_SPAWN2); + if (spawnID >= 0) + sim->player2.spawnID = spawnID; +} + Element_STKM2::~Element_STKM2() {} diff --git a/src/simulation/elements/TESC.cpp b/src/simulation/elements/TESC.cpp index d6aeaafbd..c7bf47016 100644 --- a/src/simulation/elements/TESC.cpp +++ b/src/simulation/elements/TESC.cpp @@ -41,6 +41,18 @@ Element_TESC::Element_TESC() HighTemperatureTransition = NT; Update = NULL; + Create = &Element_TESC::create; +} + +//#TPT-Directive ElementHeader Element_TESC static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_TESC::create(ELEMENT_CREATE_FUNC_ARGS) +{ + if (v >= 0) + { + sim->parts[i].tmp = v; + if (sim->parts[i].tmp > 300) + sim->parts[i].tmp = 300; + } } Element_TESC::~Element_TESC() {} diff --git a/src/simulation/elements/TRON.cpp b/src/simulation/elements/TRON.cpp index 286997e5f..ac98895a2 100644 --- a/src/simulation/elements/TRON.cpp +++ b/src/simulation/elements/TRON.cpp @@ -43,6 +43,7 @@ Element_TRON::Element_TRON() Update = &Element_TRON::update; Graphics = &Element_TRON::graphics; + Create = &Element_TRON::create; Element_TRON::init_graphics(); } @@ -158,8 +159,6 @@ int Element_TRON::update(UPDATE_FUNC_ARGS) return 0; } - - //#TPT-Directive ElementHeader Element_TRON static int graphics(GRAPHICS_FUNC_ARGS) int Element_TRON::graphics(GRAPHICS_FUNC_ARGS) { @@ -186,6 +185,18 @@ int Element_TRON::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_TRON static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_TRON::create(ELEMENT_CREATE_FUNC_ARGS) +{ + int randhue = RNG::Ref().between(0, 359); + int randomdir = RNG::Ref().between(0, 3); + // Set as a head and a direction + sim->parts[i].tmp = 1 | (randomdir << 5) | (randhue << 7); + // Tail + sim->parts[i].tmp2 = 4; + sim->parts[i].life = 5; +} + //#TPT-Directive ElementHeader Element_TRON static int new_tronhead(Simulation * sim, int x, int y, int i, int direction) int Element_TRON::new_tronhead(Simulation * sim, int x, int y, int i, int direction) { diff --git a/src/simulation/elements/WARP.cpp b/src/simulation/elements/WARP.cpp index 6d88eafa6..1878260a7 100644 --- a/src/simulation/elements/WARP.cpp +++ b/src/simulation/elements/WARP.cpp @@ -42,6 +42,7 @@ Element_WARP::Element_WARP() Update = &Element_WARP::update; Graphics = &Element_WARP::graphics; + Create = &Element_WARP::create; } //#TPT-Directive ElementHeader Element_WARP static int update(UPDATE_FUNC_ARGS) @@ -90,4 +91,10 @@ int Element_WARP::graphics(GRAPHICS_FUNC_ARGS) return 0; } +//#TPT-Directive ElementHeader Element_WARP static void create(ELEMENT_CREATE_FUNC_ARGS) +void Element_WARP::create(ELEMENT_CREATE_FUNC_ARGS) +{ + sim->parts[i].life = RNG::Ref().between(70, 164); +} + Element_WARP::~Element_WARP() {}