summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/graphics.c180
-rw-r--r--src/interface.c474
-rw-r--r--[-rwxr-xr-x]src/main.c22
-rw-r--r--src/powder.c409
4 files changed, 545 insertions, 540 deletions
diff --git a/src/graphics.c b/src/graphics.c
index 9f45526..b63e384 100644
--- a/src/graphics.c
+++ b/src/graphics.c
@@ -849,15 +849,15 @@ int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, i
#ifdef OpenGL
#else
int sx = x;
- int rh = 12;
- int rw = 0;
- int cw = x;
+ int rh = 12;
+ int rw = 0;
+ int cw = x;
for(; *s; s++)
{
if(*s == '\n')
{
x = sx;
- rw = 0;
+ rw = 0;
y += FONT_H+2;
}
else if(*s == '\b')
@@ -887,15 +887,15 @@ int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, i
s++;
}
else
- {
- if(x-cw>=w){
- x = sx;
- rw = 0;
- y+=FONT_H+2;
- rh+=FONT_H+2;
- }
+ {
+ if(x-cw>=w) {
+ x = sx;
+ rw = 0;
+ y+=FONT_H+2;
+ rh+=FONT_H+2;
+ }
x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a);
- }
+ }
}
#endif
return rh;
@@ -1476,20 +1476,20 @@ void draw_parts(pixel *vid)
cg = 0;
cb = 0;
cr = 0;
- for(x=0; x<12; x++) {
- cr += (parts[i].ctype >> (x+18)) & 1;
- cb += (parts[i].ctype >> x) & 1;
- }
- for(x=0; x<14; x++)
- cg += (parts[i].ctype >> (x+9)) & 1;
- x = 624/(cr+cg+cb+1);
- cr *= x;
- cg *= x;
- cb *= x;
+ for(x=0; x<12; x++) {
+ cr += (parts[i].ctype >> (x+18)) & 1;
+ cb += (parts[i].ctype >> x) & 1;
+ }
+ for(x=0; x<14; x++)
+ cg += (parts[i].ctype >> (x+9)) & 1;
+ x = 624/(cr+cg+cb+1);
+ cr *= x;
+ cg *= x;
+ cb *= x;
vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(cr>255?255:cr,cg>255?255:cg,cb>255?255:cb);
- cr >>= 4;
- cg >>= 4;
- cb >>= 4;
+ cr >>= 4;
+ cg >>= 4;
+ cb >>= 4;
x = nx/CELL;
y = ny/CELL;
cg += fire_g[y][x];
@@ -1504,22 +1504,22 @@ void draw_parts(pixel *vid)
}
else
{
- cg = 0;
- cb = 0;
- cr = 0;
- for(x=0; x<12; x++) {
- cr += (parts[i].ctype >> (x+18)) & 1;
- cb += (parts[i].ctype >> x) & 1;
- }
- for(x=0; x<14; x++)
- cg += (parts[i].ctype >> (x+9)) & 1;
- x = 624/(cr+cg+cb+1);
- cr *= x;
- cg *= x;
- cb *= x;
- cr = cr>255?255:cr;
- cg = cg>255?255:cg;
- cb = cb>255?255:cb;
+ cg = 0;
+ cb = 0;
+ cr = 0;
+ for(x=0; x<12; x++) {
+ cr += (parts[i].ctype >> (x+18)) & 1;
+ cb += (parts[i].ctype >> x) & 1;
+ }
+ for(x=0; x<14; x++)
+ cg += (parts[i].ctype >> (x+9)) & 1;
+ x = 624/(cr+cg+cb+1);
+ cr *= x;
+ cg *= x;
+ cb *= x;
+ cr = cr>255?255:cr;
+ cg = cg>255?255:cg;
+ cb = cb>255?255:cb;
blendpixel(vid, nx, ny, cr, cg, cb, 192);
blendpixel(vid, nx+1, ny, cr, cg, cb, 96);
blendpixel(vid, nx-1, ny, cr, cg, cb, 96);
@@ -1952,30 +1952,30 @@ void draw_parts(pixel *vid)
}
else if(t==PT_FIRE && parts[i].life)
{
- float ttemp = (float)((int)(parts[i].life/2));
- int caddress = restrict_flt(restrict_flt(ttemp, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
- uint8 R = flm_data[caddress];
- uint8 G = flm_data[caddress+1];
- uint8 B = flm_data[caddress+2];
- if(cmode == 3||cmode==4 || cmode==6)
- {
- cr = R/8;
- cg = G/8;
- cb = B/8;
- x = nx/CELL;
- y = ny/CELL;
- cg += fire_g[y][x];
- if(cg > 255) cg = 255;
- fire_g[y][x] = cg;
- cb += fire_b[y][x];
- if(cb > 255) cb = 255;
- fire_b[y][x] = cb;
- cr += fire_r[y][x];
- if(cr > 255) cr = 255;
- fire_r[y][x] = cr;
- }
- else
- {
+ float ttemp = (float)((int)(parts[i].life/2));
+ int caddress = restrict_flt(restrict_flt(ttemp, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
+ uint8 R = flm_data[caddress];
+ uint8 G = flm_data[caddress+1];
+ uint8 B = flm_data[caddress+2];
+ if(cmode == 3||cmode==4 || cmode==6)
+ {
+ cr = R/8;
+ cg = G/8;
+ cb = B/8;
+ x = nx/CELL;
+ y = ny/CELL;
+ cg += fire_g[y][x];
+ if(cg > 255) cg = 255;
+ fire_g[y][x] = cg;
+ cb += fire_b[y][x];
+ if(cb > 255) cb = 255;
+ fire_b[y][x] = cb;
+ cr += fire_r[y][x];
+ if(cr > 255) cr = 255;
+ fire_r[y][x] = cr;
+ }
+ else
+ {
cr = parts[i].life * 8;
cg = parts[i].life * 2;
cb = parts[i].life;
@@ -1991,9 +1991,9 @@ void draw_parts(pixel *vid)
blendpixel(vid, nx-1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx+1, ny+1, cr, cg, cb, 32);
blendpixel(vid, nx-1, ny-1, cr, cg, cb, 32);
- }
- // Older Code
- /*if(cmode == 3||cmode==4 || cmode==6)
+ }
+ // Older Code
+ /*if(cmode == 3||cmode==4 || cmode==6)
{
cr = parts[i].life / 4;
cg = parts[i].life / 16;
@@ -2137,28 +2137,28 @@ void draw_parts(pixel *vid)
}
if(cmode == 4&&t!=PT_FIRE&&t!=PT_PLSM&&t!=PT_HFLM&&t!=PT_NONE&&t!=PT_ACID&&t!=PT_LCRY&&t!=PT_GLOW&&t!=PT_SWCH&&t!=PT_SMKE&&t!=PT_WTRV&&!(t==PT_FIRW&&parts[i].tmp==3))
{
- if(t==PT_PHOT){
- cg = 0;
- cb = 0;
- cr = 0;
- for(x=0; x<12; x++) {
- cr += (parts[i].ctype >> (x+18)) & 1;
- cb += (parts[i].ctype >> x) & 1;
- }
- for(x=0; x<14; x++)
- cg += (parts[i].ctype >> (x+9)) & 1;
- x = 624/(cr+cg+cb+1);
- cr *= x;
- cg *= x;
- cb *= x;
- cr = cr>255?255:cr;
- cg = cg>255?255:cg;
- cb = cb>255?255:cb;
- } else {
- cr = PIXR(ptypes[t].pcolors);
- cg = PIXG(ptypes[t].pcolors);
- cb = PIXB(ptypes[t].pcolors);
- }
+ if(t==PT_PHOT) {
+ cg = 0;
+ cb = 0;
+ cr = 0;
+ for(x=0; x<12; x++) {
+ cr += (parts[i].ctype >> (x+18)) & 1;
+ cb += (parts[i].ctype >> x) & 1;
+ }
+ for(x=0; x<14; x++)
+ cg += (parts[i].ctype >> (x+9)) & 1;
+ x = 624/(cr+cg+cb+1);
+ cr *= x;
+ cg *= x;
+ cb *= x;
+ cr = cr>255?255:cr;
+ cg = cg>255?255:cg;
+ cb = cb>255?255:cb;
+ } else {
+ cr = PIXR(ptypes[t].pcolors);
+ cg = PIXG(ptypes[t].pcolors);
+ cb = PIXB(ptypes[t].pcolors);
+ }
//if(vid[(ny-1)*YRES+(nx-1)]!=0){
// blendpixel(vid, nx, ny-1, R, G, B, 46);
diff --git a/src/interface.c b/src/interface.c
index eab027a..3ed4431 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -1871,8 +1871,8 @@ int search_ui(pixel *vid_buf)
drawtext(vid_buf, XRES-61+16, 11, "\x93", 255, 255, 255, 255);
drawtext(vid_buf, XRES-46+16, 13, "My Own", 255, 255, 255, 255);
}
-
- if(search_fav)
+
+ if(search_fav)
{
fillrect(vid_buf, XRES-134, 7, 18, 18, 255, 255, 255, 255);
drawtext(vid_buf, XRES-130, 11, "\xCC", 192, 160, 64, 255);
@@ -2155,7 +2155,7 @@ int search_ui(pixel *vid_buf)
search_date = !search_date;
lasttime = TIMEOUT;
}
- if(b && !bq && mx>=XRES-134 && mx<=XRES-134+16 && my>=8 && my<=24)
+ if(b && !bq && mx>=XRES-134 && mx<=XRES-134+16 && my>=8 && my<=24)
{
search_fav = !search_fav;
lasttime = TIMEOUT;
@@ -2197,10 +2197,10 @@ int search_ui(pixel *vid_buf)
if((b && !bq && mp!=-1 && !st && !uih) || do_open==1)
{
- if(open_ui(vid_buf, search_ids[mp], search_dates[mp]?search_dates[mp]:NULL)==1){
- goto finish;
- }
- /*
+ if(open_ui(vid_buf, search_ids[mp], search_dates[mp]?search_dates[mp]:NULL)==1) {
+ goto finish;
+ }
+ /*
fillrect(vid_buf, 0, 0, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 255);
info_box(vid_buf, "Loading...");
@@ -2349,7 +2349,7 @@ int search_ui(pixel *vid_buf)
last_own = search_own;
last_date = search_date;
last_page = search_page;
- last_fav = search_fav;
+ last_fav = search_fav;
active = 1;
// TODO: Create a better fix for this bug
uri = malloc(strlen(last)*3+180+strlen(SERVER)+strlen(svf_user)+20); //Increase "padding" from 80 to 180 to fix the search memory corruption bug
@@ -2381,10 +2381,10 @@ int search_ui(pixel *vid_buf)
strcaturl(uri, " user:");
strcaturl(uri, svf_user);
}
- if(search_fav)
- {
- strcaturl(uri, " cat:favs");
- }
+ if(search_fav)
+ {
+ strcaturl(uri, " cat:favs");
+ }
if(search_date)
strcaturl(uri, " sort:date");
@@ -2524,71 +2524,71 @@ finish:
int open_ui(pixel *vid_buf, char *save_id, char *save_date)
{
- int b=1,bq,mx,my,ca=0,thumb_w,thumb_h,active=0,active_2=0,cc=0,ccy=0,cix=0,hasdrawninfo=0,hasdrawnthumb=0,authoritah=0,queue_open=0,data_size=0,retval=0;
- char *uri, *uri_2;
- void *data, *info_data;
- save_info *info = malloc(sizeof(save_info));
- void *http = NULL, *http_2 = NULL;
+ int b=1,bq,mx,my,ca=0,thumb_w,thumb_h,active=0,active_2=0,cc=0,ccy=0,cix=0,hasdrawninfo=0,hasdrawnthumb=0,authoritah=0,queue_open=0,data_size=0,retval=0;
+ char *uri, *uri_2;
+ void *data, *info_data;
+ save_info *info = malloc(sizeof(save_info));
+ void *http = NULL, *http_2 = NULL;
int lasttime = TIMEOUT;
- int status, status_2, info_ready = 0, data_ready = 0;
- time_t http_last_use = HTTP_TIMEOUT, http_last_use_2 = HTTP_TIMEOUT;
- pixel *save_pic;// = malloc((XRES/2)*(YRES/2));
+ int status, status_2, info_ready = 0, data_ready = 0;
+ time_t http_last_use = HTTP_TIMEOUT, http_last_use_2 = HTTP_TIMEOUT;
+ pixel *save_pic;// = malloc((XRES/2)*(YRES/2));
- pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
+ pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
+ fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- fillrect(vid_buf, 50, 50, XRES+BARSIZE-100, YRES+MENUSIZE-100, 0, 0, 0, 255);
- drawrect(vid_buf, 50, 50, XRES+BARSIZE-100, YRES+MENUSIZE-100, 255, 255, 255, 255);
- drawrect(vid_buf, 50, 50, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 155);
- drawrect(vid_buf, 50+(XRES/2)+1, 50, XRES+BARSIZE-100-((XRES/2)+1), YRES+MENUSIZE-100, 155, 155, 155, 255);
- drawtext(vid_buf, 50+(XRES/4)-textwidth("Loading...")/2, 50+(YRES/4), "Loading...", 255, 255, 255, 128);
+ fillrect(vid_buf, 50, 50, XRES+BARSIZE-100, YRES+MENUSIZE-100, 0, 0, 0, 255);
+ drawrect(vid_buf, 50, 50, XRES+BARSIZE-100, YRES+MENUSIZE-100, 255, 255, 255, 255);
+ drawrect(vid_buf, 50, 50, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 155);
+ drawrect(vid_buf, 50+(XRES/2)+1, 50, XRES+BARSIZE-100-((XRES/2)+1), YRES+MENUSIZE-100, 155, 155, 155, 255);
+ drawtext(vid_buf, 50+(XRES/4)-textwidth("Loading...")/2, 50+(YRES/4), "Loading...", 255, 255, 255, 128);
memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
-
- while(!sdl_poll())
+
+ while(!sdl_poll())
{
b = SDL_GetMouseState(&mx, &my);
if(!b)
break;
}
- //Begin Async loading of data
- if(save_date) {
- // We're loading an historical save
- uri = malloc(strlen(save_id)*3+strlen(save_date)*3+strlen(SERVER)+71);
- strcpy(uri, "http://" SERVER "/Get.api?Op=save&ID=");
- strcaturl(uri, save_id);
- strappend(uri, "&Date=");
- strcaturl(uri, save_date);
-
- uri_2 = malloc(strlen(save_id)*3+strlen(save_date)*3+strlen(SERVER)+71);
- strcpy(uri_2, "http://" SERVER "/Get.api?Op=save&ID=");
- strcaturl(uri_2, save_id);
- strappend(uri_2, "&Date=");
- strcaturl(uri_2, save_date);
- } else {
- //We're loading a normal save
+ //Begin Async loading of data
+ if(save_date) {
+ // We're loading an historical save
+ uri = malloc(strlen(save_id)*3+strlen(save_date)*3+strlen(SERVER)+71);
+ strcpy(uri, "http://" SERVER "/Get.api?Op=save&ID=");
+ strcaturl(uri, save_id);
+ strappend(uri, "&Date=");
+ strcaturl(uri, save_date);
+
+ uri_2 = malloc(strlen(save_id)*3+strlen(save_date)*3+strlen(SERVER)+71);
+ strcpy(uri_2, "http://" SERVER "/Get.api?Op=save&ID=");
+ strcaturl(uri_2, save_id);
+ strappend(uri_2, "&Date=");
+ strcaturl(uri_2, save_date);
+ } else {
+ //We're loading a normal save
uri = malloc(strlen(save_id)*3+strlen(SERVER)+64);
strcpy(uri, "http://" SERVER "/Get.api?Op=save&ID=");
strcaturl(uri, save_id);
- uri_2 = malloc(strlen(save_id)*3+strlen(SERVER)+64);
+ uri_2 = malloc(strlen(save_id)*3+strlen(SERVER)+64);
strcpy(uri_2, "http://" SERVER "/Info.api?ID=");
strcaturl(uri_2, save_id);
}
- http = http_async_req_start(http, uri, NULL, 0, 1);
- http_2 = http_async_req_start(http_2, uri_2, NULL, 0, 1);
- if(svf_login)
+ http = http_async_req_start(http, uri, NULL, 0, 1);
+ http_2 = http_async_req_start(http_2, uri_2, NULL, 0, 1);
+ if(svf_login)
{
- http_auth_headers(http, svf_user, svf_pass);
- http_auth_headers(http_2, svf_user, svf_pass);
+ http_auth_headers(http, svf_user, svf_pass);
+ http_auth_headers(http_2, svf_user, svf_pass);
}
http_last_use = time(NULL);
- http_last_use_2 = time(NULL);
+ http_last_use_2 = time(NULL);
free(uri);
- free(uri_2);
- active = 1;
- active_2 = 1;
+ free(uri_2);
+ active = 1;
+ active_2 = 1;
while(!sdl_poll())
{
bq = b;
@@ -2596,188 +2596,188 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
mx /= sdl_scale;
my /= sdl_scale;
- if(active && http_async_req_status(http))
+ if(active && http_async_req_status(http))
{
- int imgh, imgw, nimgh, nimgw;
+ int imgh, imgw, nimgh, nimgw;
http_last_use = time(NULL);
data = http_async_req_stop(http, &status, &data_size);
if(status == 200)
{
- pixel *full_save = prerender_save(data, data_size, &imgw, &imgh);
- save_pic = rescale_img(full_save, imgw, imgh, &thumb_w, &thumb_h, 2);
+ pixel *full_save = prerender_save(data, data_size, &imgw, &imgh);
+ save_pic = rescale_img(full_save, imgw, imgh, &thumb_w, &thumb_h, 2);
data_ready = 1;
- free(full_save);
+ free(full_save);
}
- active = 0;
- free(http);
- http = NULL;
+ active = 0;
+ free(http);
+ http = NULL;
}
- if(active_2 && http_async_req_status(http_2))
+ if(active_2 && http_async_req_status(http_2))
{
http_last_use_2 = time(NULL);
info_data = http_async_req_stop(http_2, &status_2, NULL);
if(status_2 == 200)
{
info_ready = info_parse(info_data, info);
- if(info_ready==-1){
- error_ui(vid_buf, 0, "Not found");
- break;
- }
+ if(info_ready==-1) {
+ error_ui(vid_buf, 0, "Not found");
+ break;
+ }
}
free(info_data);
active_2 = 0;
- free(http_2);
- http_2 = NULL;
- }
-
- if(data_ready && !hasdrawnthumb){
- draw_image(vid_buf, save_pic, 51, 51, thumb_w, thumb_h, 255);
- hasdrawnthumb = 1;
- memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
- }
- if(info_ready && !hasdrawninfo){
- //drawtext(vid_buf, 2, 2, info->name, 255, 255, 255, 255);
- cix = drawtext(vid_buf, 60, (YRES/2)+60, info->name, 255, 255, 255, 255);
- cix = drawtext(vid_buf, 60, (YRES/2)+72, "Author:", 255, 255, 255, 155);
- cix = drawtext(vid_buf, cix+4, (YRES/2)+72, info->author, 255, 255, 255, 255);
- cix = drawtext(vid_buf, cix+4, (YRES/2)+72, "Date:", 255, 255, 255, 155);
- cix = drawtext(vid_buf, cix+4, (YRES/2)+72, info->date, 255, 255, 255, 255);
- drawtextwrap(vid_buf, 62, (YRES/2)+86, (XRES/2)-24, info->description, 255, 255, 255, 200);
-
- ccy = 0;
- for(cc=0;cc<info->comment_count;cc++){
- drawtext(vid_buf, 60+(XRES/2)+1, ccy+60, info->commentauthors[cc], 255, 255, 255, 255);
- ccy += 12;
- ccy += drawtextwrap(vid_buf, 60+(XRES/2)+1, ccy+60, XRES+BARSIZE-100-((XRES/2)+1)-20, info->comments[cc], 255, 255, 255, 185);
- ccy += 10;
- draw_line(vid_buf, 50+(XRES/2)+2, ccy+52, XRES+BARSIZE-50, ccy+52, 100, 100, 100, XRES+BARSIZE);
- }
- hasdrawninfo = 1;
- authoritah = svf_login && (!strcmp(info->author, svf_user) || svf_admin || svf_mod);
- memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
- }
-
- if(queue_open){
- if(info_ready && data_ready){
- // Do Open!
- status = parse_save(data, data_size, 1, 0, 0);
- if(!status){
- //if(svf_last)
- //free(svf_last);
- svf_last = data;
- svf_lsize = data_size;
-
- svf_open = 1;
- svf_own = svf_login && !strcmp(info->author, svf_user);
- svf_publish = info->publish && svf_login && !strcmp(info->author, svf_user);
-
- strcpy(svf_id, save_id);
- strcpy(svf_name, info->name);
- if(info->tags)
- {
- strncpy(svf_tags, info->tags, 255);
- svf_tags[255] = 0;
- } else {
- svf_tags[0] = 0;
- }
- svf_myvote = info->myvote;
- retval = 1;
- break;
- } else {
- queue_open = 0;
-
- svf_open = 0;
- svf_publish = 0;
- svf_own = 0;
- svf_myvote = 0;
- svf_id[0] = 0;
- svf_name[0] = 0;
- svf_tags[0] = 0;
- if(svf_last)
- free(svf_last);
- svf_last = NULL;
- error_ui(vid_buf, 0, "An Error Occurred");
- }
- } else {
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 190);
- drawtext(vid_buf, XRES+BARSIZE/2, XRES+MENUSIZE, "Loading...", 0, 0, 0, 200);
- }
- }
-
- //Open Button
- if(sdl_key==SDLK_RETURN){
+ free(http_2);
+ http_2 = NULL;
+ }
+
+ if(data_ready && !hasdrawnthumb) {
+ draw_image(vid_buf, save_pic, 51, 51, thumb_w, thumb_h, 255);
+ hasdrawnthumb = 1;
+ memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
+ }
+ if(info_ready && !hasdrawninfo) {
+ //drawtext(vid_buf, 2, 2, info->name, 255, 255, 255, 255);
+ cix = drawtext(vid_buf, 60, (YRES/2)+60, info->name, 255, 255, 255, 255);
+ cix = drawtext(vid_buf, 60, (YRES/2)+72, "Author:", 255, 255, 255, 155);
+ cix = drawtext(vid_buf, cix+4, (YRES/2)+72, info->author, 255, 255, 255, 255);
+ cix = drawtext(vid_buf, cix+4, (YRES/2)+72, "Date:", 255, 255, 255, 155);
+ cix = drawtext(vid_buf, cix+4, (YRES/2)+72, info->date, 255, 255, 255, 255);
+ drawtextwrap(vid_buf, 62, (YRES/2)+86, (XRES/2)-24, info->description, 255, 255, 255, 200);
+
+ ccy = 0;
+ for(cc=0; cc<info->comment_count; cc++) {
+ drawtext(vid_buf, 60+(XRES/2)+1, ccy+60, info->commentauthors[cc], 255, 255, 255, 255);
+ ccy += 12;
+ ccy += drawtextwrap(vid_buf, 60+(XRES/2)+1, ccy+60, XRES+BARSIZE-100-((XRES/2)+1)-20, info->comments[cc], 255, 255, 255, 185);
+ ccy += 10;
+ draw_line(vid_buf, 50+(XRES/2)+2, ccy+52, XRES+BARSIZE-50, ccy+52, 100, 100, 100, XRES+BARSIZE);
+ }
+ hasdrawninfo = 1;
+ authoritah = svf_login && (!strcmp(info->author, svf_user) || svf_admin || svf_mod);
+ memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
+ }
+
+ if(queue_open) {
+ if(info_ready && data_ready) {
+ // Do Open!
+ status = parse_save(data, data_size, 1, 0, 0);
+ if(!status) {
+ //if(svf_last)
+ //free(svf_last);
+ svf_last = data;
+ svf_lsize = data_size;
+
+ svf_open = 1;
+ svf_own = svf_login && !strcmp(info->author, svf_user);
+ svf_publish = info->publish && svf_login && !strcmp(info->author, svf_user);
+
+ strcpy(svf_id, save_id);
+ strcpy(svf_name, info->name);
+ if(info->tags)
+ {
+ strncpy(svf_tags, info->tags, 255);
+ svf_tags[255] = 0;
+ } else {
+ svf_tags[0] = 0;
+ }
+ svf_myvote = info->myvote;
+ retval = 1;
+ break;
+ } else {
+ queue_open = 0;
+
+ svf_open = 0;
+ svf_publish = 0;
+ svf_own = 0;
+ svf_myvote = 0;
+ svf_id[0] = 0;
+ svf_name[0] = 0;
+ svf_tags[0] = 0;
+ if(svf_last)
+ free(svf_last);
+ svf_last = NULL;
+ error_ui(vid_buf, 0, "An Error Occurred");
+ }
+ } else {
+ fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 190);
+ drawtext(vid_buf, XRES+BARSIZE/2, XRES+MENUSIZE, "Loading...", 0, 0, 0, 200);
+ }
+ }
+
+ //Open Button
+ if(sdl_key==SDLK_RETURN) {
queue_open = 1;
- }
- drawrect(vid_buf, 70, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255);
- drawtext(vid_buf, 93, YRES+MENUSIZE-63, "Open", 255, 255, 255, 255);
- drawtext(vid_buf, 78, YRES+MENUSIZE-64, "\x81", 255, 255, 255, 255);
- if(mx > 70 && mx < 70+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50){
- fillrect(vid_buf, 70, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
- if(b && !bq){
- queue_open = 1;
- }
- }
-
- //Fav Button
- if(svf_login){
- drawrect(vid_buf, 140, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255);
- drawtext(vid_buf, 162, YRES+MENUSIZE-63, "Fav.", 255, 255, 255, 255);
- drawtext(vid_buf, 147, YRES+MENUSIZE-64, "\xCC", 255, 255, 255, 255);
- if(mx > 140 && mx < 140+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50){
- fillrect(vid_buf, 140, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
- if(b && !bq){
- //Button Clicked
- }
- }
- }
-
- //Report Button
- if(svf_login){
- drawrect(vid_buf, 210, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255);
- drawtext(vid_buf, 228, YRES+MENUSIZE-63, "Report", 255, 255, 255, 255);
- drawtext(vid_buf, 218, YRES+MENUSIZE-63, "!", 255, 255, 255, 255);
- if(mx > 210 && mx < 210+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50){
- fillrect(vid_buf, 210, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
- if(b && !bq){
- //Button Clicked
- }
- }
- }
-
- //Delete Button
- if(authoritah){
- drawrect(vid_buf, 280, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255);
- drawtext(vid_buf, 298, YRES+MENUSIZE-63, "Delete", 255, 255, 255, 255);
- drawtext(vid_buf, 286, YRES+MENUSIZE-64, "\xAA", 255, 255, 255, 255);
- if(mx > 280 && mx < 280+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50){
- fillrect(vid_buf, 280, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
- if(b && !bq){
- //Button Clicked
- }
- }
- }
-
-
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
+ }
+ drawrect(vid_buf, 70, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255);
+ drawtext(vid_buf, 93, YRES+MENUSIZE-63, "Open", 255, 255, 255, 255);
+ drawtext(vid_buf, 78, YRES+MENUSIZE-64, "\x81", 255, 255, 255, 255);
+ if(mx > 70 && mx < 70+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50) {
+ fillrect(vid_buf, 70, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
+ if(b && !bq) {
+ queue_open = 1;
+ }
+ }
+
+ //Fav Button
+ if(svf_login) {
+ drawrect(vid_buf, 140, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255);
+ drawtext(vid_buf, 162, YRES+MENUSIZE-63, "Fav.", 255, 255, 255, 255);
+ drawtext(vid_buf, 147, YRES+MENUSIZE-64, "\xCC", 255, 255, 255, 255);
+ if(mx > 140 && mx < 140+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50) {
+ fillrect(vid_buf, 140, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
+ if(b && !bq) {
+ //Button Clicked
+ }
+ }
+ }
+
+ //Report Button
+ if(svf_login) {
+ drawrect(vid_buf, 210, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255);
+ drawtext(vid_buf, 228, YRES+MENUSIZE-63, "Report", 255, 255, 255, 255);
+ drawtext(vid_buf, 218, YRES+MENUSIZE-63, "!", 255, 255, 255, 255);
+ if(mx > 210 && mx < 210+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50) {
+ fillrect(vid_buf, 210, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
+ if(b && !bq) {
+ //Button Clicked
+ }
+ }
+ }
+
+ //Delete Button
+ if(authoritah) {
+ drawrect(vid_buf, 280, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255);
+ drawtext(vid_buf, 298, YRES+MENUSIZE-63, "Delete", 255, 255, 255, 255);
+ drawtext(vid_buf, 286, YRES+MENUSIZE-64, "\xAA", 255, 255, 255, 255);
+ if(mx > 280 && mx < 280+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50) {
+ fillrect(vid_buf, 280, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
+ if(b && !bq) {
+ //Button Clicked
+ }
+ }
+ }
+
+
+ sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
memcpy(vid_buf, old_vid, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
if(sdl_key==SDLK_ESCAPE)
break;
- if(lasttime<TIMEOUT)
+ if(lasttime<TIMEOUT)
lasttime++;
- }
- return retval;
+ }
+ return retval;
}
int info_parse(char *info_data, save_info *info)
{
- int i,j;
+ int i,j;
char *p,*q,*r,*s,*vu,*vd,*pu,*sd;
- memset(info, 0, sizeof(save_info));
+ memset(info, 0, sizeof(save_info));
- if(!info_data || !*info_data)
+ if(!info_data || !*info_data)
return 0;
i = 0;
@@ -2794,87 +2794,87 @@ int info_parse(char *info_data, save_info *info)
else
*(p++) = 0;
- if(!strncmp(info_data, "TITLE ", 6))
+ if(!strncmp(info_data, "TITLE ", 6))
{
info->title = mystrdup(info_data+6);
j++;
}
- else if(!strncmp(info_data, "NAME ", 5))
+ else if(!strncmp(info_data, "NAME ", 5))
{
info->name = mystrdup(info_data+5);
j++;
}
- else if(!strncmp(info_data, "AUTHOR ", 7))
+ else if(!strncmp(info_data, "AUTHOR ", 7))
{
info->author = mystrdup(info_data+7);
j++;
}
- else if(!strncmp(info_data, "DATE ", 5))
+ else if(!strncmp(info_data, "DATE ", 5))
{
info->date = mystrdup(info_data+5);
j++;
}
- else if(!strncmp(info_data, "DESCRIPTION ", 12))
+ else if(!strncmp(info_data, "DESCRIPTION ", 12))
{
info->description = mystrdup(info_data+12);
j++;
}
- else if(!strncmp(info_data, "VOTEUP ", 7))
+ else if(!strncmp(info_data, "VOTEUP ", 7))
{
info->voteup = atoi(info_data+7);
j++;
}
- else if(!strncmp(info_data, "VOTEDOWN ", 9))
+ else if(!strncmp(info_data, "VOTEDOWN ", 9))
{
info->votedown = atoi(info_data+9);
j++;
}
- else if(!strncmp(info_data, "VOTE ", 5))
+ else if(!strncmp(info_data, "VOTE ", 5))
{
info->vote = atoi(info_data+5);
j++;
}
- else if(!strncmp(info_data, "MYVOTE ", 7))
+ else if(!strncmp(info_data, "MYVOTE ", 7))
{
info->myvote = atoi(info_data+7);
j++;
}
- else if(!strncmp(info_data, "MYFAV ", 6))
+ else if(!strncmp(info_data, "MYFAV ", 6))
{
info->myfav = atoi(info_data+6);
j++;
}
- else if(!strncmp(info_data, "PUBLISH ", 8))
+ else if(!strncmp(info_data, "PUBLISH ", 8))
{
- info->publish = atoi(info_data+8);
+ info->publish = atoi(info_data+8);
j++;
}
- else if(!strncmp(info_data, "TAGS ", 5))
+ else if(!strncmp(info_data, "TAGS ", 5))
{
info->tags = mystrdup(info_data+5);
j++;
}
- else if(!strncmp(info_data, "COMMENT ", 8))
- {
- if(info->comment_count>=6){
- info_data = p;
- continue;
- } else {
- q = strchr(info_data+8, ' ');
- *(q++) = 0;
- info->commentauthors[info->comment_count] = mystrdup(info_data+8);
- info->comments[info->comment_count] = mystrdup(q);
- info->comment_count++;
- }
+ else if(!strncmp(info_data, "COMMENT ", 8))
+ {
+ if(info->comment_count>=6) {
+ info_data = p;
+ continue;
+ } else {
+ q = strchr(info_data+8, ' ');
+ *(q++) = 0;
+ info->commentauthors[info->comment_count] = mystrdup(info_data+8);
+ info->comments[info->comment_count] = mystrdup(q);
+ info->comment_count++;
+ }
j++;
}
- info_data = p;
+ info_data = p;
+ }
+ if(j>=8) {
+ return 1;
+ } else {
+ return -1;
}
- if(j>=8){
- return 1;
- } else {
- return -1;
- }
}
int search_results(char *str, int votes)
diff --git a/src/main.c b/src/main.c
index 77133f9..5ef9ce3 100755..100644
--- a/src/main.c
+++ b/src/main.c
@@ -272,9 +272,9 @@ void *build_save(int *size, int x0, int y0, int w, int h)
y = (int)(parts[i].y+0.5f);
if(x>=x0 && x<x0+w && y>=y0 && y<y0+h) {
if(!m[(x-x0)+(y-y0)*w] ||
- parts[m[(x-x0)+(y-y0)*w]-1].type == PT_PHOT)
- m[(x-x0)+(y-y0)*w] = i+1;
- }
+ parts[m[(x-x0)+(y-y0)*w]-1].type == PT_PHOT)
+ m[(x-x0)+(y-y0)*w] = i+1;
+ }
}
for(j=0; j<w*h; j++)
{
@@ -507,18 +507,18 @@ int parse_save(void *save, int size, int replace, int x0, int y0)
if(p >= size)
goto corrupt;
j=d[p++];
- if(j >= PT_NUM){
- //TODO: Possibly some server side translation
- j = PT_DUST;//goto corrupt;
- }
+ if(j >= PT_NUM) {
+ //TODO: Possibly some server side translation
+ j = PT_DUST;//goto corrupt;
+ }
if(j)// && !(isplayer == 1 && j==PT_STKM))
{
if(pmap[y][x])
{
k = pmap[y][x]>>8;
parts[k].type = j;
- if(j == PT_PHOT)
- parts[k].ctype = 0x3fffffff;
+ if(j == PT_PHOT)
+ parts[k].ctype = 0x3fffffff;
parts[k].x = (float)x;
parts[k].y = (float)y;
m[(x-x0)+(y-y0)*w] = k+1;
@@ -526,8 +526,8 @@ int parse_save(void *save, int size, int replace, int x0, int y0)
else if(i < nf)
{
parts[fp[i]].type = j;
- if(j == PT_PHOT)
- parts[fp[i]].ctype = 0x3fffffff;
+ if(j == PT_PHOT)
+ parts[fp[i]].ctype = 0x3fffffff;
parts[fp[i]].x = (float)x;
parts[fp[i]].y = (float)y;
m[(x-x0)+(y-y0)*w] = fp[i]+1;
diff --git a/src/powder.c b/src/powder.c
index 2d2e099..9dca982 100644
--- a/src/powder.c
+++ b/src/powder.c
@@ -26,10 +26,10 @@ static int pn_junction_sprk(int x, int y, int pt)
{
unsigned r = pmap[y][x];
if((r & 0xFF) != pt)
- return 0;
+ return 0;
r >>= 8;
if(parts[r].type != pt)
- return 0;
+ return 0;
parts[r].ctype = pt;
parts[r].type = PT_SPRK;
@@ -42,16 +42,16 @@ static void photoelectric_effect(int nx, int ny)
unsigned r = pmap[ny][nx];
if((r&0xFF) == PT_PSCN) {
- if((pmap[ny][nx-1] & 0xFF) == PT_NSCN ||
- (pmap[ny][nx+1] & 0xFF) == PT_NSCN ||
- (pmap[ny-1][nx] & 0xFF) == PT_NSCN ||
- (pmap[ny+1][nx] & 0xFF) == PT_NSCN)
- pn_junction_sprk(nx, ny, PT_PSCN);
+ if((pmap[ny][nx-1] & 0xFF) == PT_NSCN ||
+ (pmap[ny][nx+1] & 0xFF) == PT_NSCN ||
+ (pmap[ny-1][nx] & 0xFF) == PT_NSCN ||
+ (pmap[ny+1][nx] & 0xFF) == PT_NSCN)
+ pn_junction_sprk(nx, ny, PT_PSCN);
}
}
/*
RETURN-value explenation
-1 = Swap
+1 = Swap
0 = No move/Bounce
2 = Both particles occupy the same space.
*/
@@ -69,16 +69,13 @@ static int eval_move(int pt, int nx, int ny, unsigned *rr)
*rr = r;
if((r&0xFF)==PT_VOID || (r&0xFF)==PT_BHOL)
- return 1;
-
- if(pt==PT_NEUT && (r&0xFF)==PT_GLAS)
- return 2;
+ return 1;
if(pt==PT_PHOT&&(
(r&0xFF)==PT_GLAS || (r&0xFF)==PT_PHOT ||
(r&0xFF)==PT_CLNE || (r&0xFF)==PT_PCLN ||
- (r&0xFF)==PT_GLOW ||
- (r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW || (r&0xFF)==PT_SLTW ||
+ (r&0xFF)==PT_GLOW || (r&0xFF)==PT_WATR ||
+ (r&0xFF)==PT_DSTW || (r&0xFF)==PT_SLTW ||
((r&0xFF)==PT_LCRY&&parts[r>>8].life > 5)))
return 2;
@@ -99,17 +96,19 @@ static int eval_move(int pt, int nx, int ny, unsigned *rr)
return 0;
if(pt == PT_PHOT)
- return 2;
-
- if(pt == PT_NEUT)
+ return 0;
+ if(pt == PT_NEUT)
return 1;
- if((r&0xFF) == PT_NEUT)
+ if(pt == PT_NEUT && (r&0xFF == PT_WATR||r&0xFF == PT_SLTW ||r&0xFF == PT_DSTW))
+ return 2;
+
+ if((r&0xFF) == PT_NEUT)
return 0;
-
- if (r && ((r&0xFF) >= PT_NUM || (ptypes[pt].weight <= ptypes[(r&0xFF)].weight)))
+
+ if (r && ((r&0xFF) >= PT_NUM || (ptypes[pt].weight <= ptypes[(r&0xFF)].weight)))
return 0;
-
-
+
+
return 1;
}
@@ -127,32 +126,38 @@ int try_move(int i, int x, int y, int nx, int ny)
/* half-silvered mirror */
if(!e && parts[i].type==PT_PHOT &&
- (((r&0xFF)==PT_BMTL && rand()<RAND_MAX/2) ||
- (pmap[y][x]&0xFF)==PT_BMTL))
- e = 2;
+ (((r&0xFF)==PT_BMTL && rand()<RAND_MAX/2) ||
+ (pmap[y][x]&0xFF)==PT_BMTL))
+ e = 2;
- if(!e) {
- if(!legacy_enable && parts[i].type==PT_PHOT) {
+ if(!e)
+ {
+ if(!legacy_enable && parts[i].type==PT_PHOT)
+ {
if((r & 0xFF) == PT_COAL || (r & 0xFF) == PT_BCOL)
parts[r>>8].temp = parts[i].temp;
+
if((r & 0xFF) < PT_NUM)
- parts[i].temp = parts[r>>8].temp =
- restrict_flt((parts[r>>8].temp+parts[i].temp)/2, MIN_TEMP, MAX_TEMP);
+ parts[i].temp = parts[r>>8].temp = restrict_flt((parts[r>>8].temp+parts[i].temp)/2, MIN_TEMP, MAX_TEMP);
}
return 0;
}
- if(e == 2) {
- if(parts[i].type == PT_PHOT && (r&0xFF)==PT_GLOW && !parts[r>>8].life)
- if(rand() < RAND_MAX/30) {
- parts[r>>8].life = 120;
- create_gain_photon(i);
- }
- if(parts[i].type == PT_NEUT && (r&0xFF)==PT_GLAS) {
- if(rand() < RAND_MAX/10)
- create_cherenkov_photon(i);
- }
+
+ if(e == 2)
+ {
+ if(parts[i].type == PT_PHOT && (r&0xFF)==PT_GLOW && !parts[r>>8].life)
+ if(rand() < RAND_MAX/30)
+ {
+ parts[r>>8].life = 120;
+ create_gain_photon(i);
+ }
+
+ if(parts[i].type == PT_NEUT && (r&0xFF)==PT_GLAS) {
+ if(rand() < RAND_MAX/10)
+ create_cherenkov_photon(i);
+ }
return 1;
- }
+ }
if((r&0xFF)==PT_VOID)
{
@@ -181,13 +186,13 @@ int try_move(int i, int x, int y, int nx, int ny)
return 0;
if(parts[i].type == PT_PHOT)
- return 1;
+ return 1;
e = r >> 8;
if(r && e<NPART)
{
- if(parts[e].type == PT_PHOT)
- return 1;
+ if(parts[e].type == PT_PHOT)
+ return 1;
parts[e].x += x-nx;
parts[e].y += y-ny;
@@ -327,7 +332,7 @@ int get_normal_interp(int pt, float x0, float y0, float dx, float dy, float *nx,
return 0;
if(pt == PT_PHOT)
- photoelectric_effect(x, y);
+ photoelectric_effect(x, y);
return get_normal(pt, x, y, dx, dy, nx, ny);
}
@@ -337,11 +342,11 @@ void kill_part(int i)
int x, y;
if(parts[i].type != PT_PHOT) {
- x = (int)(parts[i].x+0.5f);
- y = (int)(parts[i].y+0.5f);
+ x = (int)(parts[i].x+0.5f);
+ y = (int)(parts[i].y+0.5f);
- if(x>=0 && y>=0 && x<XRES && y<YRES)
- pmap[y][x] = 0;
+ if(x>=0 && y>=0 && x<XRES && y<YRES)
+ pmap[y][x] = 0;
}
parts[i].type = PT_NONE;
@@ -421,7 +426,7 @@ inline int create_part(int p, int x, int y, int t)
(pmap[y][x]&0xFF)!=PT_ETRD &&
(pmap[y][x]&0xFF)!=PT_BRMT &&
(pmap[y][x]&0xFF)!=PT_NBLE &&
- (pmap[y][x]&0xFF)!=PT_IRON &&
+ (pmap[y][x]&0xFF)!=PT_IRON &&
(pmap[y][x]&0xFF)!=PT_INWR)
return -1;
parts[pmap[y][x]>>8].type = PT_SPRK;
@@ -500,15 +505,15 @@ inline int create_part(int p, int x, int y, int t)
parts[i].vx = r*cosf(a);
parts[i].vy = r*sinf(a);
}
- if(t==PT_MORT)
- {
- parts[i].vx = 2;
- }
+ if(t==PT_MORT)
+ {
+ parts[i].vx = 2;
+ }
if(t==PT_PHOT)
{
- float a = (rand()%8) * 0.78540f;
+ float a = (rand()%8) * 0.78540f;
parts[i].life = 680;
- parts[i].ctype = 0x3FFFFFFF;
+ parts[i].ctype = 0x3FFFFFFF;
parts[i].vx = 3.0f*cosf(a);
parts[i].vy = 3.0f*sinf(a);
}
@@ -569,10 +574,10 @@ static void create_gain_photon(int pp)
lr = rand() % 2;
if(lr) {
- xx = parts[pp].x - 0.3*parts[pp].vy;
+ xx = parts[pp].x - 0.3*parts[pp].vy;
yy = parts[pp].y + 0.3*parts[pp].vx;
} else {
- xx = parts[pp].x + 0.3*parts[pp].vy;
+ xx = parts[pp].x + 0.3*parts[pp].vy;
yy = parts[pp].y - 0.3*parts[pp].vx;
}
@@ -580,10 +585,10 @@ static void create_gain_photon(int pp)
ny = (int)(yy + 0.5f);
if(nx<0 || ny<0 || nx>=XRES || ny>=YRES)
- return;
+ return;
if((pmap[ny][nx] & 0xFF) != PT_GLOW)
- return;
+ return;
pfree = parts[i].life;
@@ -614,10 +619,10 @@ static void create_cherenkov_photon(int pp)
nx = (int)(parts[pp].x + 0.5f);
ny = (int)(parts[pp].y + 0.5f);
if((pmap[ny][nx] & 0xFF) != PT_GLAS)
- return;
+ return;
if(hypotf(parts[pp].vx, parts[pp].vy) < 1.44f)
- return;
+ return;
pfree = parts[i].life;
@@ -632,11 +637,11 @@ static void create_cherenkov_photon(int pp)
parts[i].tmp = 0;
if(lr) {
- parts[i].vx = parts[pp].vx - 2.5f*parts[pp].vy;
- parts[i].vy = parts[pp].vy + 2.5f*parts[pp].vx;
+ parts[i].vx = parts[pp].vx - 2.5f*parts[pp].vy;
+ parts[i].vy = parts[pp].vy + 2.5f*parts[pp].vx;
} else {
- parts[i].vx = parts[pp].vx + 2.5f*parts[pp].vy;
- parts[i].vy = parts[pp].vy - 2.5f*parts[pp].vx;
+ parts[i].vx = parts[pp].vx + 2.5f*parts[pp].vy;
+ parts[i].vy = parts[pp].vy - 2.5f*parts[pp].vx;
}
/* photons have speed of light. no discussion. */
@@ -686,18 +691,18 @@ int get_wavelength_bin(int *wm)
int i, w0=30, wM=0;
if(!*wm)
- return -1;
+ return -1;
for(i=0; i<30; i++)
- if(*wm & (1<<i)) {
- if(i < w0)
- w0 = i;
- if(i > wM)
- wM = i;
- }
+ if(*wm & (1<<i)) {
+ if(i < w0)
+ w0 = i;
+ if(i > wM)
+ wM = i;
+ }
if(wM-w0 < 5)
- return (wM+w0)/2;
+ return (wM+w0)/2;
i = rand() % (wM-w0-3);
i += w0;
@@ -1288,67 +1293,67 @@ void update_particles_i(pixel *vid, int start, int inc)
}
}
}
- else if(t==PT_BMTL){
- if(parts[i].tmp>1){
- parts[i].tmp--;
- for(nx=-1; nx<2; nx++)
- for(ny=-1; ny<2; ny++)
- if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
- {
- r = pmap[y+ny][x+nx];
- if((r>>8)>=NPART || !r)
- continue;
- rt =parts[r>>8].type;
- if((rt==PT_METL || rt==PT_IRON) && 1>(rand()/(RAND_MAX/100)))
- {
- parts[r>>8].type=PT_BMTL;
- parts[r>>8].tmp=(parts[i].tmp<=7)?parts[i].tmp=1:parts[i].tmp-(rand()%5);//rand()/(RAND_MAX/300)+100;
- }
- }
- } else if(parts[i].tmp==1 && 1>rand()%1000){
- parts[i].tmp = 0;
- t = parts[i].type = PT_BRMT;
- }
- }
-
- else if(t==PT_IRON){
- for(nx=-1; nx<2; nx++)
- for(ny=-1; ny<2; ny++)
- if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
- {
- r = pmap[y+ny][x+nx];
- if((r>>8)>=NPART || !r)
- continue;
- if((((r&0xFF) == PT_SALT && 15>(rand()/(RAND_MAX/700))) ||
- ((r&0xFF) == PT_SLTW && 30>(rand()/(RAND_MAX/2000))) ||
- ((r&0xFF) == PT_WATR && 5 >(rand()/(RAND_MAX/6000))) ||
- ((r&0xFF) == PT_O2 && 2 >(rand()/(RAND_MAX/500))) ||
- ((r&0xFF) == PT_LO2))&&
- (!(parts[i].life))
- )
- {
- parts[i].type=PT_BMTL;
- parts[i].tmp=(rand()/(RAND_MAX/10))+20;
- }
- }
- }
- else if((t==PT_SPRK||parts[i].type==PT_SPRK) && parts[i].ctype==PT_IRON){
- for(nx=-1; nx<2; nx++)
- for(ny=-1; ny<2; ny++)
- if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
- {
- r = pmap[y+ny][x+nx];
- if((r>>8)>=NPART || !r)
- continue;
- if(((r&0xFF) == PT_DSTW && 30>(rand()/(RAND_MAX/1000))) ||
- ((r&0xFF) == PT_SLTW && 30>(rand()/(RAND_MAX/1000))) ||
- ((r&0xFF) == PT_WATR && 30>(rand()/(RAND_MAX/1000))))
- {
- parts[r>>8].type=PT_O2;
- //parts[r>>8].tmp=(rand()/(RAND_MAX/10))+20;
- }
- }
- }
+ else if(t==PT_BMTL) {
+ if(parts[i].tmp>1) {
+ parts[i].tmp--;
+ for(nx=-1; nx<2; nx++)
+ for(ny=-1; ny<2; ny++)
+ if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
+ {
+ r = pmap[y+ny][x+nx];
+ if((r>>8)>=NPART || !r)
+ continue;
+ rt =parts[r>>8].type;
+ if((rt==PT_METL || rt==PT_IRON) && 1>(rand()/(RAND_MAX/100)))
+ {
+ parts[r>>8].type=PT_BMTL;
+ parts[r>>8].tmp=(parts[i].tmp<=7)?parts[i].tmp=1:parts[i].tmp-(rand()%5);//rand()/(RAND_MAX/300)+100;
+ }
+ }
+ } else if(parts[i].tmp==1 && 1>rand()%1000) {
+ parts[i].tmp = 0;
+ t = parts[i].type = PT_BRMT;
+ }
+ }
+
+ else if(t==PT_IRON) {
+ for(nx=-1; nx<2; nx++)
+ for(ny=-1; ny<2; ny++)
+ if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
+ {
+ r = pmap[y+ny][x+nx];
+ if((r>>8)>=NPART || !r)
+ continue;
+ if((((r&0xFF) == PT_SALT && 15>(rand()/(RAND_MAX/700))) ||
+ ((r&0xFF) == PT_SLTW && 30>(rand()/(RAND_MAX/2000))) ||
+ ((r&0xFF) == PT_WATR && 5 >(rand()/(RAND_MAX/6000))) ||
+ ((r&0xFF) == PT_O2 && 2 >(rand()/(RAND_MAX/500))) ||
+ ((r&0xFF) == PT_LO2))&&
+ (!(parts[i].life))
+ )
+ {
+ parts[i].type=PT_BMTL;
+ parts[i].tmp=(rand()/(RAND_MAX/10))+20;
+ }
+ }
+ }
+ else if((t==PT_SPRK||parts[i].type==PT_SPRK) && parts[i].ctype==PT_IRON) {
+ for(nx=-1; nx<2; nx++)
+ for(ny=-1; ny<2; ny++)
+ if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
+ {
+ r = pmap[y+ny][x+nx];
+ if((r>>8)>=NPART || !r)
+ continue;
+ if(((r&0xFF) == PT_DSTW && 30>(rand()/(RAND_MAX/1000))) ||
+ ((r&0xFF) == PT_SLTW && 30>(rand()/(RAND_MAX/1000))) ||
+ ((r&0xFF) == PT_WATR && 30>(rand()/(RAND_MAX/1000))))
+ {
+ parts[r>>8].type=PT_O2;
+ //parts[r>>8].tmp=(rand()/(RAND_MAX/10))+20;
+ }
+ }
+ }
else if(t==PT_COAL)
{
if(parts[i].life<=0) {
@@ -1420,15 +1425,15 @@ void update_particles_i(pixel *vid, int start, int inc)
//t = parts[i].life = PT_NONE;
kill_part(i);
r = create_part(-1, x, y, PT_PLSM);
- if(r!=-1)
- parts[r].life = 50;
+ if(r!=-1)
+ parts[r].life = 50;
//goto killed;
} else if (parts[i].life < 40) {
parts[i].life--;
if((rand()%100)==0) {
r = create_part(-1, (nx=x+rand()%3-1), (ny=y+rand()%3-1), PT_PLSM);
- if(r!=-1)
- parts[r].life = 50;
+ if(r!=-1)
+ parts[r].life = 50;
}
}
if((pv[y/CELL][x/CELL] > 2.7f)&&parts[i].tmp>40)
@@ -1463,15 +1468,15 @@ void update_particles_i(pixel *vid, int start, int inc)
//t = PT_NONE;
kill_part(i);
r = create_part(-1, x, y, PT_PLSM);
- if(r!=-1)
- parts[r].life = 50;
+ if(r!=-1)
+ parts[r].life = 50;
//goto killed;
} else if (parts[i].life < 40) {
parts[i].life--;
if((rand()%10)==0) {
r = create_part(-1, (nx=x+rand()%3-1), (ny=y+rand()%3-1), PT_PLSM);
- if(r!=-1)
- parts[r].life = 50;
+ if(r!=-1)
+ parts[r].life = 50;
}
}
for(nx=-2; nx<3; nx++)
@@ -1777,9 +1782,9 @@ void update_particles_i(pixel *vid, int start, int inc)
}
}
}
- else if(t==PT_MORT){
- create_part(-1, x, y-1, PT_SMKE);
- }
+ else if(t==PT_MORT) {
+ create_part(-1, x, y-1, PT_SMKE);
+ }
else if(t==PT_LCRY)
{
for(nx=-1; nx<2; nx++)
@@ -1946,7 +1951,7 @@ void update_particles_i(pixel *vid, int start, int inc)
}
}
else if(parts[i].tmp==2) {
- int col = rand()%200+4;
+ int col = rand()%200+4;
for(nx=-2; nx<3; nx++) {
for(ny=-2; ny<3; ny++) {
if(x+nx>=0 && y+ny>0 && x+nx<XRES && y+ny<YRES && (nx || ny))
@@ -2040,7 +2045,7 @@ void update_particles_i(pixel *vid, int start, int inc)
continue;
rt = parts[r>>8].type;
if((a || ptypes[rt].explosive) && ((rt!=PT_RBDM && rt!=PT_LRBD && rt!=PT_INSL && rt!=PT_SWCH) || t!=PT_SPRK) &&
- !(t==PT_PHOT && rt==PT_INSL) &&
+ !(t==PT_PHOT && rt==PT_INSL) &&
(t!=PT_LAVA || parts[i].life>0 || (rt!=PT_STNE && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SWCH && rt!=PT_INWR)) &&
ptypes[rt].flammable && (ptypes[rt].flammable + (int)(pv[(y+ny)/CELL][(x+nx)/CELL]*10.0f))>(rand()%1000))
{
@@ -2621,8 +2626,8 @@ killed:
parts[i].ctype = pmap[y+ny][x+nx]&0xFF;
}
else {
- create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
- }
+ create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
+ }
}
if(parts[i].type==PT_PCLN)
@@ -2641,21 +2646,21 @@ killed:
(pmap[y+ny][x+nx]&0xFF)!=PT_STKM &&
(pmap[y+ny][x+nx]&0xFF)!=0xFF)
parts[i].ctype = pmap[y+ny][x+nx]&0xFF;
- if(parts[i].ctype && parts[i].life==10){
- if(parts[i].ctype==PT_PHOT){
- for(nx=-1; nx<2; nx++){
- for(ny=-1; ny<2; ny++){
- r = create_part(-1, x+nx, y+ny, parts[i].ctype);
- if(r!=-1){
- parts[r].vx = nx*3;
- parts[r].vy = ny*3;
- }
- }
- }
- } else {
- create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
- }
- }
+ if(parts[i].ctype && parts[i].life==10) {
+ if(parts[i].ctype==PT_PHOT) {
+ for(nx=-1; nx<2; nx++) {
+ for(ny=-1; ny<2; ny++) {
+ r = create_part(-1, x+nx, y+ny, parts[i].ctype);
+ if(r!=-1) {
+ parts[r].vx = nx*3;
+ parts[r].vy = ny*3;
+ }
+ }
+ }
+ } else {
+ create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
+ }
+ }
}
if(t==PT_YEST)
{
@@ -2697,7 +2702,7 @@ killed:
lt = pmap[y][x] & 0xFF;
- r = eval_move(PT_PHOT, nx, ny, NULL);
+ r = eval_move(PT_PHOT, nx, ny, NULL);
if(((rt==PT_GLAS && lt!=PT_GLAS) || (rt!=PT_GLAS && lt==PT_GLAS)) && r) {
if(!get_normal_interp(REFRACT|parts[i].type, x, y, parts[i].vx, parts[i].vy, &nrx, &nry)) {
@@ -2705,13 +2710,13 @@ killed:
continue;
}
- r = get_wavelength_bin(&parts[i].ctype);
- if(r == -1) {
- kill_part(i);
- continue;
- }
- nn = GLASS_IOR - GLASS_DISP*(r-15)/15.0f;
- nn *= nn;
+ r = get_wavelength_bin(&parts[i].ctype);
+ if(r == -1) {
+ kill_part(i);
+ continue;
+ }
+ nn = GLASS_IOR - GLASS_DISP*(r-15)/15.0f;
+ nn *= nn;
nrx = -nrx;
nry = -nry;
@@ -2722,10 +2727,10 @@ killed:
if(ct2 < 0.0f) {
parts[i].vx -= 2.0f*ct1*nrx;
parts[i].vy -= 2.0f*ct1*nry;
- parts[i].x = lx;
- parts[i].y = ly;
- nx = (int)(lx + 0.5f);
- ny = (int)(ly + 0.5f);
+ parts[i].x = lx;
+ parts[i].y = ly;
+ nx = (int)(lx + 0.5f);
+ ny = (int)(ly + 0.5f);
} else {
ct2 = sqrtf(ct2);
ct2 = ct2 - nn*ct1;
@@ -2855,25 +2860,25 @@ killed:
}
else if(t==PT_NEUT || t==PT_PHOT)
{
- r = pmap[ny][nx];
-
- /* this should be replaced with a particle type attribute ("photwl" or something) */
- if((r & 0xFF) == PT_PSCN) parts[i].ctype = 0x00000000;
- if((r & 0xFF) == PT_NSCN) parts[i].ctype = 0x00000000;
- if((r & 0xFF) == PT_SPRK) parts[i].ctype = 0x00000000;
- if((r & 0xFF) == PT_COAL) parts[i].ctype = 0x00000000;
- if((r & 0xFF) == PT_BCOL) parts[i].ctype = 0x00000000;
- if((r & 0xFF) == PT_PLEX) parts[i].ctype &= 0x1F00003E;
- if((r & 0xFF) == PT_NITR) parts[i].ctype &= 0x0007C000;
- if((r & 0xFF) == PT_NBLE) parts[i].ctype &= 0x3FFF8000;
- if((r & 0xFF) == PT_LAVA) parts[i].ctype &= 0x3FF00000;
- if((r & 0xFF) == PT_ACID) parts[i].ctype &= 0x1FE001FE;
- if((r & 0xFF) == PT_DUST) parts[i].ctype &= 0x3FFFFFC0;
- if((r & 0xFF) == PT_SNOW) parts[i].ctype &= 0x03FFFFFF;
- if((r & 0xFF) == PT_GOO) parts[i].ctype &= 0x3FFAAA00;
- if((r & 0xFF) == PT_PLNT) parts[i].ctype &= 0x0007C000;
- if((r & 0xFF) == PT_PLUT) parts[i].ctype &= 0x001FCE00;
- if((r & 0xFF) == PT_URAN) parts[i].ctype &= 0x003FC000;
+ r = pmap[ny][nx];
+
+ /* this should be replaced with a particle type attribute ("photwl" or something) */
+ if((r & 0xFF) == PT_PSCN) parts[i].ctype = 0x00000000;
+ if((r & 0xFF) == PT_NSCN) parts[i].ctype = 0x00000000;
+ if((r & 0xFF) == PT_SPRK) parts[i].ctype = 0x00000000;
+ if((r & 0xFF) == PT_COAL) parts[i].ctype = 0x00000000;
+ if((r & 0xFF) == PT_BCOL) parts[i].ctype = 0x00000000;
+ if((r & 0xFF) == PT_PLEX) parts[i].ctype &= 0x1F00003E;
+ if((r & 0xFF) == PT_NITR) parts[i].ctype &= 0x0007C000;
+ if((r & 0xFF) == PT_NBLE) parts[i].ctype &= 0x3FFF8000;
+ if((r & 0xFF) == PT_LAVA) parts[i].ctype &= 0x3FF00000;
+ if((r & 0xFF) == PT_ACID) parts[i].ctype &= 0x1FE001FE;
+ if((r & 0xFF) == PT_DUST) parts[i].ctype &= 0x3FFFFFC0;
+ if((r & 0xFF) == PT_SNOW) parts[i].ctype &= 0x03FFFFFF;
+ if((r & 0xFF) == PT_GOO) parts[i].ctype &= 0x3FFAAA00;
+ if((r & 0xFF) == PT_PLNT) parts[i].ctype &= 0x0007C000;
+ if((r & 0xFF) == PT_PLUT) parts[i].ctype &= 0x001FCE00;
+ if((r & 0xFF) == PT_URAN) parts[i].ctype &= 0x003FC000;
if(get_normal_interp(t, lx, ly, parts[i].vx, parts[i].vy, &nrx, &nry)) {
dp = nrx*parts[i].vx + nry*parts[i].vy;
@@ -2893,10 +2898,10 @@ killed:
continue;
}
- if(!parts[i].ctype) {
- kill_part(i);
- continue;
- }
+ if(!parts[i].ctype) {
+ kill_part(i);
+ continue;
+ }
}
else
@@ -2958,9 +2963,9 @@ void update_particles(pixel *vid)
x = (int)(parts[i].x+0.5f);
y = (int)(parts[i].y+0.5f);
if(x>=0 && y>=0 && x<XRES && y<YRES && t!=PT_PHOT) {
- if(t!=PT_NEUT || (pmap[y][x]&0xFF)!=PT_GLAS)
- pmap[y][x] = t|(i<<8);
- }
+ if(t!=PT_NEUT || (pmap[y][x]&0xFF)!=PT_GLAS)
+ pmap[y][x] = t|(i<<8);
+ }
}
else
{