Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "simulation/Elements.h"
- //#include "mover.h"
- //spawns with random life between 200 and 800 frames
- Element_PBAL::Element_PBAL()
- {
- Identifier = "DEFAULT_PT_PBAL";
- Name = "PBAL";
- Colour = PIXPACK(0x7DF9FF);
- MenuVisible = 1;
- MenuSection = SC_SPECIAL;
- Enabled = 1;
- Advection = 0.0f;
- AirDrag = 0.001f * CFDS;
- AirLoss = 0.97f;
- Loss = 0.20f;
- Collision = 0.0f;
- Gravity = 0.0f;
- Diffusion = 0.00f;
- HotAir = 0.000f * CFDS;
- Falldown = 0;
- Flammable = 0;
- Explosive = 0;
- Meltable = 0;
- Hardness = 0;
- Weight = 10;
- Temperature = R_TEMP+MAX_TEMP;
- HeatConduct = 251;
- Description = "Plasma Ball. Floats and behaves like a moving solid. Explosive.";
- State = ST_SOLID;
- Properties = TYPE_SOLID|PROP_LIFE_DEC;
- LowPressure = IPL;
- LowPressureTransition = NT;
- HighPressure = IPH;
- HighPressureTransition = NT;
- LowTemperature = ITL;
- LowTemperatureTransition = NT;
- HighTemperature = ITH;
- HighTemperatureTransition = NT;
- Update = &Element_PBAL::update;
- Graphics = &Element_PBAL::graphics;
- }
- int Element_PBAL::update(UPDATE_FUNC_ARGS)
- {
- int msindex[256];
- int msnum[256];
- float msvx[256];
- float msvy[256];
- float msrotation[256];
- float newmsrotation[256];
- int numballs;
- int ms_rotation;
- int r, rt, rx, ry;
- for (rx=-2; rx<=3; rx++)
- for (ry=-2; ry<=3; ry++)
- if (BOUNDS_CHECK) {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- int rt = r&0xFF;
- if(parts[i].tmp==0)
- {
- parts[i].temp==MAX_TEMP;
- if (((r&0xFF)!=PT_PBAL))
- {
- if(!(rand()%500))
- {
- sim->create_part(-1,x+rand()%3-1,y+rand()%3-1,PT_PLSM);
- }
- }
- if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW))
- {
- parts[r>>8].life = 4;
- parts[r>>8].ctype = rt;
- sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
- }
- }
- if(parts[i].tmp>=1)
- {
- parts[i].temp= R_TEMP+0.0f +273.15f;
- if ((sim->elements[rt].Properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW))
- {
- parts[r>>8].life = 4;
- parts[r>>8].ctype = rt;
- sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
- }
- }
- }
- int bn = parts[i].tmp2, type, bounce = 4;
- float tmp = 0, tmp2 = 0;
- bool pop = false;
- if (bn < 0 || bn > 255)
- return 0;
- //kill moving solid control particle with a lot of pressure (other ones dissapear at 30 pressure)
- if (!tmp && !tmp2 && sim->pv[y/CELL][x/CELL] > 10 || sim->pv[y/CELL][x/CELL] < -10)
- {
- parts[bn].ctype = PT_BANG;
- if ((pmap[y][x]>>8 == i))
- {
- int tempvalue = 2;
- sim->flood_prop(x, y, offsetof(Particle, tmp), &tempvalue, StructProperty::Integer);
- }
- float otemp = parts[i].temp-273.15f;
- //Explode!!
- sim->pv[y/CELL][x/CELL] += 0.5f;
- if(!(rand()%3))
- {
- if(!(rand()%2))
- {
- sim->create_part(i, x, y, PT_PLSM);
- }
- parts[i].temp = restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP);
- }
- else
- {
- if(!(rand()%15))
- {
- sim->create_part(i, x, y, PT_EMBR);
- parts[i].tmp = 0;
- parts[i].life = 50;
- parts[i].temp = restrict_flt((MAX_TEMP/3)+otemp, MIN_TEMP, MAX_TEMP);
- parts[i].vx = rand()%20-10;
- parts[i].vy = rand()%20-10;
- }
- }
- msindex[bn]-bn;
- msindex[bn]--;
- return 1;
- }
- if(parts[i].life<=0&&parts[i].tmp==0)
- {
- pop=true;
- }
- //center control particle was killed, ball explodes
- if ((!msindex[bn] && parts[i].tmp==0) || (parts[bn].ctype==PT_BANG && parts[i].tmp==0) || pop==true)
- {
- if ((pmap[y][x]>>8 == i))
- {
- int tempvalue = 2;
- sim->flood_prop(x, y, offsetof(Particle, tmp), &tempvalue, StructProperty::Integer);
- }
- else
- {
- float otemp = parts[i].temp-273.15f;
- //Explode!!
- sim->pv[y/CELL][x/CELL] += 0.5f;
- if(!(rand()%3))
- {
- if(!(rand()%2))
- {
- sim->create_part(i, x, y, PT_PLSM);
- }
- parts[i].temp = restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP);
- }
- else
- {
- if(!(rand()%15))
- {
- sim->create_part(i, x, y, PT_EMBR);
- parts[i].tmp = 0;
- parts[i].life = 50;
- parts[i].temp = restrict_flt((MAX_TEMP/3)+otemp, MIN_TEMP, MAX_TEMP);
- parts[i].vx = rand()%20-10;
- parts[i].vy = rand()%20-10;
- }
- else
- {
- sim->kill_part(i);
- }
- }
- return 1;
- }
- }
- if (!msindex[bn] && parts[i].tmp>=1)
- {
- sim->kill_part(i);
- return 1;
- }
- //speed improvement if rotation disabled, no need to do trigonometry
- else if (!ms_rotation)
- {
- tmp = parts[i].pavg[0];
- tmp2 = parts[i].pavg[1];
- }
- //determine rotated x and y coordinates relative to center
- else if (parts[i].pavg[0] != 0)
- {
- float angle = atan((float)parts[i].pavg[1]/parts[i].pavg[0]);
- float distance = sqrt(pow((float)parts[i].pavg[0],2)+pow((float)parts[i].pavg[1],2));
- if (parts[i].pavg[0] < 0)
- angle += M_PI;
- tmp = distance*cos(angle+msrotation[bn]);
- tmp2 = distance*sin(angle+msrotation[bn]);
- }
- else if (parts[i].pavg[1] != 0)
- {
- float angle = M_PI/2;
- tmp = parts[msindex[bn]-1].x + parts[i].pavg[1]*cos(angle+msrotation[bn]);
- if (parts[i].pavg[1] < 0)
- tmp2 = parts[i].pavg[1]*sin(angle+msrotation[bn]);
- else
- tmp2 = -1*parts[i].pavg[1]*sin(angle+msrotation[bn]);
- }
- type = pmap[y+1][x]&0xFF;
- //bottom side collision
- if (tmp2 > 0 && type && y+1 < YRES && ((type != parts[i].type && !sim->eval_move(parts[i].type,x,y+1,NULL)) || (type == parts[i].type && parts[pmap[y+1][x]>>8].tmp2 != bn)))
- {
- parts[i].vy -= tmp2*bounce;
- newmsrotation[bn] -= tmp/50000;
- }
- type = pmap[y-1][x]&0xFF;
- //top side collision
- if (tmp2 < 0 && type && y-1 >= 0 && ((type != parts[i].type && !sim->eval_move(parts[i].type,x,y-1,NULL)) || (type == parts[i].type && parts[pmap[y-1][x]>>8].tmp2 != bn)))
- {
- parts[i].vy -= tmp2*bounce;
- newmsrotation[bn] -= tmp/50000;
- }
- type = pmap[y][x+1]&0xFF;
- //right side collision
- if (tmp > 0 && type && x+1 < XRES && ((type != parts[i].type && !sim->eval_move(parts[i].type,x+1,y,NULL)) || (type == parts[i].type && parts[pmap[y][x+1]>>8].tmp2 != bn)))
- {
- parts[i].vx -= tmp*bounce;
- newmsrotation[bn] -= tmp/50000;
- }
- type = pmap[y][x-1]&0xFF;
- //left side collision
- if (tmp < 0 && type && x-1 >= 0 && ((type != parts[i].type && !sim->eval_move(parts[i].type,x-1,y,NULL)) || (type == parts[i].type && parts[pmap[y][x-1]>>8].tmp2 != bn)))
- {
- parts[i].vx -= tmp*bounce;
- newmsrotation[bn] -= tmp/50000;
- }
- if(sim->pv[x/CELL][y/CELL] >= 0.3)
- {
- parts[bn].vx = sim->vx[y/CELL][x/CELL];
- parts[bn].vy = sim->vy[y/CELL][x/CELL];
- newmsrotation[bn] -= tmp/50000;
- }
- return(0);
- }
- int Element_PBAL::graphics(GRAPHICS_FUNC_ARGS)
- {
- *firea = 160;
- *fireg = 192;
- *fireb = 255;
- *firer = 144;
- *pixel_mode |= FIRE_ADD;
- return NULL;
- }
- Element_PBAL::~Element_PBAL() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement