summaryrefslogtreecommitdiff
path: root/src/powder.c
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-05-24 18:53:50 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-05-24 18:53:50 (GMT)
commit8196d2a645d386b5c97134c446e959e5e50a345b (patch)
tree33e729715a6122fa5b8dac6f9abf7b784bfbfbc3 /src/powder.c
parent5a117c2d27f513942d7621980a79d357af122ba4 (diff)
parent1fb778724329782bb5616da032742dce4dbea131 (diff)
downloadpowder-8196d2a645d386b5c97134c446e959e5e50a345b.zip
powder-8196d2a645d386b5c97134c446e959e5e50a345b.tar.gz
Merge pull request #66 from jacob1/Modstuff
Code structure improvements for graphics/drawing, improvements to prevent accidental infinite loops in Lua, Fixes for fusion, improvements for VOID types. And other minor improvements
Diffstat (limited to 'src/powder.c')
-rw-r--r--src/powder.c84
1 files changed, 31 insertions, 53 deletions
diff --git a/src/powder.c b/src/powder.c
index 6d92bc8..700a6d5 100644
--- a/src/powder.c
+++ b/src/powder.c
@@ -176,6 +176,7 @@ void init_can_move()
//whol eats anar
can_move[PT_ANAR][PT_WHOL] = 1;
can_move[PT_ANAR][PT_NWHL] = 1;
+ can_move[PT_THDR][PT_THDR] = 2;
}
/*
@@ -257,7 +258,7 @@ int try_move(int i, int x, int y, int nx, int ny)
if (!e) //if no movement
{
- if (parts[i].type!=PT_NEUT && parts[i].type!=PT_PHOT && parts[i].type!=PT_ELEC)
+ if (!(ptypes[parts[i].type].properties & TYPE_ENERGY))
return 0;
if (!legacy_enable && parts[i].type==PT_PHOT && r)//PHOT heat conduction
{
@@ -271,7 +272,7 @@ int try_move(int i, int x, int y, int nx, int ny)
if (!parts[r>>8].ctype)
parts[r>>8].ctype = parts[i].type;
}
- if ((r&0xFF)==PT_PRTI && (parts[i].type==PT_PHOT || parts[i].type==PT_NEUT || parts[i].type==PT_ELEC))
+ if ((r&0xFF)==PT_PRTI && (ptypes[parts[i].type].properties & TYPE_ENERGY))
{
int nnx, count;
for (count=0; count<8; count++)
@@ -343,7 +344,8 @@ int try_move(int i, int x, int y, int nx, int ny)
}
if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_PVOD) //this is where void eats particles
{
- kill_part(i);
+ if(!parts[r>>8].ctype || (parts[r>>8].ctype==parts[i].type)!=(parts[r>>8].tmp&1))
+ kill_part(i);
return 0;
}
if ((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) //this is where blackhole eats particles
@@ -427,7 +429,7 @@ int do_move(int i, int x, int y, float nxf, float nyf)
kill_part(i);
return -1;
}
- if (t==PT_PHOT||t==PT_NEUT||t==PT_ELEC)
+ if (ptypes[t].properties & TYPE_ENERGY)
photons[ny][nx] = t|(i<<8);
else if (t)
pmap[ny][nx] = t|(i<<8);
@@ -678,7 +680,7 @@ inline void part_change_type(int i, int x, int y, int t)//changes the type of pa
}
parts[i].type = t;
- if (t==PT_PHOT || t==PT_NEUT || t==PT_ELEC)
+ if (ptypes[t].properties & TYPE_ENERGY)
{
photons[y][x] = t|(i<<8);
if ((pmap[y][x]>>8)==i)
@@ -717,23 +719,25 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
{
if (t==SPC_HEAT&&parts[pmap[y][x]>>8].temp<MAX_TEMP)
{
- if ((pmap[y][x]&0xFF)==PT_PUMP || (pmap[y][x]&0xFF)==PT_GPMP) {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp + 0.1f, MIN_TEMP, MAX_TEMP);
- } else if ((sdl_mod & (KMOD_SHIFT)) && (sdl_mod & (KMOD_CTRL))) {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp + 50.0f, MIN_TEMP, MAX_TEMP);
- } else {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp + 4.0f, MIN_TEMP, MAX_TEMP);
- }
+ float heatchange;
+ int r = pmap[y][x], fast = ((sdl_mod & (KMOD_SHIFT)) && (sdl_mod & (KMOD_CTRL)));
+ if ((r&0xFF)==PT_PUMP || (r&0xFF)==PT_GPMP)
+ heatchange = fast?1.0f:.1f;
+ else
+ heatchange = fast?50.0f:4.0f;
+
+ parts[r>>8].temp = restrict_flt(parts[r>>8].temp + heatchange, MIN_TEMP, MAX_TEMP);
}
if (t==SPC_COOL&&parts[pmap[y][x]>>8].temp>MIN_TEMP)
{
- if ((pmap[y][x]&0xFF)==PT_PUMP || (pmap[y][x]&0xFF)==PT_GPMP) {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp - 0.1f, MIN_TEMP, MAX_TEMP);
- } else if ((sdl_mod & (KMOD_SHIFT)) && (sdl_mod & (KMOD_CTRL))) {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp - 50.0f, MIN_TEMP, MAX_TEMP);
- } else {
- parts[pmap[y][x]>>8].temp = restrict_flt(parts[pmap[y][x]>>8].temp - 4.0f, MIN_TEMP, MAX_TEMP);
- }
+ float heatchange;
+ int r = pmap[y][x], fast = ((sdl_mod & (KMOD_SHIFT)) && (sdl_mod & (KMOD_CTRL)));
+ if ((r&0xFF)==PT_PUMP || (r&0xFF)==PT_GPMP)
+ heatchange = fast?1.0f:.1f;
+ else
+ heatchange = fast?50.0f:4.0f;
+
+ parts[r>>8].temp = restrict_flt(parts[r>>8].temp - heatchange, MIN_TEMP, MAX_TEMP);
}
return pmap[y][x]>>8;
}
@@ -843,7 +847,7 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
}
return -1;
}
- if (photons[y][x] && (t==PT_PHOT||t==PT_NEUT||t==PT_ELEC))
+ if (photons[y][x] && (ptypes[t].properties & TYPE_ENERGY))
return -1;
if (pfree == -1)
return -1;
@@ -963,7 +967,7 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
parts[i].tmp = 10;
if (t==PT_BRAY)
parts[i].life = 30;
- if (t==PT_PUMP)
+ if (t==PT_PUMP || t==PT_GPMP)
parts[i].life= 10;
if (t==PT_SING)
parts[i].life = rand()%50+60;
@@ -1104,7 +1108,7 @@ inline int create_part(int p, int x, int y, int tv)//the function for creating a
if (t==PT_BIZR||t==PT_BIZRG||t==PT_BIZRS)
parts[i].ctype = 0x47FFFF;
//and finally set the pmap/photon maps to the newly created particle
- if (t==PT_PHOT||t==PT_NEUT||t==PT_ELEC)
+ if (ptypes[t].properties & TYPE_ENERGY)
photons[y][x] = t|(i<<8);
else if (t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH)
pmap[y][x] = t|(i<<8);
@@ -1440,7 +1444,7 @@ void create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int
void update_particles_i(pixel *vid, int start, int inc)
{
int i, j, x, y, t, nx, ny, r, surround_space, s, lt, rt, nt, nnx, nny, q, golnum, goldelete, z, neighbors, createdsomething;
- float mv, dx, dy, ix, iy, lx, ly, nrx, nry, dp, ctemph, ctempl, gravtot;
+ float mv, dx, dy, ix, iy, lx, ly, nrx, nry, dp, ctemph, ctempl, gravtot, gel_scale;
int fin_x, fin_y, clear_x, clear_y, stagnant;
float fin_xf, fin_yf, clear_xf, clear_yf;
float nn, ct1, ct2, swappage;
@@ -1878,7 +1882,7 @@ void update_particles_i(pixel *vid, int start, int inc)
}
}
- float gel_scale = 1.0f;
+ gel_scale = 1.0f;
if (t==PT_GEL)
gel_scale = parts[i].tmp*2.55f;
@@ -2349,7 +2353,7 @@ killed:
stagnant = parts[i].flags & FLAG_STAGNANT;
parts[i].flags &= ~FLAG_STAGNANT;
- if ((t==PT_PHOT||t==PT_NEUT||t==PT_ELEC)) {
+ if (ptypes[t].properties & TYPE_ENERGY) {
if (t == PT_PHOT) {
if (parts[i].flags&FLAG_SKIPMOVE)
{
@@ -2730,8 +2734,7 @@ movedone:
int parts_lastActiveIndex = NPART-1;
void update_particles(pixel *vid)//doesn't update the particles themselves, but some other things
{
- int i, j, x, y, t, nx, ny, r, cr,cg,cb, l = -1;
- float lx, ly;
+ int i, x, y, t;
int lastPartUsed = 0;
int lastPartUnused = -1;
#ifdef MT
@@ -2751,7 +2754,7 @@ void update_particles(pixel *vid)//doesn't update the particles themselves, but
y = (int)(parts[i].y+0.5f);
if (x>=0 && y>=0 && x<XRES && y<YRES)
{
- if (t==PT_PHOT||t==PT_NEUT||t==PT_ELEC)
+ if (ptypes[t].properties & TYPE_ENERGY)
photons[y][x] = t|(i<<8);
else
pmap[y][x] = t|(i<<8);
@@ -2792,31 +2795,6 @@ void update_particles(pixel *vid)//doesn't update the particles themselves, but
}
update_particles_i(vid, 0, 1);
-
- // this should probably be elsewhere
- for (y=0; y<YRES/CELL; y++)
- for (x=0; x<XRES/CELL; x++)
- if (bmap[y][x]==WL_STREAM)
- {
- lx = x*CELL + CELL*0.5f;
- ly = y*CELL + CELL*0.5f;
- for (t=0; t<1024; t++)
- {
- nx = (int)(lx+0.5f);
- ny = (int)(ly+0.5f);
- if (nx<0 || nx>=XRES || ny<0 || ny>=YRES)
- break;
- addpixel(vid, nx, ny, 255, 255, 255, 64);
- i = nx/CELL;
- j = ny/CELL;
- lx += vx[j][i]*0.125f;
- ly += vy[j][i]*0.125f;
- if (bmap[j][i]==WL_STREAM && i!=x && j!=y)
- break;
- }
- drawtext(vid, x*CELL, y*CELL-2, "\x8D", 255, 255, 255, 128);
- }
-
}
void clear_area(int area_x, int area_y, int area_w, int area_h)