summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:43:59 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-11-17 19:43:59 (GMT)
commite3594aba9e05c6865d396418c028049cda92c2f3 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /src
parentfb43f7d23e99765ae093fc45608901cb5907d1d8 (diff)
downloadpowder-e3594aba9e05c6865d396418c028049cda92c2f3.zip
powder-e3594aba9e05c6865d396418c028049cda92c2f3.tar.gz
Remove old code
Diffstat (limited to 'src')
-rw-r--r--src/BSON.c1122
-rwxr-xr-xsrc/Resources/Font-Databin4492 -> 0 bytes
-rwxr-xr-xsrc/Resources/Font-Pointersbin512 -> 0 bytes
-rwxr-xr-xsrc/Resources/Icon-16.pngbin3161 -> 0 bytes
-rwxr-xr-xsrc/Resources/Icon-32.pngbin3896 -> 0 bytes
-rw-r--r--src/Resources/document.icobin25364 -> 0 bytes
-rw-r--r--src/Resources/icon-document-16.pngbin533 -> 0 bytes
-rw-r--r--src/Resources/icon-document-32.pngbin1253 -> 0 bytes
-rw-r--r--src/Resources/icon/powder-16.pngbin428 -> 0 bytes
-rw-r--r--src/Resources/icon/powder-24.pngbin797 -> 0 bytes
-rw-r--r--src/Resources/icon/powder-256.pngbin86288 -> 0 bytes
-rw-r--r--src/Resources/icon/powder-32.pngbin1298 -> 0 bytes
-rw-r--r--src/Resources/icon/powder-48.pngbin2699 -> 0 bytes
-rw-r--r--src/Resources/powder-res.rc4
-rwxr-xr-xsrc/Resources/powder.icnsbin98761 -> 0 bytes
-rwxr-xr-xsrc/Resources/powder.icobin90174 -> 0 bytes
-rw-r--r--src/SDLMain.m416
-rw-r--r--src/air.c306
-rw-r--r--src/cJSON.c502
-rw-r--r--src/console.c638
-rw-r--r--src/elementdata.c550
-rw-r--r--src/elements/O2.c63
-rw-r--r--src/elements/acel.c73
-rw-r--r--src/elements/acid.c91
-rw-r--r--src/elements/amtr.c43
-rw-r--r--src/elements/anar.c42
-rw-r--r--src/elements/aray.c118
-rw-r--r--src/elements/bang.c91
-rw-r--r--src/elements/bcln.c63
-rw-r--r--src/elements/bcol.c83
-rw-r--r--src/elements/bizr.c59
-rw-r--r--src/elements/bmtl.c44
-rw-r--r--src/elements/bomb.c68
-rw-r--r--src/elements/boyl.c58
-rw-r--r--src/elements/brel.c30
-rw-r--r--src/elements/brmt.c49
-rw-r--r--src/elements/btry.c39
-rw-r--r--src/elements/c5.c39
-rw-r--r--src/elements/caus.c50
-rw-r--r--src/elements/cbnw.c105
-rw-r--r--src/elements/clne.c55
-rw-r--r--src/elements/clst.c53
-rw-r--r--src/elements/co2.c63
-rw-r--r--src/elements/coal.c90
-rw-r--r--src/elements/conv.c60
-rw-r--r--src/elements/dest.c81
-rw-r--r--src/elements/deut.c109
-rw-r--r--src/elements/dlay.c63
-rw-r--r--src/elements/dstw.c56
-rw-r--r--src/elements/dtec.c59
-rw-r--r--src/elements/elec.c121
-rw-r--r--src/elements/elementmisc.c27
-rw-r--r--src/elements/embr.c94
-rw-r--r--src/elements/emp.c143
-rw-r--r--src/elements/exot.c159
-rw-r--r--src/elements/figh.c105
-rw-r--r--src/elements/fire.c34
-rw-r--r--src/elements/firw.c82
-rw-r--r--src/elements/fog.c37
-rw-r--r--src/elements/fray.c44
-rw-r--r--src/elements/frzw.c45
-rw-r--r--src/elements/frzz.c40
-rw-r--r--src/elements/fsep.c50
-rw-r--r--src/elements/fuse.c56
-rw-r--r--src/elements/fwrk.c84
-rw-r--r--src/elements/gbmb.c41
-rw-r--r--src/elements/gel.c107
-rw-r--r--src/elements/glas.c26
-rw-r--r--src/elements/glow.c43
-rw-r--r--src/elements/goo.c28
-rw-r--r--src/elements/gpmp.c47
-rw-r--r--src/elements/graphics_default.c38
-rw-r--r--src/elements/h2.c74
-rw-r--r--src/elements/hswc.c41
-rw-r--r--src/elements/ice.c40
-rw-r--r--src/elements/ignt.c59
-rw-r--r--src/elements/iron.c40
-rw-r--r--src/elements/isz.c29
-rw-r--r--src/elements/lava.c34
-rw-r--r--src/elements/lcry.c76
-rw-r--r--src/elements/legacy.c135
-rw-r--r--src/elements/ligh.c315
-rw-r--r--src/elements/merc.c85
-rw-r--r--src/elements/mort.c21
-rw-r--r--src/elements/nbhl.c24
-rw-r--r--src/elements/nble.c39
-rw-r--r--src/elements/neut.c172
-rw-r--r--src/elements/newgraphics.c530
-rw-r--r--src/elements/none.c21
-rw-r--r--src/elements/nptct.c22
-rw-r--r--src/elements/nwhl.c21
-rw-r--r--src/elements/pbcn.c115
-rw-r--r--src/elements/pcln.c105
-rw-r--r--src/elements/phot.c101
-rw-r--r--src/elements/pipe.c563
-rw-r--r--src/elements/plnt.c89
-rw-r--r--src/elements/plsm.c35
-rw-r--r--src/elements/plut.c24
-rw-r--r--src/elements/prti.c97
-rw-r--r--src/elements/prto.c139
-rw-r--r--src/elements/pump.c53
-rw-r--r--src/elements/pvod.c45
-rw-r--r--src/elements/pyro.c145
-rw-r--r--src/elements/qrtz.c109
-rw-r--r--src/elements/repl.c37
-rw-r--r--src/elements/rime.c41
-rw-r--r--src/elements/shld.c177
-rw-r--r--src/elements/sing.c119
-rw-r--r--src/elements/sltw.c45
-rw-r--r--src/elements/smke.c33
-rw-r--r--src/elements/soap.c247
-rw-r--r--src/elements/spng.c145
-rw-r--r--src/elements/sprk.c250
-rw-r--r--src/elements/stkm.c516
-rw-r--r--src/elements/stkm2.c28
-rw-r--r--src/elements/stor.c58
-rw-r--r--src/elements/swch.c59
-rw-r--r--src/elements/thdr.c53
-rw-r--r--src/elements/thrm.c44
-rw-r--r--src/elements/tron.c206
-rw-r--r--src/elements/ttan.c39
-rw-r--r--src/elements/uran.c25
-rw-r--r--src/elements/vine.c35
-rw-r--r--src/elements/warp.c59
-rw-r--r--src/elements/watr.c58
-rw-r--r--src/elements/wifi.c51
-rw-r--r--src/elements/wire.c86
-rw-r--r--src/elements/wood.c40
-rw-r--r--src/elements/wtrv.c37
-rw-r--r--src/elements/yest.c36
-rw-r--r--src/graphics.c4534
-rw-r--r--src/gravity.c525
-rw-r--r--src/http.c1079
-rw-r--r--src/interface.c7243
-rw-r--r--src/luaconsole.c2119
-rw-r--r--src/main.c2881
-rw-r--r--src/md5.c231
-rw-r--r--src/misc.c1005
-rw-r--r--src/powder.c3751
-rw-r--r--src/save.c2503
-rw-r--r--src/update.c203
141 files changed, 0 insertions, 38882 deletions
diff --git a/src/BSON.c b/src/BSON.c
deleted file mode 100644
index 61445e2..0000000
--- a/src/BSON.c
+++ /dev/null
@@ -1,1122 +0,0 @@
-/* bson.c */
-
-/* Copyright 2009, 2010 10gen Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-#include <time.h>
-#include <limits.h>
-
-#include "BSON.h"
-
-const int initialBufferSize = 128;
-
-/* only need one of these */
-static const int zero = 0;
-
-/* Custom standard function pointers. */
-void *( *bson_malloc_func )( size_t ) = malloc;
-void *( *bson_realloc_func )( void *, size_t ) = realloc;
-void ( *bson_free )( void * ) = free;
-bson_printf_func bson_printf = printf;
-bson_fprintf_func bson_fprintf = fprintf;
-bson_sprintf_func bson_sprintf = sprintf;
-
-static int _bson_errprintf( const char *, ... );
-bson_printf_func bson_errprintf = _bson_errprintf;
-
-/* ObjectId fuzz functions. */
-static int ( *oid_fuzz_func )( void ) = NULL;
-static int ( *oid_inc_func )( void ) = NULL;
-
-/* ----------------------------
- READING
- ------------------------------ */
-
-bson *bson_empty( bson *obj ) {
- static char *data = "\005\0\0\0\0";
- bson_init_data( obj, data );
- obj->finished = 1;
- obj->err = 0;
- obj->stackPos = 0;
- return obj;
-}
-
-int bson_copy( bson *out, const bson *in ) {
- if ( !out ) return BSON_ERROR;
- if ( !in->finished ) return BSON_ERROR;
- bson_init_size( out, bson_size( in ) );
- memcpy( out->data, in->data, bson_size( in ) );
- out->finished = 1;
-
- return BSON_OK;
-}
-
-int bson_init_data( bson *b, char *data ) {
- b->data = data;
- return BSON_OK;
-}
-
-int bson_init_finished_data( bson *b, char *data ) {
- bson_init_data( b, data );
- b->stackPos = 0;
- b->finished = 1;
- return BSON_OK;
-}
-
-static void _bson_reset( bson *b ) {
- b->finished = 0;
- b->stackPos = 0;
- b->err = 0;
- b->errstr = NULL;
-}
-
-int bson_size( const bson *b ) {
- int i;
- if ( ! b || ! b->data )
- return 0;
- bson_little_endian32( &i, b->data );
- return i;
-}
-
-const char *bson_data( bson *b ) {
- return (const char *)b->data;
-}
-
-static char hexbyte( char hex ) {
- switch ( hex ) {
- case '0':
- return 0x0;
- case '1':
- return 0x1;
- case '2':
- return 0x2;
- case '3':
- return 0x3;
- case '4':
- return 0x4;
- case '5':
- return 0x5;
- case '6':
- return 0x6;
- case '7':
- return 0x7;
- case '8':
- return 0x8;
- case '9':
- return 0x9;
- case 'a':
- case 'A':
- return 0xa;
- case 'b':
- case 'B':
- return 0xb;
- case 'c':
- case 'C':
- return 0xc;
- case 'd':
- case 'D':
- return 0xd;
- case 'e':
- case 'E':
- return 0xe;
- case 'f':
- case 'F':
- return 0xf;
- default:
- return 0x0; /* something smarter? */
- }
-}
-
-void bson_oid_from_string( bson_oid_t *oid, const char *str ) {
- int i;
- for ( i=0; i<12; i++ ) {
- oid->bytes[i] = ( hexbyte( str[2*i] ) << 4 ) | hexbyte( str[2*i + 1] );
- }
-}
-
-void bson_oid_to_string( const bson_oid_t *oid, char *str ) {
- static const char hex[16] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
- int i;
- for ( i=0; i<12; i++ ) {
- str[2*i] = hex[( oid->bytes[i] & 0xf0 ) >> 4];
- str[2*i + 1] = hex[ oid->bytes[i] & 0x0f ];
- }
- str[24] = '\0';
-}
-
-void bson_set_oid_fuzz( int ( *func )( void ) ) {
- oid_fuzz_func = func;
-}
-
-void bson_set_oid_inc( int ( *func )( void ) ) {
- oid_inc_func = func;
-}
-
-void bson_oid_gen( bson_oid_t *oid ) {
- static int incr = 0;
- static int fuzz = 0;
- int i;
- int t = time( NULL );
-
- if( oid_inc_func )
- i = oid_inc_func();
- else
- i = incr++;
-
- if ( !fuzz ) {
- if ( oid_fuzz_func )
- fuzz = oid_fuzz_func();
- else {
- srand( t );
- fuzz = rand();
- }
- }
-
- bson_big_endian32( &oid->ints[0], &t );
- oid->ints[1] = fuzz;
- bson_big_endian32( &oid->ints[2], &i );
-}
-
-time_t bson_oid_generated_time( bson_oid_t *oid ) {
- time_t out;
- bson_big_endian32( &out, &oid->ints[0] );
-
- return out;
-}
-
-void bson_print( bson *b ) {
- bson_print_raw( b->data , 0 );
-}
-
-void bson_print_raw( const char *data , int depth ) {
- bson_iterator i;
- const char *key;
- int temp;
- bson_timestamp_t ts;
- char oidhex[25];
- bson scope;
- bson_iterator_from_buffer( &i, data );
-
- while ( bson_iterator_next( &i ) ) {
- bson_type t = bson_iterator_type( &i );
- if ( t == 0 )
- break;
- key = bson_iterator_key( &i );
-
- for ( temp=0; temp<=depth; temp++ )
- bson_printf( "\t" );
- bson_printf( "%s : %d \t " , key , t );
- switch ( t ) {
- case BSON_DOUBLE:
- bson_printf( "%f" , bson_iterator_double( &i ) );
- break;
- case BSON_STRING:
- bson_printf( "%s" , bson_iterator_string( &i ) );
- break;
- case BSON_SYMBOL:
- bson_printf( "SYMBOL: %s" , bson_iterator_string( &i ) );
- break;
- case BSON_OID:
- bson_oid_to_string( bson_iterator_oid( &i ), oidhex );
- bson_printf( "%s" , oidhex );
- break;
- case BSON_BOOL:
- bson_printf( "%s" , bson_iterator_bool( &i ) ? "true" : "false" );
- break;
- case BSON_DATE:
- bson_printf( "%ld" , ( long int )bson_iterator_date( &i ) );
- break;
- case BSON_BINDATA:
- bson_printf( "BSON_BINDATA" );
- break;
- case BSON_UNDEFINED:
- bson_printf( "BSON_UNDEFINED" );
- break;
- case BSON_NULL:
- bson_printf( "BSON_NULL" );
- break;
- case BSON_REGEX:
- bson_printf( "BSON_REGEX: %s", bson_iterator_regex( &i ) );
- break;
- case BSON_CODE:
- bson_printf( "BSON_CODE: %s", bson_iterator_code( &i ) );
- break;
- case BSON_CODEWSCOPE:
- bson_printf( "BSON_CODE_W_SCOPE: %s", bson_iterator_code( &i ) );
- bson_init( &scope );
- bson_iterator_code_scope( &i, &scope );
- bson_printf( "\n\t SCOPE: " );
- bson_print( &scope );
- break;
- case BSON_INT:
- bson_printf( "%d" , bson_iterator_int( &i ) );
- break;
- case BSON_LONG:
- bson_printf( "%lld" , ( uint64_t )bson_iterator_long( &i ) );
- break;
- case BSON_TIMESTAMP:
- ts = bson_iterator_timestamp( &i );
- bson_printf( "i: %d, t: %d", ts.i, ts.t );
- break;
- case BSON_OBJECT:
- case BSON_ARRAY:
- bson_printf( "\n" );
- bson_print_raw( bson_iterator_value( &i ) , depth + 1 );
- break;
- default:
- bson_errprintf( "can't print type : %d\n" , t );
- }
- bson_printf( "\n" );
- }
-}
-
-/* ----------------------------
- ITERATOR
- ------------------------------ */
-
-void bson_iterator_init( bson_iterator *i, const bson *b ) {
- i->cur = b->data + 4;
- i->first = 1;
-}
-
-void bson_iterator_from_buffer( bson_iterator *i, const char *buffer ) {
- i->cur = buffer + 4;
- i->first = 1;
-}
-
-bson_type bson_find( bson_iterator *it, const bson *obj, const char *name ) {
- bson_iterator_init( it, (bson *)obj );
- while( bson_iterator_next( it ) ) {
- if ( strcmp( name, bson_iterator_key( it ) ) == 0 )
- break;
- }
- return bson_iterator_type( it );
-}
-
-bson_bool_t bson_iterator_more( const bson_iterator *i ) {
- return *( i->cur );
-}
-
-bson_type bson_iterator_next( bson_iterator *i ) {
- int ds;
-
- if ( i->first ) {
- i->first = 0;
- return ( bson_type )( *i->cur );
- }
-
- switch ( bson_iterator_type( i ) ) {
- case BSON_EOO:
- return BSON_EOO; /* don't advance */
- case BSON_UNDEFINED:
- case BSON_NULL:
- ds = 0;
- break;
- case BSON_BOOL:
- ds = 1;
- break;
- case BSON_INT:
- ds = 4;
- break;
- case BSON_LONG:
- case BSON_DOUBLE:
- case BSON_TIMESTAMP:
- case BSON_DATE:
- ds = 8;
- break;
- case BSON_OID:
- ds = 12;
- break;
- case BSON_STRING:
- case BSON_SYMBOL:
- case BSON_CODE:
- ds = 4 + bson_iterator_int_raw( i );
- break;
- case BSON_BINDATA:
- ds = 5 + bson_iterator_int_raw( i );
- break;
- case BSON_OBJECT:
- case BSON_ARRAY:
- case BSON_CODEWSCOPE:
- ds = bson_iterator_int_raw( i );
- break;
- case BSON_DBREF:
- ds = 4+12 + bson_iterator_int_raw( i );
- break;
- case BSON_REGEX: {
- const char *s = bson_iterator_value( i );
- const char *p = s;
- p += strlen( p )+1;
- p += strlen( p )+1;
- ds = p-s;
- break;
- }
-
- default: {
- char msg[] = "unknown type: 000000000000";
- bson_numstr( msg+14, ( unsigned )( i->cur[0] ) );
- bson_fatal_msg( 0, msg );
- return 0;
- }
- }
-
- i->cur += 1 + strlen( i->cur + 1 ) + 1 + ds;
-
- return ( bson_type )( *i->cur );
-}
-
-bson_type bson_iterator_type( const bson_iterator *i ) {
- return ( bson_type )i->cur[0];
-}
-
-const char *bson_iterator_key( const bson_iterator *i ) {
- return i->cur + 1;
-}
-
-const char *bson_iterator_value( const bson_iterator *i ) {
- const char *t = i->cur + 1;
- t += strlen( t ) + 1;
- return t;
-}
-
-/* types */
-
-int bson_iterator_int_raw( const bson_iterator *i ) {
- int out;
- bson_little_endian32( &out, bson_iterator_value( i ) );
- return out;
-}
-
-double bson_iterator_double_raw( const bson_iterator *i ) {
- double out;
- bson_little_endian64( &out, bson_iterator_value( i ) );
- return out;
-}
-
-int64_t bson_iterator_long_raw( const bson_iterator *i ) {
- int64_t out;
- bson_little_endian64( &out, bson_iterator_value( i ) );
- return out;
-}
-
-bson_bool_t bson_iterator_bool_raw( const bson_iterator *i ) {
- return bson_iterator_value( i )[0];
-}
-
-bson_oid_t *bson_iterator_oid( const bson_iterator *i ) {
- return ( bson_oid_t * )bson_iterator_value( i );
-}
-
-int bson_iterator_int( const bson_iterator *i ) {
- switch ( bson_iterator_type( i ) ) {
- case BSON_INT:
- return bson_iterator_int_raw( i );
- case BSON_LONG:
- return bson_iterator_long_raw( i );
- case BSON_DOUBLE:
- return bson_iterator_double_raw( i );
- default:
- return 0;
- }
-}
-
-double bson_iterator_double( const bson_iterator *i ) {
- switch ( bson_iterator_type( i ) ) {
- case BSON_INT:
- return bson_iterator_int_raw( i );
- case BSON_LONG:
- return bson_iterator_long_raw( i );
- case BSON_DOUBLE:
- return bson_iterator_double_raw( i );
- default:
- return 0;
- }
-}
-
-int64_t bson_iterator_long( const bson_iterator *i ) {
- switch ( bson_iterator_type( i ) ) {
- case BSON_INT:
- return bson_iterator_int_raw( i );
- case BSON_LONG:
- return bson_iterator_long_raw( i );
- case BSON_DOUBLE:
- return bson_iterator_double_raw( i );
- default:
- return 0;
- }
-}
-
-bson_timestamp_t bson_iterator_timestamp( const bson_iterator *i ) {
- bson_timestamp_t ts;
- bson_little_endian32( &( ts.i ), bson_iterator_value( i ) );
- bson_little_endian32( &( ts.t ), bson_iterator_value( i ) + 4 );
- return ts;
-}
-
-bson_bool_t bson_iterator_bool( const bson_iterator *i ) {
- switch ( bson_iterator_type( i ) ) {
- case BSON_BOOL:
- return bson_iterator_bool_raw( i );
- case BSON_INT:
- return bson_iterator_int_raw( i ) != 0;
- case BSON_LONG:
- return bson_iterator_long_raw( i ) != 0;
- case BSON_DOUBLE:
- return bson_iterator_double_raw( i ) != 0;
- case BSON_EOO:
- case BSON_NULL:
- return 0;
- default:
- return 1;
- }
-}
-
-const char *bson_iterator_string( const bson_iterator *i ) {
- return bson_iterator_value( i ) + 4;
-}
-
-int bson_iterator_string_len( const bson_iterator *i ) {
- return bson_iterator_int_raw( i );
-}
-
-const char *bson_iterator_code( const bson_iterator *i ) {
- switch ( bson_iterator_type( i ) ) {
- case BSON_STRING:
- case BSON_CODE:
- return bson_iterator_value( i ) + 4;
- case BSON_CODEWSCOPE:
- return bson_iterator_value( i ) + 8;
- default:
- return NULL;
- }
-}
-
-void bson_iterator_code_scope( const bson_iterator *i, bson *scope ) {
- if ( bson_iterator_type( i ) == BSON_CODEWSCOPE ) {
- int code_len;
- bson_little_endian32( &code_len, bson_iterator_value( i )+4 );
- bson_init_data( scope, ( void * )( bson_iterator_value( i )+8+code_len ) );
- _bson_reset( scope );
- scope->finished = 1;
- } else {
- bson_empty( scope );
- }
-}
-
-bson_date_t bson_iterator_date( const bson_iterator *i ) {
- return bson_iterator_long_raw( i );
-}
-
-time_t bson_iterator_time_t( const bson_iterator *i ) {
- return bson_iterator_date( i ) / 1000;
-}
-
-int bson_iterator_bin_len( const bson_iterator *i ) {
- return ( bson_iterator_bin_type( i ) == BSON_BIN_BINARY_OLD )
- ? bson_iterator_int_raw( i ) - 4
- : bson_iterator_int_raw( i );
-}
-
-char bson_iterator_bin_type( const bson_iterator *i ) {
- return bson_iterator_value( i )[4];
-}
-
-const char *bson_iterator_bin_data( const bson_iterator *i ) {
- return ( bson_iterator_bin_type( i ) == BSON_BIN_BINARY_OLD )
- ? bson_iterator_value( i ) + 9
- : bson_iterator_value( i ) + 5;
-}
-
-const char *bson_iterator_regex( const bson_iterator *i ) {
- return bson_iterator_value( i );
-}
-
-const char *bson_iterator_regex_opts( const bson_iterator *i ) {
- const char *p = bson_iterator_value( i );
- return p + strlen( p ) + 1;
-
-}
-
-void bson_iterator_subobject( const bson_iterator *i, bson *sub ) {
- bson_init_data( sub, ( char * )bson_iterator_value( i ) );
- _bson_reset( sub );
- sub->finished = 1;
-}
-
-void bson_iterator_subiterator( const bson_iterator *i, bson_iterator *sub ) {
- bson_iterator_from_buffer( sub, bson_iterator_value( i ) );
-}
-
-/* ----------------------------
- BUILDING
- ------------------------------ */
-
-static void _bson_init_size( bson *b, int size ) {
- if( size == 0 )
- b->data = NULL;
- else
- b->data = ( char * )bson_malloc( size );
- b->dataSize = size;
- b->cur = b->data + 4;
- _bson_reset( b );
-}
-
-void bson_init( bson *b ) {
- _bson_init_size( b, initialBufferSize );
-}
-
-void bson_init_size( bson *b, int size ) {
- _bson_init_size( b, size );
-}
-
-static void bson_append_byte( bson *b, char c ) {
- b->cur[0] = c;
- b->cur++;
-}
-
-static void bson_append( bson *b, const void *data, int len ) {
- memcpy( b->cur , data , len );
- b->cur += len;
-}
-
-static void bson_append32( bson *b, const void *data ) {
- bson_little_endian32( b->cur, data );
- b->cur += 4;
-}
-
-static void bson_append64( bson *b, const void *data ) {
- bson_little_endian64( b->cur, data );
- b->cur += 8;
-}
-
-int bson_ensure_space( bson *b, const int bytesNeeded ) {
- int pos = b->cur - b->data;
- char *orig = b->data;
- int new_size;
-
- if ( pos + bytesNeeded <= b->dataSize )
- return BSON_OK;
-
- new_size = 1.5 * ( b->dataSize + bytesNeeded );
-
- if( new_size < b->dataSize ) {
- if( ( b->dataSize + bytesNeeded ) < INT_MAX )
- new_size = INT_MAX;
- else {
- b->err = BSON_SIZE_OVERFLOW;
- return BSON_ERROR;
- }
- }
-
- b->data = bson_realloc( b->data, new_size );
- if ( !b->data )
- bson_fatal_msg( !!b->data, "realloc() failed" );
-
- b->dataSize = new_size;
- b->cur += b->data - orig;
-
- return BSON_OK;
-}
-
-int bson_finish( bson *b ) {
- int i;
-
- if( b->err & BSON_NOT_UTF8 )
- return BSON_ERROR;
-
- if ( ! b->finished ) {
- if ( bson_ensure_space( b, 1 ) == BSON_ERROR ) return BSON_ERROR;
- bson_append_byte( b, 0 );
- i = b->cur - b->data;
- bson_little_endian32( b->data, &i );
- b->finished = 1;
- }
-
- return BSON_OK;
-}
-
-void bson_destroy( bson *b ) {
- bson_free( b->data );
- b->err = 0;
- b->data = 0;
- b->cur = 0;
- b->finished = 1;
-}
-
-static int bson_append_estart( bson *b, int type, const char *name, const int dataSize ) {
- const int len = strlen( name ) + 1;
-
- if ( b->finished ) {
- b->err |= BSON_ALREADY_FINISHED;
- return BSON_ERROR;
- }
-
- if ( bson_ensure_space( b, 1 + len + dataSize ) == BSON_ERROR ) {
- return BSON_ERROR;
- }
-
- if( bson_check_field_name( b, ( const char * )name, len - 1 ) == BSON_ERROR ) {
- bson_builder_error( b );
- return BSON_ERROR;
- }
-
- bson_append_byte( b, ( char )type );
- bson_append( b, name, len );
- return BSON_OK;
-}
-
-/* ----------------------------
- BUILDING TYPES
- ------------------------------ */
-
-int bson_append_int( bson *b, const char *name, const int i ) {
- if ( bson_append_estart( b, BSON_INT, name, 4 ) == BSON_ERROR )
- return BSON_ERROR;
- bson_append32( b , &i );
- return BSON_OK;
-}
-
-int bson_append_long( bson *b, const char *name, const int64_t i ) {
- if ( bson_append_estart( b , BSON_LONG, name, 8 ) == BSON_ERROR )
- return BSON_ERROR;
- bson_append64( b , &i );
- return BSON_OK;
-}
-
-int bson_append_double( bson *b, const char *name, const double d ) {
- if ( bson_append_estart( b, BSON_DOUBLE, name, 8 ) == BSON_ERROR )
- return BSON_ERROR;
- bson_append64( b , &d );
- return BSON_OK;
-}
-
-int bson_append_bool( bson *b, const char *name, const bson_bool_t i ) {
- if ( bson_append_estart( b, BSON_BOOL, name, 1 ) == BSON_ERROR )
- return BSON_ERROR;
- bson_append_byte( b , i != 0 );
- return BSON_OK;
-}
-
-int bson_append_null( bson *b, const char *name ) {
- if ( bson_append_estart( b , BSON_NULL, name, 0 ) == BSON_ERROR )
- return BSON_ERROR;
- return BSON_OK;
-}
-
-int bson_append_undefined( bson *b, const char *name ) {
- if ( bson_append_estart( b, BSON_UNDEFINED, name, 0 ) == BSON_ERROR )
- return BSON_ERROR;
- return BSON_OK;
-}
-
-static int bson_append_string_base( bson *b, const char *name,
- const char *value, int len, bson_type type ) {
-
- int sl = len + 1;
- if ( bson_check_string( b, ( const char * )value, sl - 1 ) == BSON_ERROR )
- return BSON_ERROR;
- if ( bson_append_estart( b, type, name, 4 + sl ) == BSON_ERROR ) {
- return BSON_ERROR;
- }
- bson_append32( b , &sl );
- bson_append( b , value , sl - 1 );
- bson_append( b , "\0" , 1 );
- return BSON_OK;
-}
-
-int bson_append_string( bson *b, const char *name, const char *value ) {
- return bson_append_string_base( b, name, value, strlen ( value ), BSON_STRING );
-}
-
-int bson_append_symbol( bson *b, const char *name, const char *value ) {
- return bson_append_string_base( b, name, value, strlen ( value ), BSON_SYMBOL );
-}
-
-int bson_append_code( bson *b, const char *name, const char *value ) {
- return bson_append_string_base( b, name, value, strlen ( value ), BSON_CODE );
-}
-
-int bson_append_string_n( bson *b, const char *name, const char *value, int len ) {
- return bson_append_string_base( b, name, value, len, BSON_STRING );
-}
-
-int bson_append_symbol_n( bson *b, const char *name, const char *value, int len ) {
- return bson_append_string_base( b, name, value, len, BSON_SYMBOL );
-}
-
-int bson_append_code_n( bson *b, const char *name, const char *value, int len ) {
- return bson_append_string_base( b, name, value, len, BSON_CODE );
-}
-
-int bson_append_code_w_scope_n( bson *b, const char *name,
- const char *code, int len, const bson *scope ) {
-
- int sl = len + 1;
- int size = 4 + 4 + sl + bson_size( scope );
- if ( bson_append_estart( b, BSON_CODEWSCOPE, name, size ) == BSON_ERROR )
- return BSON_ERROR;
- bson_append32( b, &size );
- bson_append32( b, &sl );
- bson_append( b, code, sl );
- bson_append( b, scope->data, bson_size( scope ) );
- return BSON_OK;
-}
-
-int bson_append_code_w_scope( bson *b, const char *name, const char *code, const bson *scope ) {
- return bson_append_code_w_scope_n( b, name, code, strlen ( code ), scope );
-}
-
-int bson_append_binary( bson *b, const char *name, char type, const char *str, int len ) {
- if ( type == BSON_BIN_BINARY_OLD ) {
- int subtwolen = len + 4;
- if ( bson_append_estart( b, BSON_BINDATA, name, 4+1+4+len ) == BSON_ERROR )
- return BSON_ERROR;
- bson_append32( b, &subtwolen );
- bson_append_byte( b, type );
- bson_append32( b, &len );
- bson_append( b, str, len );
- } else {
- if ( bson_append_estart( b, BSON_BINDATA, name, 4+1+len ) == BSON_ERROR )
- return BSON_ERROR;
- bson_append32( b, &len );
- bson_append_byte( b, type );
- bson_append( b, str, len );
- }
- return BSON_OK;
-}
-
-int bson_append_oid( bson *b, const char *name, const bson_oid_t *oid ) {
- if ( bson_append_estart( b, BSON_OID, name, 12 ) == BSON_ERROR )
- return BSON_ERROR;
- bson_append( b , oid , 12 );
- return BSON_OK;
-}
-
-int bson_append_new_oid( bson *b, const char *name ) {
- bson_oid_t oid;
- bson_oid_gen( &oid );
- return bson_append_oid( b, name, &oid );
-}
-
-int bson_append_regex( bson *b, const char *name, const char *pattern, const char *opts ) {
- const int plen = strlen( pattern )+1;
- const int olen = strlen( opts )+1;
- if ( bson_append_estart( b, BSON_REGEX, name, plen + olen ) == BSON_ERROR )
- return BSON_ERROR;
- if ( bson_check_string( b, pattern, plen - 1 ) == BSON_ERROR )
- return BSON_ERROR;
- bson_append( b , pattern , plen );
- bson_append( b , opts , olen );
- return BSON_OK;
-}
-
-int bson_append_bson( bson *b, const char *name, const bson *bson ) {
- if ( bson_append_estart( b, BSON_OBJECT, name, bson_size( bson ) ) == BSON_ERROR )
- return BSON_ERROR;
- bson_append( b , bson->data , bson_size( bson ) );
- return BSON_OK;
-}
-
-int bson_append_element( bson *b, const char *name_or_null, const bson_iterator *elem ) {
- bson_iterator next = *elem;
- int size;
-
- bson_iterator_next( &next );
- size = next.cur - elem->cur;
-
- if ( name_or_null == NULL ) {
- if( bson_ensure_space( b, size ) == BSON_ERROR )
- return BSON_ERROR;
- bson_append( b, elem->cur, size );
- } else {
- int data_size = size - 2 - strlen( bson_iterator_key( elem ) );
- bson_append_estart( b, elem->cur[0], name_or_null, data_size );
- bson_append( b, bson_iterator_value( elem ), data_size );
- }
-
- return BSON_OK;
-}
-
-int bson_append_timestamp( bson *b, const char *name, bson_timestamp_t *ts ) {
- if ( bson_append_estart( b, BSON_TIMESTAMP, name, 8 ) == BSON_ERROR ) return BSON_ERROR;
-
- bson_append32( b , &( ts->i ) );
- bson_append32( b , &( ts->t ) );
-
- return BSON_OK;
-}
-
-int bson_append_date( bson *b, const char *name, bson_date_t millis ) {
- if ( bson_append_estart( b, BSON_DATE, name, 8 ) == BSON_ERROR ) return BSON_ERROR;
- bson_append64( b , &millis );
- return BSON_OK;
-}
-
-int bson_append_time_t( bson *b, const char *name, time_t secs ) {
- return bson_append_date( b, name, ( bson_date_t )secs * 1000 );
-}
-
-int bson_append_start_object( bson *b, const char *name ) {
- if ( bson_append_estart( b, BSON_OBJECT, name, 5 ) == BSON_ERROR ) return BSON_ERROR;
- b->stack[ b->stackPos++ ] = b->cur - b->data;
- bson_append32( b , &zero );
- return BSON_OK;
-}
-
-int bson_append_start_array( bson *b, const char *name ) {
- if ( bson_append_estart( b, BSON_ARRAY, name, 5 ) == BSON_ERROR ) return BSON_ERROR;
- b->stack[ b->stackPos++ ] = b->cur - b->data;
- bson_append32( b , &zero );
- return BSON_OK;
-}
-
-int bson_append_finish_object( bson *b ) {
- char *start;
- int i;
- if ( bson_ensure_space( b, 1 ) == BSON_ERROR ) return BSON_ERROR;
- bson_append_byte( b , 0 );
-
- start = b->data + b->stack[ --b->stackPos ];
- i = b->cur - start;
- bson_little_endian32( start, &i );
-
- return BSON_OK;
-}
-
-int bson_append_finish_array( bson *b ) {
- return bson_append_finish_object( b );
-}
-
-
-/* Error handling and allocators. */
-
-static bson_err_handler err_handler = NULL;
-
-bson_err_handler set_bson_err_handler( bson_err_handler func ) {
- bson_err_handler old = err_handler;
- err_handler = func;
- return old;
-}
-
-void *bson_malloc( int size ) {
- void *p;
- p = bson_malloc_func( size );
- bson_fatal_msg( !!p, "malloc() failed" );
- return p;
-}
-
-void *bson_realloc( void *ptr, int size ) {
- void *p;
- p = bson_realloc_func( ptr, size );
- bson_fatal_msg( !!p, "realloc() failed" );
- return p;
-}
-
-int _bson_errprintf( const char *format, ... ) {
- va_list ap;
- int ret;
- va_start( ap, format );
- ret = vfprintf( stderr, format, ap );
- va_end( ap );
-
- return ret;
-}
-
-/**
- * This method is invoked when a non-fatal bson error is encountered.
- * Calls the error handler if available.
- *
- * @param
- */
-void bson_builder_error( bson *b ) {
- if( err_handler )
- err_handler( "BSON error." );
-}
-
-void bson_fatal( int ok ) {
- bson_fatal_msg( ok, "" );
-}
-
-void bson_fatal_msg( int ok , const char *msg ) {
- if ( ok )
- return;
-
- if ( err_handler ) {
- err_handler( msg );
- }
-
- bson_errprintf( "error: %s\n" , msg );
- exit( -5 );
-}
-
-
-/* Efficiently copy an integer to a string. */
-
-void bson_numstr( char *str, int i ) {
- if( i < 1000 )
- memcpy( str, bson_numstrs[i], 4 );
- else
- bson_sprintf( str,"%d", i );
-}
-
-/* encoding.c */
-
-/*
- * Copyright 2009-2011 10gen, Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Portions Copyright 2001 Unicode, Inc.
- *
- * Disclaimer
- *
- * This source code is provided as is by Unicode, Inc. No claims are
- * made as to fitness for any particular purpose. No warranties of any
- * kind are expressed or implied. The recipient agrees to determine
- * applicability of information provided. If this file has been
- * purchased on magnetic or optical media from Unicode, Inc., the
- * sole remedy for any claim will be exchange of defective media
- * within 90 days of receipt.
- *
- * Limitations on Rights to Redistribute This Code
- *
- * Unicode, Inc. hereby grants the right to freely use the information
- * supplied in this file in the creation of products supporting the
- * Unicode Standard, and to make copies of this file in any form
- * for internal or external distribution as long as this notice
- * remains attached.
- */
-
-/*
- * Index into the table below with the first byte of a UTF-8 sequence to
- * get the number of trailing bytes that are supposed to follow it.
- */
-static const char trailingBytesForUTF8[256] = {
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
- 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 3,3,3,3,3,3,3,3,4,4,4,4,5,5,5,5
-};
-
-/* --------------------------------------------------------------------- */
-
-/*
- * Utility routine to tell whether a sequence of bytes is legal UTF-8.
- * This must be called with the length pre-determined by the first byte.
- * The length can be set by:
- * length = trailingBytesForUTF8[*source]+1;
- * and the sequence is illegal right away if there aren't that many bytes
- * available.
- * If presented with a length > 4, this returns 0. The Unicode
- * definition of UTF-8 goes up to 4-byte sequences.
- */
-static int isLegalUTF8( const unsigned char *source, int length ) {
- unsigned char a;
- const unsigned char *srcptr = source + length;
- switch ( length ) {
- default:
- return 0;
- /* Everything else falls through when "true"... */
- case 4:
- if ( ( a = ( *--srcptr ) ) < 0x80 || a > 0xBF ) return 0;
- case 3:
- if ( ( a = ( *--srcptr ) ) < 0x80 || a > 0xBF ) return 0;
- case 2:
- if ( ( a = ( *--srcptr ) ) > 0xBF ) return 0;
- switch ( *source ) {
- /* no fall-through in this inner switch */
- case 0xE0:
- if ( a < 0xA0 ) return 0;
- break;
- case 0xF0:
- if ( a < 0x90 ) return 0;
- break;
- case 0xF4:
- if ( a > 0x8F ) return 0;
- break;
- default:
- if ( a < 0x80 ) return 0;
- }
- case 1:
- if ( *source >= 0x80 && *source < 0xC2 ) return 0;
- if ( *source > 0xF4 ) return 0;
- }
- return 1;
-}
-
-static int bson_validate_string( bson *b, const unsigned char *string,
- const int length, const char check_utf8, const char check_dot,
- const char check_dollar ) {
-
- int position = 0;
- int sequence_length = 1;
-
- if( check_dollar && string[0] == '$' ) {
- b->err |= BSON_FIELD_INIT_DOLLAR;
- }
-
- while ( position < length ) {
- if ( check_dot && *( string + position ) == '.' ) {
- b->err |= BSON_FIELD_HAS_DOT;
- }
-
- if ( check_utf8 ) {
- sequence_length = trailingBytesForUTF8[*( string + position )] + 1;
- if ( ( position + sequence_length ) > length ) {
- b->err |= BSON_NOT_UTF8;
- return BSON_ERROR;
- }
- if ( !isLegalUTF8( string + position, sequence_length ) ) {
- b->err |= BSON_NOT_UTF8;
- return BSON_ERROR;
- }
- }
- position += sequence_length;
- }
-
- return BSON_OK;
-}
-
-
-int bson_check_string( bson *b, const char *string,
- const int length ) {
-
- return bson_validate_string( b, ( const unsigned char * )string, length, 1, 0, 0 );
-}
-
-int bson_check_field_name( bson *b, const char *string,
- const int length ) {
-
- return bson_validate_string( b, ( const unsigned char * )string, length, 1, 1, 1 );
-} \ No newline at end of file
diff --git a/src/Resources/Font-Data b/src/Resources/Font-Data
deleted file mode 100755
index 1d838b0..0000000
--- a/src/Resources/Font-Data
+++ /dev/null
Binary files differ
diff --git a/src/Resources/Font-Pointers b/src/Resources/Font-Pointers
deleted file mode 100755
index 47dd821..0000000
--- a/src/Resources/Font-Pointers
+++ /dev/null
Binary files differ
diff --git a/src/Resources/Icon-16.png b/src/Resources/Icon-16.png
deleted file mode 100755
index 5e1e1fb..0000000
--- a/src/Resources/Icon-16.png
+++ /dev/null
Binary files differ
diff --git a/src/Resources/Icon-32.png b/src/Resources/Icon-32.png
deleted file mode 100755
index 1f056bd..0000000
--- a/src/Resources/Icon-32.png
+++ /dev/null
Binary files differ
diff --git a/src/Resources/document.ico b/src/Resources/document.ico
deleted file mode 100644
index 83c57e7..0000000
--- a/src/Resources/document.ico
+++ /dev/null
Binary files differ
diff --git a/src/Resources/icon-document-16.png b/src/Resources/icon-document-16.png
deleted file mode 100644
index 5e43e8e..0000000
--- a/src/Resources/icon-document-16.png
+++ /dev/null
Binary files differ
diff --git a/src/Resources/icon-document-32.png b/src/Resources/icon-document-32.png
deleted file mode 100644
index 6b93bda..0000000
--- a/src/Resources/icon-document-32.png
+++ /dev/null
Binary files differ
diff --git a/src/Resources/icon/powder-16.png b/src/Resources/icon/powder-16.png
deleted file mode 100644
index 5934240..0000000
--- a/src/Resources/icon/powder-16.png
+++ /dev/null
Binary files differ
diff --git a/src/Resources/icon/powder-24.png b/src/Resources/icon/powder-24.png
deleted file mode 100644
index 6c2ef69..0000000
--- a/src/Resources/icon/powder-24.png
+++ /dev/null
Binary files differ
diff --git a/src/Resources/icon/powder-256.png b/src/Resources/icon/powder-256.png
deleted file mode 100644
index 73b04de..0000000
--- a/src/Resources/icon/powder-256.png
+++ /dev/null
Binary files differ
diff --git a/src/Resources/icon/powder-32.png b/src/Resources/icon/powder-32.png
deleted file mode 100644
index bdc038e..0000000
--- a/src/Resources/icon/powder-32.png
+++ /dev/null
Binary files differ
diff --git a/src/Resources/icon/powder-48.png b/src/Resources/icon/powder-48.png
deleted file mode 100644
index 8a896e7..0000000
--- a/src/Resources/icon/powder-48.png
+++ /dev/null
Binary files differ
diff --git a/src/Resources/powder-res.rc b/src/Resources/powder-res.rc
deleted file mode 100644
index 46208e2..0000000
--- a/src/Resources/powder-res.rc
+++ /dev/null
@@ -1,4 +0,0 @@
-#define IDI_ICON1 101
-#define IDI_ICON2 102
-IDI_ICON1 ICON DISCARDABLE "powder.ico"
-IDI_ICON2 ICON DISCARDABLE "document.ico"
diff --git a/src/Resources/powder.icns b/src/Resources/powder.icns
deleted file mode 100755
index 56df7eb..0000000
--- a/src/Resources/powder.icns
+++ /dev/null
Binary files differ
diff --git a/src/Resources/powder.ico b/src/Resources/powder.ico
deleted file mode 100755
index cd3f6e0..0000000
--- a/src/Resources/powder.ico
+++ /dev/null
Binary files differ
diff --git a/src/SDLMain.m b/src/SDLMain.m
deleted file mode 100644
index bca2253..0000000
--- a/src/SDLMain.m
+++ /dev/null
@@ -1,416 +0,0 @@
-/* SDLMain.m - main entry point for our Cocoa-ized SDL app
- Initial Version: Darrell Walisser <dwaliss1@purdue.edu>
- Non-NIB-Code & other changes: Max Horn <max@quendi.de>
-
- Feel free to customize this file to suit your needs
-*/
-
-#include <SDL/SDL.h>
-#include "SDLMain.h"
-#include <sys/param.h> /* for MAXPATHLEN */
-#include <unistd.h>
-#include "defines.h"
-
-/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
- but the method still is there and works. To avoid warnings, we declare
- it ourselves here. */
-@interface NSApplication(SDL_Missing_Methods)
-- (void)setAppleMenu:(NSMenu *)menu;
-@end
-
-/* Use this flag to determine whether we use SDLMain.nib or not */
-#define SDL_USE_NIB_FILE 0
-
-/* Use this flag to determine whether we use CPS (docking) or not */
-#define SDL_USE_CPS 1
-#ifdef SDL_USE_CPS
-/* Portions of CPS.h */
-typedef struct CPSProcessSerNum
-{
- UInt32 lo;
- UInt32 hi;
-} CPSProcessSerNum;
-
-extern OSErr CPSGetCurrentProcess( CPSProcessSerNum *psn);
-extern OSErr CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
-extern OSErr CPSSetFrontProcess( CPSProcessSerNum *psn);
-
-#endif /* SDL_USE_CPS */
-
-static int gArgc;
-static char **gArgv;
-static BOOL gFinderLaunch;
-static BOOL gCalledAppMainline = FALSE;
-
-static NSString *getApplicationName(void)
-{
- const NSDictionary *dict;
- NSString *appName = 0;
-
- /* Determine the application name */
- dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
- if (dict)
- appName = [dict objectForKey: @"CFBundleName"];
-
- if (![appName length])
- appName = [[NSProcessInfo processInfo] processName];
-
- return appName;
-}
-
-#if SDL_USE_NIB_FILE
-/* A helper category for NSString */
-@interface NSString (ReplaceSubString)
-- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
-@end
-#endif
-
-@interface NSApplication (SDLApplication)
-@end
-
-@implementation NSApplication (SDLApplication)
-/* Invoked from the Quit menu item */
-- (void)terminate:(id)sender
-{
- /* Post a SDL_QUIT event */
- SDL_Event event;
- event.type = SDL_QUIT;
- SDL_PushEvent(&event);
-}
-@end
-
-/* The main class of the application, the application's delegate */
-@implementation SDLMain
-
-/* Set the working directory to the .app's parent directory */
-- (void) setupWorkingDirectory:(BOOL)shouldChdir
-{
- if (shouldChdir)
- {
- char parentdir[MAXPATHLEN];
- CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
- CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
- if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
- chdir(parentdir); /* chdir to the binary app's parent */
- }
- CFRelease(url);
- CFRelease(url2);
- }
-}
-
-#if SDL_USE_NIB_FILE
-
-/* Fix menu to contain the real app name instead of "SDL App" */
-- (void)fixMenu:(NSMenu *)aMenu withAppName:(NSString *)appName
-{
- NSRange aRange;
- NSEnumerator *enumerator;
- NSMenuItem *menuItem;
-
- aRange = [[aMenu title] rangeOfString:@"SDL App"];
- if (aRange.length != 0)
- [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:appName]];
-
- enumerator = [[aMenu itemArray] objectEnumerator];
- while ((menuItem = [enumerator nextObject]))
- {
- aRange = [[menuItem title] rangeOfString:@"SDL App"];
- if (aRange.length != 0)
- [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:appName]];
- if ([menuItem hasSubmenu])
- [self fixMenu:[menuItem submenu] withAppName:appName];
- }
-}
-
-#else
-
-static void setApplicationMenu(void)
-{
- /* warning: this code is very odd */
- NSMenu *appleMenu;
- NSMenuItem *menuItem;
- NSString *title;
- NSString *appName;
-
- appName = getApplicationName();
- appleMenu = [[NSMenu alloc] initWithTitle:@""];
-
- /* Add menu items */
- title = [@"About " stringByAppendingString:appName];
- [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
-
- [appleMenu addItem:[NSMenuItem separatorItem]];
-
- title = [@"Hide " stringByAppendingString:appName];
- [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
-
- menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];
- [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
-
- [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
-
- [appleMenu addItem:[NSMenuItem separatorItem]];
-
- title = [@"Quit " stringByAppendingString:appName];
- [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
-
-
- /* Put menu into the menubar */
- menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
- [menuItem setSubmenu:appleMenu];
- [[NSApp mainMenu] addItem:menuItem];
-
- /* Tell the application object that this is now the application menu */
- [NSApp setAppleMenu:appleMenu];
-
- /* Finally give up our references to the objects */
- [appleMenu release];
- [menuItem release];
-}
-
-/* Create a window menu */
-static void setupWindowMenu(void)
-{
- NSMenu *windowMenu;
- NSMenuItem *windowMenuItem;
- NSMenuItem *menuItem;
-
- windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
-
- /* "Minimize" item */
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
- [windowMenu addItem:menuItem];
- [menuItem release];
-
- /* Put menu into the menubar */
- windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
- [windowMenuItem setSubmenu:windowMenu];
- [[NSApp mainMenu] addItem:windowMenuItem];
-
- /* Tell the application object that this is now the window menu */
- [NSApp setWindowsMenu:windowMenu];
-
- /* Finally give up our references to the objects */
- [windowMenu release];
- [windowMenuItem release];
-}
-
-/* Replacement for NSApplicationMain */
-static void CustomApplicationMain (int argc, char **argv)
-{
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
- SDLMain *sdlMain;
-
- /* Ensure the application object is initialised */
- [NSApplication sharedApplication];
-
-#ifdef SDL_USE_CPS
- {
- CPSProcessSerNum PSN;
- /* Tell the dock about us */
- if (!CPSGetCurrentProcess(&PSN))
- if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
- if (!CPSSetFrontProcess(&PSN))
- [NSApplication sharedApplication];
- }
-#endif /* SDL_USE_CPS */
-
- /* Set up the menubar */
- [NSApp setMainMenu:[[NSMenu alloc] init]];
- setApplicationMenu();
- setupWindowMenu();
-
- /* Create SDLMain and make it the app delegate */
- sdlMain = [[SDLMain alloc] init];
- [NSApp setDelegate:sdlMain];
-
- /* Start the main event loop */
- [NSApp run];
-
- [sdlMain release];
- [pool release];
-}
-
-#endif
-
-void *file_load(char *fn, int *size);
-
-/*
- * Catch document open requests...this lets us notice files when the app
- * was launched by double-clicking a document, or when a document was
- * dragged/dropped on the app's icon. You need to have a
- * CFBundleDocumentsType section in your Info.plist to get this message,
- * apparently.
- *
- * Files are added to gArgv, so to the app, they'll look like command line
- * arguments. Previously, apps launched from the finder had nothing but
- * an argv[0].
- *
- * This message may be received multiple times to open several docs on launch.
- *
- * This message is ignored once the app's mainline has been called.
- */
-- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
-{
- /*const char *temparg;
- size_t arglen;
- char *arg;
- char **newargv;
-
- if (!gFinderLaunch)
- return FALSE;
-
- if (gCalledAppMainline)
- return FALSE;
-
- temparg = [filename UTF8String];
- arglen = SDL_strlen(temparg) + 1;
- arg = (char *) SDL_malloc(arglen);
- if (arg == NULL)
- return FALSE;
-
- newargv = (char **) realloc(gArgv, sizeof (char *) * (gArgc + 3));
- if (newargv == NULL)
- {
- SDL_free(arg);
- return FALSE;
- }
- gArgv = newargv;
-
- SDL_strlcpy(arg, temparg, arglen);
- gArgv[gArgc++] = "open";
- gArgv[gArgc++] = arg;
- gArgv[gArgc] = NULL;
- return TRUE;*/
- const char * tempArg;
- char * arg;
- size_t argLen;
- tempArg = [filename UTF8String];
- argLen = SDL_strlen(tempArg)+1;
- arg = (char *) SDL_malloc(argLen);
- if (arg == NULL)
- return FALSE;
- SDL_strlcpy(arg, tempArg, argLen);
-
- saveDataOpen = file_load(arg, &saveDataOpenSize);
- if(saveDataOpen)
- return TRUE;
-
- saveDataOpen = NULL;
- saveDataOpenSize = 0;
- return FALSE;
-}
-
-- (void)handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
-{
- NSURL *url = [NSURL URLWithString:[[event paramDescriptorForKeyword:keyDirectObject] stringValue]];
- int tempSaveOpen = [[url host] intValue];
- if(tempSaveOpen > 0)
- saveURIOpen = tempSaveOpen;
-}
-
--(void)applicationWillFinishLaunching:(NSNotification *)aNotification
-{
- NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
- [appleEventManager setEventHandler:self
- andSelector:@selector(handleGetURLEvent:withReplyEvent:)
- forEventClass:kInternetEventClass andEventID:kAEGetURL];
-}
-
-/* Called when the internal event loop has just started running */
-- (void) applicationDidFinishLaunching: (NSNotification *) note
-{
- int status;
-
- /* Set the working directory to the .app's parent directory */
- [self setupWorkingDirectory:gFinderLaunch];
-
-#if SDL_USE_NIB_FILE
- /* Set the main menu to contain the real app name instead of "SDL App" */
- [self fixMenu:[NSApp mainMenu] withAppName:getApplicationName()];
-#endif
-
- /* Hand off to main application code */
- gCalledAppMainline = TRUE;
- status = SDL_main (gArgc, gArgv);
-
- /* We're done, thank you for playing */
- exit(status);
-}
-@end
-
-
-@implementation NSString (ReplaceSubString)
-
-- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
-{
- unsigned int bufferSize;
- unsigned int selfLen = [self length];
- unsigned int aStringLen = [aString length];
- unichar *buffer;
- NSRange localRange;
- NSString *result;
-
- bufferSize = selfLen + aStringLen - aRange.length;
- buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
-
- /* Get first part into buffer */
- localRange.location = 0;
- localRange.length = aRange.location;
- [self getCharacters:buffer range:localRange];
-
- /* Get middle part into buffer */
- localRange.location = 0;
- localRange.length = aStringLen;
- [aString getCharacters:(buffer+aRange.location) range:localRange];
-
- /* Get last part into buffer */
- localRange.location = aRange.location + aRange.length;
- localRange.length = selfLen - localRange.location;
- [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
-
- /* Build output string */
- result = [NSString stringWithCharacters:buffer length:bufferSize];
-
- NSDeallocateMemoryPages(buffer, bufferSize);
-
- return result;
-}
-
-@end
-
-
-
-#ifdef main
-# undef main
-#endif
-
-
-/* Main entry point to executable - should *not* be SDL_main! */
-int main (int argc, char **argv)
-{
- /* Copy the arguments into a global variable */
- /* This is passed if we are launched by double-clicking */
- if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
- gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
- gArgv[0] = argv[0];
- gArgv[1] = NULL;
- gArgc = 1;
- gFinderLaunch = YES;
- } else {
- int i;
- gArgc = argc;
- gArgv = (char **) SDL_malloc(sizeof (char *) * (argc+1));
- for (i = 0; i <= argc; i++)
- gArgv[i] = argv[i];
- gFinderLaunch = NO;
- }
-
-#if SDL_USE_NIB_FILE
- NSApplicationMain (argc, argv);
-#else
- CustomApplicationMain (argc, argv);
-#endif
- return 0;
-}
-
diff --git a/src/air.c b/src/air.c
deleted file mode 100644
index 1759883..0000000
--- a/src/air.c
+++ /dev/null
@@ -1,306 +0,0 @@
-/**
- * Powder Toy - air simulation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <math.h>
-#include <air.h>
-#include <powder.h>
-#include <defines.h>
-#include "gravity.h"
-
-float kernel[9];
-
-float vx[YRES/CELL][XRES/CELL], ovx[YRES/CELL][XRES/CELL];
-float vy[YRES/CELL][XRES/CELL], ovy[YRES/CELL][XRES/CELL];
-float pv[YRES/CELL][XRES/CELL], opv[YRES/CELL][XRES/CELL];
-unsigned char bmap_blockair[YRES/CELL][XRES/CELL];
-unsigned char bmap_blockairh[YRES/CELL][XRES/CELL];
-
-float cb_vx[YRES/CELL][XRES/CELL];
-float cb_vy[YRES/CELL][XRES/CELL];
-float cb_pv[YRES/CELL][XRES/CELL];
-float cb_hv[YRES/CELL][XRES/CELL];
-
-float fvx[YRES/CELL][XRES/CELL], fvy[YRES/CELL][XRES/CELL];
-
-float hv[YRES/CELL][XRES/CELL], ohv[YRES/CELL][XRES/CELL]; // For Ambient Heat
-
-void make_kernel(void) //used for velocity
-{
- int i, j;
- float s = 0.0f;
- for (j=-1; j<2; j++)
- for (i=-1; i<2; i++)
- {
- kernel[(i+1)+3*(j+1)] = expf(-2.0f*(i*i+j*j));
- s += kernel[(i+1)+3*(j+1)];
- }
- s = 1.0f / s;
- for (j=-1; j<2; j++)
- for (i=-1; i<2; i++)
- kernel[(i+1)+3*(j+1)] *= s;
-}
-void update_airh(void)
-{
- int x, y, i, j;
- float odh, dh, dx, dy, f, tx, ty;
-
- for (i=0; i<YRES/CELL; i++) //reduces pressure/velocity on the edges every frame
- {
- hv[i][0] = 295.15f;
- hv[i][1] = 295.15f;
- hv[i][XRES/CELL-3] = 295.15f;
- hv[i][XRES/CELL-2] = 295.15f;
- hv[i][XRES/CELL-1] = 295.15f;
- }
- for (i=0; i<XRES/CELL; i++) //reduces pressure/velocity on the edges every frame
- {
- hv[0][i] = 295.15f;
- hv[1][i] = 295.15f;
- hv[YRES/CELL-3][i] = 295.15f;
- hv[YRES/CELL-2][i] = 295.15f;
- hv[YRES/CELL-1][i] = 295.15f;
- }
- for (y=0; y<YRES/CELL; y++) //update velocity and pressure
- {
- for (x=0; x<XRES/CELL; x++)
- {
- dh = 0.0f;
- dx = 0.0f;
- dy = 0.0f;
- for (j=-1; j<2; j++)
- {
- for (i=-1; i<2; i++)
- {
- if (y+j>0 && y+j<YRES/CELL-2 &&
- x+i>0 && x+i<XRES/CELL-2 &&
- !bmap_blockairh[y+j][x+i])
- {
- f = kernel[i+1+(j+1)*3];
- dh += hv[y+j][x+i]*f;
- dx += vx[y+j][x+i]*f;
- dy += vy[y+j][x+i]*f;
- }
- else
- {
- f = kernel[i+1+(j+1)*3];
- dh += hv[y][x]*f;
- dx += vx[y][x]*f;
- dy += vy[y][x]*f;
- }
- }
- }
- tx = x - dx*0.7f;
- ty = y - dy*0.7f;
- i = (int)tx;
- j = (int)ty;
- tx -= i;
- ty -= j;
- if (i>=2 && i<XRES/CELL-3 && j>=2 && j<YRES/CELL-3)
- {
- odh = dh;
- dh *= 1.0f - AIR_VADV;
- dh += AIR_VADV*(1.0f-tx)*(1.0f-ty)*(bmap_blockairh[j][i] ? odh : hv[j][i]);
- dh += AIR_VADV*tx*(1.0f-ty)*(bmap_blockairh[j][i+1] ? odh : hv[j][i+1]);
- dh += AIR_VADV*(1.0f-tx)*ty*(bmap_blockairh[j+1][i] ? odh : hv[j+1][i]);
- dh += AIR_VADV*tx*ty*(bmap_blockairh[j+1][i+1] ? odh : hv[j+1][i+1]);
- }
- pv[y][x] += (dh-hv[y][x])/5000.0f;
- if(!gravityMode){ //Vertical gravity only for the time being
- float airdiff = hv[y-1][x]-hv[y][x];
- if(airdiff>0 && !bmap_blockairh[y-1][x])
- vy[y][x] -= airdiff/5000.0f;
- }
- ohv[y][x] = dh;
- }
- }
- memcpy(hv, ohv, sizeof(hv));
-}
-
-void update_air(void)
-{
- int x, y, i, j;
- float dp, dx, dy, f, tx, ty;
-
- if (airMode != 4) { //airMode 4 is no air/pressure update
-
- for (i=0; i<YRES/CELL; i++) //reduces pressure/velocity on the edges every frame
- {
- pv[i][0] = pv[i][0]*0.8f;
- pv[i][1] = pv[i][1]*0.8f;
- pv[i][2] = pv[i][2]*0.8f;
- pv[i][XRES/CELL-2] = pv[i][XRES/CELL-2]*0.8f;
- pv[i][XRES/CELL-1] = pv[i][XRES/CELL-1]*0.8f;
- vx[i][0] = vx[i][1]*0.9f;
- vx[i][1] = vx[i][2]*0.9f;
- vx[i][XRES/CELL-2] = vx[i][XRES/CELL-3]*0.9f;
- vx[i][XRES/CELL-1] = vx[i][XRES/CELL-2]*0.9f;
- vy[i][0] = vy[i][1]*0.9f;
- vy[i][1] = vy[i][2]*0.9f;
- vy[i][XRES/CELL-2] = vy[i][XRES/CELL-3]*0.9f;
- vy[i][XRES/CELL-1] = vy[i][XRES/CELL-2]*0.9f;
- }
- for (i=0; i<XRES/CELL; i++) //reduces pressure/velocity on the edges every frame
- {
- pv[0][i] = pv[0][i]*0.8f;
- pv[1][i] = pv[1][i]*0.8f;
- pv[2][i] = pv[2][i]*0.8f;
- pv[YRES/CELL-2][i] = pv[YRES/CELL-2][i]*0.8f;
- pv[YRES/CELL-1][i] = pv[YRES/CELL-1][i]*0.8f;
- vx[0][i] = vx[1][i]*0.9f;
- vx[1][i] = vx[2][i]*0.9f;
- vx[YRES/CELL-2][i] = vx[YRES/CELL-3][i]*0.9f;
- vx[YRES/CELL-1][i] = vx[YRES/CELL-2][i]*0.9f;
- vy[0][i] = vy[1][i]*0.9f;
- vy[1][i] = vy[2][i]*0.9f;
- vy[YRES/CELL-2][i] = vy[YRES/CELL-3][i]*0.9f;
- vy[YRES/CELL-1][i] = vy[YRES/CELL-2][i]*0.9f;
- }
-
- for (j=1; j<YRES/CELL; j++) //clear some velocities near walls
- {
- for (i=1; i<XRES/CELL; i++)
- {
- if (bmap_blockair[j][i])
- {
- vx[j][i] = 0.0f;
- vx[j][i-1] = 0.0f;
- vy[j][i] = 0.0f;
- vy[j-1][i] = 0.0f;
- }
- }
- }
-
- for (y=1; y<YRES/CELL; y++) //pressure adjustments from velocity
- for (x=1; x<XRES/CELL; x++)
- {
- dp = 0.0f;
- dp += vx[y][x-1] - vx[y][x];
- dp += vy[y-1][x] - vy[y][x];
- pv[y][x] *= AIR_PLOSS;
- pv[y][x] += dp*AIR_TSTEPP;
- }
-
- for (y=0; y<YRES/CELL-1; y++) //velocity adjustments from pressure
- for (x=0; x<XRES/CELL-1; x++)
- {
- dx = dy = 0.0f;
- dx += pv[y][x] - pv[y][x+1];
- dy += pv[y][x] - pv[y+1][x];
- vx[y][x] *= AIR_VLOSS;
- vy[y][x] *= AIR_VLOSS;
- vx[y][x] += dx*AIR_TSTEPV;
- vy[y][x] += dy*AIR_TSTEPV;
- if (bmap_blockair[y][x] || bmap_blockair[y][x+1])
- vx[y][x] = 0;
- if (bmap_blockair[y][x] || bmap_blockair[y+1][x])
- vy[y][x] = 0;
- }
-
- for (y=0; y<YRES/CELL; y++) //update velocity and pressure
- for (x=0; x<XRES/CELL; x++)
- {
- dx = 0.0f;
- dy = 0.0f;
- dp = 0.0f;
- for (j=-1; j<2; j++)
- for (i=-1; i<2; i++)
- if (y+j>0 && y+j<YRES/CELL-1 &&
- x+i>0 && x+i<XRES/CELL-1 &&
- !bmap_blockair[y+j][x+i])
- {
- f = kernel[i+1+(j+1)*3];
- dx += vx[y+j][x+i]*f;
- dy += vy[y+j][x+i]*f;
- dp += pv[y+j][x+i]*f;
- }
- else
- {
- f = kernel[i+1+(j+1)*3];
- dx += vx[y][x]*f;
- dy += vy[y][x]*f;
- dp += pv[y][x]*f;
- }
-
- tx = x - dx*0.7f;
- ty = y - dy*0.7f;
- i = (int)tx;
- j = (int)ty;
- tx -= i;
- ty -= j;
- if (i>=2 && i<XRES/CELL-3 &&
- j>=2 && j<YRES/CELL-3)
- {
- dx *= 1.0f - AIR_VADV;
- dy *= 1.0f - AIR_VADV;
-
- dx += AIR_VADV*(1.0f-tx)*(1.0f-ty)*vx[j][i];
- dy += AIR_VADV*(1.0f-tx)*(1.0f-ty)*vy[j][i];
-
- dx += AIR_VADV*tx*(1.0f-ty)*vx[j][i+1];
- dy += AIR_VADV*tx*(1.0f-ty)*vy[j][i+1];
-
- dx += AIR_VADV*(1.0f-tx)*ty*vx[j+1][i];
- dy += AIR_VADV*(1.0f-tx)*ty*vy[j+1][i];
-
- dx += AIR_VADV*tx*ty*vx[j+1][i+1];
- dy += AIR_VADV*tx*ty*vy[j+1][i+1];
- }
-
- if (bmap[y][x] == WL_FAN)
- {
- dx += fvx[y][x];
- dy += fvy[y][x];
- }
- // pressure/velocity caps
- if (dp > 256.0f) dp = 256.0f;
- if (dp < -256.0f) dp = -256.0f;
- if (dx > 256.0f) dx = 256.0f;
- if (dx < -256.0f) dx = -256.0f;
- if (dy > 256.0f) dy = 256.0f;
- if (dy < -256.0f) dy = -256.0f;
-
-
- switch (airMode)
- {
- default:
- case 0: //Default
- break;
- case 1: //0 Pressure
- dp = 0.0f;
- break;
- case 2: //0 Velocity
- dx = 0.0f;
- dy = 0.0f;
- break;
- case 3: //0 Air
- dx = 0.0f;
- dy = 0.0f;
- dp = 0.0f;
- break;
- case 4: //No Update
- break;
- }
-
- ovx[y][x] = dx;
- ovy[y][x] = dy;
- opv[y][x] = dp;
- }
- memcpy(vx, ovx, sizeof(vx));
- memcpy(vy, ovy, sizeof(vy));
- memcpy(pv, opv, sizeof(pv));
- }
-}
diff --git a/src/cJSON.c b/src/cJSON.c
deleted file mode 100644
index f922ad6..0000000
--- a/src/cJSON.c
+++ /dev/null
@@ -1,502 +0,0 @@
-/*
- Copyright (c) 2009 Dave Gamble
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
-*/
-
-/* cJSON */
-/* JSON parser in C. */
-
-#include <string.h>
-#include <stdio.h>
-#include <math.h>
-#include <stdlib.h>
-#include <float.h>
-#include <limits.h>
-#include <ctype.h>
-#include "cJSON.h"
-
-static const char *ep;
-
-const char *cJSON_GetErrorPtr() {return ep;}
-
-static int cJSON_strcasecmp(const char *s1,const char *s2)
-{
- if (!s1) return (s1==s2)?0:1;if (!s2) return 1;
- for(; tolower(*s1) == tolower(*s2); ++s1, ++s2) if(*s1 == 0) return 0;
- return tolower(*(const unsigned char *)s1) - tolower(*(const unsigned char *)s2);
-}
-
-static void *(*cJSON_malloc)(size_t sz) = malloc;
-static void (*cJSON_free)(void *ptr) = free;
-
-static char* cJSON_strdup(const char* str)
-{
- size_t len;
- char* copy;
-
- len = strlen(str) + 1;
- if (!(copy = (char*)cJSON_malloc(len))) return 0;
- memcpy(copy,str,len);
- return copy;
-}
-
-void cJSON_InitHooks(cJSON_Hooks* hooks)
-{
- if (!hooks) { /* Reset hooks */
- cJSON_malloc = malloc;
- cJSON_free = free;
- return;
- }
-
- cJSON_malloc = (hooks->malloc_fn)?hooks->malloc_fn:malloc;
- cJSON_free = (hooks->free_fn)?hooks->free_fn:free;
-}
-
-/* Internal constructor. */
-static cJSON *cJSON_New_Item()
-{
- cJSON* node = (cJSON*)cJSON_malloc(sizeof(cJSON));
- if (node) memset(node,0,sizeof(cJSON));
- return node;
-}
-
-/* Delete a cJSON structure. */
-void cJSON_Delete(cJSON *c)
-{
- cJSON *next;
- while (c)
- {
- next=c->next;
- if (!(c->type&cJSON_IsReference) && c->child) cJSON_Delete(c->child);
- if (!(c->type&cJSON_IsReference) && c->valuestring) cJSON_free(c->valuestring);
- if (c->string) cJSON_free(c->string);
- cJSON_free(c);
- c=next;
- }
-}
-
-/* Parse the input text to generate a number, and populate the result into item. */
-static const char *parse_number(cJSON *item,const char *num)
-{
- double n=0,sign=1,scale=0;int subscale=0,signsubscale=1;
-
- /* Could use sscanf for this? */
- if (*num=='-') sign=-1,num++; /* Has sign? */
- if (*num=='0') num++; /* is zero */
- if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */
- if (*num=='.') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */
- if (*num=='e' || *num=='E') /* Exponent? */
- { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */
- while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */
- }
-
- n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
-
- item->valuedouble=n;
- item->valueint=(int)n;
- item->type=cJSON_Number;
- return num;
-}
-
-/* Render the number nicely from the given item into a string. */
-static char *print_number(cJSON *item)
-{
- char *str;
- double d=item->valuedouble;
- if (fabs(((double)item->valueint)-d)<=DBL_EPSILON && d<=INT_MAX && d>=INT_MIN)
- {
- str=(char*)cJSON_malloc(21); /* 2^64+1 can be represented in 21 chars. */
- if (str) sprintf(str,"%d",item->valueint);
- }
- else
- {
- str=(char*)cJSON_malloc(64); /* This is a nice tradeoff. */
- if (str)
- {
- if (fabs(floor(d)-d)<=DBL_EPSILON) sprintf(str,"%.0f",d);
- else if (fabs(d)<1.0e-6 || fabs(d)>1.0e9) sprintf(str,"%e",d);
- else sprintf(str,"%f",d);
- }
- }
- return str;
-}
-
-/* Parse the input text into an unescaped cstring, and populate item. */
-static const unsigned char firstByteMark[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
-static const char *parse_string(cJSON *item,const char *str)
-{
- const char *ptr=str+1;char *ptr2;char *out;int len=0;unsigned uc;
- if (*str!='\"') {ep=str;return 0;} /* not a string! */
-
- while (*ptr!='\"' && *ptr && ++len) if (*ptr++ == '\\') ptr++; /* Skip escaped quotes. */
-
- out=(char*)cJSON_malloc(len+1); /* This is how long we need for the string, roughly. */
- if (!out) return 0;
-
- ptr=str+1;ptr2=out;
- while (*ptr!='\"' && *ptr)
- {
- if (*ptr!='\\') *ptr2++=*ptr++;
- else
- {
- ptr++;
- switch (*ptr)
- {
- case 'b': *ptr2++='\b'; break;
- case 'f': *ptr2++='\f'; break;
- case 'n': *ptr2++='\n'; break;
- case 'r': *ptr2++='\r'; break;
- case 't': *ptr2++='\t'; break;
- case 'u': /* transcode utf16 to utf8. DOES NOT SUPPORT SURROGATE PAIRS CORRECTLY. */
- sscanf(ptr+1,"%4x",&uc); /* get the unicode char. */
- len=3;if (uc<0x80) len=1;else if (uc<0x800) len=2;ptr2+=len;
-
- switch (len) {
- case 3: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
- case 2: *--ptr2 =((uc | 0x80) & 0xBF); uc >>= 6;
- case 1: *--ptr2 =(uc | firstByteMark[len]);
- }
- ptr2+=len;ptr+=4;
- break;
- default: *ptr2++=*ptr; break;
- }
- ptr++;
- }
- }
- *ptr2=0;
- if (*ptr=='\"') ptr++;
- item->valuestring=out;
- item->type=cJSON_String;
- return ptr;
-}
-
-/* Render the cstring provided to an escaped version that can be printed. */
-static char *print_string_ptr(const char *str)
-{
- const char *ptr;char *ptr2,*out;int len=0;unsigned char token;
-
- if (!str) return cJSON_strdup("");
- ptr=str;while ((token=*ptr) && ++len) {if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token<32) len+=5;ptr++;}
-
- out=(char*)cJSON_malloc(len+3);
- if (!out) return 0;
-
- ptr2=out;ptr=str;
- *ptr2++='\"';
- while (*ptr)
- {
- if ((unsigned char)*ptr>31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++;
- else
- {
- *ptr2++='\\';
- switch (token=*ptr++)
- {
- case '\\': *ptr2++='\\'; break;
- case '\"': *ptr2++='\"'; break;
- case '\b': *ptr2++='b'; break;
- case '\f': *ptr2++='f'; break;
- case '\n': *ptr2++='n'; break;
- case '\r': *ptr2++='r'; break;
- case '\t': *ptr2++='t'; break;
- default: sprintf(ptr2,"u%04x",token);ptr2+=5; break; /* escape and print */
- }
- }
- }
- *ptr2++='\"';*ptr2++=0;
- return out;
-}
-/* Invote print_string_ptr (which is useful) on an item. */
-static char *print_string(cJSON *item) {return print_string_ptr(item->valuestring);}
-
-/* Predeclare these prototypes. */
-static const char *parse_value(cJSON *item,const char *value);
-static char *print_value(cJSON *item,int depth,int fmt);
-static const char *parse_array(cJSON *item,const char *value);
-static char *print_array(cJSON *item,int depth,int fmt);
-static const char *parse_object(cJSON *item,const char *value);
-static char *print_object(cJSON *item,int depth,int fmt);
-
-/* Utility to jump whitespace and cr/lf */
-static const char *skip(const char *in) {while (in && *in && (unsigned char)*in<=32) in++; return in;}
-
-/* Parse an object - create a new root, and populate. */
-cJSON *cJSON_Parse(const char *value)
-{
- cJSON *c=cJSON_New_Item();
- ep=0;
- if (!c) return 0; /* memory fail */
-
- if (!parse_value(c,skip(value))) {cJSON_Delete(c);return 0;}
- return c;
-}
-
-/* Render a cJSON item/entity/structure to text. */
-char *cJSON_Print(cJSON *item) {return print_value(item,0,1);}
-char *cJSON_PrintUnformatted(cJSON *item) {return print_value(item,0,0);}
-
-/* Parser core - when encountering text, process appropriately. */
-static const char *parse_value(cJSON *item,const char *value)
-{
- if (!value) return 0; /* Fail on null. */
- if (!strncmp(value,"null",4)) { item->type=cJSON_NULL; return value+4; }
- if (!strncmp(value,"false",5)) { item->type=cJSON_False; return value+5; }
- if (!strncmp(value,"true",4)) { item->type=cJSON_True; item->valueint=1; return value+4; }
- if (*value=='\"') { return parse_string(item,value); }
- if (*value=='-' || (*value>='0' && *value<='9')) { return parse_number(item,value); }
- if (*value=='[') { return parse_array(item,value); }
- if (*value=='{') { return parse_object(item,value); }
-
- ep=value;return 0; /* failure. */
-}
-
-/* Render a value to text. */
-static char *print_value(cJSON *item,int depth,int fmt)
-{
- char *out=0;
- if (!item) return 0;
- switch ((item->type)&255)
- {
- case cJSON_NULL: out=cJSON_strdup("null"); break;
- case cJSON_False: out=cJSON_strdup("false");break;
- case cJSON_True: out=cJSON_strdup("true"); break;
- case cJSON_Number: out=print_number(item);break;
- case cJSON_String: out=print_string(item);break;
- case cJSON_Array: out=print_array(item,depth,fmt);break;
- case cJSON_Object: out=print_object(item,depth,fmt);break;
- }
- return out;
-}
-
-/* Build an array from input text. */
-static const char *parse_array(cJSON *item,const char *value)
-{
- cJSON *child;
- if (*value!='[') {ep=value;return 0;} /* not an array! */
-
- item->type=cJSON_Array;
- value=skip(value+1);
- if (*value==']') return value+1; /* empty array. */
-
- item->child=child=cJSON_New_Item();
- if (!item->child) return 0; /* memory fail */
- value=skip(parse_value(child,skip(value))); /* skip any spacing, get the value. */
- if (!value) return 0;
-
- while (*value==',')
- {
- cJSON *new_item;
- if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
- child->next=new_item;new_item->prev=child;child=new_item;
- value=skip(parse_value(child,skip(value+1)));
- if (!value) return 0; /* memory fail */
- }
-
- if (*value==']') return value+1; /* end of array */
- ep=value;return 0; /* malformed. */
-}
-
-/* Render an array to text */
-static char *print_array(cJSON *item,int depth,int fmt)
-{
- char **entries;
- char *out=0,*ptr,*ret;int len=5;
- cJSON *child=item->child;
- int numentries=0,i=0,fail=0;
-
- /* How many entries in the array? */
- while (child) numentries++,child=child->next;
- /* Allocate an array to hold the values for each */
- entries=(char**)cJSON_malloc(numentries*sizeof(char*));
- if (!entries) return 0;
- memset(entries,0,numentries*sizeof(char*));
- /* Retrieve all the results: */
- child=item->child;
- while (child && !fail)
- {
- ret=print_value(child,depth+1,fmt);
- entries[i++]=ret;
- if (ret) len+=strlen(ret)+2+(fmt?1:0); else fail=1;
- child=child->next;
- }
-
- /* If we didn't fail, try to malloc the output string */
- if (!fail) out=(char*)cJSON_malloc(len);
- /* If that fails, we fail. */
- if (!out) fail=1;
-
- /* Handle failure. */
- if (fail)
- {
- for (i=0;i<numentries;i++) if (entries[i]) cJSON_free(entries[i]);
- cJSON_free(entries);
- return 0;
- }
-
- /* Compose the output array. */
- *out='[';
- ptr=out+1;*ptr=0;
- for (i=0;i<numentries;i++)
- {
- strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
- if (i!=numentries-1) {*ptr++=',';if(fmt)*ptr++=' ';*ptr=0;}
- cJSON_free(entries[i]);
- }
- cJSON_free(entries);
- *ptr++=']';*ptr++=0;
- return out;
-}
-
-/* Build an object from the text. */
-static const char *parse_object(cJSON *item,const char *value)
-{
- cJSON *child;
- if (*value!='{') {ep=value;return 0;} /* not an object! */
-
- item->type=cJSON_Object;
- value=skip(value+1);
- if (*value=='}') return value+1; /* empty array. */
-
- item->child=child=cJSON_New_Item();
- if (!item->child) return 0;
- value=skip(parse_string(child,skip(value)));
- if (!value) return 0;
- child->string=child->valuestring;child->valuestring=0;
- if (*value!=':') {ep=value;return 0;} /* fail! */
- value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
- if (!value) return 0;
-
- while (*value==',')
- {
- cJSON *new_item;
- if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
- child->next=new_item;new_item->prev=child;child=new_item;
- value=skip(parse_string(child,skip(value+1)));
- if (!value) return 0;
- child->string=child->valuestring;child->valuestring=0;
- if (*value!=':') {ep=value;return 0;} /* fail! */
- value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
- if (!value) return 0;
- }
-
- if (*value=='}') return value+1; /* end of array */
- ep=value;return 0; /* malformed. */
-}
-
-/* Render an object to text. */
-static char *print_object(cJSON *item,int depth,int fmt)
-{
- char **entries=0,**names=0;
- char *out=0,*ptr,*ret,*str;int len=7,i=0,j;
- cJSON *child=item->child;
- int numentries=0,fail=0;
- /* Count the number of entries. */
- while (child) numentries++,child=child->next;
- /* Allocate space for the names and the objects */
- entries=(char**)cJSON_malloc(numentries*sizeof(char*));
- if (!entries) return 0;
- names=(char**)cJSON_malloc(numentries*sizeof(char*));
- if (!names) {cJSON_free(entries);return 0;}
- memset(entries,0,sizeof(char*)*numentries);
- memset(names,0,sizeof(char*)*numentries);
-
- /* Collect all the results into our arrays: */
- child=item->child;depth++;if (fmt) len+=depth;
- while (child)
- {
- names[i]=str=print_string_ptr(child->string);
- entries[i++]=ret=print_value(child,depth,fmt);
- if (str && ret) len+=strlen(ret)+strlen(str)+2+(fmt?2+depth:0); else fail=1;
- child=child->next;
- }
-
- /* Try to allocate the output string */
- if (!fail) out=(char*)cJSON_malloc(len);
- if (!out) fail=1;
-
- /* Handle failure */
- if (fail)
- {
- for (i=0;i<numentries;i++) {if (names[i]) cJSON_free(names[i]);if (entries[i]) cJSON_free(entries[i]);}
- cJSON_free(names);cJSON_free(entries);
- return 0;
- }
-
- /* Compose the output: */
- *out='{';ptr=out+1;if (fmt)*ptr++='\n';*ptr=0;
- for (i=0;i<numentries;i++)
- {
- if (fmt) for (j=0;j<depth;j++) *ptr++='\t';
- strcpy(ptr,names[i]);ptr+=strlen(names[i]);
- *ptr++=':';if (fmt) *ptr++='\t';
- strcpy(ptr,entries[i]);ptr+=strlen(entries[i]);
- if (i!=numentries-1) *ptr++=',';
- if (fmt) *ptr++='\n';*ptr=0;
- cJSON_free(names[i]);cJSON_free(entries[i]);
- }
-
- cJSON_free(names);cJSON_free(entries);
- if (fmt) for (i=0;i<depth-1;i++) *ptr++='\t';
- *ptr++='}';*ptr++=0;
- return out;
-}
-
-/* Get Array size/item / object item. */
-int cJSON_GetArraySize(cJSON *array) {cJSON *c=array->child;int i=0;while(c)i++,c=c->next;return i;}
-cJSON *cJSON_GetArrayItem(cJSON *array,int item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;}
-cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;}
-
-/* Utility for array list handling. */
-static void suffix_object(cJSON *prev,cJSON *item) {prev->next=item;item->prev=prev;}
-/* Utility for handling references. */
-static cJSON *create_reference(cJSON *item) {cJSON *ref=cJSON_New_Item();if (!ref) return 0;memcpy(ref,item,sizeof(cJSON));ref->string=0;ref->type|=cJSON_IsReference;ref->next=ref->prev=0;return ref;}
-
-/* Add item to array/object. */
-void cJSON_AddItemToArray(cJSON *array, cJSON *item) {cJSON *c=array->child;if (!item) return; if (!c) {array->child=item;} else {while (c && c->next) c=c->next; suffix_object(c,item);}}
-void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);}
-void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item) {cJSON_AddItemToArray(array,create_reference(item));}
-void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item) {cJSON_AddItemToObject(object,string,create_reference(item));}
-
-cJSON *cJSON_DetachItemFromArray(cJSON *array,int which) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return 0;
- if (c->prev) c->prev->next=c->next;if (c->next) c->next->prev=c->prev;if (c==array->child) array->child=c->next;c->prev=c->next=0;return c;}
-void cJSON_DeleteItemFromArray(cJSON *array,int which) {cJSON_Delete(cJSON_DetachItemFromArray(array,which));}
-cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string) {int i=0;cJSON *c=object->child;while (c && cJSON_strcasecmp(c->string,string)) i++,c=c->next;if (c) return cJSON_DetachItemFromArray(object,i);return 0;}
-void cJSON_DeleteItemFromObject(cJSON *object,const char *string) {cJSON_Delete(cJSON_DetachItemFromObject(object,string));}
-
-/* Replace array/object items with new ones. */
-void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem) {cJSON *c=array->child;while (c && which>0) c=c->next,which--;if (!c) return;
- newitem->next=c->next;newitem->prev=c->prev;if (newitem->next) newitem->next->prev=newitem;
- if (c==array->child) array->child=newitem; else newitem->prev->next=newitem;c->next=c->prev=0;cJSON_Delete(c);}
-void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}}
-
-/* Create basic types: */
-cJSON *cJSON_CreateNull() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_NULL;return item;}
-cJSON *cJSON_CreateTrue() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_True;return item;}
-cJSON *cJSON_CreateFalse() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_False;return item;}
-cJSON *cJSON_CreateBool(int b) {cJSON *item=cJSON_New_Item();if(item)item->type=b?cJSON_True:cJSON_False;return item;}
-cJSON *cJSON_CreateNumber(double num) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_Number;item->valuedouble=num;item->valueint=(int)num;}return item;}
-cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;}
-cJSON *cJSON_CreateArray() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Array;return item;}
-cJSON *cJSON_CreateObject() {cJSON *item=cJSON_New_Item();if(item)item->type=cJSON_Object;return item;}
-
-/* Create Arrays: */
-cJSON *cJSON_CreateIntArray(int *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
-cJSON *cJSON_CreateFloatArray(float *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
-cJSON *cJSON_CreateDoubleArray(double *numbers,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateNumber(numbers[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
-cJSON *cJSON_CreateStringArray(const char **strings,int count) {int i;cJSON *n=0,*p=0,*a=cJSON_CreateArray();for(i=0;a && i<count;i++){n=cJSON_CreateString(strings[i]);if(!i)a->child=n;else suffix_object(p,n);p=n;}return a;}
diff --git a/src/console.c b/src/console.c
deleted file mode 100644
index 55ca358..0000000
--- a/src/console.c
+++ /dev/null
@@ -1,638 +0,0 @@
-/**
- * Powder Toy - simple console
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <powder.h>
-#include <console.h>
-#include <math.h>
-
-#ifdef PYCONSOLE
-#include <pythonconsole.h>
-#endif
-
-char console_more=0;
-char console_error[255] = "";
-int file_script = 0;
-
-//takes a a string and compares it to element names, and puts it value into element.
-int console_parse_type(char *txt, int *element, char *err)
-{
- int i = -1;
- // alternative names for some elements
- if (strcasecmp(txt,"C4")==0) i = PT_PLEX;
- else if (strcasecmp(txt,"C5")==0) i = PT_C5;
- else if (strcasecmp(txt,"NONE")==0) i = PT_NONE;
- if (i>=0 && i<PT_NUM && ptypes[i].enabled)
- {
- if (element) *element = i;
- if (err) strcpy(err,"");
- return 1;
- }
- for (i=1; i<PT_NUM; i++) {
- if (strcasecmp(txt,ptypes[i].name)==0 && ptypes[i].enabled)
- {
- if (element) *element = i;
- if (err) strcpy(err,"");
- return 1;
- }
- }
- if (err) strcpy(err, "Particle type not recognised");
- return 0;
-}
-//takes a string of coords "x,y" and puts the values into x and y.
-int console_parse_coords(char *txt, int *x, int *y, char *err)
-{
- int nx = -1, ny = -1;
- if (sscanf(txt,"%d,%d",&nx,&ny)!=2 || nx<0 || nx>=XRES || ny<0 || ny>=YRES)
- {
- if (err) strcpy(err,"Invalid coordinates");
- return 0;
- }
- *x = nx;
- *y = ny;
- return 1;
-}
-//takes a string of either coords or a particle number, and puts the particle number into *which
-int console_parse_partref(char *txt, int *which, char *err)
-{
- int i = -1, nx, ny;
- if (err) strcpy(err,"");
- if (strchr(txt,',') && console_parse_coords(txt, &nx, &ny, err))
- {
- i = pmap[ny][nx];
- if (!i)
- i = -1;
- else
- i = i>>8;
- }
- else if (txt)
- {
- char *num = (char*)malloc(strlen(txt)+3);
- i = atoi(txt);
- sprintf(num,"%d",i);
- if (!txt || strcmp(txt,num)!=0)
- i = -1;
- free(num);
- }
- if (i>=0 && i<NPART && parts[i].type)
- {
- *which = i;
- if (err) strcpy(err,"");
- return 1;
- }
- if (err && strcmp(err,"")==0) strcpy(err,"Particle does not exist");
- return 0;
-}
-
-int process_command_old(pixel *vid_buf, char *console, char *console_error)
-{
- int y,x,nx,ny,i,j,k,m;
- float f;
- int do_next = 1;
- char xcoord[10] = "";
- char ycoord[10] = "";
- char console2[15] = "";
- char console3[15] = "";
- char console4[15] = "";
- char console5[15] = "";
- //sprintf(console_error, "%s", console);
- if (console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0)
- {
- sscanf(console,"%14s %14s %14s %14s", console2, console3, console4, console5);//why didn't i know about this function?!
- if (strcmp(console2, "quit")==0)
- {
- return -1;
- }
- else if (strcmp(console2, "file")==0 && console3[0])
- {
- if (file_script) {
- int filesize;
- char *fileread = file_load(console3, &filesize);
- nx = 0;
- ny = 0;
- if (console4[0] && !console_parse_coords(console4, &nx , &ny, console_error))
- {
- free(fileread);
- return 1;
- }
- if (fileread)
- {
- char pch[501];
- char tokens[31];
- int tokensize;
- j = 0; // line start position in fileread
- m = 0; // token start position in fileread
- memset(pch,0,sizeof(pch));
- for (i=0; i<filesize; i++)
- {
- if (fileread[i] != '\n' && i-m<30)
- {
- pch[i-j] = fileread[i];
- if (fileread[i] != ' ')
- tokens[i-m] = fileread[i];
- }
- if ((fileread[i] == ' ' || fileread[i] == '\n') && i-j<400)
- {
- if (sregexp(tokens,"^x.\\{0,1\\}[0-9]*,y.\\{0,1\\}[0-9]*")==0)
- {
- int starty = 0;
- tokensize = strlen(tokens);
- x = 0;
- y = 0;
- if (tokens[1]!=',')
- sscanf(tokens,"x%d,y%d",&x,&y);
- else
- sscanf(tokens,"x,y%d",&y);
- x += nx;
- y += ny;
- sprintf(xcoord,"%d",x);
- sprintf(ycoord,"%d",y);
- for (k = 0; k<strlen(xcoord); k++)//rewrite pch with numbers
- {
- pch[i-j-tokensize+k] = xcoord[k];
- starty = k+1;
- }
- pch[i-j-tokensize+starty] = ',';
- starty++;
- for (k=0; k<strlen(ycoord); k++)
- {
- pch[i-j-tokensize+starty+k] = ycoord[k];
- }
- pch[i-j-tokensize +strlen(xcoord) +1 +strlen(ycoord)] = ' ';
- j = j -tokensize +strlen(xcoord) +1 +strlen(ycoord);
- }
- memset(tokens,0,sizeof(tokens));
- m = i+1;
- }
- if (fileread[i] == '\n')
- {
-
- if (do_next)
- {
- if (strcmp(pch,"else")==0)
- do_next = 0;
- else
- do_next = process_command_old(vid_buf, pch, console_error);
- }
- else if (strcmp(pch,"endif")==0 || strcmp(pch,"else")==0)
- do_next = 1;
- memset(pch,0,sizeof(pch));
- j = i+1;
- }
- }
- free(fileread);
- }
- else
- {
- sprintf(console_error, "%s does not exist", console3);
- }
- }
- else
- {
- sprintf(console_error, "Scripts are not enabled");
- }
-
- }
- else if (strcmp(console2, "sound")==0 && console3[0])
- {
- if (sound_enable) play_sound(console3);
- else strcpy(console_error, "Audio device not available - cannot play sounds");
- }
-#ifdef PYCONSOLE
- else if (strcmp(console2, "python")==0)
- if (pygood==1)
- pyready=1;
- else
- strcpy(console_error, "python not ready. check stdout for more info.")
-#endif
- else if (strcmp(console2, "load")==0 && console3[0])
- {
- j = atoi(console3);
- if (j)
- {
- open_ui(vid_buf, console3, NULL);
- console_mode = 0;
- }
- }
- else if (strcmp(console2, "if")==0 && console3[0])
- {
- if (strcmp(console3, "type")==0)//TODO: add more than just type, and be able to check greater/less than
- {
- if (console_parse_partref(console4, &i, console_error)
- && console_parse_type(console5, &j, console_error))
- {
- if (parts[i].type==j)
- return 1;
- else
- return 0;
- }
- else
- return 0;
- }
- }
- else if (strcmp(console2, "create")==0 && console3[0] && console4[0])
- {
- if (console_parse_type(console3, &j, console_error)
- && console_parse_coords(console4, &nx, &ny, console_error))
- {
- if (!j)
- strcpy(console_error, "Cannot create particle with type NONE");
- else if (create_part(-1,nx,ny,j)<0)
- strcpy(console_error, "Could not create particle");
- }
- }
- else if (strcmp(console2, "bubble")==0 && console3[0])
- {
- if (console_parse_coords(console3, &nx, &ny, console_error))
- {
- int first, rem1, rem2;
-
- first = create_part(-1, nx+18, ny, PT_SOAP);
- rem1 = first;
-
- for (i = 1; i<=30; i++)
- {
- rem2 = create_part(-1, nx+18*cosf(i/5.0), ny+18*sinf(i/5.0), PT_SOAP);
-
- parts[rem1].ctype = 7;
- parts[rem1].tmp = rem2;
- parts[rem2].tmp2 = rem1;
-
- rem1 = rem2;
- }
-
- parts[rem1].ctype = 7;
- parts[rem1].tmp = first;
- parts[first].tmp2 = rem1;
- parts[first].ctype = 7;
- }
- }
- else if ((strcmp(console2, "delete")==0 || strcmp(console2, "kill")==0) && console3[0])
- {
- if (console_parse_partref(console3, &i, console_error))
- kill_part(i);
- }
- else if (strcmp(console2, "reset")==0 && console3[0])
- {
- if (strcmp(console3, "pressure")==0)
- {
- for (nx = 0; nx<XRES/CELL; nx++)
- for (ny = 0; ny<YRES/CELL; ny++)
- {
- pv[ny][nx] = 0;
- }
- }
- else if (strcmp(console3, "velocity")==0)
- {
- for (nx = 0; nx<XRES/CELL; nx++)
- for (ny = 0; ny<YRES/CELL; ny++)
- {
- vx[ny][nx] = 0;
- vy[ny][nx] = 0;
- }
- }
- else if (strcmp(console3, "sparks")==0)
- {
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type==PT_SPRK)
- {
- parts[i].type = parts[i].ctype;
- parts[i].life = 4;
- }
- }
- }
- else if (strcmp(console3, "temp")==0)
- {
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type)
- {
- parts[i].temp = ptypes[parts[i].type].heat;
- }
- }
- }
- }
- else if (strcmp(console2, "set")==0 && console3[0] && console4[0] && console5[0])
- {
- if (strcmp(console3, "life")==0)
- {
- if (strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type)
- parts[i].life = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type == j)
- parts[i].life = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].life = j;
- }
- }
- }
- else if (strcmp(console3, "type")==0)
- {
- if (strcmp(console4, "all")==0)
- {
- if (console_parse_type(console5, &j, console_error))
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type)
- parts[i].type = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error)
- && console_parse_type(console5, &k, console_error))
- {
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type == j)
- parts[i].type = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error)
- && console_parse_type(console5, &j, console_error))
- {
- parts[i].type = j;
- }
- }
- }
- else if (strcmp(console3, "temp")==0)
- {
- if (strcmp(console4, "all")==0)
- {
- f = atof(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type)
- parts[i].temp = f;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- f = atof(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type == j)
- parts[i].temp= f;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- f = atof(console5);
- parts[i].temp = f;
- }
- }
- }
- else if (strcmp(console3, "tmp")==0)
- {
- if (strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type)
- parts[i].tmp = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type == j)
- parts[i].tmp = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].tmp = j;
- }
- }
- }
- else if (strcmp(console3, "tmp2")==0)
- {
- if (strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type)
- parts[i].tmp2 = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type == j)
- parts[i].tmp2 = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].tmp2 = j;
- }
- }
- }
- else if (strcmp(console3, "x")==0)
- {
- if (strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type)
- parts[i].x = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type == j)
- parts[i].x = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].x = j;
- }
- }
- }
- else if (strcmp(console3, "y")==0)
- {
- if (strcmp(console4, "all")==0)
- {
- j = atoi(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type)
- parts[i].y = j;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- k = atoi(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type == j)
- parts[i].y = k;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- j = atoi(console5);
- parts[i].y = j;
- }
- }
- }
- else if (strcmp(console3, "ctype")==0)
- {
- if (strcmp(console4, "all")==0)
- {
- if (console_parse_type(console5, &j, console_error) || (j = atoi(console5)) || !strcmp(console5,"0") || !strcasecmp(console5,"NONE"))
- {
- strcpy(console_error, "");
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type)
- parts[i].ctype = j;
- }
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- if (console_parse_type(console5, &k, console_error) || (k = atoi(console5)) || !strcmp(console5,"0") || !strcasecmp(console5,"NONE"))
- {
- strcpy(console_error, "");
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type == j)
- parts[i].ctype = k;
- }
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- if (console_parse_type(console5, &j, console_error) || (j = atoi(console5)) || !strcmp(console5,"0") || !strcasecmp(console5,"NONE"))
- {
- strcpy(console_error, "");
- j = atoi(console5);
- parts[i].ctype = j;
- }
- }
- }
- }
- else if (strcmp(console3, "vx")==0)
- {
- if (strcmp(console4, "all")==0)
- {
- f = atof(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type)
- parts[i].vx = f;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- f = atof(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type == j)
- parts[i].vx = f;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- f = atof(console5);
- parts[i].vx = f;
- }
- }
- }
- else if (strcmp(console3, "vy")==0)
- {
- if (strcmp(console4, "all")==0)
- {
- f = atof(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type)
- parts[i].vy = f;
- }
- }
- else if (console_parse_type(console4, &j, console_error))
- {
- f = atof(console5);
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type == j)
- parts[i].vy = f;
- }
- }
- else
- {
- if (console_parse_partref(console4, &i, console_error))
- {
- f = atof(console5);
- parts[i].vy = f;
- }
- }
- }
- else
- strcpy(console_error, "Invalid property");
- }
- else
- strcpy(console_error, "Invalid Command");
- }
- return 1;
-}
diff --git a/src/elementdata.c b/src/elementdata.c
deleted file mode 100644
index 311b998..0000000
--- a/src/elementdata.c
+++ /dev/null
@@ -1,550 +0,0 @@
-/**
- * Powder Toy - element properties
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <powder.h>
-
-/* Weight Help
- * 1 = Gas ||
- * 2 = Light || Liquids 0-49
- * 98 = Heavy || Powder 50-99
- * 100 = Solid ||
- * -1 is Neutrons and Photons
- */
-part_type ptypes[PT_NUM] =
-{
- //Name Colour Advec Airdrag Airloss Loss Collid Grav Diffus Hotair Fal Burn Exp Mel Hrd M Use Weight Section H Ins Description
- {"", PIXPACK(0x000000), 0.0f, 0.00f * CFDS, 1.00f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 251, "Erases particles.", ST_NONE, 0, NULL, NULL},
- {"DUST", PIXPACK(0xFFE0A0), 0.7f, 0.02f * CFDS, 0.96f, 0.80f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 1, 10, 0, 0, 30, 1, 1, 85, SC_POWDERS, R_TEMP+0.0f +273.15f, 70, "Very light dust. Flammable.", ST_SOLID, TYPE_PART, NULL, NULL},
- {"WATR", PIXPACK(0x2030D0), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 30, SC_LIQUID, R_TEMP-2.0f +273.15f, 29, "Liquid. Conducts electricity. Freezes. Extinguishes fires.", ST_LIQUID, TYPE_LIQUID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_NEUTPENETRATE, &update_WATR, NULL},
- {"OIL", PIXPACK(0x404010), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 20, 0, 0, 5, 1, 1, 20, SC_LIQUID, R_TEMP+0.0f +273.15f, 42, "Liquid. Flammable.", ST_LIQUID, TYPE_LIQUID, NULL, NULL},
-#ifdef REALISTIC
- {"FIRE", PIXPACK(0xFF1000), 0.9f, 0.04f * CFDS, 0.97f, 0.20f, 0.0f, -0.1f, 0.00f, 0.001f * CFDS, 1, 0, 0, 0, 1, 1, 1, 2, SC_EXPLOSIVE, R_TEMP+400.0f+273.15f, 1, "Ignites flammable materials. Heats air.", ST_GAS, TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL, &update_PYRO, &graphics_FIRE},
-#else
- {"FIRE", PIXPACK(0xFF1000), 0.9f, 0.04f * CFDS, 0.97f, 0.20f, 0.0f, -0.1f, 0.00f, 0.001f * CFDS, 1, 0, 0, 0, 1, 1, 1, 2, SC_EXPLOSIVE, R_TEMP+400.0f+273.15f, 88, "Ignites flammable materials. Heats air.", ST_GAS, TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL, &update_PYRO, &graphics_FIRE},
-#endif
- {"STNE", PIXPACK(0xA0A0A0), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 5, 1, 1, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 150, "Heavy particles. Meltable.", ST_SOLID, TYPE_PART, NULL, NULL},
- {"LAVA", PIXPACK(0xE05010), 0.3f, 0.02f * CFDS, 0.95f, 0.80f, 0.0f, 0.15f, 0.00f, 0.0003f * CFDS, 2, 0, 0, 0, 2, 1, 1, 45, SC_LIQUID, R_TEMP+1500.0f+273.15f, 60, "Heavy liquid. Ignites flammable materials. Solidifies when cold.", ST_LIQUID, TYPE_LIQUID|PROP_LIFE_DEC, &update_PYRO, &graphics_LAVA},
- {"GUN", PIXPACK(0xC0C0D0), 0.7f, 0.02f * CFDS, 0.94f, 0.80f, -0.1f, 0.1f, 0.00f, 0.000f * CFDS, 1, 600, 1, 0, 10, 1, 1, 85, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 97, "Light dust. Explosive.", ST_SOLID, TYPE_PART, NULL, NULL},
- {"NITR", PIXPACK(0x20E010), 0.5f, 0.02f * CFDS, 0.92f, 0.97f, 0.0f, 0.2f, 0.00f, 0.000f * CFDS, 2, 1000, 2, 0, 3, 1, 1, 23, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 50, "Liquid. Pressure sensitive explosive.", ST_LIQUID, TYPE_LIQUID, NULL, NULL},
- {"CLNE", PIXPACK(0xFFD010), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 251, "Solid. Duplicates any particles it touches.", ST_SOLID, TYPE_SOLID, &update_CLNE, NULL},
- {"GAS", PIXPACK(0xE0FF20), 1.0f, 0.01f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 0.75f, 0.001f * CFDS, 0, 600, 0, 0, 1, 1, 1, 1, SC_GAS, R_TEMP+2.0f +273.15f, 42, "Gas. Diffuses. Flammable. Liquefies under pressure.", ST_GAS, TYPE_GAS, NULL, NULL},
- {"C-4", PIXPACK(0xD080E0), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 1000, 2, 50, 1, 1, 1, 100, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 88, "Solid. Pressure sensitive explosive.", ST_SOLID, TYPE_SOLID | PROP_NEUTPENETRATE, NULL, NULL},
- {"GOO", PIXPACK(0x804000), 0.0f, 0.00f * CFDS, 0.97f, 0.50f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 12, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 75, "Solid. Deforms and disappears under pressure.", ST_SOLID, TYPE_SOLID | PROP_NEUTPENETRATE|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC, &update_GOO, NULL},
- {"ICE", PIXPACK(0xA0C0FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, -0.0003f* CFDS, 0, 0, 0, 0, 20, 1, 1, 100, SC_SOLIDS, R_TEMP-50.0f+273.15f, 46, "Solid. Freezes water. Crushes under pressure. Cools down air.", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_ICEI, NULL},
- {"METL", PIXPACK(0x404060), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Solid. Conducts electricity. Meltable.", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW, NULL, NULL},
- {"SPRK", PIXPACK(0xFFFF80), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.001f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Electricity. Conducted by metal and water.", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_SPRK, &graphics_SPRK},
- {"SNOW", PIXPACK(0xC0E0FF), 0.7f, 0.01f * CFDS, 0.96f, 0.90f, -0.1f, 0.05f, 0.01f, -0.00005f* CFDS,1, 0, 0, 0, 20, 1, 1, 50, SC_POWDERS, R_TEMP-30.0f+273.15f, 46, "Light particles.", ST_SOLID, TYPE_PART|PROP_LIFE_DEC, &update_ICEI, NULL},
- {"WOOD", PIXPACK(0xC0A040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 20, 0, 0, 15, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 164, "Solid. Flammable.", ST_SOLID, TYPE_SOLID | PROP_NEUTPENETRATE, &update_WOOD, &graphics_WOOD},
- {"NEUT", PIXPACK(0x20E0FF), 0.0f, 0.00f * CFDS, 1.00f, 1.00f, -0.99f, 0.0f, 0.01f, 0.002f * CFDS, 0, 0, 0, 0, 0, 1, 1, -1, SC_NUCLEAR, R_TEMP+4.0f +273.15f, 60, "Neutrons. Interact with matter in odd ways.", ST_GAS, TYPE_ENERGY|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC, &update_NEUT, &graphics_NEUT},
- {"PLUT", PIXPACK(0x407020), 0.4f, 0.01f * CFDS, 0.99f, 0.95f, 0.0f, 0.4f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 0, 1, 1, 90, SC_NUCLEAR, R_TEMP+4.0f +273.15f, 251, "Heavy particles. Fissile. Generates neutrons under pressure.", ST_SOLID, TYPE_PART|PROP_NEUTPENETRATE|PROP_RADIOACTIVE, &update_PLUT, NULL},
- {"PLNT", PIXPACK(0x0CAC00), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 20, 0, 0, 10, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 65, "Plant, drinks water and grows.", ST_SOLID, TYPE_SOLID|PROP_NEUTPENETRATE|PROP_LIFE_DEC, &update_PLNT, &graphics_PLNT},
- {"ACID", PIXPACK(0xED55FF), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 40, 0, 0, 1, 1, 1, 10, SC_LIQUID, R_TEMP+0.0f +273.15f, 34, "Dissolves almost everything.", ST_LIQUID, TYPE_LIQUID|PROP_DEADLY, &update_ACID, &graphics_ACID},
- {"VOID", PIXPACK(0x790B0B), 0.0f, 0.00f * CFDS, 1.00f, 0.00f, 0.0f, 0.0f, 0.00f, -0.0003f* CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 251, "Hole, will drain away any particles.", ST_SOLID, TYPE_SOLID, NULL, NULL},
- {"WTRV", PIXPACK(0xA0A0FF), 1.0f, 0.01f * CFDS, 0.99f, 0.30f, -0.1f, -0.1f, 0.75f, 0.0003f * CFDS, 0, 0, 0, 0, 4, 1, 1, 1, SC_GAS, R_TEMP+100.0f+273.15f, 48, "Steam, heats up air, produced from hot water.", ST_GAS, TYPE_GAS, &update_WTRV, NULL},
- {"CNCT", PIXPACK(0xC0C0C0), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 2, 2, 1, 1, 55, SC_POWDERS, R_TEMP+0.0f +273.15f, 100, "Concrete, stronger than stone.", ST_SOLID, TYPE_PART|PROP_HOT_GLOW, NULL, NULL},
- {"DSTW", PIXPACK(0x1020C0), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 30, SC_LIQUID, R_TEMP-2.0f +273.15f, 23, "Distilled water, does not conduct electricity.", ST_LIQUID, TYPE_LIQUID|PROP_NEUTPENETRATE, &update_DSTW, NULL},
- {"SALT", PIXPACK(0xFFFFFF), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 5, 1, 1, 1, 75, SC_POWDERS, R_TEMP+0.0f +273.15f, 110, "Salt, dissolves in water.", ST_SOLID, TYPE_PART, NULL, NULL},
- {"SLTW", PIXPACK(0x4050F0), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 35, SC_LIQUID, R_TEMP+0.0f +273.15f, 75, "Saltwater, conducts electricity, difficult to freeze.", ST_LIQUID, TYPE_LIQUID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_NEUTPENETRATE, &update_SLTW, NULL},
- {"DMND", PIXPACK(0xCCFFFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 186, "Diamond. Indestructible.", ST_SOLID, TYPE_SOLID, NULL, NULL},
- {"BMTL", PIXPACK(0x505070), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 251, "Breakable metal.", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW, &update_BMTL, NULL},
- {"BRMT", PIXPACK(0x705060), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 2, 2, 1, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 211, "Broken metal.", ST_SOLID, TYPE_PART|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW, &update_BRMT, NULL},
- {"PHOT", PIXPACK(0xFFFFFF), 0.0f, 0.00f * CFDS, 1.00f, 1.00f, -0.99f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, -1, SC_NUCLEAR, R_TEMP+900.0f+273.15f, 251, "Photons. Travel in straight lines.", ST_GAS, TYPE_ENERGY|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC, &update_PHOT, &graphics_PHOT},
- {"URAN", PIXPACK(0x707020), 0.4f, 0.01f * CFDS, 0.99f, 0.95f, 0.0f, 0.4f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 0, 1, 1, 90, SC_NUCLEAR, R_TEMP+30.0f+273.15f, 251, "Heavy particles. Generates heat under pressure.", ST_SOLID, TYPE_PART | PROP_RADIOACTIVE, &update_URAN, NULL},
- {"WAX", PIXPACK(0xF0F0BB), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 10, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 44, "Wax. Melts at moderately high temperatures.", ST_SOLID, TYPE_SOLID, NULL, NULL},
- {"MWAX", PIXPACK(0xE0E0AA), 0.3f, 0.02f * CFDS, 0.95f, 0.80f, 0.0f, 0.15f, 0.00f, 0.000001f* CFDS,2, 5, 0, 0, 2, 1, 1, 25, SC_LIQUID, R_TEMP+28.0f+273.15f, 44, "Liquid Wax.", ST_LIQUID, TYPE_LIQUID, NULL, NULL},
- {"PSCN", PIXPACK(0x805050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "P-Type Silicon, Will transfer current to any conductor.", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC, NULL, NULL},
- {"NSCN", PIXPACK(0x505080), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "N-Type Silicon, Will not transfer current to P-Type Silicon.", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC, NULL, NULL},
- {"LN2", PIXPACK(0x80A0DF), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 0, 1, 1, 30, SC_LIQUID, 70.15f, 70, "Liquid Nitrogen. Very cold.", ST_SOLID, TYPE_LIQUID, NULL, NULL},
- {"INSL", PIXPACK(0x9EA3B6), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 7, 0, 0, 10, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 0, "Insulator, does not conduct heat or electricity.", ST_SOLID, TYPE_SOLID, NULL, NULL},
- {"VACU", PIXPACK(0x303030), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, -0.01f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SPECIAL, R_TEMP+70.0f+273.15f, 255, "Vacuum, sucks in other particles and heats up.", ST_NONE, TYPE_SOLID, NULL, NULL},
- {"VENT", PIXPACK(0xEFEFEF), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, 0.010f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SPECIAL, R_TEMP-16.0f+273.15f, 255, "Air vent, creates pressure and pushes other particles away.", ST_NONE, TYPE_SOLID, NULL, NULL},
- {"RBDM", PIXPACK(0xCCCCCC), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 1000, 1, 50, 1, 1, 1, 100, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 240, "Rubidium, explosive, especially on contact with water, low melting point", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC, NULL, NULL},
- {"LRBD", PIXPACK(0xAAAAAA), 0.3f, 0.02f * CFDS, 0.95f, 0.80f, 0.0f, 0.15f, 0.00f, 0.000001f* CFDS,2, 1000, 1, 0, 2, 1, 1, 45, SC_EXPLOSIVE, R_TEMP+45.0f+273.15f, 170, "Liquid Rubidium.", ST_LIQUID, TYPE_LIQUID|PROP_CONDUCTS|PROP_LIFE_DEC, NULL, NULL},
- {"NTCT", PIXPACK(0x505040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Semi-conductor. Only conducts electricity when hot (More than 100C)", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC, &update_NPTCT, NULL},
- {"SAND", PIXPACK(0xFFD090), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 5, 1, 1, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 150, "Sand, Heavy particles. Meltable.", ST_SOLID, TYPE_PART, NULL, NULL},
- {"GLAS", PIXPACK(0x404040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 150, "Solid. Meltable. Shatters under pressure", ST_SOLID, TYPE_SOLID | PROP_NEUTPASS | PROP_HOT_GLOW | PROP_SPARKSETTLE, &update_GLAS, NULL},
- {"PTCT", PIXPACK(0x405050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Semi-conductor. Only conducts electricity when cold (Less than 100C)", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC, &update_NPTCT, NULL},
- {"BGLA", PIXPACK(0x606060), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 5, 0, 1, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 150, "Broken Glass, Heavy particles. Meltable. Bagels.", ST_SOLID, TYPE_PART | PROP_HOT_GLOW, NULL, NULL},
- {"THDR", PIXPACK(0xFFFFA0), 0.0f, 0.00f * CFDS, 1.0f, 0.30f, -0.99f, 0.6f, 0.62f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 1, SC_EXPLOSIVE, 9000.0f +273.15f, 1, "Lightning! Very hot, inflicts damage upon most materials, transfers current to metals.", ST_NONE, TYPE_PART, &update_THDR, &graphics_THDR},
- {"PLSM", PIXPACK(0xBB99FF), 0.9f, 0.04f * CFDS, 0.97f, 0.20f, 0.0f, -0.1f, 0.30f, 0.001f * CFDS, 0, 0, 0, 0, 0, 1, 1, 1, SC_GAS, 10000.0f +273.15f, 5, "Plasma, extremely hot.", ST_NONE, TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL, &update_PYRO, &graphics_PLSM},
- {"ETRD", PIXPACK(0x404040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Electrode. Creates a surface that allows Plasma arcs. (Use sparingly)", ST_NONE, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC, NULL, NULL},
- {"NICE", PIXPACK(0xC0E0FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, -0.0005f* CFDS, 0, 0, 0, 0, 20, 1, 1, 100, SC_SOLIDS, 35.0f, 46, "Nitrogen Ice.", ST_SOLID, TYPE_SOLID, NULL, NULL},
- {"NBLE", PIXPACK(0xEB4917), 1.0f, 0.01f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 0.75f, 0.001f * CFDS, 0, 0, 0, 0, 1, 1, 1, 1, SC_GAS, R_TEMP+2.0f +273.15f, 106, "Noble Gas. Diffuses. Conductive. Ionizes into plasma when introduced to electricity", ST_GAS, TYPE_GAS|PROP_CONDUCTS|PROP_LIFE_DEC, &update_NBLE, NULL},
- {"BTRY", PIXPACK(0x858505), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Solid. Generates Electricity.", ST_SOLID, TYPE_SOLID, &update_BTRY, NULL},
- {"LCRY", PIXPACK(0x505050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_POWERED, R_TEMP+0.0f +273.15f, 251, "Liquid Crystal. Changes colour when charged. (PSCN Charges, NSCN Discharges)", ST_SOLID, TYPE_SOLID, &update_LCRY, &graphics_LCRY},
- {"STKM", PIXPACK(0xFFE0A0), 0.5f, 0.00f * CFDS, 0.2f, 1.0f, 0.0f, 0.0f, 0.0f, 0.00f * CFDS, 0, 0, 0, 0, 0, 1, 1, 50, SC_SPECIAL, R_TEMP+14.6f+273.15f, 0, "Stickman. Don't kill him!", ST_NONE, 0, &update_STKM, &graphics_STKM},
- {"SWCH", PIXPACK(0x103B11), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Solid. Only conducts when switched on. (PSCN switches on, NSCN switches off)", ST_SOLID, TYPE_SOLID, &update_SWCH, &graphics_SWCH},
- {"SMKE", PIXPACK(0x222222), 0.9f, 0.04f * CFDS, 0.97f, 0.20f, 0.0f, -0.1f, 0.00f, 0.001f * CFDS, 1, 0, 0, 0, 1, 1, 1, 1, SC_GAS, R_TEMP+320.0f+273.15f, 88, "Smoke", ST_SOLID, TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC, NULL, &graphics_SMKE},
- {"DESL", PIXPACK(0x440000), 1.0f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.0f, 0.0f * CFDS, 2, 2, 0, 0, 5, 1, 1, 15, SC_LIQUID, R_TEMP+0.0f +273.15f, 42, "Liquid. Explodes under high pressure and temperatures", ST_LIQUID, TYPE_LIQUID, NULL, NULL},
- {"COAL", PIXPACK(0x222222), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.0f, 0.0f * CFDS, 0, 0, 0, 0, 20, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 200, "Solid. Burns slowly.", ST_SOLID, TYPE_SOLID, &update_COAL, &graphics_COAL},
- {"LOXY", PIXPACK(0x80A0EF), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 5000, 0, 0, 0, 1, 1, 30, SC_LIQUID, 80.0f, 70, "Liquid Oxygen. Very cold. Reacts with fire", ST_LIQUID, TYPE_LIQUID, NULL, NULL},
- {"OXYG", PIXPACK(0x80A0FF), 2.0f, 0.00f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 3.0f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 1, SC_GAS, R_TEMP+0.0f +273.15f, 70, "Gas. Ignites easily.", ST_GAS, TYPE_GAS, &update_O2, NULL},
- {"INWR", PIXPACK(0x544141), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Insulated Wire. Doesn't conduct to metal or semiconductors.", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC, NULL, NULL},
- {"YEST", PIXPACK(0xEEE0C0), 0.7f, 0.02f * CFDS, 0.96f, 0.80f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 1, 15, 0, 0, 30, 1, 1, 80, SC_POWDERS, R_TEMP+0.0f +273.15f, 70, "Yeast, grows when warm (~37C).", ST_SOLID, TYPE_PART, &update_YEST, NULL},
- {"DYST", PIXPACK(0xBBB0A0), 0.7f, 0.02f * CFDS, 0.96f, 0.80f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 1, 20, 0, 0, 30, 0, 1, 80, SC_POWDERS, R_TEMP+0.0f +273.15f, 70, "Dead Yeast.", ST_SOLID, TYPE_PART, NULL, NULL},
- {"THRM", PIXPACK(0xA08090), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 2, 2, 1, 1, 90, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 211, "Thermite. Burns at extremely high temperature.", ST_SOLID, TYPE_PART, &update_THRM, NULL},
- {"GLOW", PIXPACK(0x445464), 0.3f, 0.02f * CFDS, 0.98f, 0.80f, 0.0f, 0.15f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 2, 1, 1, 40, SC_LIQUID, R_TEMP+20.0f+273.15f, 44, "Glow, Glows under pressure", ST_LIQUID, TYPE_LIQUID|PROP_LIFE_DEC, &update_GLOW, &graphics_GLOW},
- {"BRCK", PIXPACK(0x808080), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 251, "Brick, breakable building material.", ST_SOLID, TYPE_SOLID|PROP_HOT_GLOW, NULL, &graphics_BRCK},
- {"CFLM", PIXPACK(0x8080FF), 0.9f, 0.04f * CFDS, 0.97f, 0.20f, 0.0f, -0.1f, 0.00f, 0.0005f * CFDS, 1, 0, 0, 0, 1, 1, 1, 2, SC_EXPLOSIVE, 0.0f, 88, "Sub-zero flame.", ST_LIQUID, TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL, NULL, &graphics_HFLM},
- {"FIRW", PIXPACK(0xFFA040), 0.2f, 0.01f * CFDS, 0.96f, 0.95f, -0.1f, 0.1f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 30, 1, 1, 55, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 70, "Fireworks!", ST_SOLID, TYPE_PART|PROP_LIFE_DEC, &update_FIRW, &graphics_FIRW},
- {"FUSE", PIXPACK(0x0A5706), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.0f, 0.0f * CFDS, 0, 0, 0, 0, 20, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 200, "Solid. Burns slowly. Ignites at somewhat high temperatures and electricity.", ST_SOLID, TYPE_SOLID, &update_FUSE, NULL},
- {"FSEP", PIXPACK(0x63AD5F), 0.7f, 0.02f * CFDS, 0.96f, 0.80f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 30, 1, 1, 70, SC_POWDERS, R_TEMP+0.0f +273.15f, 70, "Fuse Powder. See FUSE.", ST_SOLID, TYPE_PART, &update_FSEP, NULL},
- {"AMTR", PIXPACK(0x808080), 0.7f, 0.02f * CFDS, 0.96f, 0.80f, 0.00f, 0.10f, 1.00f, 0.0000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_NUCLEAR, R_TEMP+0.0f +273.15f, 70, "Anti-Matter, Destroys a majority of particles", ST_NONE, TYPE_PART, &update_AMTR, NULL},
- {"BCOL", PIXPACK(0x333333), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 5, 2, 1, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 150, "Broken Coal. Heavy particles. See COAL", ST_SOLID, TYPE_PART, &update_BCOL, &graphics_COAL},
- {"PCLN", PIXPACK(0x3B3B0A), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_POWERED, R_TEMP+0.0f +273.15f, 251, "Solid. When activated, duplicates any particles it touches.", ST_NONE, TYPE_SOLID, &update_PCLN, &graphics_PCLN},
- {"HSWC", PIXPACK(0x3B0A0A), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_POWERED, R_TEMP+0.0f +273.15f, 251, "Heat switch. Conducts Heat only when activated", ST_NONE, TYPE_SOLID, &update_HSWC, &graphics_HSWC},
- {"IRON", PIXPACK(0x707070), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 50, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 251, "Rusts with salt, can be used for electrolysis of WATR", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW, &update_IRON, NULL},
- {"MORT", PIXPACK(0xE0E0E0), 0.0f, 0.00f * CFDS, 1.00f, 1.00f, -0.99f, 0.0f, 0.01f, 0.002f * CFDS, 0, 0, 0, 0, 0, 1, 1, -1, SC_CRACKER2, R_TEMP+4.0f +273.15f, 60, "Steam Train.", ST_NONE, TYPE_PART, &update_MORT, NULL},
- {"LIFE", PIXPACK(0x0CAC00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 1, 100, SC_LIFE, 9000.0f, 40, "Game Of Life! B3/S23", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL, &graphics_LIFE},
- {"DLAY", PIXPACK(0x753590), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_POWERED, 4.0f+273.15f, 0, "Conducts with temperature-dependent delay. (use HEAT/COOL).", ST_SOLID, TYPE_SOLID, &update_DLAY, &graphics_DLAY},
- {"CO2", PIXPACK(0x666666), 2.0f, 0.00f * CFDS, 0.99f, 0.30f, -0.1f, 0.1f, 1.0f, 0.000f * CFDS, 1, 0, 0, 0, 0, 1, 1, 1, SC_GAS, R_TEMP+273.15f, 88, "Carbon Dioxide", ST_GAS, TYPE_GAS, &update_CO2, NULL},
- {"DRIC", PIXPACK(0xE0E0E0), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, -0.0005f* CFDS, 0, 0, 0, 0, 20, 1, 1, 100, SC_SOLIDS, 172.65f, 2, "Dry Ice.", ST_SOLID, TYPE_SOLID, NULL, NULL},
- {"BUBW", PIXPACK(0x2030D0), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 30, SC_LIQUID, R_TEMP-2.0f +273.15f, 29, "Carbonated water. Conducts electricity. Freezes. Extinguishes fires.", ST_LIQUID, TYPE_LIQUID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_NEUTPENETRATE, &update_CBNW, &graphics_CBNW},
- {"STOR", PIXPACK(0x50DFDF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_POWERED, R_TEMP+0.0f +273.15f, 0, "Solid. Stores a single particle, releases when charged with PSCN, also passes to PIPE", ST_NONE, TYPE_SOLID, &update_STOR, &graphics_STOR},
- {"PVOD", PIXPACK(0x792020), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_POWERED, R_TEMP+0.0f +273.15f, 251, "Solid. When activated, destroys entering particles", ST_NONE, TYPE_SOLID, &update_PVOD, &graphics_PVOD},
- {"CONV", PIXPACK(0x0AAB0A), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 251, "Solid. Converts whatever touches it into its ctype.", ST_NONE, TYPE_SOLID, &update_CONV, NULL},
- {"CAUS", PIXPACK(0x80FFA0), 2.0f, 0.00f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 1.50f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 1, SC_GAS, R_TEMP+0.0f +273.15f, 70, "Caustic Gas, acts like Acid", ST_GAS, TYPE_GAS|PROP_DEADLY, &update_CAUS, NULL},
- {"LIGH", PIXPACK(0xFFFFC0), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 0, "More realistic lightning. Set pen size to set the size of the lightning.", ST_SOLID, TYPE_SOLID, &update_LIGH, &graphics_LIGH},
- {"TESC", PIXPACK(0x707040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Tesla coil!", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW, NULL, NULL},
- {"DEST", PIXPACK(0xFF3311), -0.05f, 0.00f * CFDS, 0.95f, 0.95f, -0.1f, 0.4f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 0, 1, 1, 101, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 150, "More destructive Bomb.", ST_SOLID, TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC, &update_DEST, &graphics_DEST},
- {"SPNG", PIXPACK(0xFFBE30), 0.00f, 0.00f * CFDS, 0.00f, 0.0f, 0.00f, 0.0f, 0.00f, 0.000f * CFDS, 0, 20, 0, 0, 30, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 251, "A sponge, absorbs water.", ST_SOLID, TYPE_SOLID, &update_SPNG, &graphics_SPNG},
- {"RIME", PIXPACK(0xCCCCCC), 0.00f, 0.00f * CFDS, 0.00f, 1.00f, 0.00f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 30, 1, 1, 100, SC_CRACKER2, 243.15f, 100, "Not quite Ice", ST_SOLID, TYPE_SOLID, &update_RIME, NULL},
- {"FOG", PIXPACK(0xAAAAAA), 0.8f, 0.00f * CFDS, 0.4f, 0.70f, -0.1f, 0.0f, 0.99f, 0.000f * CFDS, 0, 0, 0, 0, 30, 1, 1, 1, SC_CRACKER2, 243.15f, 100, "Not quite Steam", ST_GAS, TYPE_GAS|PROP_LIFE_DEC, &update_FOG, NULL},
- {"BCLN", PIXPACK(0xFFD040), 0.0f, 0.00f * CFDS, 0.97f, 0.50f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 12, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 251, "Breakable Clone.", ST_NONE, TYPE_SOLID|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC, &update_BCLN, NULL},
- {"LOVE", PIXPACK(0xFF30FF), 0.0f, 0.00f * CFDS, 0.00f, 0.00f, 0.0f, 0.0f, 0.0f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_CRACKER2, 373.0f, 40, "Love...", ST_GAS, TYPE_SOLID, &update_MISC, NULL},
- {"DEUT", PIXPACK(0x00153F), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 31, SC_NUCLEAR, R_TEMP-2.0f +273.15f, 251, "Deuterium oxide. Volume changes with temp, radioactive with neutrons.", ST_LIQUID, TYPE_LIQUID|PROP_NEUTPENETRATE, &update_DEUT, &graphics_DEUT},
- {"WARP", PIXPACK(0x101010), 0.8f, 0.00f * CFDS, 0.9f, 0.70f, -0.1f, 0.0f, 3.00f, 0.000f * CFDS, 0, 0, 0, 0, 30, 1, 1, 1, SC_NUCLEAR, R_TEMP +273.15f, 100, "Displaces other elements.", ST_GAS, TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL, &update_WARP, &graphics_WARP},
- {"PUMP", PIXPACK(0x0A0A3B), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 10, 1, 1, 100, SC_POWERED, 273.15f, 0, "Changes pressure to its temp when activated. (use HEAT/COOL).", ST_SOLID, TYPE_SOLID, &update_PUMP, &graphics_PUMP},
- {"FWRK", PIXPACK(0x666666), 0.4f, 0.01f * CFDS, 0.99f, 0.95f, 0.0f, 0.4f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 1, 1, 1, 97, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 100, "First fireworks made, activated by heat/neutrons.", ST_SOLID, TYPE_PART|PROP_LIFE_DEC, &update_FWRK, NULL},
- {"PIPE", PIXPACK(0x444444), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SOLIDS, 273.15f, 0, "Moves elements around, read FAQ on website for help.", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_PIPE, &graphics_PIPE},
- {"FRZZ", PIXPACK(0xC0E0FF), 0.7f, 0.01f * CFDS, 0.96f, 0.90f, -0.1f, 0.05f, 0.01f, -0.00005f* CFDS,1, 0, 0, 0, 20, 1, 1, 50, SC_POWDERS, 253.15f, 46, "Freeze powder. When melted, forms ice that always cools. Spreads with regular water.", ST_SOLID, TYPE_PART, &update_FRZZ, NULL},
- {"FRZW", PIXPACK(0x1020C0), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 30, SC_CRACKER2, 120.0f, 29, "Freeze water. Hybrid liquid formed when Freeze powder melts.", ST_LIQUID, TYPE_LIQUID||PROP_LIFE_DEC, &update_FRZW, NULL},
- {"GRAV", PIXPACK(0xFFE0A0), 0.7f, 0.00f * CFDS, 1.00f, 1.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 1, 10, 0, 0, 30, 1, 1, 85, SC_POWDERS, R_TEMP+0.0f +273.15f, 70, "Very light dust. Changes colour based on velocity.", ST_SOLID, TYPE_PART, &update_MISC, &graphics_GRAV},
- {"BIZR", PIXPACK(0x00FF77), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 30, SC_LIQUID, R_TEMP+0.0f +273.15f, 29, "Bizarre... contradicts the normal state changes.", ST_LIQUID, TYPE_LIQUID, &update_BIZR, &graphics_BIZR},
- {"BIZG", PIXPACK(0x00FFBB), 1.0f, 0.01f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 2.75f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 1, SC_CRACKER2, R_TEMP-200.0f+273.15f, 42, "Bizarre gas", ST_GAS, TYPE_GAS, &update_BIZR, &graphics_BIZR},
- {"BIZS", PIXPACK(0x00E455), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_CRACKER2, R_TEMP+300.0f+273.15f, 251, "Bizarre solid", ST_SOLID, TYPE_SOLID, &update_BIZR, &graphics_BIZR},
- {"INST", PIXPACK(0x404039), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Instantly conducts, PSCN to charge, NSCN to take.", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, NULL, NULL},
- {"ISOZ", PIXPACK(0xAA30D0), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 0, 1, 1, 24, SC_NUCLEAR, R_TEMP-2.0f +273.15f, 29, "Radioactive liquid", ST_LIQUID, TYPE_LIQUID|PROP_NEUTPENETRATE, &update_ISZ, NULL},
- {"ISZS", PIXPACK(0x662089), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, -0.0007f* CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_NUCLEAR, 140.00f, 251, "Solid form of ISOZ, slowly decays.", ST_SOLID, TYPE_SOLID, &update_ISZ, NULL},
- {"PRTI", PIXPACK(0xEB5917), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, -0.005f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 0, "Portal IN. Things go in here, now with channels (same as WIFI)", ST_SOLID, TYPE_SOLID, &update_PRTI, &graphics_PRTI},
- {"PRTO", PIXPACK(0x0020EB), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.005f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 0, "Portal OUT. Things come out here, now with channels (same as WIFI)", ST_SOLID, TYPE_SOLID, &update_PRTO, &graphics_PRTO},
- {"PSTE", PIXPACK(0xAA99AA), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 31, SC_LIQUID, R_TEMP-2.0f +273.15f, 29, "Colloid, Hardens under pressure", ST_LIQUID, TYPE_LIQUID, NULL, NULL},
- {"PSTS", PIXPACK(0x776677), 0.0f, 0.00f * CFDS, 0.00f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 20, 0, 1, 100, SC_CRACKER, R_TEMP-2.0f +273.15f, 29, "Solid form of PSTE, temporary", ST_SOLID, TYPE_SOLID, NULL, NULL},
- {"ANAR", PIXPACK(0xFFFFEE), -0.7f, -0.02f * CFDS, 0.96f, 0.80f, 0.1f, -0.1f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 30, 1, 1, 85, SC_POWDERS, R_TEMP+0.0f +273.15f, 70, "Very light dust. Behaves opposite gravity", ST_SOLID, TYPE_PART, &update_ANAR, NULL},
- {"VINE", PIXPACK(0x079A00), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 20, 0, 0, 10, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 65, "Vine, grows", ST_SOLID, TYPE_SOLID, &update_VINE, NULL},
- {"INVS", PIXPACK(0x00CCCC), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 15, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 164, "Invisible to everything while under pressure.", ST_SOLID, TYPE_SOLID | PROP_NEUTPASS, NULL, &graphics_INVS},
- {"EQVE", PIXPACK(0xFFE0A0), 0.7f, 0.02f * CFDS, 0.96f, 0.80f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 30, 0, 1, 85, SC_CRACKER2, R_TEMP+0.0f +273.15f, 70, "Shared velocity test", ST_SOLID, TYPE_PART, NULL, NULL},
- {"SPWN2", PIXPACK(0xAAAAAA), 0.0f, 0.00f * CFDS, 1.00f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 0, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 0, "STK2 spawn point", ST_SOLID, TYPE_SOLID, &update_SPAWN2, NULL},
- {"SPWN", PIXPACK(0xAAAAAA), 0.0f, 0.00f * CFDS, 1.00f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 0, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 0, "STKM spawn point", ST_SOLID, TYPE_SOLID, &update_SPAWN, NULL},
- {"SHLD", PIXPACK(0xAAAAAA), 0.0f, 0.00f * CFDS, 1.00f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 0, "Shield, spark it to grow", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_SHLD1, NULL},
- {"SHD2", PIXPACK(0x777777), 0.0f, 0.00f * CFDS, 1.00f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 0, 1, 100, SC_CRACKER2, R_TEMP+0.0f +273.15f, 0, "Shield lvl 2", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_SHLD2, NULL},
- {"SHD3", PIXPACK(0x444444), 0.0f, 0.00f * CFDS, 1.00f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 0, 1, 100, SC_CRACKER2, R_TEMP+0.0f +273.15f, 0, "Shield lvl 3", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_SHLD3, NULL},
- {"SHD4", PIXPACK(0x212121), 0.0f, 0.00f * CFDS, 1.00f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 0, 1, 100, SC_CRACKER2, R_TEMP+0.0f +273.15f, 0, "Shield lvl 4", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_SHLD4, NULL},
- {"LOLZ", PIXPACK(0x569212), 0.0f, 0.00f * CFDS, 0.00f, 0.00f, 0.0f, 0.0f, 0.0f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_CRACKER2, 373.0f, 40, "Lolz", ST_GAS, TYPE_SOLID, &update_MISC, NULL},
- {"WIFI", PIXPACK(0x40A060), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 2, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 0, "Wireless transmitter, color coded.", ST_SOLID, TYPE_SOLID, &update_WIFI, &graphics_WIFI},
- {"FILT", PIXPACK(0x000056), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 251, "Filter for photons, changes the color.", ST_SOLID, TYPE_SOLID | PROP_NOAMBHEAT, NULL, &graphics_FILT},
- {"ARAY", PIXPACK(0xFFBB00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 0, "Ray Emitter. Rays create points when they collide", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_ARAY, NULL},
- {"BRAY", PIXPACK(0xFFFFFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 0, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Ray Point. Rays create points when they collide", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC|PROP_LIFE_KILL, NULL, &graphics_BRAY},
- {"STK2", PIXPACK(0x6464FF), 0.5f, 0.00f * CFDS, 0.2f, 1.0f, 0.0f, 0.0f, 0.0f, 0.00f * CFDS, 0, 0, 0, 0, 0, 1, 1, 50, SC_SPECIAL, R_TEMP+14.6f+273.15f, 0, "Second Stickman. Don't kill him!", ST_NONE, 0, &update_STKM2, &graphics_STKM},
- {"BOMB", PIXPACK(0xFFF288), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 20, 1, 1, 30, SC_EXPLOSIVE, R_TEMP-2.0f +273.15f, 29, "Bomb.", ST_NONE, TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC|PROP_SPARKSETTLE, &update_BOMB, &graphics_BOMB},
- {"C-5", PIXPACK(0x2050E0), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 88, "Cold explosive", ST_SOLID, TYPE_SOLID | PROP_NEUTPENETRATE, &update_C5, NULL},
- {"SING", PIXPACK(0x242424), 0.7f, 0.36f * CFDS, 0.96f, 0.80f, 0.1f, 0.12f, 0.00f, -0.001f * CFDS, 1, 0, 0, 0, 0, 1, 1, 86, SC_NUCLEAR, R_TEMP+0.0f +273.15f, 70, "Singularity", ST_SOLID, TYPE_PART|PROP_LIFE_DEC, &update_SING, NULL},
- {"QRTZ", PIXPACK(0xAADDDD), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 3, "Quartz, breakable mineral. Conducts but becomes brittle at lower temperatures.", ST_SOLID, TYPE_SOLID|PROP_HOT_GLOW|PROP_LIFE_DEC, &update_QRTZ, &graphics_QRTZ},
- {"PQRT", PIXPACK(0x88BBBB), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.27f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 0, 1, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 3, "Broken quartz.", ST_SOLID, TYPE_PART| PROP_HOT_GLOW, &update_QRTZ, &graphics_QRTZ},
- {"EMP", PIXPACK(0x66AAFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.0f, 0.0f * CFDS, 0, 0, 0, 0, 3, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 121, "Breaks activated electronics.", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_EMP, &graphics_EMP},
- {"BREL", PIXPACK(0x707060), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.18f, 0.00f, 0.000f * CFDS, 1, 0, 0, 2, 2, 1, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 211, "Broken electronics", ST_SOLID, TYPE_PART|PROP_CONDUCTS|PROP_LIFE_DEC|PROP_HOT_GLOW, &update_BREL, NULL},
- {"ELEC", PIXPACK(0xDFEFFF), 0.0f, 0.00f * CFDS, 1.00f, 1.00f, -0.99f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, -1, SC_NUCLEAR, R_TEMP+200.0f+273.15f, 251, "Electrons", ST_GAS, TYPE_ENERGY|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC, &update_ELEC, &graphics_ELEC},
- {"ACEL", PIXPACK(0x0099CC), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_FORCE, R_TEMP+0.0f +273.15f, 251, "Accelerator", ST_NONE, TYPE_SOLID, &update_ACEL, &graphics_ACEL},
- {"DCEL", PIXPACK(0x99CC00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_FORCE, R_TEMP+0.0f +273.15f, 251, "Decelerator", ST_NONE, TYPE_SOLID, &update_DCEL, &graphics_DCEL},
- {"TNT", PIXPACK(0xC05050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 88, "Explosive.", ST_SOLID, TYPE_SOLID | PROP_NEUTPENETRATE, &update_BANG, NULL},
- {"IGNC", PIXPACK(0xC0B050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 88, "Ignition cord.", ST_SOLID, TYPE_SOLID | PROP_NEUTPENETRATE | PROP_SPARKSETTLE | PROP_LIFE_KILL, &update_IGNT, NULL},
- {"BOYL", PIXPACK(0x0A3200), 1.0f, 0.01f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 0.18f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 1, SC_GAS, R_TEMP+2.0f +273.15f, 42, "Boyle, variable pressure gas. Expands when heated.", ST_GAS, TYPE_GAS, &update_BOYL, NULL},
- {"GEL", PIXPACK(0xFF9900), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 35, SC_LIQUID, R_TEMP-2.0f +273.15f, 29, "Gel. A liquid with variable viscosity and heat conductivity", ST_LIQUID, TYPE_LIQUID|PROP_LIFE_DEC|PROP_NEUTPENETRATE, &update_GEL, &graphics_GEL},
- {"TRON", PIXPACK(0xA9FF00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SPECIAL, 0.0f, 40, "Smart particles, Travels in straight lines and avoids obstacles. Grows with time.", ST_NONE, TYPE_SOLID|PROP_LIFE_DEC|PROP_LIFE_KILL, &update_TRON, &graphics_TRON},
- {"TTAN", PIXPACK(0x909090), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 50, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 251, "Titanium, Higher melting temperature than other metals, blocks all air pressure", ST_SOLID, TYPE_SOLID|PROP_CONDUCTS|PROP_HOT_GLOW|PROP_LIFE_DEC, &update_TTAN, NULL},
- {"EXOT", PIXPACK(0x404040), 0.3f, 0.02f * CFDS, 0.95f, 0.80f, 0.0f, 0.15f, 0.00f, 0.0003f * CFDS, 2, 0, 0, 0, 2, 1, 1, 46, SC_NUCLEAR, R_TEMP-2.0f +273.15f, 250, "Exotic matter. Explodes with excess exposure to electrons.", ST_LIQUID, TYPE_LIQUID, &update_EXOT, &graphics_EXOT},
- /*FREE*/{"BRAN", PIXPACK(0xCCCC00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 0, 0, 100, SC_LIFE, 9000.0f, 40, "Brian 6 S6/B246/3", ST_NONE, TYPE_SOLID|PROP_LIFE, NULL, NULL},
- {"EMBR", PIXPACK(0xFFF288), 0.4f, 0.001f * CFDS, 0.99f, 0.90f, 0.0f, 0.07f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 20, 0, 1, 30, SC_EXPLOSIVE, 500.0f +273.15f, 29, "Sparks. Formed by explosions.", ST_NONE, TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL|PROP_SPARKSETTLE, &update_EMBR, &graphics_EMBR},
- {"HYGN", PIXPACK(0x5070FF), 2.0f, 0.00f * CFDS, 0.99f, 0.30f, -0.10f, 0.00f, 3.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 1, SC_GAS, R_TEMP+0.0f +273.15f, 251, "Combines with O2 to make WATR", ST_GAS, TYPE_GAS, &update_H2, NULL},
- {"SOAP", PIXPACK(0xF5F5DC), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 35, SC_LIQUID, R_TEMP-2.0f +273.15f, 29, "Soap. Creates bubbles.", ST_LIQUID, TYPE_LIQUID|PROP_NEUTPENETRATE|PROP_LIFE_DEC, &update_SOAP, NULL},
- {"BHOL", PIXPACK(0x202020), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 186, "Black hole (Requires newtonian gravity)", ST_SOLID, TYPE_SOLID, &update_NBHL, NULL},
- {"WHOL", PIXPACK(0xFFFFFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 186, "White hole (Requires newtonian gravity)", ST_SOLID, TYPE_SOLID, &update_NWHL, NULL},
- {"MERC", PIXPACK(0x736B6D), 0.4f, 0.04f * CFDS, 0.94f, 0.80f, 0.0f, 0.3f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 1, 91, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Mercury. Volume changes with temperature, Conductive.", ST_LIQUID, TYPE_LIQUID|PROP_CONDUCTS|PROP_NEUTABSORB|PROP_LIFE_DEC, &update_MERC, NULL},
- {"PBCN", PIXPACK(0x3B1D0A), 0.0f, 0.00f * CFDS, 0.97f, 0.50f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 12, 1, 1, 100, SC_POWERED, R_TEMP+0.0f +273.15f, 251, "Powered breakable clone", ST_NONE, TYPE_SOLID, &update_PBCN, &graphics_PBCN},
- {"GPMP", PIXPACK(0x0A3B3B), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_POWERED, 0.0f +273.15f, 0, "Changes gravity to its temp when activated. (use HEAT/COOL).", ST_NONE, TYPE_SOLID, &update_GPMP, &graphics_GPMP},
- {"CLST", PIXPACK(0xE4A4A4), 0.7f, 0.02f * CFDS, 0.94f, 0.95f, 0.0f, 0.2f, 0.00f, 0.000f * CFDS, 1, 0, 0, 2, 2, 1, 1, 55, SC_POWDERS, R_TEMP+0.0f +273.15f, 70, "Clay dust. Produces paste when mixed with water.", ST_SOLID, TYPE_PART, &update_CLST, &graphics_CLST},
- {"WIRE", PIXPACK(0xFFCC00), 0.0f, 0.00f * CFDS, 0.00f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 250, "WireWorld wires.",ST_SOLID,TYPE_SOLID,&update_WIRE, &graphics_WIRE},
- {"GBMB", PIXPACK(0x1144BB), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 20, 1, 1, 30, SC_EXPLOSIVE, R_TEMP-2.0f +273.15f, 29, "Sticks to first object it touches then produces strong gravity push.", ST_NONE, TYPE_PART|PROP_LIFE_DEC|PROP_LIFE_KILL_DEC, &update_GBMB, &graphics_GBMB},
- {"FIGH", PIXPACK(0xFFE0A0), 0.5f, 0.00f * CFDS, 0.2f, 1.0f, 0.0f, 0.0f, 0.0f, 0.00f * CFDS, 0, 0, 0, 0, 0, 1, 1, 50, SC_SPECIAL, R_TEMP+14.6f+273.15f, 0, "Fighter. Tries to kill stickmen.", ST_NONE, 0, &update_FIGH, &graphics_STKM},
- {"FRAY", PIXPACK(0x00BBFF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_FORCE, 20.0f+0.0f +273.15f, 0, "Force Emitter. Push or pull objects based on temp value, use like ARAY", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_FRAY, NULL},
- {"RPEL", PIXPACK(0x99CC00), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_FORCE, 20.0f+0.0f +273.15f, 0, "Repel or attract particles based on temp value.", ST_NONE, TYPE_SOLID, &update_REPL, NULL},
- {"PPIP", PIXPACK(0x444466), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, 100, SC_POWERED, 273.15f, 0, "Powered pipe", ST_SOLID, TYPE_SOLID|PROP_LIFE_DEC, &update_PIPE, &graphics_PIPE},
- {"DTEC", PIXPACK(0xFD9D18), 0.0f, 0.00f * CFDS, 0.96f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+273.15f, 0, "Creates a spark when something with its ctype is nearby", ST_SOLID, TYPE_SOLID, &update_DTEC, NULL},
- //Name Colour Advec Airdrag Airloss Loss Collid Grav Diffus Hotair Fal Burn Exp Mel Hrd M Use Weight Section H Ins Description
-};
-
-// temporarily define abbreviations for impossible p/t values
-#define IPL -257.0f
-#define IPH 257.0f
-#define ITL MIN_TEMP-1
-#define ITH MAX_TEMP+1
-// no transition (PT_NONE means kill part)
-#define NT -1
-// special transition - lava ctypes etc need extra code, which is only found and run if ST is given
-#define ST PT_NUM
-part_transition ptransitions[PT_NUM] =
-{ // if low pressure if high pressure if low temperature if high temperature
- // Name plv plt phv pht tlv tlt thv tht
- /* NONE */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* DUST */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* WATR */ {IPL, NT, IPH, NT, 273.15f,PT_ICEI, 373.0f, PT_WTRV},
- /* OIL */ {IPL, NT, IPH, NT, ITL, NT, 333.0f, PT_GAS},
- /* FIRE */ {IPL, NT, IPH, NT, ITL, NT, 2773.0f,PT_PLSM},
- /* STNE */ {IPL, NT, IPH, NT, ITL, NT, 983.0f, PT_LAVA},
- /* LAVA */ {IPL, NT, IPH, NT, 2573.15f,ST, ITH, NT}, // 2573.15f is highest melt pt of possible ctypes
- /* GUN */ {IPL, NT, IPH, NT, ITL, NT, 673.0f, PT_FIRE},
- /* NITR */ {IPL, NT, IPH, NT, ITL, NT, 673.0f, PT_FIRE},
- /* CLNE */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* GAS */ {IPL, NT, 6.0f, PT_OIL, ITL, NT, 573.0f, PT_FIRE},
- /* C-4 */ {IPL, NT, IPH, NT, ITL, NT, 673.0f, PT_FIRE},
- /* GOO */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* ICE */ {IPL, NT, 0.8f, PT_SNOW, ITL, NT, 252.05f, ST},
- /* METL */ {IPL, NT, IPH, NT, ITL, NT, 1273.0f,PT_LAVA},
- /* SPRK */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* SNOW */ {IPL, NT, IPH, NT, ITL, NT, 273.0f, ST},
- /* WOOD */ {IPL, NT, IPH, NT, ITL, NT, 873.0f, PT_FIRE},
- /* NEUT */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* PLUT */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* PLNT */ {IPL, NT, IPH, NT, ITL, NT, 573.0f, PT_FIRE},
- /* ACID */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* VOID */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* WTRV */ {IPL, NT, IPH, NT, 371.0f, ST, ITH, NT},
- /* CNCT */ {IPL, NT, IPH, NT, ITL, NT, 1123.0f,PT_LAVA},
- /* DSTW */ {IPL, NT, IPH, NT, 273.15f,PT_ICEI, 373.0f, PT_WTRV},
- /* SALT */ {IPL, NT, IPH, NT, ITL, NT, 1173.0f,PT_LAVA},
- /* SLTW */ {IPL, NT, IPH, NT, 252.05f, PT_ICEI, 383.0f, ST},
- /* DMND */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* BMTL */ {IPL, NT, 1.0f, ST, ITL, NT, 1273.0f,PT_LAVA},
- /* BRMT */ {IPL, NT, IPH, NT, ITL, NT, 1273.0f,PT_LAVA},
- /* PHOT */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* URAN */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* WAX */ {IPL, NT, IPH, NT, ITL, NT, 319.0f, PT_MWAX},
- /* MWAX */ {IPL, NT, IPH, NT, 318.0f, PT_WAX, 673.0f, PT_FIRE},
- /* PSCN */ {IPL, NT, IPH, NT, ITL, NT, 1687.0f,PT_LAVA},
- /* NSCN */ {IPL, NT, IPH, NT, ITL, NT, 1687.0f,PT_LAVA},
- /* LN2 */ {IPL, NT, IPH, NT, 63.0f, PT_NICE, 77.0f, PT_NONE},
- /* INSL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* VACU */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* VENT */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* RBDM */ {IPL, NT, IPH, NT, ITL, NT, 312.0f, PT_LRBD},
- /* LRBD */ {IPL, NT, IPH, NT, 311.0f, PT_RBDM, 961.0f, PT_FIRE},
- /* NTCT */ {IPL, NT, IPH, NT, ITL, NT, 1687.0f,PT_LAVA},
- /* SAND */ {IPL, NT, IPH, NT, ITL, NT, 1973.0f,PT_LAVA},
- /* GLAS */ {IPL, NT, IPH, NT, ITL, NT, 1973.0f,PT_LAVA},
- /* PTCT */ {IPL, NT, IPH, NT, ITL, NT, 1414.0f,PT_LAVA},
- /* BGLA */ {IPL, NT, IPH, NT, ITL, NT, 1973.0f,PT_LAVA},
- /* THDR */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* PLSM */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* ETRD */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* NICE */ {IPL, NT, IPH, NT, ITL, NT, 63.1f, PT_LNTG},
- /* NBLE */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* BTRY */ {IPL, NT, IPH, NT, ITL, NT, 2273.0f,PT_PLSM},
- /* LCRY */ {IPL, NT, IPH, NT, ITL, NT, 1273.0f,PT_BGLA},
- /* STKM */ {IPL, NT, IPH, NT, ITL, NT, 620.0f, PT_FIRE},
- /* SWCH */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* SMKE */ {IPL, NT, IPH, NT, ITL, NT, 625.0f, PT_FIRE},
- /* DESL */ {IPL, NT, 5.0f, PT_FIRE, ITL, NT, 335.0f, PT_FIRE},
- /* COAL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* LO2 */ {IPL, NT, IPH, NT, ITL, NT, 90.1f, PT_O2},
- /* O2 */ {IPL, NT, IPH, NT, 90.0f, PT_LO2, ITH, NT},
- /* INWR */ {IPL, NT, IPH, NT, ITL, NT, 1687.0f,PT_LAVA},
- /* YEST */ {IPL, NT, IPH, NT, ITL, NT, 373.0f, PT_DYST},
- /* DYST */ {IPL, NT, IPH, NT, ITL, NT, 473.0f, PT_DUST},
- /* THRM */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* GLOW */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* BRCK */ {IPL, NT, 8.8f, PT_STNE, ITL, NT, 1223.0f,PT_LAVA},
- /* CFLM */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* FIRW */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* FUSE */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* FSEP */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* AMTR */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* BCOL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* PCLN */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* HSWC */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* IRON */ {IPL, NT, IPH, NT, ITL, NT, 1687.0f,PT_LAVA},
- /* MORT */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* LIFE */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* DLAY */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* CO2 */ {IPL, NT, IPH, NT, 194.65f,PT_DRIC, ITH, NT},
- /* DRIC */ {IPL, NT, IPH, NT, ITL, NT, 195.65f,PT_CO2},
- /* CBNW */ {IPL, NT, IPH, NT, 273.15f,PT_ICEI, 373.0f, PT_WTRV},
- /* STOR */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* STOR */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /*FREE*//* GOL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /*FREE*//* GOL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /*FREE*//* GOL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /*FREE*//* GOL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /*FREE*//* GOL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* SPNG */ {IPL, NT, IPH, NT, ITL, NT, 2730.0f,PT_FIRE},
- /* RIME */ {IPL, NT, IPH, NT, ITL, NT, 273.15f,PT_WATR},
- /* FOG */ {IPL, NT, IPH, NT, ITL, NT, 373.15f,PT_WTRV},
- /* BCLN */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* LOVE */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* DEUT */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* WARP */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* PUMP */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* FWRK */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* PIPE */ {IPL, NT, 10.0f, PT_BRMT, ITL, NT, ITH, NT},
- /* FRZZ */ {IPL, NT, 1.8f, PT_SNOW, 50.0f,PT_ICEI, 273.15f,PT_WATR},
- /* FRZW */ {IPL, NT, IPH, NT, ITL, NT, 53.0f, PT_ICEI},
- /* GRAV */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* BIZR */ {IPL, NT, IPH, NT, 100.0f, PT_BIZRG, 400.0f, PT_BIZRS},
- /* BIZRG*/ {IPL, NT, IPH, NT, ITL, NT, 100.0f, PT_BIZR},//, 400.0f, PT_BIZRS},
- /* BIZRS*/ {IPL, NT, IPH, NT, 400.0f, PT_BIZR, ITH, NT},// 100.0f, PT_BIZRG},
- /* INST */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* ISOZ */ {IPL, NT, IPH, NT, 160.0f, PT_ISZS, ITH, NT},
- /* ISZS */ {IPL, NT, IPH, NT, ITL, NT, 300.0f, PT_ISOZ},
- /* PRTI */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* PRTO */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* PSTE */ {IPL, NT, 0.5f, PT_PSTS, ITL, NT, 747.0f, PT_BRCK},
- /* PSTS */ {0.5f, PT_PSTE, IPH, NT, ITL, NT, ITH, NT},
- /* ANAR */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* VINE */ {IPL, NT, IPH, NT, ITL, NT, 573.0f, PT_FIRE},
- /* INVS */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* EQVE */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* SPWN2*/ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* SPAWN*/ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* SHLD1*/ {IPL, NT, 7.0f, PT_NONE, ITL, NT, ITH, NT},
- /* SHLD2*/ {IPL, NT, 15.0f, PT_NONE, ITL, NT, ITH, NT},
- /* SHLD3*/ {IPL, NT, 25.0f, PT_NONE, ITL, NT, ITH, NT},
- /* SHLD4*/ {IPL, NT, 40.0f, PT_NONE, ITL, NT, ITH, NT},
- /* LOlZ */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* WIFI */ {IPL, NT, 15.0f, PT_BRMT, ITL, NT, ITH, NT},
- /* FILT */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* ARAY */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* BRAY */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* STKM2*/ {IPL, NT, IPH, NT, ITL, NT, 620.0f, PT_FIRE},
- /* BOMB */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* C-5 */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* SING */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* QRTZ */ {IPL, NT, IPH, NT, ITL, NT, 2573.15f,PT_LAVA},
- /* PQRT */ {IPL, NT, IPH, NT, ITL, NT, 2573.15f,PT_LAVA},
- /* EMP */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* BREL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* ELEC */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* ACEL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* DCEL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* TNT */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* IGNP */ {IPL, NT, IPH, NT, ITL, NT, 673.0f, PT_FIRE},
- /* BOYL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* GEL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* TRON */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* TTAN */ {IPL, NT, IPH, NT, ITL, NT, 1941.0f,PT_LAVA},
- /* EXOT */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /*FREE*//* GOL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* WIND */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* H2 */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* SOAP */ {IPL, NT, IPH, NT, ITL, NT, ITL, NT},
- /* NBHL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* NWHL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* MERC */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* PBCN */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* GPMP */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* CLST */ {IPL, NT, IPH, NT, ITL, NT, 1256.0f, PT_LAVA},
- /* WIRE */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* GBMB */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* FIGH */ {IPL, NT, IPH, NT, ITL, NT, 620.0f, PT_FIRE},
- /* FRAY */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* REPL */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* PPIP */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
- /* DTEC */ {IPL, NT, IPH, NT, ITL, NT, ITH, NT},
-};
-
-// This is an enthalpy values table, converted into TPT imaginary units
-// table value is - 750/226*enthalpy value of the material
-unsigned int platent[PT_NUM] =
-{
- /* NONE */ 0,
- /* DUST */ 0,
- /* WATR */ 7500,
- /* OIL */ 0,
- /* FIRE */ 0,
- /* STNE */ 0,
- /* LAVA */ 0,
- /* GUN */ 0,
- /* NITR */ 0,
- /* CLNE */ 0,
- /* GAS */ 0,
- /* C-4 */ 0,
- /* GOO */ 0,
- /* ICE */ 1095,
- /* METL */ 919,
- /* SPRK */ 0,
- /* SNOW */ 1095,
- /* WOOD */ 0,
- /* NEUT */ 0,
- /* PLUT */ 0,
- /* PLNT */ 0,
- /* ACID */ 0,
- /* VOID */ 0,
- /* WTRV */ 0,
- /* CNCT */ 0,
- /* DSTW */ 7500,
- /* SALT */ 0,
- /* SLTW */ 7500,
- /* DMND */ 0,
- /* BMTL */ 0,
- /* BRMT */ 0,
- /* PHOT */ 0,
- /* URAN */ 0,
- /* WAX */ 0,
- /* MWAX */ 0,
- /* PSCN */ 0,
- /* NSCN */ 0,
- /* LN2 */ 0,
- /* INSL */ 0,
- /* VACU */ 0,
- /* VENT */ 0,
- /* RBDM */ 0,
- /* LRBD */ 0,
- /* NTCT */ 0,
- /* SAND */ 0,
- /* GLAS */ 0,
- /* PTCT */ 0,
- /* BGLA */ 0,
- /* THDR */ 0,
- /* PLSM */ 0,
- /* ETRD */ 0,
- /* NICE */ 0,
- /* NBLE */ 0,
- /* BTRY */ 0,
- /* LCRY */ 0,
- /* STKM */ 0,
- /* SWCH */ 0,
- /* SMKE */ 0,
- /* DESL */ 0,
- /* COAL */ 0,
- /* LO2 */ 0,
- /* O2 */ 0,
- /* INWR */ 0,
- /* YEST */ 0,
- /* DYST */ 0,
- /* THRM */ 0,
- /* GLOW */ 0,
- /* BRCK */ 0,
- /* CFLM */ 0,
- /* FIRW */ 0,
- /* FUSE */ 0,
- /* FSEP */ 0,
- /* AMTR */ 0,
- /* BCOL */ 0,
- /* PCLN */ 0,
- /* HSWC */ 0,
- /* IRON */ 0,
- /* MORT */ 0,
- /* LIFE */ 0,
- /* DLAY */ 0,
- /* CO2 */ 0,
- /* DRIC */ 0,
- /* CBNW */ 7500,
- /* STOR */ 0,
- /* STOR */ 0,
- /* FREE */ 0,
- /* FREE */ 0,
- /* FREE */ 0,
- /* FREE */ 0,
- /* FREE */ 0,
- /* SPNG */ 0,
- /* RIME */ 0,
- /* FOG */ 0,
- /* BCLN */ 0,
- /* LOVE */ 0,
- /* DEUT */ 0,
- /* WARP */ 0,
- /* PUMP */ 0,
- /* FWRK */ 0,
- /* PIPE */ 0,
- /* FRZZ */ 0,
- /* FRZW */ 0,
- /* GRAV */ 0,
- /* BIZR */ 0,
- /* BIZRG*/ 0,
- /* BIZRS*/ 0,
- /* INST */ 0,
- /* ISOZ */ 0,
- /* ISZS */ 0,
- /* PRTI */ 0,
- /* PRTO */ 0,
- /* PSTE */ 0,
- /* PSTS */ 0,
- /* ANAR */ 0,
- /* VINE */ 0,
- /* INVS */ 0,
- /* EQVE */ 0,
- /* SPWN2*/ 0,
- /* SPAWN*/ 0,
- /* SHLD1*/ 0,
- /* SHLD2*/ 0,
- /* SHLD3*/ 0,
- /* SHLD4*/ 0,
- /* LOlZ */ 0,
- /* WIFI */ 0,
- /* FILT */ 0,
- /* ARAY */ 0,
- /* BRAY */ 0,
- /* STKM2*/ 0,
- /* BOMB */ 0,
- /* C-5 */ 0,
- /* SING */ 0,
- /* QRTZ */ 0,
- /* PQRT */ 0,
- /* EMP */ 0,
- /* BREL */ 0,
- /* ELEC */ 0,
- /* ACEL */ 0,
- /* DCEL */ 0,
- /* TNT */ 0,
- /* IGNP */ 0,
- /* BOYL */ 0,
- /* GEL */ 0,
- /* EXOT */ 0,
- /* FREE */ 0,
- /* FREE */ 0,
- /* FREE */ 0,
- /* WIND */ 0,
- /* H2 */ 0,
- /* SOAP */ 0,
- /* NBHL */ 0,
- /* NWHL */ 0,
- /* MERC */ 0,
- /* PBCN */ 0,
- /* GPMP */ 0,
- /* CLST */ 0,
- /* WIRE */ 0,
- /* GBMB */ 0,
- /* FIGH */ 0,
- /* FRAY */ 0,
- /* REPL */ 0,
- /* PPIP */ 0,
- /* DTEC */ 0,
-};
-#undef IPL
-#undef IPH
-#undef ITL
-#undef ITH
-#undef NT
-#undef ST
diff --git a/src/elements/O2.c b/src/elements/O2.c
deleted file mode 100644
index a189e12..0000000
--- a/src/elements/O2.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_O2(UPDATE_FUNC_ARGS)
-{
- int r,rx,ry;
- if (parts[i].temp < 9273.15)
- {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
-
- if ((r&0xFF)==PT_FIRE)
- {
- parts[r>>8].temp+=(rand()/(RAND_MAX/100));
- if(parts[r>>8].tmp&0x01)
- parts[r>>8].temp=3473;
- parts[r>>8].tmp |= 2;
- }
- if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM)
- {
- create_part(i,x,y,PT_FIRE);
- parts[i].temp+=(rand()/(RAND_MAX/100));
- parts[i].tmp |= 2;
- }
-
- }
- }
- else if (parts[i].temp > 9973.15 && pv[y/CELL][x/CELL] > 250.0f && fabsf(gravx[((y/CELL)*(XRES/CELL))+(x/CELL)]) + fabsf(gravy[((y/CELL)*(XRES/CELL))+(x/CELL)]) > 20)
- {
- if (rand()%5 < 1)
- {
- int j;
- create_part(i,x,y,PT_BRMT);
-
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1) parts[j].temp = 15000;
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PHOT); if (j != -1) parts[j].temp = 15000;
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PLSM); if (j != -1) parts[j].temp = 15000;
-
- parts[i].temp = 15000;
- pv[y/CELL][x/CELL] += 300;
- }
- }
- return 0;
-}
diff --git a/src/elements/acel.c b/src/elements/acel.c
deleted file mode 100644
index 17b89c5..0000000
--- a/src/elements/acel.c
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_ACEL(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- parts[i].tmp = 0;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry) && !(rx && ry))
- {
- r = pmap[y+ry][x+rx];
- if(!r)
- r = photons[y+ry][x+rx];
- if ((r>>8)>=NPART || !r)
- continue;
- if(ptypes[r&0xFF].properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))
- {
- parts[r>>8].vx *= 1.1f;
- parts[r>>8].vy *= 1.1f;
- parts[i].tmp = 1;
- }
- }
- return 0;
-}
-
-int graphics_ACEL(GRAPHICS_FUNC_ARGS)
-{
- if(cpart->tmp)
- *pixel_mode |= PMODE_GLOW;
- return 0;
-}
-int update_DCEL(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- parts[i].tmp = 0;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry) && !(rx && ry))
- {
- r = pmap[y+ry][x+rx];
- if(!r)
- r = photons[y+ry][x+rx];
- if ((r>>8)>=NPART || !r)
- continue;
- if(ptypes[r&0xFF].properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY))
- {
- parts[r>>8].vx *= 0.9f;
- parts[r>>8].vy *= 0.9f;
- parts[i].tmp = 1;
- }
- }
- return 0;
-}
-
-int graphics_DCEL(GRAPHICS_FUNC_ARGS)
-{
- if(cpart->tmp)
- *pixel_mode |= PMODE_GLOW;
- return 0;
-}
diff --git a/src/elements/acid.c b/src/elements/acid.c
deleted file mode 100644
index 2e1f33e..0000000
--- a/src/elements/acid.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_ACID(UPDATE_FUNC_ARGS) {
- int r, rx, ry, trade, np;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_ACID && (r&0xFF)!=PT_CAUS)
- {
- if ((r&0xFF)==PT_PLEX || (r&0xFF)==PT_NITR || (r&0xFF)==PT_GUNP || (r&0xFF)==PT_RBDM || (r&0xFF)==PT_LRBD)
- {
- part_change_type(i,x,y,PT_FIRE);
- part_change_type(r>>8,x+rx,y+ry,PT_FIRE);
- parts[i].life = 4;
- parts[r>>8].life = 4;
- }
- else if ((r&0xFF)==PT_WTRV)
- {
- if(!(rand()%250))
- {
- part_change_type(i, x, y, PT_CAUS);
- parts[i].life = (rand()%50)+25;
- kill_part(r>>8);
- }
- }
- else if (((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && ptypes[r&0xFF].hardness>(rand()%1000))&&parts[i].life>=50)
- {
- if (parts_avg(i, r>>8,PT_GLAS)!= PT_GLAS)//GLAS protects stuff from acid
- {
- float newtemp = ((60.0f-(float)ptypes[r&0xFF].hardness))*7.0f;
- if(newtemp < 0){
- newtemp = 0;
- }
- parts[i].temp += newtemp;
- parts[i].life--;
- kill_part(r>>8);
- }
- }
- else if (parts[i].life<=50)
- {
- kill_part(i);
- return 1;
- }
- }
- }
- for ( trade = 0; trade<2; trade ++)
- {
- rx = rand()%5-2;
- ry = rand()%5-2;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if ((r>>8)>=NPART || !r)
- continue;
- if ((r&0xFF)==PT_ACID&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0)//diffusion
- {
- int temp = parts[i].life - parts[r>>8].life;
- if (temp ==1)
- {
- parts[r>>8].life ++;
- parts[i].life --;
- }
- else if (temp>0)
- {
- parts[r>>8].life += temp/2;
- parts[i].life -= temp/2;
- }
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/amtr.c b/src/elements/amtr.c
deleted file mode 100644
index dcbad5f..0000000
--- a/src/elements/amtr.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_AMTR(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_AMTR && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_NONE && (r&0xFF)!=PT_PHOT && (r&0xFF)!=PT_VOID && (r&0xFF)!=PT_BHOL && (r&0xFF)!=PT_NBHL && (r&0xFF)!=PT_PRTI && (r&0xFF)!=PT_PRTO)
- {
- parts[i].life++;
- if (parts[i].life==4)
- {
- kill_part(i);
- return 1;
- }
- if (10>(rand()/(RAND_MAX/100)))
- create_part(r>>8, x+rx, y+ry, PT_PHOT);
- else
- kill_part(r>>8);
- pv[y/CELL][x/CELL] -= 2.0f;
- }
- }
- return 0;
-}
diff --git a/src/elements/anar.c b/src/elements/anar.c
deleted file mode 100644
index c6fb880..0000000
--- a/src/elements/anar.c
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_ANAR(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
-
- //if (parts[i].temp >= 0.23)
- // parts[i].temp --;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_HFLM)
- {
- if (1>rand()%22)
- {
- part_change_type(i,x,y,PT_HFLM);
- parts[i].life = rand()%150+50;
- parts[r>>8].temp = parts[i].temp = 0;
- pv[y/CELL][x/CELL] -= 0.5;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/aray.c b/src/elements/aray.c
deleted file mode 100644
index e569d84..0000000
--- a/src/elements/aray.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_ARAY(UPDATE_FUNC_ARGS) {
- int r, nxx, nyy, docontinue, nxi, nyi, rx, ry, nr, ry1, rx1;
- if (parts[i].life==0) {
- int colored =0;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_SPRK && parts[r>>8].life==3) {
- int destroy = (parts[r>>8].ctype==PT_PSCN)?1:0;
- int nostop = (parts[r>>8].ctype==PT_INST)?1:0;
- for (docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1; docontinue; nyy+=nyi, nxx+=nxi) {
- if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0)) {
- break;
- }
- r = pmap[y+nyi+nyy][x+nxi+nxx];
- if (!r) {
- int nr = create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_BRAY);
- if (nr!=-1) {
- if (destroy) {//if it came from PSCN
- parts[nr].tmp = 2;
- parts[nr].life = 2;
- } else
- parts[nr].ctype = colored;
- parts[nr].temp = parts[i].temp;
- }
- } else if (!destroy) {
- if ((r&0xFF)==PT_BRAY&&parts[r>>8].tmp==0) {//if it hits another BRAY that isn't red
- if (nyy!=0 || nxx!=0) {
- parts[r>>8].life = 1020;//makes it last a while
- parts[r>>8].tmp = 1;
- if (!parts[r>>8].ctype)//and colors it if it isn't already
- parts[r>>8].ctype = colored;
- }
- docontinue = 0;//then stop it
- } else if ((r&0xFF)==PT_BRAY&&parts[r>>8].tmp==1) {//if it hits one that already was a long life, reset it
- parts[r>>8].life = 1020;
- //docontinue = 1;
- } else if ((r&0xFF)==PT_FILT) {//get color if passed through FILT
- colored = parts[r>>8].ctype;
- //this if prevents BRAY from stopping on certain materials
- } else if ((r&0xFF)!=PT_STOR && (r&0xFF)!=PT_INWR && ((r&0xFF)!=PT_SPRK || parts[r>>8].ctype!=PT_INWR) && (r&0xFF)!=PT_ARAY && (r&0xFF)!=PT_WIFI && !((r&0xFF)==PT_SWCH && parts[r>>8].life>=10)) {
- if (nyy!=0 || nxx!=0) {
- create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_SPRK);
- }
- if (!(nostop && parts[r>>8].type==PT_SPRK && parts[r>>8].ctype >= 0 && parts[r>>8].ctype < PT_NUM && (ptypes[parts[r>>8].ctype].properties&PROP_CONDUCTS))) {
- docontinue = 0;
- } else {
- docontinue = 1;
- }
- } else if((r&0xFF)==PT_STOR) {
- if(parts[r>>8].tmp)
- {
- //Cause STOR to release
- for(ry1 = 1; ry1 >= -1; ry1--){
- for(rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1-rx1+1){
- int np = create_part(-1, x+nxi+nxx+rx1, y+nyi+nyy+ry1, parts[r>>8].tmp);
- if (np!=-1)
- {
- parts[np].temp = parts[r>>8].temp;
- parts[np].life = parts[r>>8].tmp2;
- parts[np].tmp = parts[r>>8].pavg[0];
- parts[np].ctype = parts[r>>8].pavg[1];
- parts[r>>8].tmp = 0;
- parts[r>>8].life = 10;
- break;
- }
- }
- }
- }
- else
- {
- parts[r>>8].life = 10;
- }
- }
- } else if (destroy) {
- if ((r&0xFF)==PT_BRAY) {
- parts[r>>8].life = 1;
- docontinue = 1;
- //this if prevents red BRAY from stopping on certain materials
- } else if ((r&0xFF)==PT_STOR || (r&0xFF)==PT_INWR || ((r&0xFF)==PT_SPRK && parts[r>>8].ctype==PT_INWR) || (r&0xFF)==PT_ARAY || (r&0xFF)==PT_WIFI || (r&0xFF)==PT_FILT || ((r&0xFF)==PT_SWCH && parts[r>>8].life>=10)) {
- if((r&0xFF)==PT_STOR)
- {
- parts[r>>8].tmp = 0;
- parts[r>>8].life = 0;
- }
- docontinue = 1;
- } else {
- docontinue = 0;
- }
- }
- }
- }
- //parts[i].life = 4;
- }
- }
- return 0;
-}
diff --git a/src/elements/bang.c b/src/elements/bang.c
deleted file mode 100644
index 1a2a1ec..0000000
--- a/src/elements/bang.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_BANG(UPDATE_FUNC_ARGS) {
- int r, rx, ry, nb;
- if(parts[i].tmp==0)
- {
- if(parts[i].temp>=673.0f)
- parts[i].tmp = 1;
- else
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM)
- {
- parts[i].tmp = 1;
- }
- else if ((r&0xFF)==PT_SPRK || (r&0xFF)==PT_LIGH)
- {
- parts[i].tmp = 1;
- }
- }
-
- }
- else if(parts[i].tmp==1)
- {
- int tempvalue = 2;
- flood_prop(x, y, offsetof(particle, tmp), &tempvalue, 0);
- parts[i].tmp = 2;
- }
- else if(parts[i].tmp==2)
- {
- parts[i].tmp = 3;
- }
- else if(parts[i].tmp>=3)
- {
- float otemp = parts[i].temp-275.13f;
- //Explode!!
- pv[y/CELL][x/CELL] += 0.5f;
- parts[i].tmp = 0;
- if(!(rand()%3))
- {
- if(!(rand()%2))
- {
- create_part(i, x, y, PT_FIRE);
- parts[i].temp = restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP);
- }
- else
- {
- create_part(i, x, y, PT_SMKE);
- parts[i].temp = restrict_flt((MAX_TEMP/4)+otemp, MIN_TEMP, MAX_TEMP);
- }
- }
- else
- {
- if(!(rand()%15))
- {
- 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
- {
- kill_part(i);
- }
- }
- return 1;
- }
- return 0;
-}
diff --git a/src/elements/bcln.c b/src/elements/bcln.c
deleted file mode 100644
index 63a2bbc..0000000
--- a/src/elements/bcln.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_BCLN(UPDATE_FUNC_ARGS) {
- if (!parts[i].life && pv[y/CELL][x/CELL]>4.0f)
- parts[i].life = rand()%40+80;
- if (parts[i].life)
- {
- float advection = 0.1f;
- parts[i].vx += advection*vx[y/CELL][x/CELL];
- parts[i].vy += advection*vy[y/CELL][x/CELL];
- }
- if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !ptypes[parts[i].ctype].enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT)))
- {
- int r, rx, ry;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
- {
- r = photons[y+ry][x+rx];
- if (!r)
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN &&
- (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_STKM &&
- (r&0xFF)!=PT_PBCN && (r&0xFF)!=PT_STKM2 &&
- (r&0xFF)<PT_NUM)
- {
- parts[i].ctype = r&0xFF;
- if ((r&0xFF)==PT_LIFE || (r&0xFF)==PT_LAVA)
- parts[i].tmp = parts[r>>8].ctype;
- }
- }
- }
- else {
- if (parts[i].ctype==PT_LIFE) create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype|(parts[i].tmp<<8));
- else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0)
- {
- int np = create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
- if (np>=0)
- {
- if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && ptransitions[parts[i].tmp].tht==PT_LAVA)
- parts[np].ctype = parts[i].tmp;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/bcol.c b/src/elements/bcol.c
deleted file mode 100644
index 1593470..0000000
--- a/src/elements/bcol.c
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_BCOL(UPDATE_FUNC_ARGS) {
- int r, rx, ry, trade, temp;
- if (parts[i].life<=0) {
- create_part(i, x, y, PT_FIRE);
- return 1;
- } else if (parts[i].life < 100) {
- parts[i].life--;
- create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE);
- }
-
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM) && 1>(rand()%500))
- {
- if (parts[i].life>100) {
- parts[i].life = 99;
- }
- }
- if ((r&0xFF)==PT_LAVA && 1>(rand()%500))
- {
- if (parts[r>>8].ctype == PT_IRON) {
- parts[r>>8].ctype = PT_METL;
- kill_part(i);
- return 1;
- }
- }
- }
- /*if(100-parts[i].life > parts[i].tmp2)
- parts[i].tmp2 = 100-parts[i].life;
- if(parts[i].tmp2 < 0) parts[i].tmp2 = 0;
- for ( trade = 0; trade<4; trade ++)
- {
- rx = rand()%5-2;
- ry = rand()%5-2;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_COAL || (r&0xFF)==PT_BCOL)&&(parts[i].tmp2>parts[r>>8].tmp2)&&parts[i].tmp2>0)//diffusion
- {
- int temp = parts[i].tmp2 - parts[r>>8].tmp2;
- if(temp < 10)
- continue;
- if (temp ==1)
- {
- parts[r>>8].tmp2 ++;
- parts[i].tmp2 --;
- }
- else if (temp>0)
- {
- parts[r>>8].tmp2 += temp/2;
- parts[i].tmp2 -= temp/2;
- }
- }
- }
- }*/
- if(parts[i].temp > parts[i].tmp2)
- parts[i].tmp2 = parts[i].temp;
- return 0;
-}
diff --git a/src/elements/bizr.c b/src/elements/bizr.c
deleted file mode 100644
index e0fbd84..0000000
--- a/src/elements/bizr.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-//Used by ALL 3 BIZR states
-int update_BIZR(UPDATE_FUNC_ARGS) {
- int r, rx, ry, nr, ng, nb, na;
- float tr, tg, tb, ta, mr, mg, mb, ma;
- float blend;
- if(parts[i].dcolour){
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_BIZR && (r&0xFF)!=PT_BIZRG && (r&0xFF)!=PT_BIZRS)
- {
- blend = 0.95f;
- tr = (parts[r>>8].dcolour>>16)&0xFF;
- tg = (parts[r>>8].dcolour>>8)&0xFF;
- tb = (parts[r>>8].dcolour)&0xFF;
- ta = (parts[r>>8].dcolour>>24)&0xFF;
-
- mr = (parts[i].dcolour>>16)&0xFF;
- mg = (parts[i].dcolour>>8)&0xFF;
- mb = (parts[i].dcolour)&0xFF;
- ma = (parts[i].dcolour>>24)&0xFF;
-
- nr = (tr*blend) + (mr*(1-blend));
- ng = (tg*blend) + (mg*(1-blend));
- nb = (tb*blend) + (mb*(1-blend));
- na = (ta*blend) + (ma*(1-blend));
-
- parts[r>>8].dcolour = nr<<16 | ng<<8 | nb | na<<24;
- }
- }
- }
- if(((r = photons[y][x])&0xFF)==PT_PHOT || ((r = pmap[y][x])&0xFF)==PT_PHOT)
- {
- part_change_type(r>>8, x, y, PT_ELEC);
- parts[r>>8].ctype = 0;
- }
- return 0;
-}
diff --git a/src/elements/bmtl.c b/src/elements/bmtl.c
deleted file mode 100644
index 06c2f47..0000000
--- a/src/elements/bmtl.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_BMTL(UPDATE_FUNC_ARGS) {
- int r, rx, ry, rt, tempFactor;
- if (parts[i].tmp>1)
- {
- parts[i].tmp--;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- rt = parts[r>>8].type;
- if ((rt==PT_METL || rt==PT_IRON) && 1>(rand()/(RAND_MAX/100)))
- {
- part_change_type(r>>8,x+rx,y+ry,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;
- part_change_type(i,x,y,PT_BRMT);
- }
- return 0;
-}
diff --git a/src/elements/bomb.c b/src/elements/bomb.c
deleted file mode 100644
index f60c86b..0000000
--- a/src/elements/bomb.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_BOMB(UPDATE_FUNC_ARGS) {
- int r, rx, ry, nb;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_BOMB && (r&0xFF)!=PT_EMBR && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_BCLN)
- {
- int rad = 8;
- int nxi;
- int nxj;
- pmap[y][x] = 0;
- for (nxj=-rad; nxj<=rad; nxj++)
- for (nxi=-rad; nxi<=rad; nxi++)
- if ((pow(nxi,2))/(pow(rad,2))+(pow(nxj,2))/(pow(rad,2))<=1)
- if ((pmap[y+nxj][x+nxi]&0xFF)!=PT_DMND && (pmap[y+nxj][x+nxi]&0xFF)!=PT_CLNE && (pmap[y+nxj][x+nxi]&0xFF)!=PT_PCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_BCLN) {
- delete_part(x+nxi, y+nxj, 0);
- pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f;
- nb = create_part(-3, x+nxi, y+nxj, PT_EMBR);
- if (nb!=-1) {
- parts[nb].tmp = 2;
- parts[nb].life = 2;
- parts[nb].temp = MAX_TEMP;
- }
- }
- for (nxj=-(rad+1); nxj<=(rad+1); nxj++)
- for (nxi=-(rad+1); nxi<=(rad+1); nxi++)
- if ((pow(nxi,2))/(pow((rad+1),2))+(pow(nxj,2))/(pow((rad+1),2))<=1 && !(pmap[y+nxj][x+nxi]&0xFF)) {
- nb = create_part(-3, x+nxi, y+nxj, PT_EMBR);
- if (nb!=-1) {
- parts[nb].tmp = 0;
- parts[nb].life = 50;
- parts[nb].temp = MAX_TEMP;
- parts[nb].vx = rand()%40-20;
- parts[nb].vy = rand()%40-20;
- }
- }
- kill_part(i);
- return 1;
- }
- }
- return 0;
-}
-int graphics_BOMB(GRAPHICS_FUNC_ARGS)
-{
- *pixel_mode |= PMODE_FLARE;
- return 1;
-}
diff --git a/src/elements/boyl.c b/src/elements/boyl.c
deleted file mode 100644
index 5121e9c..0000000
--- a/src/elements/boyl.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_BOYL(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- if (pv[y/CELL][x/CELL]<(parts[i].temp/100))
- pv[y/CELL][x/CELL] += 0.001f*((parts[i].temp/100)-pv[y/CELL][x/CELL]);
- if (y+CELL<YRES && pv[y/CELL+1][x/CELL]<(parts[i].temp/100))
- pv[y/CELL+1][x/CELL] += 0.001f*((parts[i].temp/100)-pv[y/CELL+1][x/CELL]);
- if (x+CELL<XRES)
- {
- pv[y/CELL][x/CELL+1] += 0.001f*((parts[i].temp/100)-pv[y/CELL][x/CELL+1]);
- if (y+CELL<YRES)
- pv[y/CELL+1][x/CELL+1] += 0.001f*((parts[i].temp/100)-pv[y/CELL+1][x/CELL+1]);
- }
- if (y-CELL>=0 && pv[y/CELL-1][x/CELL]<(parts[i].temp/100))
- pv[y/CELL-1][x/CELL] += 0.001f*((parts[i].temp/100)-pv[y/CELL-1][x/CELL]);
- if (x-CELL>=0)
- {
- pv[y/CELL][x/CELL-1] += 0.001f*((parts[i].temp/100)-pv[y/CELL][x/CELL-1]);
- if (y-CELL>=0)
- pv[y/CELL-1][x/CELL-1] += 0.001f*((parts[i].temp/100)-pv[y/CELL-1][x/CELL-1]);
- }
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 &&
- x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_WATR && 1>rand()%30)
- {
- part_change_type(r>>8,x+rx,y+ry,PT_FOG);
- }
- else if ((r&0xFF)==PT_O2 && 1>rand()%9)
- {
- kill_part(r>>8);
- part_change_type(i,x,y,PT_WATR);
- pv[y/CELL][x/CELL] += 4.0;
- }
- }
- return 0;
-}
diff --git a/src/elements/brel.c b/src/elements/brel.c
deleted file mode 100644
index c97118b..0000000
--- a/src/elements/brel.c
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_BREL(UPDATE_FUNC_ARGS) {
- int np;
- if (1>rand()%200 && (pv[y/CELL][x/CELL] > 30.0f) && parts[i].temp>9000 && parts[i].life>0)
- {
- part_change_type(i, x ,y ,PT_EXOT);
- parts[i].life = 1000;
- }
- if ((pv[y/CELL][x/CELL] > 10.0f) && (parts[i].life>0)) {
- parts[i].temp = parts[i].temp + (pv[y/CELL][x/CELL])/8;
- }
- return 0;
-}
-
diff --git a/src/elements/brmt.c b/src/elements/brmt.c
deleted file mode 100644
index 99702a2..0000000
--- a/src/elements/brmt.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_BRMT(UPDATE_FUNC_ARGS) {
- int r, rx, ry, rt, tempFactor;
- if (parts[i].temp > (250.0f+273.15f))
- {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- rt = parts[r>>8].type;
- tempFactor = 1000 - (((250.0f+273.15f)-parts[i].temp)*2);
- if(tempFactor < 2)
- tempFactor = 2;
- if ((rt==PT_BREL) && 1 > (rand()%tempFactor))
- {
- if(rand()%2)
- {
- create_part(r>>8, x+rx, y+ry, PT_THRM);
- }
- else
- { create_part(i, x, y, PT_THRM);
- }
- return 1;
- //part_change_type(r>>8,x+rx,y+ry,PT_BMTL);
- //parts[r>>8].tmp=(parts[i].tmp<=7)?parts[i].tmp=1:parts[i].tmp-(rand()%5);//rand()/(RAND_MAX/300)+100;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/btry.c b/src/elements/btry.c
deleted file mode 100644
index d220b83..0000000
--- a/src/elements/btry.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_BTRY(UPDATE_FUNC_ARGS) {
- int r, rx, ry, rt;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- rt = parts[r>>8].type;
- if (parts_avg(i,r>>8,PT_INSL) != PT_INSL)
- {
- if ((ptypes[rt].properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[r>>8].life==0 && abs(rx)+abs(ry) < 4)
- {
- parts[r>>8].life = 4;
- parts[r>>8].ctype = rt;
- part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/c5.c b/src/elements/c5.c
deleted file mode 100644
index 827df6d..0000000
--- a/src/elements/c5.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_C5(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)!=PT_C5 && parts[r>>8].temp<100 && ptypes[r&0xFF].hconduct && ((r&0xFF)!=PT_HSWC||parts[r>>8].life==10)) || (r&0xFF)==PT_HFLM)
- {
- if (1>rand()%6)
- {
- part_change_type(i,x,y,PT_HFLM);
- parts[r>>8].temp = parts[i].temp = 0;
- parts[i].life = rand()%150+50;
- pv[y/CELL][x/CELL] += 1.5;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/caus.c b/src/elements/caus.c
deleted file mode 100644
index 012b4c4..0000000
--- a/src/elements/caus.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_CAUS(UPDATE_FUNC_ARGS) {
- int r, rx, ry, trade, np;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_ACID && (r&0xFF)!=PT_CAUS)
- {
- if (((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN && ptypes[r&0xFF].hardness>(rand()%1000))&&parts[i].life>=50)
- {
- if (parts_avg(i, r>>8,PT_GLAS)!= PT_GLAS)//GLAS protects stuff from acid
- {
- float newtemp = ((60.0f-(float)ptypes[r&0xFF].hardness))*7.0f;
- if(newtemp < 0){
- newtemp = 0;
- }
- parts[i].temp += newtemp;
- parts[i].life--;
- kill_part(r>>8);
- }
- }
- else if (parts[i].life<=50)
- {
- kill_part(i);
- return 1;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/cbnw.c b/src/elements/cbnw.c
deleted file mode 100644
index 8d68c84..0000000
--- a/src/elements/cbnw.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_CBNW(UPDATE_FUNC_ARGS) {
- int r, rx, ry, oldt;
- oldt = parts[i].tmp;
- if (pv[y/CELL][x/CELL]<=3)
- {
- if(20>(rand()%80000))
- {
- part_change_type(i,x,y,PT_CO2);
- parts[i].ctype = 5;
- pv[y/CELL][x/CELL] += 0.5f;
- }
- else if(pv[y/CELL][x/CELL]<=-0.5)
- {
- part_change_type(i,x,y,PT_CO2);
- parts[i].ctype = 5;
- pv[y/CELL][x/CELL] += 0.5f;
- }
- }
- if (parts[i].tmp>0)
- parts[i].tmp--;
- if(!(rand()%200))
- {
- parts[i].tmp2 = rand()%40;
- } else if(parts[i].tmp2!=20) {
- parts[i].tmp2 -= (parts[i].tmp2>20)?1:-1;
- }
- if(oldt==1)
- {
- //Explode
- if(rand()%4)
- {
- part_change_type(i,x,y,PT_CO2);
- parts[i].ctype = 5;
- pv[y/CELL][x/CELL] += 0.2f;
- }
- }
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (ptypes[r&0xFF].properties&TYPE_PART && parts[i].tmp == 0 && 1>(rand()%250))
- {
- //Start explode
- parts[i].tmp = rand()%25;//(rand()%100)+50;
- }
- else if(ptypes[r&0xFF].properties&TYPE_SOLID && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_GLAS && parts[i].tmp == 0 && (2-pv[y/CELL][x/CELL])>(rand()%20000))
- {
- if(rand()%2)
- {
- part_change_type(i,x,y,PT_CO2);
- parts[i].ctype = 5;
- pv[y/CELL][x/CELL] += 0.2f;
- }
- }
- if ((r&0xFF)==PT_CBNW)
- {
- if(!parts[i].tmp && parts[r>>8].tmp)
- {
- parts[i].tmp = parts[r>>8].tmp;
- if((r>>8)>i) //If the other particle hasn't been life updated
- parts[i].tmp--;
- }
- else if(parts[i].tmp && !parts[r>>8].tmp)
- {
- parts[r>>8].tmp = parts[i].tmp;
- if((r>>8)>i) //If the other particle hasn't been life updated
- parts[r>>8].tmp++;
- }
- }
- if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (legacy_enable||parts[i].temp>(273.15f+12.0f)) && 1>(rand()%500))
- {
- part_change_type(i,x,y,PT_FIRE);
- parts[i].life = 4;
- parts[i].ctype = PT_WATR;
- }
- if ((r&0xFF)==PT_FIRE && parts[r>>8].ctype!=PT_WATR){
- kill_part(r>>8);
- if(1>(rand()%150)){
- kill_part(i);
- return 1;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/clne.c b/src/elements/clne.c
deleted file mode 100644
index 05834b0..0000000
--- a/src/elements/clne.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_CLNE(UPDATE_FUNC_ARGS) {
- if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !ptypes[parts[i].ctype].enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT)))
- {
- int r, rx, ry;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
- {
- r = photons[y+ry][x+rx];
- if (!r)
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN &&
- (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_STKM &&
- (r&0xFF)!=PT_PBCN && (r&0xFF)!=PT_STKM2 &&
- (r&0xFF)<PT_NUM)
- {
- parts[i].ctype = r&0xFF;
- if ((r&0xFF)==PT_LIFE || (r&0xFF)==PT_LAVA)
- parts[i].tmp = parts[r>>8].ctype;
- }
- }
- }
- else {
- if (parts[i].ctype==PT_LIFE) create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype|(parts[i].tmp<<8));
- else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0)
- {
- int np = create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
- if (np>=0)
- {
- if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && ptransitions[parts[i].tmp].tht==PT_LAVA)
- parts[np].ctype = parts[i].tmp;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/clst.c b/src/elements/clst.c
deleted file mode 100644
index 8fe1a6c..0000000
--- a/src/elements/clst.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_CLST(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- float cxy;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_WATR && 1>(rand()%1500))
- {
- part_change_type(i,x,y,PT_PSTS);
- kill_part(r>>8);
- }
- if ((r&0xFF)==PT_NITR)
- {
- create_part(i, x, y, PT_BANG);
- create_part(r>>8, x+rx, y+ry, PT_BANG);
- }
- if ((r&0xFF)==PT_CLST)
- {
- if(parts[i].temp <195)
- cxy = 0.05;
- if(parts[i].temp >= 195 && parts[i].temp <295)
- cxy = 0.015;
- if(parts[i].temp >= 295 && parts[i].temp <350)
- cxy = 0.01;
- if(parts[i].temp > 350)
- cxy = 0.005;
- parts[i].vx += cxy*rx;
- parts[i].vy += cxy*ry;//These two can be set not to calculate over 350 later. They do virtually nothing over 0.005.
- }
- }
- return 0;
-}
diff --git a/src/elements/co2.c b/src/elements/co2.c
deleted file mode 100644
index d25b5f5..0000000
--- a/src/elements/co2.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_CO2(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (parts[i].ctype==5 && 20>(rand()%40000))
- {
- if (create_part(-1, x+rx, y+ry, PT_WATR)>=0)
- parts[i].ctype = 0;
- }
- if ((r>>8)>=NPART || !r)
- continue;
- if ((r&0xFF)==PT_FIRE){
- kill_part(r>>8);
- if(1>(rand()%150)){
- kill_part(i);
- return 1;
- }
- }
- if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 1>(rand()%250))
- {
- part_change_type(r>>8, x+rx, y+ry, PT_CBNW);
- if (parts[i].ctype==5) //conserve number of water particles - ctype=5 means this CO2 hasn't released the water particle from BUBW yet
- create_part(i, x, y, PT_WATR);
- else
- kill_part(i);
- }
- }
- if (parts[i].temp > 9773.15 && pv[y/CELL][x/CELL] > 200.0f)
- {
- if (rand()%5 < 1)
- {
- int j;
- create_part(i,x,y,PT_O2);
-
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1) parts[j].temp = 15000;
- if (!(rand()%50)) { j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); if (j != -1) parts[j].temp = 15000; }
-
- parts[i].temp = 15000;
- pv[y/CELL][x/CELL] += 100;
- }
- }
- return 0;
-}
diff --git a/src/elements/coal.c b/src/elements/coal.c
deleted file mode 100644
index 63eca57..0000000
--- a/src/elements/coal.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_COAL(UPDATE_FUNC_ARGS) {
- int r, rx, ry, trade, temp;
- if (parts[i].life<=0) {
- create_part(i, x, y, PT_FIRE);
- return 1;
- } else if (parts[i].life < 100) {
- parts[i].life--;
- create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE);
- }
- if ((pv[y/CELL][x/CELL] > 4.3f)&&parts[i].tmp>40)
- parts[i].tmp=39;
- else if (parts[i].tmp<40&&parts[i].tmp>0)
- parts[i].tmp--;
- else if (parts[i].tmp<=0) {
- create_part(i, x, y, PT_BCOL);
- return 1;
- }
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM) && 1>(rand()%500))
- {
- if (parts[i].life>100) {
- parts[i].life = 99;
- }
- }
- if ((r&0xFF)==PT_LAVA && 1>(rand()%500))
- {
- if (parts[r>>8].ctype == PT_IRON) {
- parts[r>>8].ctype = PT_METL;
- kill_part(i);
- return 1;
- }
- }
- }
- /*if(100-parts[i].life > parts[i].tmp2)
- parts[i].tmp2 = 100-parts[i].life;
- if(parts[i].tmp2 < 0) parts[i].tmp2 = 0;
- for ( trade = 0; trade<4; trade ++)
- {
- rx = rand()%5-2;
- ry = rand()%5-2;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_COAL || (r&0xFF)==PT_BCOL)&&(parts[i].tmp2>parts[r>>8].tmp2)&&parts[i].tmp2>0)//diffusion
- {
- int temp = parts[i].tmp2 - parts[r>>8].tmp2;
- if(temp < 10)
- continue;
- if (temp ==1)
- {
- parts[r>>8].tmp2 ++;
- parts[i].tmp2 --;
- }
- else if (temp>0)
- {
- parts[r>>8].tmp2 += temp/2;
- parts[i].tmp2 -= temp/2;
- }
- }
- }
- }*/
- if(parts[i].temp > parts[i].tmp2)
- parts[i].tmp2 = parts[i].temp;
- return 0;
-}
diff --git a/src/elements/conv.c b/src/elements/conv.c
deleted file mode 100644
index 95edc0c..0000000
--- a/src/elements/conv.c
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_CONV(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !ptypes[parts[i].ctype].enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT)))
- {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
- {
- r = photons[y+ry][x+rx];
- if (!r)
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN &&
- (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_STKM &&
- (r&0xFF)!=PT_PBCN && (r&0xFF)!=PT_STKM2 &&
- (r&0xFF)!=PT_CONV && (r&0xFF)<PT_NUM)
- {
- parts[i].ctype = r&0xFF;
- if ((r&0xFF)==PT_LIFE)
- parts[i].tmp = parts[r>>8].ctype;
- }
- }
- }
- else if(parts[i].ctype>0 && parts[i].ctype<PT_NUM && ptypes[parts[i].ctype].enabled && parts[i].ctype!=PT_CONV) {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
- {
- r = photons[y+ry][x+rx];
- if (!r)
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if((r&0xFF)!=PT_CONV && (r&0xFF)!=PT_DMND && (r&0xFF)!=parts[i].ctype)
- {
- if (parts[i].ctype==PT_LIFE) create_part(r>>8, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8));
- else create_part(r>>8, x+rx, y+ry, parts[i].ctype);
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/dest.c b/src/elements/dest.c
deleted file mode 100644
index b6d5e71..0000000
--- a/src/elements/dest.c
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_DEST(UPDATE_FUNC_ARGS) {
- int r,rx,ry,topv;
- rx=rand()%5-2;
- ry=rand()%5-2;
-
- r = pmap[y+ry][x+rx];
- if (!r || (r&0xFF)==PT_DEST || (r&0xFF)==PT_DMND || (r&0xFF)==PT_BCLN || (r&0xFF)==PT_CLNE || (r&0xFF)==PT_PCLN || (r&0xFF)==PT_PBCN)
- return 0;
-
- if (parts[i].life<=0 || parts[i].life>37)
- {
- parts[i].life=30+rand()%20;
- parts[i].temp+=20000;
- pv[y/CELL][x/CELL]+=60.0f;
- }
- parts[i].temp+=10000;
- if ((r&0xFF)==PT_PLUT || (r&0xFF)==PT_DEUT)
- {
- pv[y/CELL][x/CELL]+=20.0f;
- parts[i].temp+=18000;
- if (rand()%2==0)
- {
- float orig_temp = parts[r>>8].temp;
- create_part(r>>8, x+rx, y+ry, PT_NEUT);
- parts[r>>8].temp = restrict_flt(orig_temp+40000.0f, MIN_TEMP, MAX_TEMP);
- pv[y/CELL][x/CELL] += 10.0f;
- parts[i].life-=4;
- }
- }
- else if ((r&0xFF)==PT_INSL)
- {
- create_part(r>>8, x+rx, y+ry, PT_PLSM);
- }
- else if (rand()%3==0)
- {
- kill_part(r>>8);
- parts[i].life -= 4*((ptypes[r&0xFF].properties&TYPE_SOLID)?3:1);
- if (parts[i].life<=0)
- parts[i].life=1;
- parts[i].temp+=10000;
- }
- else
- {
- if (ptypes[r&0xFF].hconduct) parts[r>>8].temp = restrict_flt(parts[r>>8].temp+10000.0f, MIN_TEMP, MAX_TEMP);
- }
- topv=pv[y/CELL][x/CELL]/9+parts[r>>8].temp/900;
- if (topv>40.0f)
- topv=40.0f;
- pv[y/CELL][x/CELL]+=40.0f+topv;
- parts[i].temp = restrict_flt(parts[i].temp, MIN_TEMP, MAX_TEMP);
- return 0;
-}
-int graphics_DEST(GRAPHICS_FUNC_ARGS)
-{
- if(cpart->life)
- {
- *pixel_mode |= PMODE_LFLARE;
- }
- else
- {
- *pixel_mode |= PMODE_SPARK;
- }
- return 0;
-}
diff --git a/src/elements/deut.c b/src/elements/deut.c
deleted file mode 100644
index 73b95a9..0000000
--- a/src/elements/deut.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_DEUT(UPDATE_FUNC_ARGS) {
- int r, rx, ry, trade, np;
- float gravtot = fabs(gravy[(y/CELL)*(XRES/CELL)+(x/CELL)])+fabs(gravx[(y/CELL)*(XRES/CELL)+(x/CELL)]);
- int maxlife = ((10000/(parts[i].temp + 1))-1);
- if ((10000%((int)parts[i].temp+1))>rand()%((int)parts[i].temp+1))
- maxlife ++;
- // Compress when Newtonian gravity is applied
- // multiplier=1 when gravtot=0, multiplier -> 5 as gravtot -> inf
- maxlife = maxlife*(5.0f - 8.0f/(gravtot+2.0f));
- if (parts[i].life < maxlife)
- {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r || (parts[i].life >=maxlife))
- continue;
- if ((r&0xFF)==PT_DEUT&&33>=rand()/(RAND_MAX/100)+1)
- {
- if ((parts[i].life + parts[r>>8].life + 1) <= maxlife)
- {
- parts[i].life += parts[r>>8].life + 1;
- kill_part(r>>8);
- }
- }
- }
- }
- else
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (parts[i].life<=maxlife)
- continue;
- if ((!r)&&parts[i].life>=1)//if nothing then create deut
- {
- np = create_part(-1,x+rx,y+ry,PT_DEUT);
- if (np<0) continue;
- parts[i].life--;
- parts[np].temp = parts[i].temp;
- parts[np].life = 0;
- }
- }
- for ( trade = 0; trade<4; trade ++)
- {
- rx = rand()%5-2;
- ry = rand()%5-2;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_DEUT&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0)//diffusion
- {
- int temp = parts[i].life - parts[r>>8].life;
- if (temp ==1)
- {
- parts[r>>8].life ++;
- parts[i].life --;
- }
- else if (temp>0)
- {
- parts[r>>8].life += temp/2;
- parts[i].life -= temp/2;
- }
- }
- }
- }
- return 0;
-}
-
-int graphics_DEUT(GRAPHICS_FUNC_ARGS)
-{
- if(cpart->life>=240)
- {
- *firea = 60;
- *firer = *colr += cpart->life*1;
- *fireg = *colg += cpart->life*2;
- *fireb = *colb += cpart->life*3;
- *pixel_mode |= PMODE_GLOW | FIRE_ADD;
- }
- else
- {
- *colr += cpart->life*1;
- *colg += cpart->life*2;
- *colb += cpart->life*3;
- *pixel_mode |= PMODE_BLUR;
- }
- return 0;
-}
diff --git a/src/elements/dlay.c b/src/elements/dlay.c
deleted file mode 100644
index 961b115..0000000
--- a/src/elements/dlay.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_DLAY(UPDATE_FUNC_ARGS) {
- int r, rx, ry, oldl;
- oldl = parts[i].life;
- if (parts[i].life>0)
- parts[i].life--;
- //if (parts[i].life==1)
- //{
- if (parts[i].temp>=MAX_TEMP+273.15f)
- parts[i].temp = MAX_TEMP+273.15f;
- if (parts[i].temp<= 1.0f+273.15f)
- parts[i].temp = 1.0f+273.15f;
-
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r || parts_avg(r>>8, i,PT_INSL)==PT_INSL)
- continue;
- if ((r&0xFF)==PT_SPRK && parts[i].life==0 && parts[r>>8].life>0 && parts[r>>8].life<4 && parts[r>>8].ctype==PT_PSCN)
- {
- parts[i].life = (int)(parts[i].temp-273.15);
- }
- else if ((r&0xFF)==PT_DLAY)
- {
- if(!parts[i].life && parts[r>>8].life)
- {
- parts[i].life = parts[r>>8].life;
- if((r>>8)>i) //If the other particle hasn't been life updated
- parts[i].life--;
- }
- else if(parts[i].life && !parts[r>>8].life)
- {
- parts[r>>8].life = parts[i].life;
- if((r>>8)>i) //If the other particle hasn't been life updated
- parts[r>>8].life++;
- }
- }
- else if((r&0xFF)==PT_NSCN && oldl==1)
- {
- create_part(-1, x+rx, y+ry, PT_SPRK);
- }
- }
- //}
- return 0;
-}
diff --git a/src/elements/dstw.c b/src/elements/dstw.c
deleted file mode 100644
index a0aa23b..0000000
--- a/src/elements/dstw.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_DSTW(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_SALT && 1>(rand()%250))
- {
- part_change_type(i,x,y,PT_SLTW);
- // on average, convert 3 DSTW to SLTW before SALT turns into SLTW
- if (rand()%3==0)
- part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
- }
- if (((r&0xFF)==PT_WATR||(r&0xFF)==PT_SLTW) && 1>(rand()%500))
- {
- part_change_type(i,x,y,PT_WATR);
- }
- if ((r&0xFF)==PT_SLTW && 1>(rand()%10000))
- {
- part_change_type(i,x,y,PT_SLTW);
- }
- if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (legacy_enable||parts[i].temp>12.0f) && 1>(rand()%500))
- {
- part_change_type(i,x,y,PT_FIRE);
- parts[i].life = 4;
- }
- if ((r&0xFF)==PT_FIRE){
- kill_part(r>>8);
- if(1>(rand()%150)){
- kill_part(i);
- return 1;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/dtec.c b/src/elements/dtec.c
deleted file mode 100644
index 28058e7..0000000
--- a/src/elements/dtec.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_DTEC(UPDATE_FUNC_ARGS) {
- int r, rx, ry, rt, rd = parts[i].tmp2;
- if (rd > 25) parts[i].tmp2 = rd = 25;
- if (parts[i].life)
- {
- parts[i].life = 0;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- rt = parts[r>>8].type;
- if (parts_avg(i,r>>8,PT_INSL) != PT_INSL)
- {
- if ((ptypes[rt].properties&PROP_CONDUCTS) && !(rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR) && parts[r>>8].life==0 && in_radius(rd, rx, ry))
- {
- parts[r>>8].life = 4;
- parts[r>>8].ctype = rt;
- part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
- }
- }
- }
- }
- for (rx=-rd; rx<rd+1; rx++)
- for (ry=-rd; ry<rd+1; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (parts[r>>8].type == parts[i].ctype && (parts[i].ctype != PT_LIFE || parts[i].tmp == parts[r>>8].tmp))
- parts[i].life = 1;
- }
- return 0;
-}
-
-int in_radius(int rd, int x, int y)
-{
- return (pow((double)x,2)*pow((double)rd,2)+pow((double)y,2)*pow((double)rd,2)<=pow((double)rd,2)*pow((double)rd,2));
-} \ No newline at end of file
diff --git a/src/elements/elec.c b/src/elements/elec.c
deleted file mode 100644
index bafe939..0000000
--- a/src/elements/elec.c
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_ELEC(UPDATE_FUNC_ARGS) {
- int r, rt, rx, ry, nb, rrx, rry;
- float rr, rrr;
- parts[i].pavg[0] = x;
- parts[i].pavg[1] = y;
- if(pmap[y][x]==PT_GLOW)
- {
- part_change_type(i, x, y, PT_PHOT);
- }
- for (rx=-2; rx<=2; rx++)
- for (ry=-2; ry<=2; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) {
- r = pmap[y+ry][x+rx];
- if (!r)
- r = photons[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_GLAS)
- {
- for (rrx=-1; rrx<=1; rrx++)
- {
- for (rry=-1; rry<=1; rry++)
- {
- if (x+rx+rrx>=0 && y+ry+rry>=0 && x+rx+rrx<XRES && y+ry+rry<YRES) {
- nb = create_part(-1, x+rx+rrx, y+ry+rry, PT_EMBR);
- if (nb!=-1) {
- parts[nb].tmp = 0;
- parts[nb].life = 50;
- parts[nb].temp = parts[i].temp*0.8f;
- parts[nb].vx = rand()%20-10;
- parts[nb].vy = rand()%20-10;
- }
- }
- }
- }
- fire_r[y/CELL][x/CELL] += rand()%200; //D: Doesn't work with OpenGL, also shouldn't be here
- fire_g[y/CELL][x/CELL] += rand()%200;
- fire_b[y/CELL][x/CELL] += rand()%200;
- /* possible alternative, but doesn't work well at the moment because FIRE_ADD divides firea by 8, so the glow isn't strong enough
- create_part(i, x, y, PT_EMBR);
- parts[i].tmp = 2;
- parts[i].life = 2;
- parts[i].ctype = ((rand()%200)<<16) | ((rand()%200)<<8) | (rand()%200);
- */
- kill_part(i);
- return 1;
- }
- if ((r&0xFF)==PT_LCRY)
- {
- parts[r>>8].tmp2 = 5+rand()%5;
- }
- if ((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW || (r&0xFF)==PT_SLTW || (r&0xFF)==PT_CBNW)
- {
- if(rand()<RAND_MAX/3)
- {
- create_part(r>>8, x+rx, y+ry, PT_O2);
- }
- else
- {
- create_part(r>>8, x+rx, y+ry, PT_H2);
- }
- kill_part(i);
- return 1;
- }
- if ((r&0xFF)==PT_NEUT && !pmap[y+ry][x+rx])
- {
- part_change_type(r>>8, x+rx, y+ry, PT_H2);
- parts[r>>8].life = 0;
- parts[r>>8].ctype = 0;
- }
- if ((r&0xFF)==PT_DEUT)
- {
- if(parts[r>>8].life < 6000)
- parts[r>>8].life += 1;
- parts[r>>8].temp = 0;
- parts[i].temp = 0;
- kill_part(i);
- return 1;
- }
- if ((r&0xFF)==PT_EXOT)
- {
- parts[r>>8].tmp2 += 5;
- parts[r>>8].life = 1000;
- }
- if (ptypes[r&0xFF].properties & PROP_CONDUCTS && ((r&0xFF)!=PT_NBLE||parts[i].temp<2273.15))
- {
- create_part(-1, x+rx, y+ry, PT_SPRK);
- kill_part(i);
- return 1;
- }
- }
- return 0;
-}
-
-int graphics_ELEC(GRAPHICS_FUNC_ARGS)
-{
- *firea = 70;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
-
- *pixel_mode |= FIRE_ADD;
- return 0;
-}
diff --git a/src/elements/elementmisc.c b/src/elements/elementmisc.c
deleted file mode 100644
index 71c3379..0000000
--- a/src/elements/elementmisc.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_MISC(UPDATE_FUNC_ARGS) {
- int t = parts[i].type;
- if (t==PT_LOVE)
- ISLOVE=1;
- else if (t==PT_LOLZ)
- ISLOLZ=1;
- else if (t==PT_GRAV)
- ISGRAV=1;
- return 0;
-}
diff --git a/src/elements/embr.c b/src/elements/embr.c
deleted file mode 100644
index 16c4e70..0000000
--- a/src/elements/embr.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-/* ctype - colour RRGGBB (optional)
- * life - decremented each frame, disappears when life reaches zero
- * tmp - mode
- * 0 - BOMB sparks
- * 1 - firework sparks (colour defaults to white)
- * 2 - flash (colour defaults to white)
- */
-int update_EMBR(UPDATE_FUNC_ARGS) {
- int r, rx, ry, nb;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((ptypes[r&0xFF].properties & (TYPE_SOLID | TYPE_PART | TYPE_LIQUID)) && !(ptypes[r&0xFF].properties & PROP_SPARKSETTLE))
- {
- kill_part(i);
- return 1;
- }
- }
- return 0;
-}
-int graphics_EMBR(GRAPHICS_FUNC_ARGS)
-{
- if (cpart->ctype&0xFFFFFF)
- {
- int maxComponent;
- *colr = (cpart->ctype&0xFF0000)>>16;
- *colg = (cpart->ctype&0x00FF00)>>8;
- *colb = (cpart->ctype&0x0000FF);
- maxComponent = *colr;
- if (*colg>maxComponent) maxComponent = *colg;
- if (*colb>maxComponent) maxComponent = *colb;
- if (maxComponent<60)//make sure it isn't too dark to see
- {
- float multiplier = 60.0f/maxComponent;
- *colr *= multiplier;
- *colg *= multiplier;
- *colb *= multiplier;
- }
- }
- else if (cpart->tmp != 0)
- {
- *colr = *colg = *colb = 255;
- }
-
- if (decorations_enable && cpart->dcolour)
- {
- int a = (cpart->dcolour>>24)&0xFF;
- *colr = (a*((cpart->dcolour>>16)&0xFF) + (255-a)**colr) >> 8;
- *colg = (a*((cpart->dcolour>>8)&0xFF) + (255-a)**colg) >> 8;
- *colb = (a*((cpart->dcolour)&0xFF) + (255-a)**colb) >> 8;
- }
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
-
- if (cpart->tmp==1)
- {
- *pixel_mode = FIRE_ADD | PMODE_BLEND | PMODE_GLOW;
- *firea = (cpart->life-15)*4;
- *cola = (cpart->life+15)*4;
- }
- else if (cpart->tmp==2)
- {
- *pixel_mode = PMODE_FLAT | FIRE_ADD;
- *firea = 255;
- }
- else
- {
- *pixel_mode = PMODE_SPARK | PMODE_ADD;
- if (cpart->life<64) *cola = 4*cpart->life;
- }
- return 0;
-}
diff --git a/src/elements/emp.c b/src/elements/emp.c
deleted file mode 100644
index 7b3dbba..0000000
--- a/src/elements/emp.c
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_EMP(UPDATE_FUNC_ARGS) {
- int r,rx,ry,ok=0,t,n,nx,ny;
- if (parts[i].life)
- return 0;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_SPRK && parts[r>>8].life>0 && parts[r>>8].life<4)
- {
- ok=1;
- break;
- }
- }
- if (!ok)
- return 0;
- parts[i].life=220;
- emp_decor+=3;
- if (emp_decor>40)
- emp_decor=40;
- for (r=0; r<=parts_lastActiveIndex; r++)
- {
- t=parts[r].type;
- rx=parts[r].x;
- ry=parts[r].y;
- if (t==PT_SPRK || (t==PT_SWCH && parts[r].life!=0 && parts[r].life!=10) || (t==PT_WIRE && parts[r].ctype>0))
- {
- int is_elec=0;
- if ((parts[r].ctype==PT_PSCN || parts[r].ctype==PT_NSCN || parts[r].ctype==PT_PTCT ||
- parts[r].ctype==PT_NTCT || parts[r].ctype==PT_INST || parts[r].ctype==PT_SWCH) || t==PT_WIRE || t==PT_SWCH)
- {
- is_elec=1;
- if (ptypes[parts[r].type].hconduct && rand()%100==0)
- parts[r].temp = restrict_flt(parts[r].temp+3000.0f, MIN_TEMP, MAX_TEMP);
- if (rand()%80==0)
- part_change_type(r, rx, ry, PT_BREL);
- else if (rand()%120==0)
- part_change_type(r, rx, ry, PT_NTCT);
- }
-
- for (nx=-2; nx<3; nx++)
- for (ny=-2; ny<3; ny++)
- if (rx+nx>=0 && ry+ny>=0 && rx+nx<XRES && ry+ny<YRES && (rx || ry))
- {
- n = pmap[ry+ny][rx+nx];
- if (!n)
- continue;
- /*if ((n&0xFF)==PT_BTRY && rand()%60==0)
- {
- part_change_type(n>>8, rx+nx, ry+ny, PT_PLSM);
- parts[n>>8].life=rand()%100+70;
- parts[n>>8].temp+=3000;
- }*/
-
- //Some elements should only be affected by wire/swch, or by a spark on inst/semiconductor
- //So not affected by spark on metl, watr etc
- if (is_elec)
- {
- if (((n&0xFF)==PT_METL || (n&0xFF)==PT_BMTL) && rand()%280==0)
- {
- parts[n>>8].temp = restrict_flt(parts[n>>8].temp+3000.0f, MIN_TEMP, MAX_TEMP);
- }
- if ((n&0xFF)==PT_BMTL && rand()%160==0)
- {
- part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL);//TODO: Redundant, was this meant to be BRMT or something?
- parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
- }
- if ((n&0xFF)==PT_METL && rand()%300==0)
- {
- part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL);
- }
- if ((n&0xFF)==PT_WIFI && rand()%8==0)
- {
- //Randomise channel
- parts[n>>8].temp = rand()%MAX_TEMP;
- }
- if ((n&0xFF)==PT_WIFI && rand()%16==0)
- {
- create_part(n>>8, rx+nx, ry+ny, PT_BREL);
- parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
- }
- }
- if ((n&0xFF)==PT_SWCH && rand()%100==0)
- {
- part_change_type(n>>8, rx+nx, ry+ny, PT_BREL);
- }
- if ((n&0xFF)==PT_SWCH && rand()%100==0)
- {
- parts[n>>8].temp = restrict_flt(parts[n>>8].temp+2000.0f, MIN_TEMP, MAX_TEMP);
- }
- if ((n&0xFF)==PT_ARAY && rand()%60==0)
- {
- create_part(n>>8, rx+nx, ry+ny, PT_BREL);
- parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
- }
- if (t==PT_DLAY && rand()%70==0)
- {
- //Randomise delay
- parts[n>>8].temp = (rand()%256) + 273.15f;
- }
- }
- }
- }
- return 0;
-}
-int graphics_EMP(GRAPHICS_FUNC_ARGS)
-{
- if(cpart->life)
- {
- *colr = cpart->life*1.5;
- *colg = cpart->life*1.5;
- *colb = 200-(cpart->life);
- if (*colr>255)
- *colr = 255;
- if (*colg>255)
- *colg = 255;
- if (*colb>255)
- *colb = 255;
- if (*colb<=0)
- *colb = 0;
- }
- return 0;
-}
diff --git a/src/elements/exot.c b/src/elements/exot.c
deleted file mode 100644
index 6be47cb..0000000
--- a/src/elements/exot.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_EXOT(UPDATE_FUNC_ARGS) {
- int r, rt, rx, ry, nb, rrx, rry, trade, tym, t;
- t = parts[i].type;
- for (rx=-2; rx<=2; rx++)
- for (ry=-2; ry<=2; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES) {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_WARP)
- {
- if (parts[r>>8].tmp2>2000)
- if (1>rand()%100)
- {
- parts[i].tmp2 += 100;
- }
- }
- if ((r&0xFF)==PT_EXOT && parts[r>>8].life==1500 && 1>rand()%1000)
- parts[i].life = 1500;
- if ((parts[i].tmp>245) && (parts[i].life>1000))
- if ((r&0xFF)!=PT_EXOT && (r&0xFF)!=PT_BREL && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PRTI && (r&0xFF)!=PT_PRTO && (r&0xFF)!=PT_PCLN && (r&0xFF)!=PT_PHOT && (r&0xFF)!=PT_VOID && (r&0xFF)!=PT_NBHL && (r&0xFF)!=PT_WARP && (r&0xFF)!=PT_NEUT)
- {
- create_part(i, x, y, parts[r>>8].type);
- return 0;
- }
- }
- parts[i].tmp--;
- parts[i].tmp2--;
- if (parts[i].tmp<1 || parts[i].tmp>250)
- parts[i].tmp = 250;
- if (parts[i].tmp2<1)
- parts[i].tmp2 = 1;
- else if (parts[i].tmp2>6000)
- {
- parts[i].tmp2 = 10000;
- if (parts[i].life<1001)
- {
- part_change_type(i, x, y, PT_WARP);
- return 0;
- }
- }
- else if (parts[i].life<1001)
- pv[y/CELL][x/CELL] += (parts[i].tmp2*CFDS)/160000;
- if (pv[y/CELL][x/CELL]>200 && parts[i].temp>9000 && parts[i].tmp2>200)
- {
- parts[i].tmp2 = 6000;
- part_change_type(i, x, y, PT_WARP);
- return 0;
- }
- if (parts[i].tmp2>100)
- {
- for ( trade = 0; trade<9; trade ++)
- {
- rx = rand()%5-2;
- ry = rand()%5-2;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==t && (parts[i].tmp2>parts[r>>8].tmp2) && parts[r>>8].tmp2>=0 )//diffusion
- {
- tym = parts[i].tmp2 - parts[r>>8].tmp2;
- if (tym ==1)
- {
- parts[r>>8].tmp2 ++;
- parts[i].tmp2 --;
- break;
- }
- if (tym>0)
- {
- parts[r>>8].tmp2 += tym/2;
- parts[i].tmp2 -= tym/2;
- break;
- }
- }
- }
- }
- }
- if (parts[i].temp<273.15f)
- {
- parts[i].vx = 0;
- parts[i].vy = 0;
- pv[y/CELL][x/CELL] -= 0.01;
- parts[i].tmp--;
- }
- return 0;
-
-}
-int graphics_EXOT(GRAPHICS_FUNC_ARGS)
-{
- int q = cpart->temp;
- int b = cpart->tmp;
- int c = cpart->tmp2;
- if (cpart->life < 1001)
- {
- if ((cpart->tmp2 - 1)>rand()%1000)
- {
- float frequency = 0.04045;
- *colr = (sin(frequency*c + 4) * 127 + 150);
- *colg = (sin(frequency*c + 6) * 127 + 150);
- *colb = (sin(frequency*c + 8) * 127 + 150);
- *firea = 100;
- *firer = 0;
- *fireg = 0;
- *fireb = 0;
- *pixel_mode |= PMODE_FLAT;
- *pixel_mode |= PMODE_FLARE;
- }
- else
- {
- float frequency = 0.00045;
- *colr = (sin(frequency*q + 4) * 127 + (b/1.7));
- *colg = (sin(frequency*q + 6) * 127 + (b/1.7));
- *colb = (sin(frequency*q + 8) * 127 + (b/1.7));
- *cola = cpart->tmp / 6;
- *firea = *cola;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
- *pixel_mode |= FIRE_ADD;
- *pixel_mode |= PMODE_BLUR;
- }
- }
- else
- {
- float frequency = 0.01300;
- *colr = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80));
- *colg = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80));
- *colb = (sin(frequency*q + 6.00) * 127 + ((b/2.9) + 80));
- *cola = cpart->tmp / 6;
- *firea = *cola;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
- *pixel_mode |= FIRE_ADD;
- *pixel_mode |= PMODE_BLUR;
-
-
- }
- return 0;
-}
diff --git a/src/elements/figh.c b/src/elements/figh.c
deleted file mode 100644
index 7c8c46c..0000000
--- a/src/elements/figh.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_FIGH(UPDATE_FUNC_ARGS)
-{
- playerst* figh = &fighters[(unsigned char)parts[i].tmp];
-
- unsigned int tarx, tary;
-
- parts[i].tmp2 = 0; //0 - stay in place, 1 - seek a stick man
-
- //Set target coords
- if (player.spwn && player2.spwn)
- {
- if ((pow(player.legs[2]-x, 2) + pow(player.legs[3]-y, 2))<=
- (pow(player2.legs[2]-x, 2) + pow(player2.legs[3]-y, 2)))
- {
- tarx = (unsigned int)player.legs[2];
- tary = (unsigned int)player.legs[3];
- }
- else
- {
- tarx = (unsigned int)player2.legs[2];
- tary = (unsigned int)player2.legs[3];
- }
- parts[i].tmp2 = 1;
- }
- else
- {
- if (player.spwn)
- {
- tarx = (unsigned int)player.legs[2];
- tary = (unsigned int)player.legs[3];
- parts[i].tmp2 = 1;
- }
- if (player2.spwn)
- {
- tarx = (unsigned int)player2.legs[2];
- tary = (unsigned int)player2.legs[3];
- parts[i].tmp2 = 1;
- }
- }
-
- switch (parts[i].tmp2)
- {
- case 1:
- if ((pow(tarx-x, 2) + pow(tary-y, 2))<600)
- {
- if (figh->elem == PT_LIGH || figh->elem == PT_NEUT
- || ptypes[figh->elem].properties&(PROP_DEADLY|PROP_RADIOACTIVE)
- || ptypes[figh->elem].heat>=323 || ptypes[figh->elem].heat<=243)
- figh->comm = (int)figh->comm | 0x08;
- }
- else
- if (tarx<x)
- {
- if(!(eval_move(PT_FIGH, figh->legs[4]-10, figh->legs[5]+6, NULL)
- && eval_move(PT_FIGH, figh->legs[4]-10, figh->legs[5]+3, NULL)))
- figh->comm = 0x01;
- else
- figh->comm = 0x02;
-
- if (!eval_move(PT_FIGH, figh->legs[4]-4, figh->legs[5]-1, NULL)
- || !eval_move(PT_FIGH, figh->legs[12]-4, figh->legs[13]-1, NULL)
- || eval_move(PT_FIGH, 2*figh->legs[4]-figh->legs[6], figh->legs[5]+5, NULL))
- figh->comm = (int)figh->comm | 0x04;
- }
- else
- {
- if (!(eval_move(PT_FIGH, figh->legs[12]+10, figh->legs[13]+6, NULL)
- && eval_move(PT_FIGH, figh->legs[12]+10, figh->legs[13]+3, NULL)))
- figh->comm = 0x02;
- else
- figh->comm = 0x01;
-
- if (!eval_move(PT_FIGH, figh->legs[4]+4, figh->legs[5]-1, NULL)
- || !eval_move(PT_FIGH, figh->legs[4]+4, figh->legs[5]-1, NULL)
- || eval_move(PT_FIGH, 2*figh->legs[12]-figh->legs[14], figh->legs[13]+5, NULL))
- figh->comm = (int)figh->comm | 0x04;
- }
- break;
- default:
- figh->comm = 0;
- break;
- }
-
- figh->pcomm = figh->comm;
-
- run_stickman(figh, UPDATE_FUNC_SUBCALL_ARGS);
- return 0;
-}
diff --git a/src/elements/fire.c b/src/elements/fire.c
deleted file mode 100644
index bc288bc..0000000
--- a/src/elements/fire.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int graphics_FIRE(GRAPHICS_FUNC_ARGS)
-{
- int caddress = restrict_flt(restrict_flt((float)cpart->life, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
- *colr = (unsigned char)flm_data[caddress];
- *colg = (unsigned char)flm_data[caddress+1];
- *colb = (unsigned char)flm_data[caddress+2];
-
- *firea = 255;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
-
- *pixel_mode = PMODE_NONE; //Clear default, don't draw pixel
- *pixel_mode |= FIRE_ADD;
- //Returning 0 means dynamic, do not cache
- return 0;
-}
diff --git a/src/elements/firw.c b/src/elements/firw.c
deleted file mode 100644
index 8033d41..0000000
--- a/src/elements/firw.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-#include "hmap.h"
-
-int update_FIRW(UPDATE_FUNC_ARGS) {
- int r, rx, ry, rt, np;
- if (parts[i].tmp<=0) {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- rt = parts[r>>8].type;
- if (rt==PT_FIRE||rt==PT_PLSM||rt==PT_THDR)
- {
- float gx, gy, multiplier;
- get_gravity_field(x, y, ptypes[PT_FIRW].gravity, 1.0f, &gx, &gy);
- if (gx*gx+gy*gy < 0.001f)
- {
- float angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi)
- gx += sinf(angle)*ptypes[PT_FIRW].gravity*0.5f;
- gy += cosf(angle)*ptypes[PT_FIRW].gravity*0.5f;
- }
- parts[i].tmp = 1;
- parts[i].life = rand()%10+20;
- multiplier = (parts[i].life+20)*0.2f/sqrtf(gx*gx+gy*gy);
- parts[i].vx -= gx*multiplier;
- parts[i].vy -= gy*multiplier;
- return 0;
- }
- }
- }
- else if (parts[i].tmp==1) {
- if (parts[i].life<=0) {
- parts[i].tmp=2;
- } else {
- parts[i].flags &= ~FLAG_STAGNANT;
- }
- }
- else if (parts[i].tmp>=2) {
- float angle, magnitude;
- int caddress = (rand()%200)*3;
- int n;
- unsigned col = (((unsigned char)(firw_data[caddress]))<<16) | (((unsigned char)(firw_data[caddress+1]))<<8) | ((unsigned char)(firw_data[caddress+2]));
- for (n=0; n<40; n++)
- {
- np = create_part(-3, x, y, PT_EMBR);
- if (np>-1)
- {
- magnitude = ((rand()%60)+40)*0.05f;
- angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi)
- parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude;
- parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude;
- parts[np].ctype = col;
- parts[np].tmp = 1;
- parts[np].life = rand()%40+70;
- parts[np].temp = (rand()%500)+5750.0f;
- parts[np].dcolour = parts[i].dcolour;
- }
- }
- pv[y/CELL][x/CELL] += 8.0f;
- kill_part(i);
- return 1;
- }
- return 0;
-}
diff --git a/src/elements/fog.c b/src/elements/fog.c
deleted file mode 100644
index 8acb632..0000000
--- a/src/elements/fog.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_FOG(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (ptypes[r&0xFF].state==ST_SOLID&&5>=rand()%50&&parts[i].life==0&&!((r&0xFF)==PT_CLNE||(r&0xFF)==PT_PCLN)) // TODO: should this also exclude BCLN?
- {
- part_change_type(i,x,y,PT_RIME);
- }
- if ((r&0xFF)==PT_SPRK)
- {
- parts[i].life += rand()%20;
- }
- }
- return 0;
-}
diff --git a/src/elements/fray.c b/src/elements/fray.c
deleted file mode 100644
index 6036d92..0000000
--- a/src/elements/fray.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_FRAY(UPDATE_FUNC_ARGS) {
- int r, nxx, nyy, docontinue, len, nxi, nyi, rx, ry, nr, ry1, rx1;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_SPRK) {
- for (docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1, len = 0; docontinue; nyy+=nyi, nxx+=nxi, len++) {
- if (!(x+nxi+nxx<XRES && y+nyi+nyy<YRES && x+nxi+nxx >= 0 && y+nyi+nyy >= 0) || len>10) {
- break;
- }
- r = pmap[y+nyi+nyy][x+nxi+nxx];
- if (!r)
- r = photons[y+nyi+nyy][x+nxi+nxx];
-
- if (r && !(ptypes[r&0xFF].properties & TYPE_SOLID)){
- parts[r>>8].vx += nxi*((parts[i].temp-273.15)/10.0f);
- parts[r>>8].vy += nyi*((parts[i].temp-273.15)/10.0f);
- }
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/frzw.c b/src/elements/frzw.c
deleted file mode 100644
index b2f55e8..0000000
--- a/src/elements/frzw.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_FRZW(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_WATR&&5>rand()%70)
- {
- part_change_type(r>>8,x+rx,y+ry,PT_FRZW);
- }
- }
- if (parts[i].life==0&&13>rand()%2500)
- {
- part_change_type(i,x,y,PT_ICEI);
- parts[i].ctype=PT_FRZW;
- parts[i].temp = restrict_flt(parts[i].temp-200.0f, MIN_TEMP, MAX_TEMP);
- }
- else if ((100-(parts[i].life))>rand()%50000)
- {
- part_change_type(i,x,y,PT_ICEI);
- parts[i].ctype=PT_FRZW;
- parts[i].temp = restrict_flt(parts[i].temp-200.0f, MIN_TEMP, MAX_TEMP);
- }
- return 0;
-}
diff --git a/src/elements/frzz.c b/src/elements/frzz.c
deleted file mode 100644
index 37119ab..0000000
--- a/src/elements/frzz.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_FRZZ(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_WATR&&5>rand()%100)
- {
- part_change_type(r>>8,x+rx,y+ry,PT_FRZW);
- parts[r>>8].life = 100;
- parts[i].type = PT_NONE;
- }
-
- }
- if (parts[i].type==PT_NONE) {
- kill_part(i);
- return 1;
- }
- return 0;
-}
diff --git a/src/elements/fsep.c b/src/elements/fsep.c
deleted file mode 100644
index f189ba7..0000000
--- a/src/elements/fsep.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_FSEP(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- if (parts[i].life<=0) {
- r = create_part(i, x, y, PT_PLSM);
- if (r!=-1)
- parts[r].life = 50;
- return 1;
- } else if (parts[i].life < 40) {
- parts[i].life--;
- if ((rand()%10)==0) {
- r = create_part(-1, (rx=x+rand()%3-1), (ry=y+rand()%3-1), PT_PLSM);
- if (r!=-1)
- parts[r].life = 50;
- }
- }
- else {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_SPRK || (parts[i].temp>=(273.15+400.0f))) && 1>(rand()%15))
- {
- if (parts[i].life>40) {
- parts[i].life = 39;
- }
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/fuse.c b/src/elements/fuse.c
deleted file mode 100644
index e917b9a..0000000
--- a/src/elements/fuse.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_FUSE(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- if (parts[i].life<=0) {
- r = create_part(i, x, y, PT_PLSM);
- if (r!=-1)
- parts[r].life = 50;
- return 1;
- } else if (parts[i].life < 40) {
- parts[i].life--;
- if ((rand()%100)==0) {
- r = create_part(-1, (rx=x+rand()%3-1), (ry=y+rand()%3-1), PT_PLSM);
- if (r!=-1)
- parts[r].life = 50;
- }
- }
- if ((pv[y/CELL][x/CELL] > 2.7f)&&parts[i].tmp>40)
- parts[i].tmp=39;
- else if (parts[i].tmp<40&&parts[i].tmp>0)
- parts[i].tmp--;
- else if (parts[i].tmp<=0) {
- create_part(i, x, y, PT_FSEP);
- return 1;
- }
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_SPRK || ((parts[i].temp>=(273.15+700.0f)) && 1>(rand()%20)))
- {
- if (parts[i].life>40) {
- parts[i].life = 39;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/fwrk.c b/src/elements/fwrk.c
deleted file mode 100644
index d6dc59c..0000000
--- a/src/elements/fwrk.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_FWRK(UPDATE_FUNC_ARGS) {
- int r, rx, ry, np;
- if (parts[i].life==0 && ((parts[i].temp>400&&(9+parts[i].temp/40)>rand()%100000&&surround_space)||parts[i].ctype==PT_DUST))
- {
- float gx, gy, multiplier, gmax;
- int randTmp;
- get_gravity_field(x, y, ptypes[PT_FWRK].gravity, 1.0f, &gx, &gy);
- if (gx*gx+gy*gy < 0.001f)
- {
- float angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi)
- gx += sinf(angle)*ptypes[PT_FWRK].gravity*0.5f;
- gy += cosf(angle)*ptypes[PT_FWRK].gravity*0.5f;
- }
- gmax = fmaxf(fabsf(gx), fabsf(gy));
- if (eval_move(PT_FWRK, (int)(x-(gx/gmax)+0.5f), (int)(y-(gy/gmax)+0.5f), NULL))
- {
- multiplier = 15.0f/sqrtf(gx*gx+gy*gy);
-
- //Some variation in speed parallel to gravity direction
- randTmp = (rand()%200)-100;
- gx += gx*randTmp*0.002f;
- gy += gy*randTmp*0.002f;
- //and a bit more variation in speed perpendicular to gravity direction
- randTmp = (rand()%200)-100;
- gx += -gy*randTmp*0.005f;
- gy += gx*randTmp*0.005f;
-
- parts[i].life=rand()%10+18;
- parts[i].ctype=0;
- parts[i].vx -= gx*multiplier;
- parts[i].vy -= gy*multiplier;
- parts[i].dcolour = parts[i].dcolour;
- return 0;
- }
- }
- if (parts[i].life>=45)
- parts[i].life=0;
- if (parts[i].life<3&&parts[i].life>0)
- {
- int r = (rand()%245+11);
- int g = (rand()%245+11);
- int b = (rand()%245+11);
- int n;
- float angle, magnitude;
- unsigned col = (r<<16) | (g<<8) | b;
- for (n=0; n<40; n++)
- {
- np = create_part(-3, x, y, PT_EMBR);
- if (np>-1)
- {
- magnitude = ((rand()%60)+40)*0.05f;
- angle = (rand()%6284)*0.001f;//(in radians, between 0 and 2*pi)
- parts[np].vx = parts[i].vx*0.5f + cosf(angle)*magnitude;
- parts[np].vy = parts[i].vy*0.5f + sinf(angle)*magnitude;
- parts[np].ctype = col;
- parts[np].tmp = 1;
- parts[np].life = rand()%40+70;
- parts[np].temp = (rand()%500)+5750.0f;
- parts[np].dcolour = parts[i].dcolour;
- }
- }
- pv[y/CELL][x/CELL] += 8.0f;
- kill_part(i);
- return 1;
- }
- return 0;
-}
diff --git a/src/elements/gbmb.c b/src/elements/gbmb.c
deleted file mode 100644
index a1da981..0000000
--- a/src/elements/gbmb.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-int update_GBMB(UPDATE_FUNC_ARGS) {
- int rx,ry,r;
- if (parts[i].life<=0)
- {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- {
- r = pmap[y+ry][x+rx];
- if(!r)
- continue;
- if((r&0xFF)!=PT_BOMB && (r&0xFF)!=PT_GBMB &&
- (r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN &&
- (r&0xFF)!=PT_DMND)
- {
- parts[i].life=60;
- break;
- }
- }
- }
- if(parts[i].life>20)
- gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 20;
- if(parts[i].life<20 && parts[i].life>=1)
- gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = -80;
- return 0;
-}
diff --git a/src/elements/gel.c b/src/elements/gel.c
deleted file mode 100644
index 86cb15a..0000000
--- a/src/elements/gel.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_GEL(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- float dx, dy;
- char gel;
- int absorbChanceDenom;
- if (parts[i].tmp>100) parts[i].tmp = 100;
- if (parts[i].tmp<0) parts[i].tmp = 0;
- absorbChanceDenom = parts[i].tmp*10 + 500;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
-
- //Desaturation
- if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW || (r&0xFF)==PT_FRZW) && parts[i].tmp<100 && 500>rand()%absorbChanceDenom)
- {
- parts[i].tmp++;
- kill_part(r>>8);
- }
- if (((r&0xFF)==PT_PSTE) && parts[i].tmp<100 && 20>rand()%absorbChanceDenom)
- {
- parts[i].tmp++;
- create_part(r>>8, x+rx, y+ry, PT_CLST);
- }
- if (((r&0xFF)==PT_SLTW) && parts[i].tmp<100 && 50>rand()%absorbChanceDenom)
- {
- parts[i].tmp++;
- if (rand()%4)
- kill_part(r>>8);
- else
- part_change_type(r>>8, x+rx, y+ry, PT_SALT);
- }
- if (((r&0xFF)==PT_CBNW) && parts[i].tmp<100 && 100>rand()%absorbChanceDenom)
- {
- parts[i].tmp++;
- part_change_type(r>>8, x+rx, y+ry, PT_CO2);
- }
-
- if ((r&0xFF)==PT_SPNG && parts[i].tmp<100 && ((parts[r>>8].life+1)>parts[i].tmp))
- {
- parts[r>>8].life--;
- parts[i].tmp++;
- }
-
- gel = 0;
- if ((r&0xFF)==PT_GEL)
- gel = 1;
-
- //Concentration diffusion
- if (gel && (parts[r>>8].tmp+1)<parts[i].tmp)
- {
- parts[r>>8].tmp++;
- parts[i].tmp--;
- }
-
- if ((r&0xFF)==PT_SPNG && (parts[r>>8].life+1)<parts[i].tmp)
- {
- parts[r>>8].life++;
- parts[i].tmp--;
- }
-
- dx = parts[i].x - parts[r>>8].x;
- dy = parts[i].y - parts[r>>8].y;
-
- //Stickness
- if ((dx*dx + dy*dy)>1.5 && (gel || !ptypes[r&0xFF].falldown || (fabs(rx)<2 && fabs(ry)<2)))
- {
- float per, nd;
- nd = dx*dx + dy*dy - 0.5;
-
- per = 5*(1 - parts[i].tmp/100)*(nd/(dx*dx + dy*dy + nd) - 0.5);
- if (ptypes[r&0xFF].state==ST_LIQUID)
- per *= 0.1;
-
- dx *= per; dy *= per;
- parts[i].vx += dx;
- parts[i].vy += dy;
-
- if (ptypes[r&0xFF].properties&TYPE_PART || (r&0xFF)==PT_GOO)
- {
- parts[r>>8].vx -= dx;
- parts[r>>8].vy -= dy;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/glas.c b/src/elements/glas.c
deleted file mode 100644
index 23f4d1e..0000000
--- a/src/elements/glas.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_GLAS(UPDATE_FUNC_ARGS) {
- parts[i].pavg[0] = parts[i].pavg[1];
- parts[i].pavg[1] = pv[y/CELL][x/CELL];
- if (parts[i].pavg[1]-parts[i].pavg[0] > 0.25f || parts[i].pavg[1]-parts[i].pavg[0] < -0.25f)
- {
- part_change_type(i,x,y,PT_BGLA);
- }
- return 0;
-}
diff --git a/src/elements/glow.c b/src/elements/glow.c
deleted file mode 100644
index de8cfea..0000000
--- a/src/elements/glow.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_GLOW(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_WATR&&5>(rand()%2000))
- {
- parts[i].type = PT_NONE;
- part_change_type(r>>8,x+rx,y+ry,PT_DEUT);
- parts[r>>8].life = 10;
- }
- }
- parts[i].ctype = pv[y/CELL][x/CELL]*16;
-
- parts[i].tmp = abs((int)((vx[y/CELL][x/CELL]+vy[y/CELL][x/CELL])*16.0f)) + abs((int)((parts[i].vx+parts[i].vy)*64.0f));
- //printf("%f %f\n", parts[i].vx, parts[i].vy);
- if (parts[i].type==PT_NONE) {
- kill_part(i);
- return 1;
- }
- return 0;
-}
diff --git a/src/elements/goo.c b/src/elements/goo.c
deleted file mode 100644
index bf25799..0000000
--- a/src/elements/goo.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_GOO(UPDATE_FUNC_ARGS) {
- if (!parts[i].life && pv[y/CELL][x/CELL]>1.0f)
- parts[i].life = rand()%80+300;
- if (parts[i].life)
- {
- float advection = 0.1f;
- parts[i].vx += advection*vx[y/CELL][x/CELL];
- parts[i].vy += advection*vy[y/CELL][x/CELL];
- }
- return 0;
-}
diff --git a/src/elements/gpmp.c b/src/elements/gpmp.c
deleted file mode 100644
index 819a1e3..0000000
--- a/src/elements/gpmp.c
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_GPMP(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- if (parts[i].life>0 && parts[i].life!=10)
- parts[i].life--;
- if (parts[i].life==10)
- {
- if (parts[i].temp>=256.0+273.15)
- parts[i].temp=256.0+273.15;
- if (parts[i].temp<= -256.0+273.15)
- parts[i].temp = -256.0+273.15;
-
- gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 0.2f*(parts[i].temp-273.15);
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_GPMP)
- {
- if (parts[r>>8].life<10&&parts[r>>8].life>0)
- parts[i].life = 9;
- else if (parts[r>>8].life==0)
- parts[r>>8].life = 10;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/graphics_default.c b/src/elements/graphics_default.c
deleted file mode 100644
index eb5df95..0000000
--- a/src/elements/graphics_default.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int graphics_DEFAULT(GRAPHICS_FUNC_ARGS)
-{
- int t = cpart->type;
- //Property based defaults
- if(ptypes[t].properties & PROP_RADIOACTIVE) *pixel_mode |= PMODE_GLOW;
- if(ptypes[t].properties & TYPE_LIQUID)
- {
- *pixel_mode |= PMODE_BLUR;
- }
- if(ptypes[t].properties & TYPE_GAS)
- {
- *pixel_mode &= ~PMODE;
- *pixel_mode |= FIRE_BLEND;
- *firer = *colr/2;
- *fireg = *colg/2;
- *fireb = *colb/2;
- *firea = 125;
- *pixel_mode |= DECO_FIRE;
- }
- return 1;
-}
diff --git a/src/elements/h2.c b/src/elements/h2.c
deleted file mode 100644
index 833ee7c..0000000
--- a/src/elements/h2.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_H2(UPDATE_FUNC_ARGS)
-{
- int r,rx,ry,rt;
- if (parts[i].temp > 2273.15 && pv[y/CELL][x/CELL] > 50.0f)
- parts[i].tmp = 1;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- rt = (r&0xFF);
- if (!r)
- continue;
- if (pv[y/CELL][x/CELL] > 8.0f && rt == PT_DESL) // This will not work. DESL turns to fire above 5.0 pressure
- {
- part_change_type(r>>8,x+rx,y+ry,PT_WATR);
- part_change_type(i,x,y,PT_OIL);
- }
- if (parts[r>>8].temp > 2273.15)// && pv[y/CELL][x/CELL] > 50.0f)
- continue;
- if (parts[i].temp < 2273.15)
- {
- if (rt==PT_FIRE)
- {
- parts[r>>8].temp=2473.15;
- if(parts[r>>8].tmp&0x02)
- parts[r>>8].temp=3473;
- parts[r>>8].tmp |= 1;
- }
- if (rt==PT_FIRE || rt==PT_PLSM || rt==PT_LAVA)
- {
- create_part(i,x,y,PT_FIRE);
- parts[i].temp+=(rand()/(RAND_MAX/100));
- parts[i].tmp |= 1;
- }
- }
- }
- if (parts[i].temp > 2273.15 && pv[y/CELL][x/CELL] > 50.0f)
- {
- if (rand()%5 < 1)
- {
- int j;
- float temp = parts[i].temp;
- create_part(i,x,y,PT_NBLE);
-
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1) parts[j].temp = temp;
- if (!(rand()%10)) { j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); if (j != -1) parts[j].temp = temp; }
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PHOT); if (j != -1) { parts[j].ctype = 0xFFFF00; parts[j].temp = temp; }
-
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PLSM); if (j != -1) parts[j].temp = temp;
-
- parts[i].temp = temp+750+rand()%500;
- pv[y/CELL][x/CELL] += 30;
- }
- }
- return 0;
-}
diff --git a/src/elements/hswc.c b/src/elements/hswc.c
deleted file mode 100644
index 6287126..0000000
--- a/src/elements/hswc.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_HSWC(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- if (parts[i].life>0 && parts[i].life!=10)
- parts[i].life--;
- if (parts[i].life==10)
- {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_HSWC)
- {
- if (parts[r>>8].life<10&&parts[r>>8].life>0)
- parts[i].life = 9;
- else if (parts[r>>8].life==0)
- parts[r>>8].life = 10;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/ice.c b/src/elements/ice.c
deleted file mode 100644
index 009cc9c..0000000
--- a/src/elements/ice.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_ICEI(UPDATE_FUNC_ARGS) { //currently used for snow as well
- int r, rx, ry;
- if (parts[i].ctype==PT_FRZW)//get colder if it is from FRZW
- {
- parts[i].temp = restrict_flt(parts[i].temp-1.0f, MIN_TEMP, MAX_TEMP);
- }
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_SALT || (r&0xFF)==PT_SLTW) && parts[i].temp > ptransitions[PT_SLTW].tlv && 1>(rand()%1000))
- {
- part_change_type(i,x,y,PT_SLTW);
- part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
- }
- if (((r&0xFF)==PT_FRZZ) && (parts[i].ctype=PT_FRZW) && 1>(rand()%1000))
- part_change_type(r>>8,x+rx,y+ry,PT_ICEI);
- }
- return 0;
-}
diff --git a/src/elements/ignt.c b/src/elements/ignt.c
deleted file mode 100644
index bf706bc..0000000
--- a/src/elements/ignt.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_IGNT(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- if(parts[i].tmp==0)
- {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM)
- {
- parts[i].tmp = 1;
- }
- else if ((r&0xFF)==PT_SPRK || (r&0xFF)==PT_LIGH || ((r&0xFF)==PT_IGNT && parts[r>>8].life==1))
- {
- parts[i].tmp = 1;
- }
- }
- }
- else if(parts[i].life > 0)
- {
- if(rand()%3)
- {
- int nb = create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_EMBR);
- if (nb!=-1) {
- parts[nb].tmp = 0;
- parts[nb].life = 30;
- parts[nb].vx = rand()%20-10;
- parts[nb].vy = rand()%20-10;
- parts[nb].temp = restrict_flt(400.0f+parts[i].temp-273.15, MIN_TEMP, MAX_TEMP);
- }
- }
- else
- {
- create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE);
- }
- parts[i].life--;
- }
- return 0;
-}
diff --git a/src/elements/iron.c b/src/elements/iron.c
deleted file mode 100644
index 55e8e75..0000000
--- a/src/elements/iron.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_IRON(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!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))
- )
- {
- part_change_type(i,x,y,PT_BMTL);
- parts[i].tmp=(rand()/(RAND_MAX/10))+20;
- }
- }
- return 0;
-}
diff --git a/src/elements/isz.c b/src/elements/isz.c
deleted file mode 100644
index aa081c0..0000000
--- a/src/elements/isz.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_ISZ(UPDATE_FUNC_ARGS) { // for both ISZS and ISOZ
- float rr, rrr;
- if (1>rand()%200 && ((int)(-4.0f*(pv[y/CELL][x/CELL])))>(rand()%1000))
- {
- create_part(i, x, y, PT_PHOT);
- rr = (rand()%228+128)/127.0f;
- rrr = (rand()%360)*3.14159f/180.0f;
- parts[i].vx = rr*cosf(rrr);
- parts[i].vy = rr*sinf(rrr);
- }
- return 0;
-}
diff --git a/src/elements/lava.c b/src/elements/lava.c
deleted file mode 100644
index 8847485..0000000
--- a/src/elements/lava.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int graphics_LAVA(GRAPHICS_FUNC_ARGS)
-{
- *colr = cpart->life * 2 + 0xE0;
- *colg = cpart->life * 1 + 0x50;
- *colb = cpart->life / 2 + 0x10;
- if (*colr>255) *colr = 255;
- if (*colg>192) *colg = 192;
- if (*colb>128) *colb = 128;
- *firea = 40;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
- *pixel_mode |= FIRE_ADD;
- *pixel_mode |= PMODE_BLUR;
- //Returning 0 means dynamic, do not cache
- return 0;
-}
diff --git a/src/elements/lcry.c b/src/elements/lcry.c
deleted file mode 100644
index cc1e625..0000000
--- a/src/elements/lcry.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_LCRY(UPDATE_FUNC_ARGS)
-{
- int r, rx, ry;
- if(parts[i].tmp==1 || parts[i].tmp==0)
- {
- if(parts[i].tmp==1)
- {
- if(parts[i].life<=0)
- parts[i].tmp = 0;
- else
- {
- parts[i].life-=2;
- if(parts[i].life < 0)
- parts[i].life = 0;
- parts[i].tmp2 = parts[i].life;
- }
- }
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_LCRY && parts[r>>8].tmp == 3)
- {
- parts[r>>8].tmp = 1;
- }
- }
- }
- else if(parts[i].tmp==2 || parts[i].tmp==3)
- {
- if(parts[i].tmp==2)
- {
- if(parts[i].life>=10)
- parts[i].tmp = 3;
- else
- {
- parts[i].life+=2;
- if(parts[i].life > 10)
- parts[i].life = 10;
- parts[i].tmp2 = parts[i].life;
- }
- }
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_LCRY && parts[r>>8].tmp == 0)
- {
- parts[r>>8].tmp = 2;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/legacy.c b/src/elements/legacy.c
deleted file mode 100644
index 1db6966..0000000
--- a/src/elements/legacy.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-// Interactions which only occur when legacy_enable is on
-int update_legacy_all(UPDATE_FUNC_ARGS) {
- int r, rx, ry, rt;
- int t = parts[i].type;
- if (!legacy_enable) return 0;
- if (t==PT_WTRV) {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 &&
- x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_WATR||(r&0xFF)==PT_DSTW||(r&0xFF)==PT_SLTW) && 1>(rand()%1000))
- {
- part_change_type(i,x,y,PT_WATR);
- part_change_type(r>>8,x+rx,y+ry,PT_WATR);
- }
- if (((r&0xFF)==PT_ICEI || (r&0xFF)==PT_SNOW) && 1>(rand()%1000))
- {
- part_change_type(i,x,y,PT_WATR);
- if (1>(rand()%1000))
- part_change_type(r>>8,x+rx,y+ry,PT_WATR);
- }
- }
- }
- else if (t==PT_WATR) {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 &&
- x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_LAVA) && 1>(rand()%10))
- {
- part_change_type(i,x,y,PT_WTRV);
- }
- }
- }
- else if (t==PT_SLTW) {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 &&
- x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_LAVA) && 1>(rand()%10))
- {
- if (rand()%4==0) part_change_type(i,x,y,PT_SALT);
- else part_change_type(i,x,y,PT_WTRV);
- }
- }
- }
- else if (t==PT_DSTW) {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 &&
- x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_LAVA) && 1>(rand()%10))
- {
- part_change_type(i,x,y,PT_WTRV);
- }
- }
- }
- else if (t==PT_ICEI) {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 1>(rand()%1000))
- {
- part_change_type(i,x,y,PT_ICEI);
- part_change_type(r>>8,x+rx,y+ry,PT_ICEI);
- }
- }
- }
- else if (t==PT_SNOW) {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 1>(rand()%1000))
- {
- part_change_type(i,x,y,PT_ICEI);
- part_change_type(r>>8,x+rx,y+ry,PT_ICEI);
- }
- if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && 15>(rand()%1000))
- part_change_type(i,x,y,PT_WATR);
- }
- }
- if (t==PT_WTRV && pv[y/CELL][x/CELL]>4.0f)
- part_change_type(i,x,y,PT_DSTW);
- if (t==PT_OIL && pv[y/CELL][x/CELL]<-6.0f)
- part_change_type(i,x,y,PT_GAS);
- if (t==PT_GAS && pv[y/CELL][x/CELL]>6.0f)
- part_change_type(i,x,y,PT_OIL);
- if (t==PT_DESL && pv[y/CELL][x/CELL]>12.0f)
- {
- part_change_type(i,x,y,PT_FIRE);
- parts[i].life = rand()%50+120;
- }
- return 0;
-}
diff --git a/src/elements/ligh.c b/src/elements/ligh.c
deleted file mode 100644
index 31f53b3..0000000
--- a/src/elements/ligh.c
+++ /dev/null
@@ -1,315 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-#define LIGHTING_POWER 0.65
-
-int LIGH_nearest_part(int ci, int max_d)
-{
- int distance = (max_d!=-1)?max_d:MAX_DISTANCE;
- int ndistance = 0;
- int id = -1;
- int i = 0;
- int cx = (int)parts[ci].x;
- int cy = (int)parts[ci].y;
- for (i=0; i<=parts_lastActiveIndex; i++)
- {
- if (parts[i].type && !parts[i].life && i!=ci && parts[i].type!=PT_LIGH && parts[i].type!=PT_THDR && parts[i].type!=PT_NEUT && parts[i].type!=PT_PHOT)
- {
- ndistance = abs(cx-parts[i].x)+abs(cy-parts[i].y);// Faster but less accurate Older: sqrt(pow(cx-parts[i].x, 2)+pow(cy-parts[i].y, 2));
- if (ndistance<distance)
- {
- distance = ndistance;
- id = i;
- }
- }
- }
- return id;
-}
-
-int contact_part(int i, int tp)
-{
- int x=parts[i].x, y=parts[i].y;
- int r,rx,ry;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==tp)
- return r>>8;
- }
- return -1;
-}
-
-void create_line_par(int x1, int y1, int x2, int y2, int c, int temp, int life, int tmp, int tmp2)
-{
- int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
- float e, de;
- if (c==WL_EHOLE || c==WL_ALLOWGAS || c==WL_ALLOWALLELEC || c==WL_ALLOWSOLID || c==WL_ALLOWAIR || c==WL_WALL || c==WL_DESTROYALL || c==WL_ALLOWLIQUID || c==WL_FAN || c==WL_STREAM || c==WL_DETECT || c==WL_EWALL || c==WL_WALLELEC)
- return; // this function only for particles, no walls
- if (cp)
- {
- y = x1;
- x1 = y1;
- y1 = y;
- y = x2;
- x2 = y2;
- y2 = y;
- }
- if (x1 > x2)
- {
- y = x1;
- x1 = x2;
- x2 = y;
- y = y1;
- y1 = y2;
- y2 = y;
- }
- dx = x2 - x1;
- dy = abs(y2 - y1);
- e = 0.0f;
- if (dx)
- de = dy/(float)dx;
- else
- de = 0.0f;
- y = y1;
- sy = (y1<y2) ? 1 : -1;
- for (x=x1; x<=x2; x++)
- {
- int p;
- if (cp)
- p=create_part(-1, y, x, c);
- else
- p=create_part(-1, x, y,c);
- if (p!=-1)
- {
- parts[p].life=life;
- parts[p].temp=temp;
- parts[p].tmp=tmp;
- parts[p].tmp2=tmp2;
- }
- e += de;
- if (e >= 0.5f)
- {
- y += sy;
- e -= 1.0f;
- }
- }
-}
-
-int update_LIGH(UPDATE_FUNC_ARGS)
-{
- /*
- *
- * tmp2:
- * -1 - part will be removed
- * 0 - "branches" of the lightning
- * 1 - bending
- * 2 - branching
- * 3 - transfer spark or make destruction
- * 4 - first pixel
- *
- * life - "thickness" of lighting (but anyway one pixel)
- *
- * tmp - angle of lighting, measured in degrees anticlockwise from the positive x direction
- *
- */
- int r,rx,ry, multipler, powderful;
- float angle, angle2=-1;
- int near;
- powderful = powderful=parts[i].temp*(1+parts[i].life/40)*LIGHTING_POWER;
- update_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
- if (aheat_enable)
- {
- hv[y/CELL][x/CELL]+=powderful/50;
- if (hv[y/CELL][x/CELL]>MAX_TEMP)
- hv[y/CELL][x/CELL]=MAX_TEMP;
- }
-
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_LIGH && (r&0xFF)!=PT_TESC)
- {
- if ((r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_THDR&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_FIRE&&(r&0xFF)!=PT_NEUT&&(r&0xFF)!=PT_PHOT)
- {
- if ((ptypes[r&0xFF].properties&PROP_CONDUCTS) && parts[r>>8].life==0)
- {
- create_part(r>>8,x+rx,y+ry,PT_SPRK);
- }
- pv[y/CELL][x/CELL] += powderful/400;
- if (ptypes[r&0xFF].hconduct) parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/1.5, MIN_TEMP, MAX_TEMP);
- }
- if ((r&0xFF)==PT_DEUT || (r&0xFF)==PT_PLUT) // start nuclear reactions
- {
- parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful, MIN_TEMP, MAX_TEMP);
- pv[y/CELL][x/CELL] +=powderful/35;
- if (rand()%3==0)
- {
- part_change_type(r>>8,x+rx,y+ry,PT_NEUT);
- parts[r>>8].life = rand()%480+480;
- parts[r>>8].vx=rand()%10-5;
- parts[r>>8].vy=rand()%10-5;
- }
- }
- if ((r&0xFF)==PT_COAL || (r&0xFF)==PT_BCOL) // ignite coal
- {
- if (parts[r>>8].life>100) {
- parts[r>>8].life = 99;
- }
- }
- if (ptypes[r&0xFF].hconduct)
- parts[r>>8].temp = restrict_flt(parts[r>>8].temp+powderful/10, MIN_TEMP, MAX_TEMP);
- if (((r&0xFF)==PT_STKM && player.elem!=PT_LIGH) || ((r&0xFF)==PT_STKM2 && player2.elem!=PT_LIGH))
- {
- parts[r>>8].life-=powderful/100;
- }
- }
- }
- if (parts[i].tmp2==3)
- {
- parts[i].tmp2=0;
- return 1;
- }
-
- if (parts[i].tmp2==-1)
- {
- kill_part(i);
- return 1;
- }
- if (parts[i].tmp2<=0 || parts[i].life<=1)
- {
- if (parts[i].tmp2>0)
- parts[i].tmp2=0;
- parts[i].tmp2--;
- return 1;
- }
- if (parts[i].tmp2<=-2)
- {
- kill_part(i);
- return 1;
- }
-
- angle2=-1;
-
- near = LIGH_nearest_part(i, parts[i].life*2.5);
- if (near!=-1)
- {
- int t=parts[near].type;
- float n_angle; // angle to nearest part
- float angle_diff;
- rx=parts[near].x-x;
- ry=parts[near].y-y;
- if (rx!=0 || ry!=0)
- n_angle = atan2f(-ry, rx);
- else
- n_angle = 0;
- if (n_angle<0)
- n_angle+=M_PI*2;
- angle_diff = fabsf(n_angle-parts[i].tmp*M_PI/180);
- if (angle_diff>M_PI)
- angle_diff = M_PI*2 - angle_diff;
- if (parts[i].life<5 || angle_diff<M_PI*0.8) // lightning strike
- {
- create_line_par(x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, parts[i].tmp-90, 0);
-
- if (t!=PT_TESC)
- {
- near=contact_part(near, PT_LIGH);
- if (near!=-1)
- {
- parts[near].tmp2=3;
- parts[near].life=(int)(1.0*parts[i].life/2-1);
- parts[near].tmp=parts[i].tmp-180;
- parts[near].temp=parts[i].temp;
- }
- }
- }
- else near=-1;
- }
-
- //if (parts[i].tmp2==1/* || near!=-1*/)
- //angle=0;//parts[i].tmp-30+rand()%60;
- angle = parts[i].tmp-30+rand()%60;
- if (angle<0)
- angle+=360;
- if (angle>=360)
- angle-=360;
- if (parts[i].tmp2==2 && near==-1)
- {
- angle2=angle+100-rand()%200;
- if (angle2<0)
- angle2+=360;
- if (angle2>=360)
- angle-=360;
- }
-
- multipler=parts[i].life*1.5+rand()%((int)(parts[i].life+1));
- rx=cos(angle*M_PI/180)*multipler;
- ry=-sin(angle*M_PI/180)*multipler;
- create_line_par(x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle, 0);
-
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if ((r&0xFF)==PT_LIGH)
- {
- parts[r>>8].tmp2=1+(rand()%200>parts[i].tmp2*parts[i].tmp2/10+60);
- parts[r>>8].life=(int)(1.0*parts[i].life/1.5-rand()%2);
- parts[r>>8].tmp=angle;
- parts[r>>8].temp=parts[i].temp;
- }
- }
-
- if (angle2!=-1)
- {
- multipler=parts[i].life*1.5+rand()%((int)(parts[i].life+1));
- rx=cos(angle2*M_PI/180)*multipler;
- ry=-sin(angle2*M_PI/180)*multipler;
- create_line_par(x, y, x+rx, y+ry, PT_LIGH, parts[i].temp, parts[i].life, angle2, 0);
-
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if ((r&0xFF)==PT_LIGH)
- {
- parts[r>>8].tmp2=1+(rand()%200>parts[i].tmp2*parts[i].tmp2/10+40);
- parts[r>>8].life=(int)(1.0*parts[i].life/1.5-rand()%2);
- parts[r>>8].tmp=angle;
- parts[r>>8].temp=parts[i].temp;
- }
- }
- }
-
- parts[i].tmp2=-1;
- return 1;
-}
-int graphics_LIGH(GRAPHICS_FUNC_ARGS)
-{
- *firea = 120;
- *firer = *colr = 235;
- *fireg = *colg = 245;
- *fireb = *colb = 255;
- *pixel_mode |= PMODE_GLOW | FIRE_ADD;
- return 1;
-}
diff --git a/src/elements/merc.c b/src/elements/merc.c
deleted file mode 100644
index dcecdde..0000000
--- a/src/elements/merc.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_MERC(UPDATE_FUNC_ARGS) {
- int r, rx, ry, trade, np;
- int maxtmp = ((10000/(parts[i].temp + 1))-1);
- if ((10000%((int)parts[i].temp+1))>rand()%((int)parts[i].temp+1))
- maxtmp ++;
- if (parts[i].tmp < maxtmp)
- {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r || (parts[i].tmp >=maxtmp))
- continue;
- if ((r&0xFF)==PT_MERC&&33>=rand()/(RAND_MAX/100)+1)
- {
- if ((parts[i].tmp + parts[r>>8].tmp + 1) <= maxtmp)
- {
- parts[i].tmp += parts[r>>8].tmp + 1;
- kill_part(r>>8);
- }
- }
- }
- }
- else
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (parts[i].tmp<=maxtmp)
- continue;
- if ((!r)&&parts[i].tmp>=1)//if nothing then create deut
- {
- np = create_part(-1,x+rx,y+ry,PT_MERC);
- if (np<0) continue;
- parts[i].tmp--;
- parts[np].temp = parts[i].temp;
- parts[np].tmp = 0;
- }
- }
- for ( trade = 0; trade<4; trade ++)
- {
- rx = rand()%5-2;
- ry = rand()%5-2;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_MERC&&(parts[i].tmp>parts[r>>8].tmp)&&parts[i].tmp>0)//diffusion
- {
- int temp = parts[i].tmp - parts[r>>8].tmp;
- if (temp ==1)
- {
- parts[r>>8].tmp ++;
- parts[i].tmp --;
- }
- else if (temp>0)
- {
- parts[r>>8].tmp += temp/2;
- parts[i].tmp -= temp/2;
- }
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/mort.c b/src/elements/mort.c
deleted file mode 100644
index 669fd0b..0000000
--- a/src/elements/mort.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_MORT(UPDATE_FUNC_ARGS) {
- create_part(-1, x, y-1, PT_SMKE);
- return 0;
-}
diff --git a/src/elements/nbhl.c b/src/elements/nbhl.c
deleted file mode 100644
index 362c120..0000000
--- a/src/elements/nbhl.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_NBHL(UPDATE_FUNC_ARGS) {
- if (parts[i].tmp)
- gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] += restrict_flt(0.001f*parts[i].tmp, 0.1f, 51.2f);
- else
- gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] += 0.1f;
- return 0;
-}
diff --git a/src/elements/nble.c b/src/elements/nble.c
deleted file mode 100644
index 31f6fc8..0000000
--- a/src/elements/nble.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_NBLE(UPDATE_FUNC_ARGS)
-{
- if (parts[i].temp > 5273.15 && pv[y/CELL][x/CELL] > 100.0f)
- {
- if (rand()%5 < 1)
- {
- int j;
- float temp = parts[i].temp;
- create_part(i,x,y,PT_CO2);
-
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1) parts[j].temp = temp;
- if (!(rand()%25)) { j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); if (j != -1) parts[j].temp = temp; }
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PHOT); if (j != -1) { parts[j].ctype = 0xFF0000; parts[j].temp = temp; }
-
- j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PLSM); if (j != -1) parts[j].temp = temp;
-
- parts[i].temp = temp+1750+rand()%500;
- pv[y/CELL][x/CELL] += 50;
- }
- }
- return 0;
-}
diff --git a/src/elements/neut.c b/src/elements/neut.c
deleted file mode 100644
index 5b8a4ae..0000000
--- a/src/elements/neut.c
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-
-int create_n_parts(int n, int x, int y, float vx, float vy, float temp, int t)//testing a new deut create part
-{
- int i, c;
- n = (n/50);
- if (n<1) {
- n = 1;
- }
- if (n>340) {
- n = 340;
- }
- if (x<0 || y<0 || x>=XRES || y>=YRES || t<0 || t>=PT_NUM || !ptypes[t].enabled)
- return -1;
-
- for (c=0; c<n; c++) {
- float r = (rand()%128+128)/127.0f;
- float a = (rand()%360)*M_PI/180.0f;
- if (pfree == -1)
- return -1;
- i = pfree;
- pfree = parts[i].life;
- if (i>parts_lastActiveIndex) parts_lastActiveIndex = i;
-
- parts[i].x = (float)x;
- parts[i].y = (float)y;
-#ifdef OGLR
- parts[i].lastX = (float)x;
- parts[i].lastY = (float)y;
-#endif
- parts[i].type = t;
- parts[i].life = rand()%480+480;
- parts[i].vx = r*cosf(a);
- parts[i].vy = r*sinf(a);
- parts[i].ctype = 0;
- parts[i].temp = temp;
- parts[i].tmp = 0;
- if (t!=PT_STKM&&t!=PT_STKM2 && t!=PT_PHOT && t!=PT_NEUT && !pmap[y][x])
- pmap[y][x] = t|(i<<8);
- else if ((t==PT_PHOT||t==PT_NEUT) && !photons[y][x])
- photons[y][x] = t|(i<<8);
-
- pv[y/CELL][x/CELL] += 6.0f * CFDS;
- }
- return 0;
-}
-
-int update_NEUT(UPDATE_FUNC_ARGS) {
- int r, rx, ry, rt;
- int pressureFactor = 3 + (int)pv[y/CELL][x/CELL];
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_WATR || (r&0xFF)==PT_ICEI || (r&0xFF)==PT_SNOW)
- {
- parts[i].vx *= 0.995;
- parts[i].vy *= 0.995;
- }
- if ((r&0xFF)==PT_PLUT && pressureFactor>(rand()%1000))
- {
- if (33>rand()%100)
- {
- create_part(r>>8, x+rx, y+ry, rand()%3 ? PT_LAVA : PT_URAN);
- parts[r>>8].temp = MAX_TEMP;
- if (parts[r>>8].type==PT_LAVA) {
- parts[r>>8].tmp = 100;
- parts[r>>8].ctype = PT_PLUT;
- }
- }
- else
- {
- create_part(r>>8, x+rx, y+ry, PT_NEUT);
- parts[r>>8].vx = 0.25f*parts[r>>8].vx + parts[i].vx;
- parts[r>>8].vy = 0.25f*parts[r>>8].vy + parts[i].vy;
- }
- pv[y/CELL][x/CELL] += 10.0f * CFDS; //Used to be 2, some people said nukes weren't powerful enough
- update_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
- }
-#ifdef SDEUT
- else if ((r&0xFF)==PT_DEUT && (pressureFactor+1+(parts[r>>8].life/100))>(rand()%1000))
- {
- create_n_parts(parts[r>>8].life, x+rx, y+ry, parts[i].vx, parts[i].vy, restrict_flt(parts[r>>8].temp + parts[r>>8].life*500, MIN_TEMP, MAX_TEMP), PT_NEUT);
- kill_part(r>>8);
- }
-#else
- else if ((r&0xFF)==PT_DEUT && (pressureFactor+1)>(rand()%1000))
- {
- create_part(r>>8, x+rx, y+ry, PT_NEUT);
- parts[r>>8].vx = 0.25f*parts[r>>8].vx + parts[i].vx;
- parts[r>>8].vy = 0.25f*parts[r>>8].vy + parts[i].vy;
- if (parts[r>>8].life>0)
- {
- parts[r>>8].life --;
- parts[r>>8].temp = restrict_flt(parts[r>>8].temp + parts[r>>8].life*17, MIN_TEMP, MAX_TEMP);
- pv[y/CELL][x/CELL] += 6.0f * CFDS;
- }
- else
- kill_part(r>>8);
- }
-#endif
- else if ((r&0xFF)==PT_GUNP && 15>(rand()%1000))
- part_change_type(r>>8,x+rx,y+ry,PT_DUST);
- else if ((r&0xFF)==PT_DYST && 15>(rand()%1000))
- part_change_type(r>>8,x+rx,y+ry,PT_YEST);
- else if ((r&0xFF)==PT_YEST)
- part_change_type(r>>8,x+rx,y+ry,PT_DYST);
- else if ((r&0xFF)==PT_WATR && 15>(rand()%100))
- part_change_type(r>>8,x+rx,y+ry,PT_DSTW);
- else if ((r&0xFF)==PT_PLEX && 15>(rand()%1000))
- part_change_type(r>>8,x+rx,y+ry,PT_GOO);
- else if ((r&0xFF)==PT_NITR && 15>(rand()%1000))
- part_change_type(r>>8,x+rx,y+ry,PT_DESL);
- else if ((r&0xFF)==PT_PLNT && 5>(rand()%100))
- create_part(r>>8, x+rx, y+ry, PT_WOOD);
- else if ((r&0xFF)==PT_DESL && 15>(rand()%1000))
- part_change_type(r>>8,x+rx,y+ry,PT_GAS);
- else if ((r&0xFF)==PT_COAL && 5>(rand()%100))
- create_part(r>>8, x+rx, y+ry, PT_WOOD);
- else if ((r&0xFF)==PT_DUST && 5>(rand()%100))
- part_change_type(r>>8, x+rx, y+ry, PT_FWRK);
- else if ((r&0xFF)==PT_FWRK && 5>(rand()%100))
- parts[r>>8].ctype = PT_DUST;
- else if ((r&0xFF)==PT_ACID && 5>(rand()%100))
- create_part(r>>8, x+rx, y+ry, PT_ISOZ);
- else if ((r&0xFF)==PT_TTAN && 5>(rand()%100))
- {
- kill_part(i);
- return 1;
- }
- else if ((r&0xFF)==PT_EXOT && 5>(rand()%100))
- parts[r>>8].life = 1500;
- /*if(parts[r>>8].type>1 && parts[r>>8].type!=PT_NEUT && parts[r>>8].type-1!=PT_NEUT && parts[r>>8].type-1!=PT_STKM &&
- (ptypes[parts[r>>8].type-1].menusection==SC_LIQUID||
- ptypes[parts[r>>8].type-1].menusection==SC_EXPLOSIVE||
- ptypes[parts[r>>8].type-1].menusection==SC_GAS||
- ptypes[parts[r>>8].type-1].menusection==SC_POWDERS) && 15>(rand()%1000))
- parts[r>>8].type--;*/
- }
- return 0;
-}
-
-int graphics_NEUT(GRAPHICS_FUNC_ARGS)
-{
- *firea = 120;
- *firer = 10;
- *fireg = 80;
- *fireb = 120;
-
- *pixel_mode &= ~PMODE_FLAT;
- *pixel_mode |= FIRE_ADD | PMODE_ADD;
- return 1;
-}
diff --git a/src/elements/newgraphics.c b/src/elements/newgraphics.c
deleted file mode 100644
index da3cb26..0000000
--- a/src/elements/newgraphics.c
+++ /dev/null
@@ -1,530 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-#include "hmap.h"
-
-int graphics_QRTZ(GRAPHICS_FUNC_ARGS) //QRTZ and PQRT
-{
- int t = cpart->type, z = cpart->tmp - 5;//speckles!
- if (cpart->temp>(ptransitions[t].thv-800.0f))//hotglow for quartz
- {
- float frequency = 3.1415/(2*ptransitions[t].thv-(ptransitions[t].thv-800.0f));
- int q = (cpart->temp>ptransitions[t].thv)?ptransitions[t].thv-(ptransitions[t].thv-800.0f):cpart->temp-(ptransitions[t].thv-800.0f);
- *colr += sin(frequency*q) * 226 + (z * 16);
- *colg += sin(frequency*q*4.55 +3.14) * 34 + (z * 16);
- *colb += sin(frequency*q*2.22 +3.14) * 64 + (z * 16);
- }
- else
- {
- *colr += z * 16;
- *colg += z * 16;
- *colb += z * 16;
- }
- return 0;
-}
-int graphics_CLST(GRAPHICS_FUNC_ARGS)
-{
- int z = cpart->tmp - 5;//speckles!
- *colr += z * 16;
- *colg += z * 16;
- *colb += z * 16;
- return 0;
-}
-int graphics_CBNW(GRAPHICS_FUNC_ARGS)
-{
- int z = cpart->tmp2 - 20;//speckles!
- *colr += z * 1;
- *colg += z * 2;
- *colb += z * 8;
- return 0;
-}
-int graphics_SPNG(GRAPHICS_FUNC_ARGS)
-{
- *colr -= cpart->life*15;
- *colg -= cpart->life*15;
- *colb -= cpart->life*15;
- if (*colr<=50)
- *colr = 50;
- if (*colg<=50)
- *colg = 50;
- if (*colb<=20)
- *colb = 20;
- return 0;
-}
-int graphics_LIFE(GRAPHICS_FUNC_ARGS)
-{
- pixel pc;
- if (cpart->ctype==NGT_LOTE)//colors for life states
- {
- if (cpart->tmp==2)
- pc = PIXRGB(255, 128, 0);
- else if (cpart->tmp==1)
- pc = PIXRGB(255, 255, 0);
- else
- pc = PIXRGB(255, 0, 0);
- }
- else if (cpart->ctype==NGT_FRG2)//colors for life states
- {
- if (cpart->tmp==2)
- pc = PIXRGB(0, 100, 50);
- else
- pc = PIXRGB(0, 255, 90);
- }
- else if (cpart->ctype==NGT_STAR)//colors for life states
- {
- if (cpart->tmp==4)
- pc = PIXRGB(0, 0, 128);
- else if (cpart->tmp==3)
- pc = PIXRGB(0, 0, 150);
- else if (cpart->tmp==2)
- pc = PIXRGB(0, 0, 190);
- else if (cpart->tmp==1)
- pc = PIXRGB(0, 0, 230);
- else
- pc = PIXRGB(0, 0, 70);
- }
- else if (cpart->ctype==NGT_FROG)//colors for life states
- {
- if (cpart->tmp==2)
- pc = PIXRGB(0, 100, 0);
- else
- pc = PIXRGB(0, 255, 0);
- }
- else if (cpart->ctype==NGT_BRAN)//colors for life states
- {
- if (cpart->tmp==1)
- pc = PIXRGB(150, 150, 0);
- else
- pc = PIXRGB(255, 255, 0);
- } else {
- pc = gmenu[cpart->ctype].colour;
- }
- *colr = PIXR(pc);
- *colg = PIXG(pc);
- *colb = PIXB(pc);
- return 0;
-}
-int graphics_GRAV(GRAPHICS_FUNC_ARGS)
-{
- *colr = 20;
- *colg = 20;
- *colb = 20;
- if (cpart->vx>0)
- {
- *colr += (cpart->vx)*GRAV_R;
- *colg += (cpart->vx)*GRAV_G;
- *colb += (cpart->vx)*GRAV_B;
- }
- if (cpart->vy>0)
- {
- *colr += (cpart->vy)*GRAV_G;
- *colg += (cpart->vy)*GRAV_B;
- *colb += (cpart->vy)*GRAV_R;
-
- }
- if (cpart->vx<0)
- {
- *colr -= (cpart->vx)*GRAV_B;
- *colg -= (cpart->vx)*GRAV_R;
- *colb -= (cpart->vx)*GRAV_G;
-
- }
- if (cpart->vy<0)
- {
- *colr -= (cpart->vy)*GRAV_R2;
- *colg -= (cpart->vy)*GRAV_G2;
- *colb -= (cpart->vy)*GRAV_B2;
- }
- return 0;
-}
-int graphics_WIFI(GRAPHICS_FUNC_ARGS)
-{
- float frequency = 0.0628;
- int q = cpart->tmp;
- *colr = sin(frequency*q + 0) * 127 + 128;
- *colg = sin(frequency*q + 2) * 127 + 128;
- *colb = sin(frequency*q + 4) * 127 + 128;
- *pixel_mode |= EFFECT_LINES;
- return 0;
-}
-int graphics_GEL(GRAPHICS_FUNC_ARGS)
-{
- int q = cpart->tmp;
- *colr = q*(32-255)/120+255;
- *colg = q*(48-186)/120+186;
- *colb = q*208/120;
- return 0;
-}
-int graphics_PRTI(GRAPHICS_FUNC_ARGS)
-{
- *firea = 8;
- *firer = 255;
- *fireg = 0;
- *fireb = 0;
- *pixel_mode |= EFFECT_GRAVIN;
- *pixel_mode |= EFFECT_LINES;
- *pixel_mode &= ~PMODE;
- *pixel_mode |= PMODE_ADD;
- return 1;
-}
-int graphics_PRTO(GRAPHICS_FUNC_ARGS)
-{
- *firea = 8;
- *firer = 0;
- *fireg = 0;
- *fireb = 255;
- *pixel_mode |= EFFECT_GRAVOUT;
- *pixel_mode |= EFFECT_LINES;
- *pixel_mode &= ~PMODE;
- *pixel_mode |= PMODE_ADD;
- return 1;
-}
-int graphics_BIZR(GRAPHICS_FUNC_ARGS) //BIZR, BIZRG, BIZRS
-{
- int x = 0;
- *colg = 0;
- *colb = 0;
- *colr = 0;
- for (x=0; x<12; x++) {
- *colr += (cpart->ctype >> (x+18)) & 1;
- *colb += (cpart->ctype >> x) & 1;
- }
- for (x=0; x<12; x++)
- *colg += (cpart->ctype >> (x+9)) & 1;
- x = 624/(*colr+*colg+*colb+1);
- *colr *= x;
- *colg *= x;
- *colb *= x;
- if(fabs(cpart->vx)+fabs(cpart->vy)>0)
- {
- *firea = 255;
- *fireg = *colg/5 * fabs(cpart->vx)+fabs(cpart->vy);
- *fireb = *colb/5 * fabs(cpart->vx)+fabs(cpart->vy);
- *firer = *colr/5 * fabs(cpart->vx)+fabs(cpart->vy);
- *pixel_mode |= FIRE_ADD;
- }
- return 0;
-}
-int graphics_INVS(GRAPHICS_FUNC_ARGS)
-{
- if(pv[ny/CELL][nx/CELL]>4.0f || pv[ny/CELL][nx/CELL]<-4.0f)
- {
- *cola = 100;
- *colr = 15;
- *colg = 0;
- *colb = 150;
- *pixel_mode = PMODE_BLEND;
- }
- return 0;
-}
-int graphics_ACID(GRAPHICS_FUNC_ARGS)
-{
- int s = cpart->life;
- if (s>75) s = 75; //These two should not be here.
- if (s<49) s = 49;
- s = (s-49)*3;
- if (s==0) s = 1;
- *colr += s*4;
- *colg += s*1;
- *colb += s*2;
- *pixel_mode |= PMODE_BLUR;
- return 0;
-}
-int graphics_FILT(GRAPHICS_FUNC_ARGS)
-{
- int x, temp_bin = (int)((cpart->temp-273.0f)*0.025f);
- if (temp_bin < 0) temp_bin = 0;
- if (temp_bin > 25) temp_bin = 25;
- cpart->ctype = 0x1F << temp_bin;
- *colg = 0;
- *colb = 0;
- *colr = 0;
- for (x=0; x<12; x++) {
- *colr += (cpart->ctype >> (x+18)) & 1;
- *colb += (cpart->ctype >> x) & 1;
- }
- for (x=0; x<12; x++)
- *colg += (cpart->ctype >> (x+9)) & 1;
- x = 624/(*colr+*colg+*colb+1);
- *cola = 127;
- *colr *= x;
- *colg *= x;
- *colb *= x;
- *pixel_mode &= ~PMODE;
- *pixel_mode |= PMODE_BLEND;
- return 0;
-}
-int graphics_BRAY(GRAPHICS_FUNC_ARGS)
-{
- int x, trans = 255;
- if(cpart->tmp==0)
- {
- trans = cpart->life * 7;
- if (trans>255) trans = 255;
- if (cpart->ctype) {
- *colg = 0;
- *colb = 0;
- *colr = 0;
- for (x=0; x<12; x++) {
- *colr += (cpart->ctype >> (x+18)) & 1;
- *colb += (cpart->ctype >> x) & 1;
- }
- for (x=0; x<12; x++)
- *colg += (cpart->ctype >> (x+9)) & 1;
- x = 624/(*colr+*colg+*colb+1);
- *colr *= x;
- *colg *= x;
- *colb *= x;
- }
- }
- else if(cpart->tmp==1)
- {
- trans = cpart->life/4;
- if (trans>255) trans = 255;
- if (cpart->ctype) {
- *colg = 0;
- *colb = 0;
- *colr = 0;
- for (x=0; x<12; x++) {
- *colr += (cpart->ctype >> (x+18)) & 1;
- *colb += (cpart->ctype >> x) & 1;
- }
- for (x=0; x<12; x++)
- *colg += (cpart->ctype >> (x+9)) & 1;
- x = 624/(*colr+*colg+*colb+1);
- *colr *= x;
- *colg *= x;
- *colb *= x;
- }
- }
- else if(cpart->tmp==2)
- {
- trans = cpart->life*100;
- if (trans>255) trans = 255;
- *colr = 255;
- *colg = 150;
- *colb = 50;
- }
- *cola = trans;
- *pixel_mode &= ~PMODE;
- *pixel_mode |= PMODE_BLEND | PMODE_GLOW;
- return 0;
-}
-int graphics_SWCH(GRAPHICS_FUNC_ARGS)
-{
- if(cpart->life >= 10)
- {
- *colr = 17;
- *colg = 217;
- *colb = 24;
- *pixel_mode |= PMODE_GLOW;
- }
- return 0;
-}
-int graphics_THDR(GRAPHICS_FUNC_ARGS)
-{
- *firea = 160;
- *fireg = 192;
- *fireb = 255;
- *firer = 144;
- *pixel_mode |= FIRE_ADD;
- return 1;
-}
-int graphics_GLOW(GRAPHICS_FUNC_ARGS)
-{
- *firer = restrict_flt(cpart->temp-(275.13f+32.0f), 0, 128)/50.0f;
- *fireg = restrict_flt(cpart->ctype, 0, 128)/50.0f;
- *fireb = restrict_flt(cpart->tmp, 0, 128)/50.0f;
-
- *colr = restrict_flt(64.0f+cpart->temp-(275.13f+32.0f), 0, 255);
- *colg = restrict_flt(64.0f+cpart->ctype, 0, 255);
- *colb = restrict_flt(64.0f+cpart->tmp, 0, 255);
-
- *pixel_mode |= FIRE_ADD;
- return 0;
-}
-int graphics_LCRY(GRAPHICS_FUNC_ARGS)
-{
- if(decorations_enable && cpart->dcolour && cpart->dcolour&0xFF000000)
- {
- *colr = (cpart->dcolour>>16)&0xFF;
- *colg = (cpart->dcolour>>8)&0xFF;
- *colb = (cpart->dcolour)&0xFF;
-
- if(cpart->tmp2<10){
- *colr /= 10-cpart->tmp2;
- *colg /= 10-cpart->tmp2;
- *colb /= 10-cpart->tmp2;
- }
-
- }
- else
- {
- *colr = *colg = *colb = 0x50+((cpart->tmp2>10?10:cpart->tmp2)*10);
- }
- *pixel_mode |= NO_DECO;
- return 0;
-
- /*int lifemod = ((cpart->tmp2>10?10:cpart->tmp2)*10);
- *colr += lifemod;
- *colg += lifemod;
- *colb += lifemod;
- if(decorations_enable && cpart->dcolour && cpart->dcolour&0xFF000000)
- {
- lifemod *= 2.5f;
- if(lifemod < 40)
- lifemod = 40;
- *colr = (lifemod*((cpart->dcolour>>16)&0xFF) + (255-lifemod)**colr) >> 8;
- *colg = (lifemod*((cpart->dcolour>>8)&0xFF) + (255-lifemod)**colg) >> 8;
- *colb = (lifemod*((cpart->dcolour)&0xFF) + (255-lifemod)**colb) >> 8;
- }
- *pixel_mode |= NO_DECO;
- return 0;*/
-}
-int graphics_PCLN(GRAPHICS_FUNC_ARGS)
-{
- int lifemod = ((cpart->life>10?10:cpart->life)*10);
- *colr += lifemod;
- *colg += lifemod;
- return 0;
-}
-int graphics_PBCN(GRAPHICS_FUNC_ARGS)
-{
- int lifemod = ((cpart->life>10?10:cpart->life)*10);
- *colr += lifemod;
- *colg += lifemod/2;
- return 0;
-}
-int graphics_DLAY(GRAPHICS_FUNC_ARGS)
-{
- int stage = (int)(((float)cpart->life/(cpart->temp-273.15))*100.0f);
- *colr += stage;
- *colg += stage;
- *colb += stage;
- return 0;
-}
-int graphics_HSWC(GRAPHICS_FUNC_ARGS)
-{
- int lifemod = ((cpart->life>10?10:cpart->life)*19);
- *colr += lifemod;
- return 0;
-}
-int graphics_PVOD(GRAPHICS_FUNC_ARGS)
-{
- int lifemod = ((cpart->life>10?10:cpart->life)*16);
- *colr += lifemod;
- return 0;
-}
-int graphics_STOR(GRAPHICS_FUNC_ARGS)
-{
- if(cpart->tmp){
- *pixel_mode |= PMODE_GLOW;
- *colr = 0x50;
- *colg = 0xDF;
- *colb = 0xDF;
- } else {
- *colr = 0x20;
- *colg = 0xAF;
- *colb = 0xAF;
- }
- return 0;
-}
-int graphics_PUMP(GRAPHICS_FUNC_ARGS)
-{
- int lifemod = ((cpart->life>10?10:cpart->life)*19);
- *colb += lifemod;
- return 0;
-}
-int graphics_GPMP(GRAPHICS_FUNC_ARGS)
-{
- int lifemod = ((cpart->life>10?10:cpart->life)*19);
- *colg += lifemod;
- *colb += lifemod;
- return 0;
-}
-int graphics_HFLM(GRAPHICS_FUNC_ARGS)
-{
- int caddress = restrict_flt(restrict_flt((float)((int)(cpart->life/2)), 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
- *colr = (unsigned char)hflm_data[caddress];
- *colg = (unsigned char)hflm_data[caddress+1];
- *colb = (unsigned char)hflm_data[caddress+2];
-
- *firea = 255;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
-
- *pixel_mode = PMODE_NONE; //Clear default, don't draw pixel
- *pixel_mode |= FIRE_ADD;
- //Returning 0 means dynamic, do not cache
- return 0;
-}
-int graphics_FIRW(GRAPHICS_FUNC_ARGS)
-{
- if(cpart->tmp > 0)
- {
- *pixel_mode |= PMODE_GLOW;
- }
- return 0;
-}
-int graphics_GBMB(GRAPHICS_FUNC_ARGS)
-{
- if (cpart->life <= 0) {
- *pixel_mode |= PMODE_FLARE;
- }
- else
- {
- *pixel_mode |= PMODE_SPARK;
- }
- return 0;
-}
-int graphics_COAL(GRAPHICS_FUNC_ARGS) //Both COAL and Broken Coal
-{
- *colr += (cpart->tmp2-295.15f)/3;
-
- if (*colr > 170)
- *colr = 170;
- if (*colr < *colg)
- *colr = *colg;
-
- *colg = *colb = *colr;
-
- if((cpart->temp-295.15f) > 300.0f-200.0f)
- {
- float frequency = 3.1415/(2*300.0f-(300.0f-200.0f));
- int q = ((cpart->temp-295.15f)>300.0f)?300.0f-(300.0f-200.0f):(cpart->temp-295.15f)-(300.0f-200.0f);
-
- *colr += sin(frequency*q) * 226;
- *colg += sin(frequency*q*4.55 +3.14) * 34;
- *colb += sin(frequency*q*2.22 +3.14) * 64;
- }
- return 0;
-}
-
-int graphics_BRCK(GRAPHICS_FUNC_ARGS)
-{
- if (cpart->tmp == 1)
- {
- *pixel_mode |= FIRE_ADD;
- *colb += 100;
-
- *firea = 40;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
- }
- return 0;
-}
diff --git a/src/elements/none.c b/src/elements/none.c
deleted file mode 100644
index f2a7e2d..0000000
--- a/src/elements/none.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_(UPDATE_FUNC_ARGS) {
-
- return 0;
-}
diff --git a/src/elements/nptct.c b/src/elements/nptct.c
deleted file mode 100644
index 4f32bd7..0000000
--- a/src/elements/nptct.c
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_NPTCT(UPDATE_FUNC_ARGS) {
- if (parts[i].temp>295.0f)
- parts[i].temp -= 2.5f;
- return 0;
-}
diff --git a/src/elements/nwhl.c b/src/elements/nwhl.c
deleted file mode 100644
index c1d75fa..0000000
--- a/src/elements/nwhl.c
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_NWHL(UPDATE_FUNC_ARGS) {
- gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] -= 0.1f;
- return 0;
-}
diff --git a/src/elements/pbcn.c b/src/elements/pbcn.c
deleted file mode 100644
index 2754a1a..0000000
--- a/src/elements/pbcn.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_PBCN(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- if (parts[i].life>0 && parts[i].life!=10)
- parts[i].life--;
- if (!parts[i].tmp2 && pv[y/CELL][x/CELL]>4.0f)
- parts[i].tmp2 = rand()%40+80;
- if (parts[i].tmp2)
- {
- float advection = 0.1f;
- parts[i].vx += advection*vx[y/CELL][x/CELL];
- parts[i].vy += advection*vy[y/CELL][x/CELL];
- parts[i].tmp2--;
- if(!parts[i].tmp2){
- kill_part(i);
- return 1;
- }
- }
- if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !ptypes[parts[i].ctype].enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT)))
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
- {
- r = photons[y+ry][x+rx];
- if (!r)
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN &&
- (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_SPRK &&
- (r&0xFF)!=PT_NSCN && (r&0xFF)!=PT_PSCN &&
- (r&0xFF)!=PT_STKM && (r&0xFF)!=PT_STKM2 &&
- (r&0xFF)!=PT_PBCN && (r&0xFF)<PT_NUM)
- {
- parts[i].ctype = r&0xFF;
- if ((r&0xFF)==PT_LIFE || (r&0xFF)==PT_LAVA)
- parts[i].tmp = parts[r>>8].ctype;
- }
- }
- if (parts[i].life==10)
- {
-
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_PBCN)
- {
- if (parts[r>>8].life<10&&parts[r>>8].life>0)
- parts[i].life = 9;
- else if (parts[r>>8].life==0)
- parts[r>>8].life = 10;
- }
- }
- }
- if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && ptypes[parts[i].ctype].enabled && parts[i].life==10) {
- if (parts[i].ctype==PT_PHOT) {//create photons a different way
- for (rx=-1; rx<2; rx++) {
- for (ry=-1; ry<2; ry++)
- {
- if (rx || ry)
- {
- int r = create_part(-1, x+rx, y+ry, parts[i].ctype);
- if (r!=-1)
- {
- parts[r].vx = rx*3;
- parts[r].vy = ry*3;
- if (r>i)
- {
- // Make sure movement doesn't happen until next frame, to avoid gaps in the beams of photons produced
- parts[r].flags |= FLAG_SKIPMOVE;
- }
- }
- }
- }
- }
- }
- else if (parts[i].ctype==PT_LIFE) {//create life a different way
- for (rx=-1; rx<2; rx++) {
- for (ry=-1; ry<2; ry++) {
- create_part(-1, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8));
- }
- }
- }
- else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0)
- {
- int np = create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
- if (np>=0)
- {
- if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && ptransitions[parts[i].tmp].tht==PT_LAVA)
- parts[np].ctype = parts[i].tmp;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/pcln.c b/src/elements/pcln.c
deleted file mode 100644
index 30055e8..0000000
--- a/src/elements/pcln.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_PCLN(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- if (parts[i].life>0 && parts[i].life!=10)
- parts[i].life--;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_SPRK && parts[r>>8].life>0 && parts[r>>8].life<4)
- {
- if (parts[r>>8].ctype==PT_PSCN)
- parts[i].life = 10;
- else if (parts[r>>8].ctype==PT_NSCN)
- parts[i].life = 9;
- }
- if ((r&0xFF)==PT_PCLN)
- {
- if (parts[i].life==10&&parts[r>>8].life<10&&parts[r>>8].life>0)
- parts[i].life = 9;
- else if (parts[i].life==0&&parts[r>>8].life==10)
- parts[i].life = 10;
- }
- }
- if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !ptypes[parts[i].ctype].enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT)))
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
- {
- r = photons[y+ry][x+rx];
- if (!r)
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_CLNE && (r&0xFF)!=PT_PCLN &&
- (r&0xFF)!=PT_BCLN && (r&0xFF)!=PT_SPRK &&
- (r&0xFF)!=PT_NSCN && (r&0xFF)!=PT_PSCN &&
- (r&0xFF)!=PT_STKM && (r&0xFF)!=PT_STKM2 &&
- (r&0xFF)!=PT_PBCN && (r&0xFF)<PT_NUM)
- {
- parts[i].ctype = r&0xFF;
- if ((r&0xFF)==PT_LIFE || (r&0xFF)==PT_LAVA)
- parts[i].tmp = parts[r>>8].ctype;
- }
- }
- if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && ptypes[parts[i].ctype].enabled && parts[i].life==10) {
- if (parts[i].ctype==PT_PHOT) {//create photons a different way
- for (rx=-1; rx<2; rx++) {
- for (ry=-1; ry<2; ry++)
- {
- if (rx || ry)
- {
- int r = create_part(-1, x+rx, y+ry, parts[i].ctype);
- if (r!=-1)
- {
- parts[r].vx = rx*3;
- parts[r].vy = ry*3;
- if (r>i)
- {
- // Make sure movement doesn't happen until next frame, to avoid gaps in the beams of photons produced
- parts[r].flags |= FLAG_SKIPMOVE;
- }
- }
- }
- }
- }
- }
- else if (parts[i].ctype==PT_LIFE) {//create life a different way
- for (rx=-1; rx<2; rx++) {
- for (ry=-1; ry<2; ry++) {
- create_part(-1, x+rx, y+ry, parts[i].ctype|(parts[i].tmp<<8));
- }
- }
- }
- else if (parts[i].ctype!=PT_LIGH || (rand()%30)==0)
- {
- int np = create_part(-1, x+rand()%3-1, y+rand()%3-1, parts[i].ctype);
- if (np>=0)
- {
- if (parts[i].ctype==PT_LAVA && parts[i].tmp>0 && parts[i].tmp<PT_NUM && ptransitions[parts[i].tmp].tht==PT_LAVA)
- parts[np].ctype = parts[i].tmp;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/phot.c b/src/elements/phot.c
deleted file mode 100644
index d014ba5..0000000
--- a/src/elements/phot.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_PHOT(UPDATE_FUNC_ARGS) {
- int r, rt, rx, ry;
- float rr, rrr;
- parts[i].pavg[0] = x;
- parts[i].pavg[1] = y;
- if (!(parts[i].ctype&0x3FFFFFFF)) {
- kill_part(i);
- return 1;
- }
- if (parts[i].temp > 506)
- if (1>rand()%10) update_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_ISOZ && 5>(rand()%2000))
- {
- parts[i].vx *= 0.90;
- parts[i].vy *= 0.90;
- create_part(r>>8, x+rx, y+ry, PT_PHOT);
- rrr = (rand()%360)*3.14159f/180.0f;
- rr = (rand()%128+128)/127.0f;
- parts[r>>8].vx = rr*cosf(rrr);
- parts[r>>8].vy = rr*sinf(rrr);
- pv[y/CELL][x/CELL] -= 15.0f * CFDS;
- }
- if ((r&0xFF)==PT_ISZS && 5>(rand()%2000))
- {
- parts[i].vx *= 0.90;
- parts[i].vy *= 0.90;
- create_part(r>>8, x+rx, y+ry, PT_PHOT);
- rr = (rand()%228+128)/127.0f;
- rrr = (rand()%360)*3.14159f/180.0f;
- parts[r>>8].vx = rr*cosf(rrr);
- parts[r>>8].vy = rr*sinf(rrr);
- pv[y/CELL][x/CELL] -= 15.0f * CFDS;
- }
- }
- r = pmap[y][x];
- if((r&0xFF) == PT_QRTZ && r)// && parts[i].ctype==0x3FFFFFFF)
- {
- float a = (rand()%360)*3.14159f/180.0f;
- parts[i].vx = 3.0f*cosf(a);
- parts[i].vy = 3.0f*sinf(a);
- if(parts[i].ctype == 0x3FFFFFFF)
- parts[i].ctype = 0x1F<<(rand()%26);
- parts[i].life++; //Delay death
- }
- //r = pmap[y][x];
- //rt = r&0xFF;
- /*if (rt==PT_CLNE || rt==PT_PCLN || rt==PT_BCLN || rt==PT_PBCN) {
- if (!parts[r>>8].ctype)
- parts[r>>8].ctype = PT_PHOT;
- }*/
-
- return 0;
-}
-
-int graphics_PHOT(GRAPHICS_FUNC_ARGS)
-{
- int x = 0;
- *colr = *colg = *colb = 0;
- for (x=0; x<12; x++) {
- *colr += (cpart->ctype >> (x+18)) & 1;
- *colb += (cpart->ctype >> x) & 1;
- }
- for (x=0; x<12; x++)
- *colg += (cpart->ctype >> (x+9)) & 1;
- x = 624/(*colr+*colg+*colb+1);
- *colr *= x;
- *colg *= x;
- *colb *= x;
-
- *firea = 100;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
-
- *pixel_mode &= ~PMODE_FLAT;
- *pixel_mode |= FIRE_ADD | PMODE_ADD;
- return 0;
-}
diff --git a/src/elements/pipe.c b/src/elements/pipe.c
deleted file mode 100644
index 9502d38..0000000
--- a/src/elements/pipe.c
+++ /dev/null
@@ -1,563 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-#define PFLAG_NORMALSPEED 0x00010000
-
-// parts[].tmp flags
-// trigger flags to be processed this frame (trigger flags for next frame are shifted 3 bits to the left):
-#define PPIP_TMPFLAG_TRIGGER_ON 0x10000000
-#define PPIP_TMPFLAG_TRIGGER_OFF 0x08000000
-#define PPIP_TMPFLAG_TRIGGER_REVERSE 0x04000000
-#define PPIP_TMPFLAG_TRIGGERS 0x1C000000
-// current status of the pipe
-#define PPIP_TMPFLAG_PAUSED 0x02000000
-#define PPIP_TMPFLAG_REVERSED 0x01000000
-// 0x000000FF element
-// 0x00000100 is single pixel pipe
-// 0x00000200 will transfer like a single pixel pipe when in forward mode
-// 0x00001C00 forward single pixel pipe direction
-// 0x00002000 will transfer like a single pixel pipe when in reverse mode
-// 0x0001C000 reverse single pixel pipe direction
-
-signed char pos_1_rx[] = {-1,-1,-1, 0, 0, 1, 1, 1};
-signed char pos_1_ry[] = {-1, 0, 1,-1, 1,-1, 0, 1};
-
-int ppip_changed = 0;
-
-void PPIP_flood_trigger(int x, int y, int sparkedBy)
-{
- int coord_stack_limit = XRES*YRES;
- unsigned short (*coord_stack)[2];
- int coord_stack_size = 0;
- int x1, x2;
-
- // Separate flags for on and off in case PPIP is sparked by PSCN and NSCN on the same frame
- // - then PSCN can override NSCN and behaviour is not dependent on particle order
- int prop = 0;
- if (sparkedBy==PT_PSCN) prop = PPIP_TMPFLAG_TRIGGER_ON << 3;
- else if (sparkedBy==PT_NSCN) prop = PPIP_TMPFLAG_TRIGGER_OFF << 3;
- else if (sparkedBy==PT_INST) prop = PPIP_TMPFLAG_TRIGGER_REVERSE << 3;
-
- if (prop==0 || (pmap[y][x]&0xFF)!=PT_PPIP || (parts[pmap[y][x]>>8].tmp & prop))
- return;
-
- coord_stack = malloc(sizeof(unsigned short)*2*coord_stack_limit);
- coord_stack[coord_stack_size][0] = x;
- coord_stack[coord_stack_size][1] = y;
- coord_stack_size++;
-
- do
- {
- coord_stack_size--;
- x = coord_stack[coord_stack_size][0];
- y = coord_stack[coord_stack_size][1];
- x1 = x2 = x;
- // go left as far as possible
- while (x1>=CELL)
- {
- if ((pmap[y][x1-1]&0xFF)!=PT_PPIP)
- {
- break;
- }
- x1--;
- }
- // go right as far as possible
- while (x2<XRES-CELL)
- {
- if ((pmap[y][x2+1]&0xFF)!=PT_PPIP)
- {
- break;
- }
- x2++;
- }
- // fill span
- for (x=x1; x<=x2; x++)
- {
- if (!(parts[pmap[y][x]>>8].tmp & prop))
- ppip_changed = 1;
- parts[pmap[y][x]>>8].tmp |= prop;
- }
-
- // add adjacent pixels to stack
- // +-1 to x limits to include diagonally adjacent pixels
- // Don't need to check x bounds here, because already limited to [CELL, XRES-CELL]
- if (y>=CELL+1)
- for (x=x1-1; x<=x2+1; x++)
- if ((pmap[y-1][x]&0xFF)==PT_PPIP && !(parts[pmap[y-1][x]>>8].tmp & prop))
- {
- coord_stack[coord_stack_size][0] = x;
- coord_stack[coord_stack_size][1] = y-1;
- coord_stack_size++;
- if (coord_stack_size>=coord_stack_limit)
- {
- free(coord_stack);
- return;
- }
- }
- if (y<YRES-CELL-1)
- for (x=x1-1; x<=x2+1; x++)
- if ((pmap[y+1][x]&0xFF)==PT_PPIP && !(parts[pmap[y+1][x]>>8].tmp & prop))
- {
- coord_stack[coord_stack_size][0] = x;
- coord_stack[coord_stack_size][1] = y+1;
- coord_stack_size++;
- if (coord_stack_size>=coord_stack_limit)
- {
- free(coord_stack);
- return;
- }
- }
- } while (coord_stack_size>0);
- free(coord_stack);
-}
-
-void PIPE_transfer_pipe_to_part(particle *pipe, particle *part)
-{
- part->type = (pipe->tmp & 0xFF);
- part->temp = pipe->temp;
- part->life = pipe->tmp2;
- part->tmp = pipe->pavg[0];
- part->ctype = pipe->pavg[1];
- pipe->tmp &= ~0xFF;
-
- if (!ptypes[part->type].properties & TYPE_ENERGY)
- {
- part->vx = 0.0f;
- part->vy = 0.0f;
- }
- else if (part->type == PT_PHOT && part->ctype == 0x40000000)
- part->ctype = 0x3FFFFFFF;
- part->tmp2 = 0;
- part->flags = 0;
- part->dcolour = 0;
-}
-
-void PIPE_transfer_part_to_pipe(particle *part, particle *pipe)
-{
- pipe->tmp = (pipe->tmp&~0xFF) | part->type;
- pipe->temp = part->temp;
- pipe->tmp2 = part->life;
- pipe->pavg[0] = part->tmp;
- pipe->pavg[1] = part->ctype;
-}
-
-void PIPE_transfer_pipe_to_pipe(particle *src, particle *dest)
-{
- dest->tmp = (dest->tmp&~0xFF) | (src->tmp&0xFF);
- dest->temp = src->temp;
- dest->tmp2 = src->tmp2;
- dest->pavg[0] = src->pavg[0];
- dest->pavg[1] = src->pavg[1];
- src->tmp &= ~0xFF;
-}
-
-
-void pushParticle(int i, int count, int original)
-{
- int rndstore, rnd, rx, ry, r, x, y, np, q, notctype=(((parts[i].ctype)%3)+2);
- if ((parts[i].tmp&0xFF) == 0 || count >= 2)//don't push if there is nothing there, max speed of 2 per frame
- return;
- x = (int)(parts[i].x+0.5f);
- y = (int)(parts[i].y+0.5f);
- if( !(parts[i].tmp&0x200) )
- {
- //normal random push
- rndstore = rand();
- // RAND_MAX is at least 32767 on all platforms i.e. pow(8,5)-1
- // so can go 5 cycles without regenerating rndstore
- for (q=0; q<3; q++)//try to push 3 times
- {
- rnd = rndstore&7;
- rndstore = rndstore>>3;
- rx = pos_1_rx[rnd];
- ry = pos_1_ry[rnd];
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- else if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP) && parts[r>>8].ctype!=notctype && (parts[r>>8].tmp&0xFF)==0)
- {
- PIPE_transfer_pipe_to_pipe(parts+i, parts+(r>>8));
- if (r>>8 > original)
- parts[r>>8].flags |= PFLAG_NORMALSPEED;//skip particle push, normalizes speed
- count++;
- pushParticle(r>>8,count,original);
- }
- else if ((r&0xFF) == PT_PRTI) //Pass particles into PRTI for a pipe speed increase
- {
- int nnx;
- for (nnx=0; nnx<80; nnx++)
- if (!portalp[parts[r>>8].tmp][count][nnx].type)
- {
- PIPE_transfer_pipe_to_part(parts+i, &(portalp[parts[r>>8].tmp][count][nnx]));
- count++;
- break;
- }
- }
- }
- }
- }
- else //predefined 1 pixel thick pipe movement
- {
- int coords = 7 - ((parts[i].tmp>>10)&7);
- r = pmap[y+ pos_1_ry[coords]][x+ pos_1_rx[coords]];
- if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP) && parts[r>>8].ctype!=notctype && (parts[r>>8].tmp&0xFF)==0)
- {
- PIPE_transfer_pipe_to_pipe(parts+i, parts+(r>>8));
- if (r>>8 > original)
- parts[r>>8].flags |= PFLAG_NORMALSPEED;//skip particle push, normalizes speed
- count++;
- pushParticle(r>>8,count,original);
- }
- else if ((r&0xFF) == PT_PRTI) //Pass particles into PRTI for a pipe speed increase
- {
- int nnx;
- for (nnx=0; nnx<80; nnx++)
- if (!portalp[parts[r>>8].tmp][count][nnx].type)
- {
- PIPE_transfer_pipe_to_part(parts+i, &(portalp[parts[r>>8].tmp][count][nnx]));
- count++;
- break;
- }
- }
- else if ((r&0xFF) == PT_NONE) //Move particles out of pipe automatically, much faster at ends
- {
- rx = pos_1_rx[coords];
- ry = pos_1_ry[coords];
- np = create_part(-1,x+rx,y+ry,parts[i].tmp&0xFF);
- if (np!=-1)
- {
- PIPE_transfer_pipe_to_part(parts+i, parts+np);
- }
- }
- }
- return;
-}
-
-int update_PIPE(UPDATE_FUNC_ARGS) {
- int r, rx, ry, np;
- int rnd, rndstore;
- if (parts[i].tmp & PPIP_TMPFLAG_TRIGGERS)
- {
- int pause_changed = 0;
- if (parts[i].tmp & PPIP_TMPFLAG_TRIGGER_ON) // TRIGGER_ON overrides TRIGGER_OFF
- {
- if (parts[i].tmp & PPIP_TMPFLAG_PAUSED)
- pause_changed = 1;
- parts[i].tmp &= ~PPIP_TMPFLAG_PAUSED;
- }
- else if (parts[i].tmp & PPIP_TMPFLAG_TRIGGER_OFF)
- {
- if (!(parts[i].tmp & PPIP_TMPFLAG_PAUSED))
- pause_changed = 1;
- parts[i].tmp |= PPIP_TMPFLAG_PAUSED;
- }
- if (pause_changed)
- {
- int rx, ry, r;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- {
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if ((r&0xFF) == PT_BRCK)
- {
- if (parts[i].tmp & PPIP_TMPFLAG_PAUSED)
- parts[r>>8].tmp = 0;
- else
- parts[r>>8].tmp = 1; //make surrounding BRCK glow
- }
- }
- }
- }
-
- if (parts[i].tmp & PPIP_TMPFLAG_TRIGGER_REVERSE)
- {
- parts[i].tmp ^= PPIP_TMPFLAG_REVERSED;
- if (parts[i].ctype == 2) //Switch colors so it goes in reverse
- parts[i].ctype = 4;
- else if (parts[i].ctype == 4)
- parts[i].ctype = 2;
- if (parts[i].tmp & 0x100) //Switch one pixel pipe direction
- {
- int coords = (parts[i].tmp>>13)&0xF;
- int coords2 = (parts[i].tmp>>9)&0xF;
- parts[i].tmp &= ~0x1FE00;
- parts[i].tmp |= coords<<9;
- parts[i].tmp |= coords2<<13;
- }
- }
-
- parts[i].tmp &= ~PPIP_TMPFLAG_TRIGGERS;
- }
-
- if (parts[i].ctype>=2 && parts[i].ctype<=4 && !(parts[i].tmp & PPIP_TMPFLAG_PAUSED))
- {
- if (parts[i].life==3)
- {
- int lastneighbor = -1;
- int neighborcount = 0;
- int count = 0;
- // make automatic pipe pattern
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP)&&parts[r>>8].ctype==1)
- {
- parts[r>>8].ctype = (((parts[i].ctype)%3)+2);//reverse
- parts[r>>8].life = 6;
- if ( parts[i].tmp&0x100)//is a single pixel pipe
- {
- parts[r>>8].tmp |= 0x200;//will transfer to a single pixel pipe
- parts[r>>8].tmp |= count<<10;//coords of where it came from
- parts[i].tmp |= ((7-count)<<14);
- parts[i].tmp |= 0x2000;
- }
- neighborcount ++;
- lastneighbor = r>>8;
- }
- else if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP)&&parts[r>>8].ctype!=(((parts[i].ctype-1)%3)+2))
- {
- neighborcount ++;
- lastneighbor = r>>8;
- }
- count++;
- }
- if(neighborcount == 1)
- parts[lastneighbor].tmp |= 0x100;
- }
- else
- {
- if (parts[i].flags&PFLAG_NORMALSPEED)//skip particle push to prevent particle number being higher causing speed up
- {
- parts[i].flags &= ~PFLAG_NORMALSPEED;
- }
- else
- {
- pushParticle(i,0,i);
- }
-
- if (nt)//there is something besides PIPE around current particle
- {
- rndstore = rand();
- rnd = rndstore&7;
- rndstore = rndstore>>3;
- rx = pos_1_rx[rnd];
- ry = pos_1_ry[rnd];
- if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
- {
- r = pmap[y+ry][x+rx];
- if(!r)
- r = photons[y+ry][x+rx];
- if (surround_space && !r && (parts[i].tmp&0xFF)!=0) //creating at end
- {
- np = create_part(-1,x+rx,y+ry,parts[i].tmp&0xFF);
- if (np!=-1)
- {
- PIPE_transfer_pipe_to_part(parts+i, parts+np);
- }
- }
- //try eating particle at entrance
- else if ((parts[i].tmp&0xFF) == 0 && (ptypes[r&0xFF].properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)))
- {
- if ((r&0xFF)==PT_SOAP)
- detach(r>>8);
- PIPE_transfer_part_to_pipe(parts+(r>>8), parts+i);
- kill_part(r>>8);
- }
- else if ((parts[i].tmp&0xFF) == 0 && (r&0xFF)==PT_STOR && parts[r>>8].tmp && (ptypes[parts[r>>8].tmp].properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)))
- {
- // STOR stores properties in the same places as PIPE does
- PIPE_transfer_pipe_to_pipe(parts+(r>>8), parts+i);
- }
- }
- }
- }
- }
- else if (!parts[i].ctype && parts[i].life<=10)
- {
- if (parts[i].temp<272.15)//manual pipe colors
- {
- if (parts[i].temp>173.25&&parts[i].temp<273.15)
- {
- parts[i].ctype = 2;
- parts[i].life = 0;
- }
- if (parts[i].temp>73.25&&parts[i].temp<=173.15)
- {
- parts[i].ctype = 3;
- parts[i].life = 0;
- }
- if (parts[i].temp>=0&&parts[i].temp<=73.15)
- {
- parts[i].ctype = 4;
- parts[i].life = 0;
- }
- }
- else
- {
- // make a border
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- {
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- {
- int index = create_part(-1,x+rx,y+ry,PT_BRCK);//BRCK border, people didn't like DMND
- if (parts[i].type == PT_PPIP && index != -1)
- parts[index].tmp = 1;
- }
- }
- }
- if (parts[i].life<=1)
- parts[i].ctype = 1;
- }
- }
- else if (parts[i].ctype==1)//wait for empty space before starting to generate automatic pipe pattern
- {
- if (!parts[i].life)
- {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- if (!pmap[y+ry][x+rx] && bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_ALLOWAIR && bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_WALL && bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_WALLELEC && (bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_EWALL || emap[(y+ry)/CELL][(x+rx)/CELL]))
- parts[i].life=50;
- }
- }
- else if (parts[i].life==5)//check for beginning of pipe single pixel
- {
- int issingle = 1;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP) && parts[i].ctype==1 && parts[i].life )
- issingle = 0;
- }
- if (issingle)
- parts[i].tmp |= 0x100;
- }
- else if (parts[i].life==2)
- {
- parts[i].ctype = 2;
- parts[i].life = 6;
- }
- }
- return 0;
-}
-
-int graphics_PIPE(GRAPHICS_FUNC_ARGS)
-{
-
- if ((cpart->tmp&0xFF)>0 && (cpart->tmp&0xFF)<PT_NUM)
- {
- //Create a temp. particle and do a subcall.
- particle tpart;
- int t;
- memset(&tpart, 0, sizeof(particle));
- tpart.type = cpart->tmp&0xFF;
- tpart.temp = cpart->temp;
- tpart.life = cpart->tmp2;
- tpart.tmp = cpart->pavg[0];
- tpart.ctype = cpart->pavg[1];
- if (tpart.type == PT_PHOT && tpart.ctype == 0x40000000)
- tpart.ctype = 0x3FFFFFFF;
- t = tpart.type;
- if (graphicscache[t].isready)
- {
- *pixel_mode = graphicscache[t].pixel_mode;
- *cola = graphicscache[t].cola;
- *colr = graphicscache[t].colr;
- *colg = graphicscache[t].colg;
- *colb = graphicscache[t].colb;
- *firea = graphicscache[t].firea;
- *firer = graphicscache[t].firer;
- *fireg = graphicscache[t].fireg;
- *fireb = graphicscache[t].fireb;
- }
- else
- {
- *colr = PIXR(ptypes[t].pcolors);
- *colg = PIXG(ptypes[t].pcolors);
- *colb = PIXB(ptypes[t].pcolors);
- if (ptypes[t].graphics_func)
- {
- (*(ptypes[t].graphics_func))(&tpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb);
- }
- else
- {
- graphics_DEFAULT(&tpart, nx, ny, pixel_mode, cola, colr, colg, colb, firea, firer, fireg, fireb);
- }
- }
- //*colr = PIXR(ptypes[cpart->tmp&0xFF].pcolors);
- //*colg = PIXG(ptypes[cpart->tmp&0xFF].pcolors);
- //*colb = PIXB(ptypes[cpart->tmp&0xFF].pcolors);
- }
- else
- {
- if (cpart->ctype==2)
- {
- *colr = 50;
- *colg = 1;
- *colb = 1;
- }
- else if (cpart->ctype==3)
- {
- *colr = 1;
- *colg = 50;
- *colb = 1;
- }
- else if (cpart->ctype==4)
- {
- *colr = 1;
- *colg = 1;
- *colb = 50;
- }
- else if (cpart->temp<272.15&&cpart->ctype!=1)
- {
- if (cpart->temp>173.25&&cpart->temp<273.15)
- {
- *colr = 50;
- *colg = 1;
- *colb = 1;
- }
- if (cpart->temp>73.25&&cpart->temp<=173.15)
- {
- *colr = 1;
- *colg = 50;
- *colb = 1;
- }
- if (cpart->temp>=0&&cpart->temp<=73.15)
- {
- *colr = 1;
- *colg = 1;
- *colb = 50;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/plnt.c b/src/elements/plnt.c
deleted file mode 100644
index 3bdfeac..0000000
--- a/src/elements/plnt.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_PLNT(UPDATE_FUNC_ARGS) {
- int r, rx, ry, np;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_WATR && 1>(rand()%250))
- {
- np = create_part(r>>8,x+rx,y+ry,PT_PLNT);
- if (np<0) continue;
- parts[np].life = 0;
- }
- else if ((r&0xFF)==PT_LAVA && 1>(rand()%250))
- {
- part_change_type(i,x,y,PT_FIRE);
- parts[i].life = 4;
- }
- else if (((r&0xFF)==PT_SMKE || (r&0xFF)==PT_CO2) && (1>rand()%250))
- {
- kill_part(r>>8);
- parts[i].life = rand()%60 + 60;
- }
- else if (surround_space && ((r&0xFF)==PT_WOOD) && (1>rand()%20) && (abs(rx+ry)<=2) && (VINE_MODE || parts[i].tmp==1) )
- {
- int nnx = rand()%3 -1;
- int nny = rand()%3 -1;
- if (x+rx+nnx>=0 && y+ry+nny>0 && x+rx+nnx<XRES && y+ry+nny<YRES && (nnx || nny))
- {
- if (pmap[y+ry+nny][x+rx+nnx])
- continue;
- np = create_part(-1,x+rx+nnx,y+ry+nny,PT_VINE);
- if (np<0) continue;
- parts[np].temp = parts[i].temp;
- }
- }
- }
- if (parts[i].life==2)
- {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- create_part(-1,x+rx,y+ry,PT_O2);
- }
- parts[i].life = 0;
- }
- if (parts[i].temp > 400 && parts[i].temp > parts[i].tmp2)
- parts[i].tmp2 = (int)parts[i].temp;
- return 0;
-}
-
-int graphics_PLNT(GRAPHICS_FUNC_ARGS)
-{
- float maxtemp = fmax(cpart->tmp2,cpart->temp);
- if (maxtemp > 300)
- {
- *colr += (int)restrict_flt((maxtemp-300)/5,0,58);
- *colg -= (int)restrict_flt((maxtemp-300)/2,0,102);
- *colb += (int)restrict_flt((maxtemp-300)/5,0,70);
- }
- if (maxtemp < 273)
- {
- *colg += (int)restrict_flt((273-maxtemp)/4,0,255);
- *colb += (int)restrict_flt((273-maxtemp)/1.5,0,255);
- }
- return 0;
-}
diff --git a/src/elements/plsm.c b/src/elements/plsm.c
deleted file mode 100644
index 2861c25..0000000
--- a/src/elements/plsm.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-#include "hmap.h"
-
-int graphics_PLSM(GRAPHICS_FUNC_ARGS)
-{
- int caddress = restrict_flt(restrict_flt((float)cpart->life, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
- *colr = (unsigned char)plasma_data[caddress];
- *colg = (unsigned char)plasma_data[caddress+1];
- *colb = (unsigned char)plasma_data[caddress+2];
-
- *firea = 255;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
-
- *pixel_mode = PMODE_GLOW | PMODE_ADD; //Clear default, don't draw pixel
- *pixel_mode |= FIRE_ADD;
- //Returning 0 means dynamic, do not cache
- return 0;
-}
diff --git a/src/elements/plut.c b/src/elements/plut.c
deleted file mode 100644
index e453b56..0000000
--- a/src/elements/plut.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_PLUT(UPDATE_FUNC_ARGS) {
- if (1>rand()%100 && ((int)(5.0f*pv[y/CELL][x/CELL]))>(rand()%1000))
- {
- create_part(i, x, y, PT_NEUT);
- }
- return 0;
-}
diff --git a/src/elements/prti.c b/src/elements/prti.c
deleted file mode 100644
index fc6f37b..0000000
--- a/src/elements/prti.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-/*these are the count values of where the particle gets stored, depending on where it came from
- 0 1 2
- 7 . 3
- 6 5 4
- PRTO does (count+4)%8, so that it will come out at the opposite place to where it came in
- PRTO does +/-1 to the count, so it doesn't jam as easily
-*/
-int portal_rx[8] = {-1, 0, 1, 1, 1, 0,-1,-1};
-int portal_ry[8] = {-1,-1,-1, 0, 1, 1, 1, 0};
-
-int update_PRTI(UPDATE_FUNC_ARGS) {
- int r, nnx, rx, ry, fe = 0;
- int count =0;
- parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1);
- if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1;
- else if (parts[i].tmp<0) parts[i].tmp = 0;
- for (count=0; count<8; count++)
- {
- rx = portal_rx[count];
- ry = portal_ry[count];
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- fe = 1;
- if (!r || (r&0xFF)==PT_PRTI || (r&0xFF)==PT_PRTO || (!(ptypes[r&0xFF].properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)) && (r&0xFF)!=PT_SPRK))
- {
- r = photons[y+ry][x+rx];
- if (!r || (r&0xFF)==PT_PRTI || (r&0xFF)==PT_PRTO || (!(ptypes[r&0xFF].properties & (TYPE_PART | TYPE_LIQUID | TYPE_GAS | TYPE_ENERGY)) && (r&0xFF)!=PT_SPRK))
- continue;
- }
-
- if ((r&0xFF)==PT_STKM || (r&0xFF)==PT_STKM2 || (r&0xFF)==PT_FIGH)
- continue;// Handling these is a bit more complicated, and is done in STKM_interact()
-
- if ((r&0xFF) == PT_SOAP)
- detach(r>>8);
-
- for ( nnx=0; nnx<80; nnx++)
- if (!portalp[parts[i].tmp][count][nnx].type)
- {
- portalp[parts[i].tmp][count][nnx] = parts[r>>8];
- if ((r&0xFF)==PT_SPRK)
- part_change_type(r>>8,x+rx,y+ry,parts[r>>8].ctype);
- else
- kill_part(r>>8);
- fe = 1;
- break;
- }
- }
- }
-
-
- if (fe) {
- int orbd[4] = {0, 0, 0, 0}; //Orbital distances
- int orbl[4] = {0, 0, 0, 0}; //Orbital locations
- if (!parts[i].life) parts[i].life = rand()*rand()*rand();
- if (!parts[i].ctype) parts[i].ctype = rand()*rand()*rand();
- orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl);
- for (r = 0; r < 4; r++) {
- if (orbd[r]>1) {
- orbd[r] -= 12;
- if (orbd[r]<1) {
- orbd[r] = (rand()%128)+128;
- orbl[r] = rand()%255;
- } else {
- orbl[r] += 2;
- orbl[r] = orbl[r]%255;
- }
- } else {
- orbd[r] = (rand()%128)+128;
- orbl[r] = rand()%255;
- }
- }
- orbitalparts_set(&parts[i].life, &parts[i].ctype, orbd, orbl);
- } else {
- parts[i].life = 0;
- parts[i].ctype = 0;
- }
- return 0;
-}
diff --git a/src/elements/prto.c b/src/elements/prto.c
deleted file mode 100644
index d7eb642..0000000
--- a/src/elements/prto.c
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-/*these are the count values of where the particle gets stored, depending on where it came from
- 0 1 2
- 7 . 3
- 6 5 4
- PRTO does (count+4)%8, so that it will come out at the opposite place to where it came in
- PRTO does +/-1 to the count, so it doesn't jam as easily
-*/
-int update_PRTO(UPDATE_FUNC_ARGS) {
- int r, nnx, rx, ry, np, fe = 0;
- int count = 0;
- parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1);
- if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1;
- else if (parts[i].tmp<0) parts[i].tmp = 0;
- for (count=0; count<8; count++)
- {
- rx = portal_rx[count];
- ry = portal_ry[count];
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- fe = 1;
- if (r)
- continue;
- if (!r)
- {
- for ( nnx =0 ; nnx<80; nnx++)
- {
- int randomness = (count + rand()%3-1 + 4)%8;//add -1,0,or 1 to count
- if (portalp[parts[i].tmp][randomness][nnx].type==PT_SPRK)// TODO: make it look better, spark creation
- {
- create_part(-1,x+1,y,PT_SPRK);
- create_part(-1,x+1,y+1,PT_SPRK);
- create_part(-1,x+1,y-1,PT_SPRK);
- create_part(-1,x,y-1,PT_SPRK);
- create_part(-1,x,y+1,PT_SPRK);
- create_part(-1,x-1,y+1,PT_SPRK);
- create_part(-1,x-1,y,PT_SPRK);
- create_part(-1,x-1,y-1,PT_SPRK);
- portalp[parts[i].tmp][randomness][nnx] = emptyparticle;
- break;
- }
- else if (portalp[parts[i].tmp][randomness][nnx].type)
- {
- if (portalp[parts[i].tmp][randomness][nnx].type==PT_STKM)
- player.spwn = 0;
- if (portalp[parts[i].tmp][randomness][nnx].type==PT_STKM2)
- player2.spwn = 0;
- if (portalp[parts[i].tmp][randomness][nnx].type==PT_FIGH)
- {
- fighcount--;
- fighters[(unsigned char)portalp[parts[i].tmp][randomness][nnx].tmp].spwn = 0;
- }
- np = create_part(-1,x+rx,y+ry,portalp[parts[i].tmp][randomness][nnx].type);
- if (np<0)
- {
- if (portalp[parts[i].tmp][randomness][nnx].type==PT_STKM)
- player.spwn = 1;
- if (portalp[parts[i].tmp][randomness][nnx].type==PT_STKM2)
- player2.spwn = 1;
- if (portalp[parts[i].tmp][randomness][nnx].type==PT_FIGH)
- {
- fighcount++;
- fighters[(unsigned char)portalp[parts[i].tmp][randomness][nnx].tmp].spwn = 1;
- }
- continue;
- }
- if (parts[np].type==PT_FIGH)
- {
- // Release the fighters[] element allocated by create_part, the one reserved when the fighter went into the portal will be used
- fighters[(unsigned char)parts[np].tmp].spwn = 0;
- fighters[(unsigned char)portalp[parts[i].tmp][randomness][nnx].tmp].spwn = 1;
- }
- if (portalp[parts[i].tmp][randomness][nnx].vx == 0.0f && portalp[parts[i].tmp][randomness][nnx].vy == 0.0f)
- {
- // particles that have passed from PIPE into PRTI have lost their velocity, so use the velocity of the newly created particle if the particle in the portal has no velocity
- float tmp_vx = parts[np].vx;
- float tmp_vy = parts[np].vy;
- parts[np] = portalp[parts[i].tmp][randomness][nnx];
- parts[np].vx = tmp_vx;
- parts[np].vy = tmp_vy;
- }
- else
- {
- parts[np] = portalp[parts[i].tmp][randomness][nnx];
- }
- parts[np].x = x+rx;
- parts[np].y = y+ry;
- portalp[parts[i].tmp][randomness][nnx] = emptyparticle;
- break;
- }
- }
- }
- }
- }
- if (fe) {
- int orbd[4] = {0, 0, 0, 0}; //Orbital distances
- int orbl[4] = {0, 0, 0, 0}; //Orbital locations
- if (!parts[i].life) parts[i].life = rand()*rand()*rand();
- if (!parts[i].ctype) parts[i].ctype = rand()*rand()*rand();
- orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl);
- for (r = 0; r < 4; r++) {
- if (orbd[r]<254) {
- orbd[r] += 16;
- if (orbd[r]>254) {
- orbd[r] = 0;
- orbl[r] = rand()%255;
- } else {
- orbl[r] += 1;
- orbl[r] = orbl[r]%255;
- }
- } else {
- orbd[r] = 0;
- orbl[r] = rand()%255;
- }
- }
- orbitalparts_set(&parts[i].life, &parts[i].ctype, orbd, orbl);
- } else {
- parts[i].life = 0;
- parts[i].ctype = 0;
- }
- return 0;
-}
diff --git a/src/elements/pump.c b/src/elements/pump.c
deleted file mode 100644
index 77369c2..0000000
--- a/src/elements/pump.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_PUMP(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- if (parts[i].life>0 && parts[i].life!=10)
- parts[i].life--;
- if (parts[i].life==10)
- {
- if (parts[i].temp>=256.0+273.15)
- parts[i].temp=256.0+273.15;
- if (parts[i].temp<= -256.0+273.15)
- parts[i].temp = -256.0+273.15;
-
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if ((x+rx)-CELL>=0 && (y+ry)-CELL>0 && (x+rx)+CELL<XRES && (y+ry)+CELL<YRES && !(rx && ry))
- {
- pv[(y/CELL)+ry][(x/CELL)+rx] += 0.1f*((parts[i].temp-273.15)-pv[(y/CELL)+ry][(x/CELL)+rx]);
- }
-
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_PUMP)
- {
- if (parts[r>>8].life<10&&parts[r>>8].life>0)
- parts[i].life = 9;
- else if (parts[r>>8].life==0)
- parts[r>>8].life = 10;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/pvod.c b/src/elements/pvod.c
deleted file mode 100644
index 5078745..0000000
--- a/src/elements/pvod.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_PVOD(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- if (parts[i].life>0 && parts[i].life!=10)
- parts[i].life--;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_SPRK && parts[r>>8].life>0 && parts[r>>8].life<4)
- {
- if (parts[r>>8].ctype==PT_PSCN)
- parts[i].life = 10;
- else if (parts[r>>8].ctype==PT_NSCN)
- parts[i].life = 9;
- }
- if ((r&0xFF)==PT_PVOD)
- {
- if (parts[i].life==10&&parts[r>>8].life<10&&parts[r>>8].life>0)
- parts[i].life = 9;
- else if (parts[i].life==0&&parts[r>>8].life==10)
- parts[i].life = 10;
- }
- }
- return 0;
-}
diff --git a/src/elements/pyro.c b/src/elements/pyro.c
deleted file mode 100644
index c09dd63..0000000
--- a/src/elements/pyro.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_PYRO(UPDATE_FUNC_ARGS) {
- int r, rx, ry, rt, t = parts[i].type;
- if (t==PT_PLSM&&parts[i].ctype == PT_NBLE&&parts[i].life <=1)
- {
- t = PT_NBLE;
- part_change_type(i,x,y,t);
- parts[i].life = 0;
- }
- if(t==PT_FIRE && parts[i].life <=1)
- {
- if (parts[i].tmp==3){
- t = PT_DSTW;
- part_change_type(i,x,y,t);
- parts[i].life = 0;
- parts[i].ctype = PT_FIRE;
- }
- else if (parts[i].temp<625)
- {
- t = PT_SMKE;
- part_change_type(i,x,y,t);
- parts[i].life = rand()%20+250;
- }
- }
- if(t==PT_PLSM && parts[i].life <=1)
- {
- if (parts[i].tmp==3){
- t = PT_DSTW;
- part_change_type(i,x,y,t);
- parts[i].life = 0;
- parts[i].ctype = PT_FIRE;
- }
- }
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (bmap[(y+ry)/CELL][(x+rx)/CELL] && bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_STREAM)
- continue;
- rt = parts[r>>8].type;
- if ((surround_space || ptypes[rt].explosive) &&
- (t!=PT_SPRK || (rt!=PT_RBDM && rt!=PT_LRBD && rt!=PT_INSL)) &&
- (t!=PT_PHOT || rt!=PT_INSL) &&
- (rt!=PT_SPNG || parts[r>>8].life==0) &&
- (rt!=PT_H2 || parts[r>>8].temp < 2273.15) &&
- ptypes[rt].flammable && (ptypes[rt].flammable + (int)(pv[(y+ry)/CELL][(x+rx)/CELL]*10.0f))>(rand()%1000))
- {
- part_change_type(r>>8,x+rx,y+ry,PT_FIRE);
- parts[r>>8].temp = restrict_flt(ptypes[PT_FIRE].heat + (ptypes[rt].flammable/2), MIN_TEMP, MAX_TEMP);
- parts[r>>8].life = rand()%80+180;
- parts[r>>8].tmp = parts[r>>8].ctype = 0;
- if (ptypes[rt].explosive)
- pv[y/CELL][x/CELL] += 0.25f * CFDS;
- }
- }
- if (legacy_enable) update_legacy_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
- return 0;
-}
-
-int update_legacy_PYRO(UPDATE_FUNC_ARGS) {
- int r, rx, ry, rt, lpv, t = parts[i].type;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (bmap[(y+ry)/CELL][(x+rx)/CELL] && bmap[(y+ry)/CELL][(x+rx)/CELL]!=WL_STREAM)
- continue;
- rt = r&0xFF;
- lpv = (int)pv[(y+ry)/CELL][(x+rx)/CELL];
- if (lpv < 1) lpv = 1;
- if (t!=PT_SPRK && ptypes[rt].meltable && ((rt!=PT_RBDM && rt!=PT_LRBD) || t!=PT_SPRK) && ((t!=PT_FIRE&&t!=PT_PLSM) || (rt!=PT_METL && rt!=PT_IRON && rt!=PT_ETRD && rt!=PT_PSCN && rt!=PT_NSCN && rt!=PT_NTCT && rt!=PT_PTCT && rt!=PT_BMTL && rt!=PT_BRMT && rt!=PT_SALT && rt!=PT_INWR)) &&
- ptypes[rt].meltable*lpv>(rand()%1000))
- {
- if (t!=PT_LAVA || parts[i].life>0)
- {
- parts[r>>8].ctype = (rt==PT_BRMT)?PT_BMTL:parts[r>>8].type;
- parts[r>>8].ctype = (parts[r>>8].ctype==PT_SAND)?PT_GLAS:parts[r>>8].ctype;
- part_change_type(r>>8,x+rx,y+ry,PT_LAVA);
- parts[r>>8].life = rand()%120+240;
- }
- else
- {
- parts[i].life = 0;
- t = parts[i].type = (parts[i].ctype)?parts[i].ctype:PT_STNE;
- parts[i].ctype = PT_NONE;//rt;
- part_change_type(i,x,y,t);
- return 1;
- }
- }
- if (t!=PT_SPRK && (rt==PT_ICEI || rt==PT_SNOW))
- {
- parts[r>>8].type = PT_WATR;
- if (t==PT_FIRE)
- {
- kill_part(i);
- return 1;
- }
- if (t==PT_LAVA)
- {
- parts[i].life = 0;
- t = parts[i].type = PT_STNE;
- part_change_type(i,x,y,t);
- }
- }
- if (t!=PT_SPRK && (rt==PT_WATR || rt==PT_DSTW || rt==PT_SLTW))
- {
- kill_part(r>>8);
- if (t==PT_FIRE)
- {
- kill_part(i);
- return 1;
- }
- if (t==PT_LAVA)
- {
- parts[i].life = 0;
- t = parts[i].type = (parts[i].ctype)?parts[i].ctype:PT_STNE;
- parts[i].ctype = PT_NONE;
- part_change_type(i,x,y,t);
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/qrtz.c b/src/elements/qrtz.c
deleted file mode 100644
index 26c9f45..0000000
--- a/src/elements/qrtz.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_QRTZ(UPDATE_FUNC_ARGS) {
- int r, tmp, trade, rx, ry, np, t;
- t = parts[i].type;
- if (t == PT_QRTZ)
- {
- parts[i].pavg[0] = parts[i].pavg[1];
- parts[i].pavg[1] = pv[y/CELL][x/CELL];
- if (parts[i].pavg[1]-parts[i].pavg[0] > 0.05*(parts[i].temp/3) || parts[i].pavg[1]-parts[i].pavg[0] < -0.05*(parts[i].temp/3))
- {
- part_change_type(i,x,y,PT_PQRT);
- }
- }
- // absorb SLTW
- if (parts[i].ctype!=-1)
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- else if ((r&0xFF)==PT_SLTW && (1>rand()%2500))
- {
- kill_part(r>>8);
- parts[i].ctype ++;
- }
- }
- // grow if absorbed SLTW
- if (parts[i].ctype>0)
- {
- for ( trade = 0; trade<5; trade ++)
- {
- rx = rand()%3-1;
- ry = rand()%3-1;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r && parts[i].ctype!=0)
- {
- np = create_part(-1,x+rx,y+ry,PT_QRTZ);
- if (np>-1)
- {
- parts[np].tmp = parts[i].tmp;
- parts[i].ctype--;
- if (5>rand()%10)
- {
- parts[np].ctype=-1;//dead qrtz
- }
- else if (!parts[i].ctype && 1>rand()%15)
- {
- parts[i].ctype=-1;
- }
-
- break;
- }
- }
- }
- }
- }
- // diffuse absorbed SLTW
- if (parts[i].ctype>0)
- {
- for ( trade = 0; trade<9; trade ++)
- {
- rx = rand()%5-2;
- ry = rand()%5-2;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==t && (parts[i].ctype>parts[r>>8].ctype) && parts[r>>8].ctype>=0 )//diffusion
- {
- tmp = parts[i].ctype - parts[r>>8].ctype;
- if (tmp ==1)
- {
- parts[r>>8].ctype ++;
- parts[i].ctype --;
- break;
- }
- if (tmp>0)
- {
- parts[r>>8].ctype += tmp/2;
- parts[i].ctype -= tmp/2;
- break;
- }
- }
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/repl.c b/src/elements/repl.c
deleted file mode 100644
index 7b7605d..0000000
--- a/src/elements/repl.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_REPL(UPDATE_FUNC_ARGS) {
- int r, rx, ry, ri;
- for(ri = 0; ri <= 10; ri++)
- {
- rx = (rand()%20)-10;
- ry = (rand()%20)-10;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- r = photons[y+ry][x+rx];
-
- if (r && !(ptypes[r&0xFF].properties & TYPE_SOLID)){
- parts[r>>8].vx += isign(rx)*((parts[i].temp-273.15)/10.0f);
- parts[r>>8].vy += isign(ry)*((parts[i].temp-273.15)/10.0f);
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/rime.c b/src/elements/rime.c
deleted file mode 100644
index 4ac6c29..0000000
--- a/src/elements/rime.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_RIME(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- parts[i].vx = 0;
- parts[i].vy = 0;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_SPRK)
- {
- part_change_type(i,x,y,PT_FOG);
- parts[i].life = rand()%50 + 60;
- }
- else if ((r&0xFF)==PT_FOG&&parts[r>>8].life>0)
- {
- part_change_type(i,x,y,PT_FOG);
- parts[i].life = parts[r>>8].life;
- }
- }
- return 0;
-}
diff --git a/src/elements/shld.c b/src/elements/shld.c
deleted file mode 100644
index b1661c9..0000000
--- a/src/elements/shld.c
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_SHLD1(UPDATE_FUNC_ARGS) {
- int r, nnx, nny, rx, ry;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- else if ((r&0xFF)==PT_SPRK&&parts[i].life==0)
- {
- if (55>rand()%200&&parts[i].life==0)
- {
- part_change_type(i,x,y,PT_SHLD2);
- parts[i].life = 7;
- }
- for ( nnx=-1; nnx<2; nnx++)
- for ( nny=-1; nny<2; nny++)
- {
- if (!pmap[y+ry+nny][x+rx+nnx])
- {
- create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1);
- //parts[pmap[y+ny+nny][x+nx+nnx]>>8].life=7;
- }
- }
- }
- else if ((r&0xFF)==PT_SHLD3&&4>rand()%10)
- {
- part_change_type(i,x,y,PT_SHLD2);
- parts[i].life = 7;
- }
- }
- return 0;
-}
-
-int update_SHLD2(UPDATE_FUNC_ARGS) {
- int r, nnx, nny, rx, ry, np;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r && parts[i].life>0)
- create_part(-1,x+rx,y+ry,PT_SHLD1);
- if (!r)
- continue;
- else if ((r&0xFF)==PT_SPRK&&parts[i].life==0)
- {
- if (25>rand()%200&&parts[i].life==0)
- {
- part_change_type(i,x,y,PT_SHLD3);
- parts[i].life = 7;
- }
- for ( nnx=-1; nnx<2; nnx++)
- for ( nny=-1; nny<2; nny++)
- {
- if (!pmap[y+ry+nny][x+rx+nnx])
- {
- np = create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1);
- if (np<0) continue;
- parts[np].life=7;
- }
- }
- }
- else if ((r&0xFF)==PT_SHLD4&&4>rand()%10)
- {
- part_change_type(i,x,y,PT_SHLD3);
- parts[i].life = 7;
- }
- }
- return 0;
-}
-
-int update_SHLD3(UPDATE_FUNC_ARGS) {
- int r, nnx, nny, rx, ry, np;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- {
- if (1>rand()%2500)
- {
- np = create_part(-1,x+rx,y+ry,PT_SHLD1);
- if (np<0) continue;
- parts[np].life=7;
- part_change_type(i,x,y,PT_SHLD2);
- }
- else
- continue;
-
- }
- if ((r&0xFF)==PT_SHLD1 && parts[i].life>3)
- {
- part_change_type(r>>8,x+rx,y+ry,PT_SHLD2);
- parts[r>>8].life=7;
- }
- else if ((r&0xFF)==PT_SPRK&&parts[i].life==0)
- {
- if (18>rand()%3000&&parts[i].life==0)
- {
- part_change_type(i,x,y,PT_SHLD4);
- parts[i].life = 7;
- }
- for ( nnx=-1; nnx<2; nnx++)
- for ( nny=-1; nny<2; nny++)
- {
-
- if (!pmap[y+ry+nny][x+rx+nnx])
- {
- np = create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1);
- if (np<0) continue;
- parts[np].life=7;
- }
- }
- }
- }
- return 0;
-}
-
-int update_SHLD4(UPDATE_FUNC_ARGS) {
- int r, nnx, nny, rx, ry, np;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- {
- if (1>rand()%5500)
- {
- np = create_part(-1,x+rx,y+ry,PT_SHLD1);
- if (np<0) continue;
- parts[np].life=7;
- part_change_type(i,x,y,PT_SHLD2);
- }
- else
- continue;
-
- }
- if ((r&0xFF)==PT_SHLD2 && parts[i].life>3)
- {
- part_change_type(r>>8,x+rx,y+ry,PT_SHLD3);
- parts[r>>8].life = 7;
- }
- else if ((r&0xFF)==PT_SPRK&&parts[i].life==0)
- for ( nnx=-1; nnx<2; nnx++)
- for ( nny=-1; nny<2; nny++)
- {
- if (!pmap[y+ry+nny][x+rx+nnx])
- {
- np = create_part(-1,x+rx+nnx,y+ry+nny,PT_SHLD1);
- if (np<0) continue;
- parts[np].life=7;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/sing.c b/src/elements/sing.c
deleted file mode 100644
index e8b4a07..0000000
--- a/src/elements/sing.c
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_SING(UPDATE_FUNC_ARGS) {
- int r, rx, ry, cry, crx, rad, nxi, nxj, nb, j, spawncount;
- int singularity = -parts[i].life;
- float angle, v;
-
- if (pv[y/CELL][x/CELL]<singularity)
- pv[y/CELL][x/CELL] += 0.1f*(singularity-pv[y/CELL][x/CELL]);
- if (y+CELL<YRES && pv[y/CELL+1][x/CELL]<singularity)
- pv[y/CELL+1][x/CELL] += 0.1f*(singularity-pv[y/CELL+1][x/CELL]);
- if (x+CELL<XRES)
- {
- pv[y/CELL][x/CELL+1] += 0.1f*(singularity-pv[y/CELL][x/CELL+1]);
- if (y+CELL<YRES)
- pv[y/CELL+1][x/CELL+1] += 0.1f*(singularity-pv[y/CELL+1][x/CELL+1]);
- }
- if (y-CELL>=0 && pv[y/CELL-1][x/CELL]<singularity)
- pv[y/CELL-1][x/CELL] += 0.1f*(singularity-pv[y/CELL-1][x/CELL]);
- if (x-CELL>=0)
- {
- pv[y/CELL][x/CELL-1] += 0.1f*(singularity-pv[y/CELL][x/CELL-1]);
- if (y-CELL>=0)
- pv[y/CELL-1][x/CELL-1] += 0.1f*(singularity-pv[y/CELL-1][x/CELL-1]);
- }
- if (parts[i].life<1) {
- //Pop!
- for (rx=-1; rx<2; rx++) {
- crx = (x/CELL)+rx;
- for (ry=-1; ry<2; ry++) {
- cry = (y/CELL)+ry;
- if (cry >= 0 && crx >= 0 && crx < (XRES/CELL) && cry < (YRES/CELL)) {
- pv[cry][crx] += (float)parts[i].tmp;
- }
- }
- }
- spawncount = (parts[i].tmp>255)?255:parts[i].tmp;
- if (spawncount>=1)
- spawncount = spawncount/8;
- spawncount = spawncount*spawncount*M_PI;
- for (j=0;j<spawncount;j++)
- {
- switch(rand()%3)
- {
- case 0:
- nb = create_part(-3, x, y, PT_PHOT);
- break;
- case 1:
- nb = create_part(-3, x, y, PT_NEUT);
- break;
- case 2:
- nb = create_part(-3, x, y, PT_ELEC);
- break;
- }
- if (nb!=-1) {
- parts[nb].life = (rand()%300);
- parts[nb].temp = MAX_TEMP/2;
- angle = rand()*2.0f*M_PI/RAND_MAX;
- v = (float)(rand())*5.0f/RAND_MAX;
- parts[nb].vx = v*cosf(angle);
- parts[nb].vy = v*sinf(angle);
- }
- else if (pfree==-1)
- break;//if we've run out of particles, stop trying to create them - saves a lot of lag on "sing bomb" saves
- }
- kill_part(i);
- return 1;
- }
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_DMND&&33>=rand()/(RAND_MAX/100)+1)
- {
- if ((r&0xFF)==PT_SING && parts[r>>8].life >10)
- {
- if (parts[i].life+parts[r>>8].life > 255)
- continue;
- parts[i].life += parts[r>>8].life;
- }
- else
- {
- if (parts[i].life+3 > 255)
- {
- if (parts[r>>8].type!=PT_SING && 1>rand()%100)
- {
- int np;
- np = create_part(r>>8,x+rx,y+ry,PT_SING);
- parts[np].life = rand()%50+60;
- }
- continue;
- }
- parts[i].life += 3;
- parts[i].tmp++;
- }
- parts[i].temp = restrict_flt(parts[r>>8].temp+parts[i].temp, MIN_TEMP, MAX_TEMP);
- kill_part(r>>8);
- }
- }
- return 0;
-}
diff --git a/src/elements/sltw.c b/src/elements/sltw.c
deleted file mode 100644
index 4e562f7..0000000
--- a/src/elements/sltw.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_SLTW(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_SALT && 1>(rand()%10000))
- part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
- if ((r&0xFF)==PT_PLNT&&5>(rand()%1000))
- kill_part(r>>8);
- if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && !legacy_enable && parts[i].temp>(273.15f+12.0f) && 1>(rand()%500))
- {
- part_change_type(i,x,y,PT_FIRE);
- parts[i].life = 4;
- }
- if ((r&0xFF)==PT_FIRE){
- kill_part(r>>8);
- if(1>(rand()%150)){
- kill_part(i);
- return 1;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/smke.c b/src/elements/smke.c
deleted file mode 100644
index 5949034..0000000
--- a/src/elements/smke.c
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int graphics_SMKE(GRAPHICS_FUNC_ARGS)
-{
- *colr = 55;
- *colg = 55;
- *colb = 55;
-
- *firea = 75;
- *firer = 55;
- *fireg = 55;
- *fireb = 55;
-
- *pixel_mode = PMODE_NONE; //Clear default, don't draw pixel
- *pixel_mode |= FIRE_BLEND;
- //Returning 1 means static, cache as we please
- return 1;
-}
diff --git a/src/elements/soap.c b/src/elements/soap.c
deleted file mode 100644
index 6b69778..0000000
--- a/src/elements/soap.c
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-void attach(int i1, int i2)
-{
- if (!(parts[i2].ctype&4))
- {
- parts[i1].ctype |= 2;
- parts[i1].tmp = i2;
-
- parts[i2].ctype |= 4;
- parts[i2].tmp2 = i1;
- }
- else
- if (!(parts[i2].ctype&2))
- {
- parts[i1].ctype |= 4;
- parts[i1].tmp2= i2;
-
- parts[i2].ctype |= 2;
- parts[i2].tmp = i1;
- }
-}
-
-int update_SOAP(UPDATE_FUNC_ARGS)
-{
- int r, rx, ry, nr, ng, nb, na;
- float tr, tg, tb, ta;
- float blend;
-
- //0x01 - bubble on/off
- //0x02 - first mate yes/no
- //0x04 - "back" mate yes/no
-
- if (parts[i].ctype&1)
- {
- if (parts[i].temp>0)
- {
- if (parts[i].life<=0)
- {
- if ((parts[i].ctype&6) != 6 && (parts[i].ctype&6))
- {
- int target;
-
- target = i;
-
- while((parts[target].ctype&6) != 6 && (parts[target].ctype&6))
- {
- if (parts[target].ctype&2)
- {
- target = parts[target].tmp;
- detach(target);
- }
-
- if (parts[target].ctype&4)
- {
- target = parts[target].tmp2;
- detach(target);
- }
- }
- }
-
- if ((parts[i].ctype&6) != 6)
- parts[i].ctype = 0;
-
- if ((parts[i].ctype&6) == 6 && (parts[parts[i].tmp].ctype&6) == 6 && parts[parts[i].tmp].tmp == i)
- detach(i);
- }
-
- parts[i].vy -= 0.1f;
-
- parts[i].vy *= 0.5f;
- parts[i].vx *= 0.5f;
- }
-
- if (!(parts[i].ctype&2))
- {
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
-
- if ((parts[r>>8].type == PT_SOAP) && (parts[r>>8].ctype&1) && !(parts[r>>8].ctype&4))
- attach(i, r>>8);
- }
- }
- else
- {
- if (parts[i].life<=0)
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r && !bmap[(y+ry)/CELL][(x+rx)/CELL])
- continue;
-
- if (parts[i].temp>0)
- {
- if (bmap[(y+ry)/CELL][(x+rx)/CELL]
- || (r && ptypes[r&0xFF].state != ST_GAS
- && (r&0xFF) != PT_SOAP && (r&0xFF) != PT_GLAS))
- {
- detach(i);
- continue;
- }
- }
-
- if ((r&0xFF) == PT_SOAP && parts[r>>8].ctype == 1)
- {
- int buf;
-
- buf = parts[i].tmp;
-
- parts[i].tmp = r>>8;
- parts[buf].tmp2 = r>>8;
- parts[r>>8].tmp2 = i;
- parts[r>>8].tmp = buf;
- parts[r>>8].ctype = 7;
- }
-
- if ((r&0xFF) == PT_SOAP && parts[r>>8].ctype == 7 && parts[i].tmp != r>>8 && parts[i].tmp2 != r>>8)
- {
- int buf;
-
- parts[parts[i].tmp].tmp2 = parts[r>>8].tmp2;
- parts[parts[r>>8].tmp2].tmp = parts[i].tmp;
- parts[r>>8].tmp2 = i;
- parts[i].tmp = r>>8;
- }
- }
- }
-
- if(parts[i].ctype&2)
- {
- float d, dx, dy;
-
- dx = parts[i].x - parts[parts[i].tmp].x;
- dy = parts[i].y - parts[parts[i].tmp].y;
-
- d = 9/(pow(dx, 2)+pow(dy, 2)+9)-0.5;
-
- parts[parts[i].tmp].vx -= dx*d;
- parts[parts[i].tmp].vy -= dy*d;
-
- parts[i].vx += dx*d;
- parts[i].vy += dy*d;
-
- if ((parts[parts[i].tmp].ctype&2) && (parts[parts[i].tmp].ctype&1)
- && (parts[parts[parts[i].tmp].tmp].ctype&2) && (parts[parts[parts[i].tmp].tmp].ctype&1))
- {
- int ii;
-
- ii = parts[parts[parts[i].tmp].tmp].tmp;
-
- dx = parts[ii].x - parts[parts[i].tmp].x;
- dy = parts[ii].y - parts[parts[i].tmp].y;
-
- d = 81/(pow(dx, 2)+pow(dy, 2)+81)-0.5;
-
- parts[parts[i].tmp].vx -= dx*d*0.5f;
- parts[parts[i].tmp].vy -= dy*d*0.5f;
-
- parts[ii].vx += dx*d*0.5f;
- parts[ii].vy += dy*d*0.5f;
- }
- }
- }
- else
- {
- if (pv[y/CELL][x/CELL]>0.5f || pv[y/CELL][x/CELL]<(-0.5f))
- {
- parts[i].ctype = 1;
- parts[i].life = 10;
- }
-
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
-
- if ((r&0xFF) == PT_OIL)
- {
- float ax, ay;
-
- parts[i].vy -= 0.1f;
-
- parts[i].vy *= 0.5f;
- parts[i].vx *= 0.5f;
-
- ax = (parts[i].vx + parts[r>>8].vx)/2;
- ay = (parts[i].vy + parts[r>>8].vy)/2;
-
- parts[i].vx = ax;
- parts[i].vy = ay;
- parts[r>>8].vx = ax;
- parts[r>>8].vy = ay;
- }
- }
- }
-
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_SOAP)
- {
- blend = 0.85f;
- tr = (parts[r>>8].dcolour>>16)&0xFF;
- tg = (parts[r>>8].dcolour>>8)&0xFF;
- tb = (parts[r>>8].dcolour)&0xFF;
- ta = (parts[r>>8].dcolour>>24)&0xFF;
-
- nr = (tr*blend);
- ng = (tg*blend);
- nb = (tb*blend);
- na = (ta*blend);
-
- parts[r>>8].dcolour = nr<<16 | ng<<8 | nb | na<<24;
- }
- }
-
- return 0;
-}
diff --git a/src/elements/spng.c b/src/elements/spng.c
deleted file mode 100644
index 9776c79..0000000
--- a/src/elements/spng.c
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_SPNG(UPDATE_FUNC_ARGS) {
- int r, trade, rx, ry, tmp, np;
- int limit = 50;
- if (parts[i].life<limit && pv[y/CELL][x/CELL]<=3&&pv[y/CELL][x/CELL]>=-3&&parts[i].temp<=374.0f)
- {
- int absorbChanceDenom = parts[i].life*1000/limit + 500;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW || (r&0xFF)==PT_FRZW) && parts[i].life<limit && 500>rand()%absorbChanceDenom)
- {
- parts[i].life++;
- kill_part(r>>8);
- }
- if ((r&0xFF)==PT_SLTW && parts[i].life<limit && 50>rand()%absorbChanceDenom)
- {
- parts[i].life++;
- if (rand()%4)
- kill_part(r>>8);
- else
- part_change_type(r>>8, x+rx, y+ry, PT_SALT);
- }
- if ((r&0xFF)==PT_CBNW && parts[i].life<limit && 100>rand()%absorbChanceDenom)
- {
- parts[i].life++;
- part_change_type(r>>8, x+rx, y+ry, PT_CO2);
- }
- if ((r&0xFF)==PT_PSTE && parts[i].life<limit && 20>rand()%absorbChanceDenom)
- {
- parts[i].life++;
- create_part(r>>8, x+rx, y+ry, PT_CLST);
- }
- }
- }
- else
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if ((!r)&&parts[i].life>=1)//if nothing then create water
- {
- np = create_part(-1,x+rx,y+ry,PT_WATR);
- if (np>-1) parts[i].life--;
- }
- }
- for ( trade = 0; trade<9; trade ++)
- {
- rx = rand()%5-2;
- ry = rand()%5-2;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_SPNG&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0)//diffusion
- {
- tmp = parts[i].life - parts[r>>8].life;
- if (tmp ==1)
- {
- parts[r>>8].life ++;
- parts[i].life --;
- trade = 9;
- }
- else if (tmp>0)
- {
- parts[r>>8].life += tmp/2;
- parts[i].life -= tmp/2;
- trade = 9;
- }
- }
- }
- }
- tmp = 0;
- if (parts[i].life>0)
- {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_FIRE)
- {
- tmp++;
- if (parts[r>>8].life>60)
- parts[r>>8].life -= parts[r>>8].life/60;
- else if (parts[r>>8].life>2)
- parts[r>>8].life--;
- }
- }
- }
- if (tmp && parts[i].life>3)
- parts[i].life -= parts[i].life/3;
- if (tmp>1)
- tmp = tmp/2;
- if (tmp || parts[i].temp>=374)
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if ((!r)&&parts[i].life>=1)//if nothing then create steam
- {
- np = create_part(-1,x+rx,y+ry,PT_WTRV);
- if (np>-1)
- {
- parts[np].temp = parts[i].temp;
- tmp--;
- parts[i].life--;
- parts[i].temp -= 20.0f;
- }
- }
- }
- if (tmp>0)
- {
- if (parts[i].life>tmp)
- parts[i].life -= tmp;
- else
- parts[i].life = 0;
- }
- return 0;
-}
diff --git a/src/elements/sprk.c b/src/elements/sprk.c
deleted file mode 100644
index 1c4c5bc..0000000
--- a/src/elements/sprk.c
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_SPRK(UPDATE_FUNC_ARGS) {
- int r, rx, ry, rt, conduct_sprk, nearp, pavg, ct = parts[i].ctype;
- update_PYRO(UPDATE_FUNC_SUBCALL_ARGS);
-
- if (parts[i].life<=0)
- {
- if (ct==PT_WATR||ct==PT_SLTW||ct==PT_PSCN||ct==PT_NSCN||ct==PT_ETRD||ct==PT_INWR)
- parts[i].temp = R_TEMP + 273.15f;
- if (ct<=0 || ct>=PT_NUM || !ptypes[ct].enabled)
- ct = PT_METL;
- part_change_type(i,x,y,ct);
- parts[i].ctype = PT_NONE;
- parts[i].life = 4;
- if (ct == PT_WATR)
- parts[i].life = 64;
- if (ct == PT_SLTW)
- parts[i].life = 54;
- if (ct == PT_SWCH)
- parts[i].life = 14;
- return 0;
- }
- if (ct==PT_SPRK)
- {
- kill_part(i);
- return 1;
- }
- else if (ct==PT_NTCT || ct==PT_PTCT)
- {
- update_NPTCT(UPDATE_FUNC_SUBCALL_ARGS);
- }
- else if (ct==PT_ETRD&&parts[i].life==1)
- {
- nearp = nearest_part(i, PT_ETRD, -1);
- if (nearp!=-1&&parts_avg(i, nearp, PT_INSL)!=PT_INSL)
- {
- create_line(x, y, (int)(parts[nearp].x+0.5f), (int)(parts[nearp].y+0.5f), 0, 0, PT_PLSM, 0);
- part_change_type(i,x,y,ct);
- ct = parts[i].ctype = PT_NONE;
- parts[i].life = 20;
- part_change_type(nearp,(int)(parts[nearp].x+0.5f),(int)(parts[nearp].y+0.5f),PT_SPRK);
- parts[nearp].life = 9;
- parts[nearp].ctype = PT_ETRD;
- }
- }
- else if (ct==PT_NBLE&&parts[i].life<=1&&parts[i].temp<5273.15)
- {
- parts[i].life = rand()%150+50;
- part_change_type(i,x,y,PT_PLSM);
- parts[i].ctype = PT_NBLE;
- parts[i].temp = 3500;
- pv[y/CELL][x/CELL] += 1;
- }
- else if (ct==PT_TESC) // tesla coil code
- {
- if (parts[i].tmp>300)
- parts[i].tmp=300;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (r)
- continue;
- if (parts[i].tmp>4 && rand()%(parts[i].tmp*parts[i].tmp/20+6)==0)
- {
- int p=create_part(-1, x+rx*2, y+ry*2, PT_LIGH);
- if (p!=-1)
- {
- parts[p].life=rand()%(2+parts[i].tmp/15)+parts[i].tmp/7;
- if (parts[i].life>60)
- parts[i].life=60;
- parts[p].temp=parts[p].life*parts[i].tmp/2.5;
- parts[p].tmp2=1;
- parts[p].tmp=atan2(-ry, rx)/M_PI*360;
- parts[i].temp-=parts[i].tmp*2+parts[i].temp/5; // slight self-cooling
- if (fabs(pv[y/CELL][x/CELL])!=0.0f)
- {
- if (fabs(pv[y/CELL][x/CELL])<=0.5f)
- pv[y/CELL][x/CELL]=0;
- else
- pv[y/CELL][x/CELL]-=(pv[y/CELL][x/CELL]>0)?0.5:-0.5;
- }
- }
- }
- }
- }
- else if (ct==PT_IRON) {
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!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))))
- {
- if (rand()<RAND_MAX/3)
- part_change_type(r>>8,x+rx,y+ry,PT_O2);
- else
- part_change_type(r>>8,x+rx,y+ry,PT_H2);
- }
- }
- }
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- rt = parts[r>>8].type;
- conduct_sprk = 1;
-
-
- pavg = parts_avg(r>>8, i,PT_INSL);
- if ((rt==PT_SWCH||(rt==PT_SPRK&&parts[r>>8].ctype==PT_SWCH)) && pavg!=PT_INSL && parts[i].life<4) // make sparked SWCH turn off correctly
- {
- if (rt==PT_SWCH&&ct==PT_PSCN&&parts[r>>8].life<10) {
- parts[r>>8].life = 10;
- }
- if (ct==PT_NSCN) {
- part_change_type(r>>8,x+rx,y+ry,PT_SWCH);
- parts[r>>8].ctype = PT_NONE;
- parts[r>>8].life = 9;
- }
- }
- else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_PUMP||rt==PT_GPMP||rt==PT_HSWC||rt==PT_PBCN) && parts[i].life<4) // PROP_PTOGGLE, Maybe? We seem to use 2 different methods for handling actived elements, this one seems better. Yes, use this one for new elements, PCLN is different for compatibility with existing saves
- {
- if (ct==PT_PSCN) parts[r>>8].life = 10;
- else if (ct==PT_NSCN && parts[r>>8].life>=10) parts[r>>8].life = 9;
- }
- else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_LCRY&&abs(rx)<2&&abs(ry)<2) && parts[i].life<4)
- {
- if (ct==PT_PSCN && parts[r>>8].tmp == 0) parts[r>>8].tmp = 2;
- else if (ct==PT_NSCN && parts[r>>8].tmp == 3) parts[r>>8].tmp = 1;
- }
-
- if (rt == PT_PPIP && parts[i].life == 3 && pavg!=PT_INSL)
- {
- if (ct == PT_NSCN || ct == PT_PSCN || ct == PT_INST)
- PPIP_flood_trigger(x+rx, y+ry, ct);
- }
-
- // ct = spark from material, rt = spark to material. Make conduct_sprk = 0 if conduction not allowed
-
- if (pavg == PT_INSL) conduct_sprk = 0;
- if (!(ptypes[rt].properties&PROP_CONDUCTS||rt==PT_INST||rt==PT_QRTZ)) conduct_sprk = 0;
- if (abs(rx)+abs(ry)>=4 &&ct!=PT_SWCH&&rt!=PT_SWCH)
- conduct_sprk = 0;
-
-
- if (ct==PT_METL && (rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR||(rt==PT_SPRK&&(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT))) && pavg!=PT_INSL && parts[i].life<4)
- {
- parts[r>>8].temp = 473.0f;
- if (rt==PT_NTCT||rt==PT_PTCT)
- conduct_sprk = 0;
- }
- if (ct==PT_NTCT && !(rt==PT_PSCN || rt==PT_NTCT || (rt==PT_NSCN&&parts[i].temp>373.0f)))
- conduct_sprk = 0;
- if (ct==PT_PTCT && !(rt==PT_PSCN || rt==PT_PTCT || (rt==PT_NSCN&&parts[i].temp<373.0f)))
- conduct_sprk = 0;
- if (ct==PT_INWR && !(rt==PT_NSCN || rt==PT_INWR || rt==PT_PSCN))
- conduct_sprk = 0;
- if (ct==PT_NSCN && rt==PT_PSCN)
- conduct_sprk = 0;
- if (ct==PT_ETRD && !(rt==PT_METL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN))
- conduct_sprk = 0;
- if (ct==PT_INST&&rt!=PT_NSCN) conduct_sprk = 0;
- if (ct==PT_SWCH && (rt==PT_PSCN||rt==PT_NSCN||rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR))
- conduct_sprk = 0;
- if (rt==PT_QRTZ && !((ct==PT_NSCN||ct==PT_METL||ct==PT_PSCN||ct==PT_QRTZ) && (parts[r>>8].temp<173.15||pv[(y+ry)/CELL][(x+rx)/CELL]>8)))
- conduct_sprk = 0;
- if (rt==PT_NTCT && !(ct==PT_NSCN || ct==PT_NTCT || (ct==PT_PSCN&&parts[r>>8].temp>373.0f)))
- conduct_sprk = 0;
- if (rt==PT_PTCT && !(ct==PT_NSCN || ct==PT_PTCT || (ct==PT_PSCN&&parts[r>>8].temp<373.0f)))
- conduct_sprk = 0;
- if (rt==PT_INWR && !(ct==PT_NSCN || ct==PT_INWR || ct==PT_PSCN))
- conduct_sprk = 0;
- if (rt==PT_INST&&ct!=PT_PSCN)
- conduct_sprk = 0;
- if (rt == PT_NBLE && parts[r>>8].temp > 5273.15)
- conduct_sprk = 0;
-
- if (conduct_sprk) {
- if (rt==PT_WATR||rt==PT_SLTW) {
- if (parts[r>>8].life==0 && parts[i].life<3)
- {
- part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
- if (rt==PT_WATR) parts[r>>8].life = 6;
- else parts[r>>8].life = 5;
- parts[r>>8].ctype = rt;
- }
- }
- else if (rt==PT_INST) {
- if (parts[r>>8].life==0 && parts[i].life<4)
- {
- flood_INST(x+rx,y+ry,PT_SPRK,PT_INST);//spark the wire
- }
- }
- else if (parts[r>>8].life==0 && parts[i].life<4) {
- parts[r>>8].life = 4;
- parts[r>>8].ctype = rt;
- part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
- if (parts[r>>8].temp+10.0f<673.0f&&!legacy_enable&&(rt==PT_METL||rt==PT_BMTL||rt==PT_BRMT||rt==PT_PSCN||rt==PT_NSCN||rt==PT_ETRD||rt==PT_NBLE||rt==PT_IRON))
- parts[r>>8].temp = parts[r>>8].temp+10.0f;
- }
- else if (ct==PT_ETRD && parts[i].life==5)
- {
- part_change_type(i,x,y,ct);
- parts[i].ctype = PT_NONE;
- parts[i].life = 20;
- parts[r>>8].life = 4;
- parts[r>>8].ctype = rt;
- part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
- }
- }
- }
- return 0;
-}
-
-int graphics_SPRK(GRAPHICS_FUNC_ARGS)
-{
- *firea = 80;
-
- *firer = 170;
- *fireg = 200;
- *fireb = 220;
- //*pixel_mode |= FIRE_ADD;
- *pixel_mode |= FIRE_ADD;
- return 1;
-}
diff --git a/src/elements/stkm.c b/src/elements/stkm.c
deleted file mode 100644
index d517844..0000000
--- a/src/elements/stkm.c
+++ /dev/null
@@ -1,516 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#define INBOND(x, y) ((x)>=0 && (y)>=0 && (x)<XRES && (y)<YRES)
-
-#include <element.h>
-
-int update_SPAWN(UPDATE_FUNC_ARGS) {
- if (!player.spwn)
- create_part(-1, x, y, PT_STKM);
-
- return 0;
-}
-
-int update_STKM(UPDATE_FUNC_ARGS)
-{
- run_stickman(&player, UPDATE_FUNC_SUBCALL_ARGS);
- return 0;
-}
-
-int graphics_STKM(GRAPHICS_FUNC_ARGS)
-{
- *colr = *colg = *colb = *cola = 0;
- *pixel_mode = PSPEC_STICKMAN;
- return 0;
-}
-
-int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- int t = parts[i].type;
- float pp, d;
- float dt = 0.9;///(FPSB*FPSB); //Delta time in square
- float gvx, gvy;
- float gx, gy, dl, dr;
-
- if ((parts[i].ctype>0 && parts[i].ctype<PT_NUM && ptypes[parts[i].ctype].enabled && ptypes[parts[i].ctype].falldown>0) || parts[i].ctype==SPC_AIR || parts[i].ctype == PT_NEUT || parts[i].ctype == PT_PHOT || parts[i].ctype == PT_LIGH)
- playerp->elem = parts[i].ctype;
- playerp->frames++;
-
- //Temperature handling
- if (parts[i].temp<243)
- parts[i].life -= 1;
- if ((parts[i].temp<309.6f) && (parts[i].temp>=243))
- parts[i].temp += 1;
-
- //Death
- if (parts[i].life<1 || (pv[y/CELL][x/CELL]>=4.5f && playerp->elem != SPC_AIR) ) //If his HP is less that 0 or there is very big wind...
- {
- for (r=-2; r<=1; r++)
- {
- create_part(-1, x+r, y-2, playerp->elem);
- create_part(-1, x+r+1, y+2, playerp->elem);
- create_part(-1, x-2, y+r+1, playerp->elem);
- create_part(-1, x+2, y+r, playerp->elem);
- }
- kill_part(i); //Kill him
- return 1;
- }
-
- //Follow gravity
- gvx = gvy = 0.0f;
- switch (gravityMode)
- {
- default:
- case 0:
- gvy = 1;
- break;
- case 1:
- gvy = gvx = 0.0f;
- break;
- case 2:
- {
- float gravd;
- gravd = 0.01f - hypotf((parts[i].x - XCNTR), (parts[i].y - YCNTR));
- gvx = ((float)(parts[i].x - XCNTR) / gravd);
- gvy = ((float)(parts[i].y - YCNTR) / gravd);
- }
- }
-
- gvx += gravx[((int)parts[i].y/CELL)*(XRES/CELL)+((int)parts[i].x/CELL)];
- gvy += gravy[((int)parts[i].y/CELL)*(XRES/CELL)+((int)parts[i].x/CELL)];
-
- parts[i].vx -= gvx*dt; //Head up!
- parts[i].vy -= gvy*dt;
-
- //Verlet integration
- pp = 2*playerp->legs[0]-playerp->legs[2]+playerp->accs[0]*dt*dt;
- playerp->legs[2] = playerp->legs[0];
- playerp->legs[0] = pp;
- pp = 2*playerp->legs[1]-playerp->legs[3]+playerp->accs[1]*dt*dt;
- playerp->legs[3] = playerp->legs[1];
- playerp->legs[1] = pp;
-
- pp = 2*playerp->legs[4]-playerp->legs[6]+(playerp->accs[2]+gvx)*dt*dt;
- playerp->legs[6] = playerp->legs[4];
- playerp->legs[4] = pp;
- pp = 2*playerp->legs[5]-playerp->legs[7]+(playerp->accs[3]+gvy)*dt*dt;
- playerp->legs[7] = playerp->legs[5];
- playerp->legs[5] = pp;
-
- pp = 2*playerp->legs[8]-playerp->legs[10]+playerp->accs[4]*dt*dt;
- playerp->legs[10] = playerp->legs[8];
- playerp->legs[8] = pp;
- pp = 2*playerp->legs[9]-playerp->legs[11]+playerp->accs[5]*dt*dt;
- playerp->legs[11] = playerp->legs[9];
- playerp->legs[9] = pp;
-
- pp = 2*playerp->legs[12]-playerp->legs[14]+(playerp->accs[6]+gvx)*dt*dt;
- playerp->legs[14] = playerp->legs[12];
- playerp->legs[12] = pp;
- pp = 2*playerp->legs[13]-playerp->legs[15]+(playerp->accs[7]+gvy)*dt*dt;
- playerp->legs[15] = playerp->legs[13];
- playerp->legs[13] = pp;
-
- //Setting acceleration to 0
- playerp->accs[0] = 0;
- playerp->accs[1] = 0;
-
- playerp->accs[2] = 0;
- playerp->accs[3] = 0;
-
- playerp->accs[4] = 0;
- playerp->accs[5] = 0;
-
- playerp->accs[6] = 0;
- playerp->accs[7] = 0;
-
- gx = (playerp->legs[4] + playerp->legs[12])/2 - gvy;
- gy = (playerp->legs[5] + playerp->legs[13])/2 + gvx;
- dl = pow(gx - playerp->legs[4], 2) + pow(gy - playerp->legs[5], 2);
- dr = pow(gx - playerp->legs[12], 2) + pow(gy - playerp->legs[13], 2);
-
- //Go left
- if (((int)(playerp->comm)&0x01) == 0x01)
- {
- if (dl>dr)
- {
- if (INBOND(playerp->legs[4], playerp->legs[5]) && !eval_move(t, playerp->legs[4], playerp->legs[5], NULL))
- {
- playerp->accs[2] = -3*gvy-3*gvx;
- playerp->accs[3] = 3*gvx-3*gvy;
- playerp->accs[0] = -gvy;
- playerp->accs[1] = gvx;
- }
- }
- else
- {
- if (INBOND(playerp->legs[12], playerp->legs[13]) && !eval_move(t, playerp->legs[12], playerp->legs[13], NULL))
- {
- playerp->accs[6] = -3*gvy-3*gvx;
- playerp->accs[7] = 3*gvx-3*gvy;
- playerp->accs[0] = -gvy;
- playerp->accs[1] = gvx;
- }
- }
- }
-
- //Go right
- if (((int)(playerp->comm)&0x02) == 0x02)
- {
- if (dl<dr)
- {
- if (INBOND(playerp->legs[4], playerp->legs[5]) && !eval_move(t, playerp->legs[4], playerp->legs[5], NULL))
- {
- playerp->accs[2] = 3*gvy-3*gvx;
- playerp->accs[3] = -3*gvx-3*gvy;
- playerp->accs[0] = gvy;
- playerp->accs[1] = -gvx;
- }
- }
- else
- {
- if (INBOND(playerp->legs[12], playerp->legs[13]) && !eval_move(t, playerp->legs[12], playerp->legs[13], NULL))
- {
- playerp->accs[6] = 3*gvy-3*gvx;
- playerp->accs[7] = -3*gvx-3*gvy;
- playerp->accs[0] = gvy;
- playerp->accs[1] = -gvx;
- }
- }
- }
-
- //Jump
- if (((int)(playerp->comm)&0x04) == 0x04 &&
- ((INBOND(playerp->legs[4], playerp->legs[5]) && !eval_move(t, playerp->legs[4], playerp->legs[5], NULL))
- || (INBOND(playerp->legs[12], playerp->legs[13]) && !eval_move(t, playerp->legs[12], playerp->legs[13], NULL))))
- {
- parts[i].vy -= 4*gvy;
- playerp->accs[3] -= gvy;
- playerp->accs[7] -= gvy;
- }
-
- //Charge detector wall if foot inside
- if (bmap[(int)(playerp->legs[5]+0.5)/CELL][(int)(playerp->legs[4]+0.5)/CELL]==WL_DETECT)
- set_emap((int)playerp->legs[4]/CELL, (int)playerp->legs[5]/CELL);
- if (bmap[(int)(playerp->legs[13]+0.5)/CELL][(int)(playerp->legs[12]+0.5)/CELL]==WL_DETECT)
- set_emap((int)(playerp->legs[12]+0.5)/CELL, (int)(playerp->legs[13]+0.5)/CELL);
-
- //Searching for particles near head
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- r = photons[y+ry][x+rx];
-
- if (!r && !bmap[(y+ry)/CELL][(x+rx)/CELL])
- continue;
-
- if (ptypes[r&0xFF].falldown!=0 || ptypes[r&0xFF].state == ST_GAS
- || ptypes[r&0xFF].properties&TYPE_GAS
- || ptypes[r&0xFF].properties&TYPE_LIQUID
- || (r&0xFF) == PT_NEUT || (r&0xFF) == PT_PHOT)
- {
- playerp->elem = r&0xFF; //Current element
- }
- if ((r&0xFF)==PT_TESC || (r&0xFF)==PT_LIGH)
- playerp->elem = PT_LIGH;
- if ((r&0xFF) == PT_PLNT && parts[i].life<100) //Plant gives him 5 HP
- {
- if (parts[i].life<=95)
- parts[i].life += 5;
- else
- parts[i].life = 100;
- kill_part(r>>8);
- }
-
- if ((r&0xFF) == PT_NEUT)
- {
- if (parts[i].life<=100) parts[i].life -= (102-parts[i].life)/2;
- else parts[i].life *= 0.9f;
- kill_part(r>>8);
- }
- if (bmap[(ry+y)/CELL][(rx+x)/CELL]==WL_FAN)
- playerp->elem = SPC_AIR;
- if ((r&0xFF)==PT_PRTI)
- STKM_interact(playerp, i, rx, ry);
- if (!parts[i].type)//STKM_interact may kill STKM
- return 1;
- }
-
- //Head position
- rx = x + 3*((((int)playerp->pcomm)&0x02) == 0x02) - 3*((((int)playerp->pcomm)&0x01) == 0x01);
- ry = y - 3*(playerp->pcomm == 0);
-
- //Spawn
- if (((int)(playerp->comm)&0x08) == 0x08)
- {
- ry -= 2*(rand()%2)+1;
- r = pmap[ry][rx];
- if (ptypes[r&0xFF].state == ST_SOLID)
- {
- create_part(-1, rx, ry, PT_SPRK);
- playerp->frames = 0;
- }
- else
- {
- int np = -1;
- if (playerp->elem == SPC_AIR)
- create_parts(rx + 3*((((int)playerp->pcomm)&0x02) == 0x02) - 3*((((int)playerp->pcomm)&0x01) == 0x01), ry, 4, 4, SPC_AIR, 0, 1);
- else if (playerp->elem==PT_LIGH && playerp->frames<30)//limit lightning creation rate
- np = -1;
- else
- np = create_part(-1, rx, ry, playerp->elem);
- if ( (np < NPART) && np>=0)
- {
- if (playerp->elem == PT_PHOT)
- {
- int random = abs(rand()%3-1)*3;
- if (random==0)
- {
- kill_part(np);
- }
- else
- {
- parts[np].vy = 0;
- if (((int)playerp->pcomm)&(0x01|0x02))
- parts[np].vx = (((((int)playerp->pcomm)&0x02) == 0x02) - (((int)(playerp->pcomm)&0x01) == 0x01))*random;
- else
- parts[np].vx = random;
- }
- }
- else if (playerp->elem == PT_LIGH)
- {
- float angle;
- int power = 100;
- if (gvx!=0 || gvy!=0)
- angle = atan2(gvx, gvy)*180.0f/M_PI;
- else
- angle = rand()%360;
- if (((int)playerp->comm)&0x01)
- angle += 180;
- if (angle>360)
- angle-=360;
- if (angle<0)
- angle+=360;
- parts[np].tmp = angle;
- parts[np].life=rand()%(2+power/15)+power/7;
- parts[np].temp=parts[np].life*power/2.5;
- parts[np].tmp2=1;
- }
- else if (playerp->elem != SPC_AIR)
- {
- parts[np].vx -= -gvy*(5*((((int)playerp->pcomm)&0x02) == 0x02) - 5*(((int)(playerp->pcomm)&0x01) == 0x01));
- parts[np].vy -= gvx*(5*((((int)playerp->pcomm)&0x02) == 0x02) - 5*(((int)(playerp->pcomm)&0x01) == 0x01));
- parts[i].vx -= (ptypes[(int)playerp->elem].weight*parts[np].vx)/1000;
- }
- playerp->frames = 0;
- }
-
- }
- }
-
- //Simulation of joints
- d = 25/(pow((playerp->legs[0]-playerp->legs[4]), 2) + pow((playerp->legs[1]-playerp->legs[5]), 2)+25) - 0.5; //Fast distance
- playerp->legs[4] -= (playerp->legs[0]-playerp->legs[4])*d;
- playerp->legs[5] -= (playerp->legs[1]-playerp->legs[5])*d;
- playerp->legs[0] += (playerp->legs[0]-playerp->legs[4])*d;
- playerp->legs[1] += (playerp->legs[1]-playerp->legs[5])*d;
-
- d = 25/(pow((playerp->legs[8]-playerp->legs[12]), 2) + pow((playerp->legs[9]-playerp->legs[13]), 2)+25) - 0.5;
- playerp->legs[12] -= (playerp->legs[8]-playerp->legs[12])*d;
- playerp->legs[13] -= (playerp->legs[9]-playerp->legs[13])*d;
- playerp->legs[8] += (playerp->legs[8]-playerp->legs[12])*d;
- playerp->legs[9] += (playerp->legs[9]-playerp->legs[13])*d;
-
- d = 36/(pow((playerp->legs[0]-parts[i].x), 2) + pow((playerp->legs[1]-parts[i].y), 2)+36) - 0.5;
- parts[i].vx -= (playerp->legs[0]-parts[i].x)*d;
- parts[i].vy -= (playerp->legs[1]-parts[i].y)*d;
- playerp->legs[0] += (playerp->legs[0]-parts[i].x)*d;
- playerp->legs[1] += (playerp->legs[1]-parts[i].y)*d;
-
- d = 36/(pow((playerp->legs[8]-parts[i].x), 2) + pow((playerp->legs[9]-parts[i].y), 2)+36) - 0.5;
- parts[i].vx -= (playerp->legs[8]-parts[i].x)*d;
- parts[i].vy -= (playerp->legs[9]-parts[i].y)*d;
- playerp->legs[8] += (playerp->legs[8]-parts[i].x)*d;
- playerp->legs[9] += (playerp->legs[9]-parts[i].y)*d;
-
- if (INBOND(playerp->legs[4], playerp->legs[5]) && !eval_move(t, playerp->legs[4], playerp->legs[5], NULL))
- {
- playerp->legs[4] = playerp->legs[6];
- playerp->legs[5] = playerp->legs[7];
- }
-
- if (INBOND(playerp->legs[12], playerp->legs[13]) && !eval_move(t, playerp->legs[12], playerp->legs[13], NULL))
- {
- playerp->legs[12] = playerp->legs[14];
- playerp->legs[13] = playerp->legs[15];
- }
-
- //This makes stick man "pop" from obstacles
- if (INBOND(playerp->legs[4], playerp->legs[5]) && !eval_move(t, playerp->legs[4], playerp->legs[5], NULL))
- {
- float t;
- t = playerp->legs[4]; playerp->legs[4] = playerp->legs[6]; playerp->legs[6] = t;
- t = playerp->legs[5]; playerp->legs[5] = playerp->legs[7]; playerp->legs[7] = t;
- }
-
- if (INBOND(playerp->legs[12], playerp->legs[13]) && !eval_move(t, playerp->legs[12], playerp->legs[13], NULL))
- {
- float t;
- t = playerp->legs[12]; playerp->legs[12] = playerp->legs[14]; playerp->legs[14] = t;
- t = playerp->legs[13]; playerp->legs[13] = playerp->legs[15]; playerp->legs[15] = t;
- }
-
- //Keeping legs distance
- if ((pow((playerp->legs[4] - playerp->legs[12]), 2) + pow((playerp->legs[5]-playerp->legs[13]), 2))<16)
- {
- float tvx, tvy;
- tvx = -gvy;
- tvy = gvx;
-
- if (tvx || tvy)
- {
- playerp->accs[2] -= 0.2*tvx/hypot(tvx, tvy);
- playerp->accs[3] -= 0.2*tvy/hypot(tvx, tvy);
-
- playerp->accs[6] += 0.2*tvx/hypot(tvx, tvy);
- playerp->accs[7] += 0.2*tvy/hypot(tvx, tvy);
- }
- }
-
- if ((pow((playerp->legs[0] - playerp->legs[8]), 2) + pow((playerp->legs[1]-playerp->legs[9]), 2))<16)
- {
- float tvx, tvy;
- tvx = -gvy;
- tvy = gvx;
-
- if (tvx || tvy)
- {
- playerp->accs[0] -= 0.2*tvx/hypot(tvx, tvy);
- playerp->accs[1] -= 0.2*tvy/hypot(tvx, tvy);
-
- playerp->accs[4] += 0.2*tvx/hypot(tvx, tvy);
- playerp->accs[5] += 0.2*tvy/hypot(tvx, tvy);
- }
- }
-
- //If legs touch something
- STKM_interact(playerp, i, (int)(playerp->legs[4]+0.5), (int)(playerp->legs[5]+0.5));
- STKM_interact(playerp, i, (int)(playerp->legs[12]+0.5), (int)(playerp->legs[13]+0.5));
- STKM_interact(playerp, i, (int)(playerp->legs[4]+0.5), (int)playerp->legs[5]);
- STKM_interact(playerp, i, (int)(playerp->legs[12]+0.5), (int)playerp->legs[13]);
- if (!parts[i].type)
- return 1;
-
- parts[i].ctype = playerp->elem;
- return 0;
-}
-
-void STKM_interact(playerst* playerp, int i, int x, int y)
-{
- int r;
- if (x<0 || y<0 || x>=XRES || y>=YRES || !parts[i].type)
- return;
- r = pmap[y][x];
- if (r)
- {
- if ((r&0xFF)==PT_SPRK && playerp->elem!=PT_LIGH) //If on charge
- {
- parts[i].life -= (int)(rand()*20/RAND_MAX)+32;
- }
-
- if (ptypes[r&0xFF].hconduct && ((playerp->elem!=PT_LIGH && parts[r>>8].temp>=323) || parts[r>>8].temp<=243))
- {
- parts[i].life -= 2;
- playerp->accs[3] -= 1;
- }
-
- if (ptypes[r&0xFF].properties&PROP_DEADLY)
- switch (r&0xFF)
- {
- case PT_ACID:
- parts[i].life -= 5;
- break;
- default:
- parts[i].life -= 1;
- }
-
- if (ptypes[r&0xFF].properties&PROP_RADIOACTIVE)
- parts[i].life -= 1;
-
- if ((r&0xFF)==PT_PRTI && parts[i].type)
- {
- int nnx, count=1;//gives rx=0, ry=1 in update_PRTO
- parts[r>>8].tmp = (int)((parts[r>>8].temp-73.15f)/100+1);
- if (parts[r>>8].tmp>=CHANNELS) parts[r>>8].tmp = CHANNELS-1;
- else if (parts[r>>8].tmp<0) parts[r>>8].tmp = 0;
- for (nnx=0; nnx<80; nnx++)
- if (!portalp[parts[r>>8].tmp][count][nnx].type)
- {
- portalp[parts[r>>8].tmp][count][nnx] = parts[i];
- kill_part(i);
- //stop new STKM/fighters being created to replace the ones in the portal:
- playerp->spwn = 1;
- if (portalp[parts[r>>8].tmp][count][nnx].type==PT_FIGH)
- fighcount++;
- break;
- }
- }
-
- if (((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) && parts[i].type)
- {
- if (!legacy_enable)
- {
- parts[r>>8].temp = restrict_flt(parts[r>>8].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);
- }
- kill_part(i);
- }
- if (((r&0xFF)==PT_VOID || ((r&0xFF)==PT_PVOD && parts[r>>8].life==10)) && (!parts[r>>8].ctype || (parts[r>>8].ctype==parts[i].type)!=(parts[r>>8].tmp&1)) && parts[i].type)
- {
- kill_part(i);
- }
- }
-}
-
-void STKM_init_legs(playerst* playerp, int i)
-{
- int x, y;
-
- x = (int)(parts[i].x+0.5f);
- y = (int)(parts[i].y+0.5f);
-
- playerp->legs[0] = x-1;
- playerp->legs[1] = y+6;
- playerp->legs[2] = x-1;
- playerp->legs[3] = y+6;
-
- playerp->legs[4] = x-3;
- playerp->legs[5] = y+12;
- playerp->legs[6] = x-3;
- playerp->legs[7] = y+12;
-
- playerp->legs[8] = x+1;
- playerp->legs[9] = y+6;
- playerp->legs[10] = x+1;
- playerp->legs[11] = y+6;
-
- playerp->legs[12] = x+3;
- playerp->legs[13] = y+12;
- playerp->legs[14] = x+3;
- playerp->legs[15] = y+12;
-}
diff --git a/src/elements/stkm2.c b/src/elements/stkm2.c
deleted file mode 100644
index a83f0d0..0000000
--- a/src/elements/stkm2.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_SPAWN2(UPDATE_FUNC_ARGS) {
- if (!player2.spwn)
- create_part(-1, x, y, PT_STKM2);
-
- return 0;
-}
-
-int update_STKM2(UPDATE_FUNC_ARGS) {
- run_stickman(&player2, UPDATE_FUNC_SUBCALL_ARGS);
- return 0;
-} \ No newline at end of file
diff --git a/src/elements/stor.c b/src/elements/stor.c
deleted file mode 100644
index 72cfef6..0000000
--- a/src/elements/stor.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_STOR(UPDATE_FUNC_ARGS) {
- int r, rx, ry, np, rx1, ry1;
- if(parts[i].life && !parts[i].tmp)
- parts[i].life--;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if ((r>>8)>=NPART || !r)
- continue;
- if (!parts[i].tmp && !parts[i].life && (r&0xFF)!=PT_STOR && !(ptypes[(r&0xFF)].properties&TYPE_SOLID) && (!parts[i].ctype || (r&0xFF)==parts[i].ctype))
- {
- parts[i].tmp = parts[r>>8].type;
- parts[i].temp = parts[r>>8].temp;
- parts[i].tmp2 = parts[r>>8].life;
- parts[i].pavg[0] = parts[r>>8].tmp;
- parts[i].pavg[1] = parts[r>>8].ctype;
- kill_part(r>>8);
- }
- if(parts[i].tmp && (r&0xFF)==PT_SPRK && parts[r>>8].ctype==PT_PSCN && parts[r>>8].life>0 && parts[r>>8].life<4)
- {
- for(ry1 = 1; ry1 >= -1; ry1--){
- for(rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1-rx1+1){ // Oscilate the X starting at 0, 1, -1, 3, -5, etc (Though stop at -1)
- np = create_part(-1,x+rx1,y+ry1,parts[i].tmp);
- if (np!=-1)
- {
- parts[np].temp = parts[i].temp;
- parts[np].life = parts[i].tmp2;
- parts[np].tmp = parts[i].pavg[0];
- parts[np].ctype = parts[i].pavg[1];
- parts[i].tmp = 0;
- parts[i].life = 10;
- break;
- }
- }
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/swch.c b/src/elements/swch.c
deleted file mode 100644
index d0acf45..0000000
--- a/src/elements/swch.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_SWCH(UPDATE_FUNC_ARGS) {
- int r, rt, rx, ry;
- if (parts[i].life>0 && parts[i].life!=10)
- parts[i].life--;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (parts_avg(i,r>>8,PT_INSL)!=PT_INSL) {
- rt = r&0xFF;
- if (rt==PT_SWCH)
- {
- if (parts[i].life>=10&&parts[r>>8].life<10&&parts[r>>8].life>0)
- parts[i].life = 9;
- else if (parts[i].life==0&&parts[r>>8].life>=10)
- {
- //Set to other particle's life instead of 10, otherwise spark loops form when SWCH is sparked while turning on
- parts[i].life = parts[r>>8].life;
- }
- }
- else if (rt==PT_SPRK&&parts[i].life==10&&parts[r>>8].ctype!=PT_PSCN&&parts[r>>8].ctype!=PT_NSCN) {
- part_change_type(i,x,y,PT_SPRK);
- parts[i].ctype = PT_SWCH;
- parts[i].life = 4;
- }
- }
- }
- //turn off SWCH from two red BRAYS
- if (parts[i].life==10 && (!(pmap[y-1][x-1]&0xFF) && ((pmap[y-1][x]&0xFF)==PT_BRAY&&parts[pmap[y-1][x]>>8].tmp==2) && !(pmap[y-1][x+1]&0xFF) && ((pmap[y][x+1]&0xFF)==PT_BRAY&&parts[pmap[y][x+1]>>8].tmp==2)))
- {
- parts[i].life = 9;
- }
- //turn on SWCH from two red BRAYS
- else if (parts[i].life<=5 && (!(pmap[y-1][x-1]&0xFF) && (((pmap[y-1][x]&0xFF)==PT_BRAY&&parts[pmap[y-1][x]>>8].tmp==2) || ((pmap[y+1][x]&0xFF)==PT_BRAY&&parts[pmap[y+1][x]>>8].tmp==2)) && !(pmap[y-1][x+1]&0xFF) && (((pmap[y][x+1]&0xFF)==PT_BRAY&&parts[pmap[y][x+1]>>8].tmp==2) || ((pmap[y][x-1]&0xFF)==PT_BRAY&&parts[pmap[y][x-1]>>8].tmp==2))))
- {
- parts[i].life = 14;
- }
- return 0;
-}
diff --git a/src/elements/thdr.c b/src/elements/thdr.c
deleted file mode 100644
index f1aafa3..0000000
--- a/src/elements/thdr.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_THDR(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((ptypes[r&0xFF].properties&PROP_CONDUCTS) && parts[r>>8].life==0 && !((r&0xFF)==PT_WATR||(r&0xFF)==PT_SLTW) && parts[r>>8].ctype!=PT_SPRK)
- {
- parts[i].type = PT_NONE;
- parts[r>>8].ctype = parts[r>>8].type;
- part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
- parts[r>>8].life = 4;
- }
- else if ((r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_THDR&&(r&0xFF)!=PT_SPRK&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_FIRE&&(r&0xFF)!=PT_NEUT&&(r&0xFF)!=PT_PHOT&&(r&0xFF))
- {
- pv[y/CELL][x/CELL] += 100.0f;
- if (legacy_enable&&1>(rand()%200))
- {
- parts[i].life = rand()%50+120;
- part_change_type(i,x,y,PT_FIRE);
- }
- else
- {
- parts[i].type = PT_NONE;
- }
- }
- }
- if (parts[i].type==PT_NONE) {
- kill_part(i);
- return 1;
- }
- return 0;
-}
diff --git a/src/elements/thrm.c b/src/elements/thrm.c
deleted file mode 100644
index b953d72..0000000
--- a/src/elements/thrm.c
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_THRM(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM || (r&0xFF)==PT_LAVA)) // TODO: could this go in update_PYRO?
- {
- if (1>(rand()%500)) {
- part_change_type(i,x,y,PT_LAVA);
- parts[i].ctype = PT_BMTL;
- parts[i].temp = 3500.0f;
- pv[y/CELL][x/CELL] += 50.0f;
- } else {
- part_change_type(i,x,y,PT_LAVA);
- parts[i].life = 400;
- parts[i].ctype = PT_THRM;
- parts[i].temp = 3500.0f;
- parts[i].tmp = 20;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/tron.c b/src/elements/tron.c
deleted file mode 100644
index 4c50321..0000000
--- a/src/elements/tron.c
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-/* TRON element is meant to resemble a tron bike (or worm) moving around and trying to avoid obstacles itself.
- * It has four direction each turn to choose from, 0 (left) 1 (up) 2 (right) 3 (down).
- * Each turn has a small random chance to randomly turn one way (so it doesn't do the exact same thing in a large room)
- * If the place it wants to move isn't a barrier, it will try and 'see' infront of itself to determine its safety.
- * For now the tron can only see its own body length in pixels ahead of itself (and around corners)
- * - - - - - - - - - -
- * - - - - + - - - - -
- * - - - + + + - - - -
- * - - +<--+-->+ - - -
- * - +<----+---->+ - -
- * - - - - H - - - - -
- * Where H is the head with tail length 4, it checks the + area to see if it can hit any of the edges, then it is called safe, or picks the biggest area if none safe.
- * .tmp bit values: 1st head, 2nd no tail growth, 3rd wait flag, 4th Nodie, 5th Dying, 6th & 7th is direction, 8th - 16th hue
- * .tmp2 is tail length (gets longer every few hundred frames)
- * .life is the timer that kills the end of the tail (the head uses life for how often it grows longer)
- * .ctype Contains the colour, lost on save, regenerated using hue tmp (bits 7 - 16)
- */
-#define TRON_HEAD 1
-#define TRON_NOGROW 2
-#define TRON_WAIT 4 //it was just created, so WAIT a frame
-#define TRON_NODIE 8
-#define TRON_DEATH 16 //Crashed, now dying
-int tron_rx[4] = {-1, 0, 1, 0};
-int tron_ry[4] = { 0,-1, 0, 1};
-unsigned int tron_colours[32];
-int new_tronhead(int x, int y, int i, int direction)
-{
- int np = create_part(-1, x , y ,PT_TRON);
- if (np==-1)
- return -1;
- if (parts[i].life >= 100) // increase tail length
- {
- if (!(parts[i].tmp&TRON_NOGROW))
- parts[i].tmp2++;
- parts[i].life = 5;
- }
- //give new head our properties
- parts[np].tmp = 1 | direction<<5 | parts[i].tmp&(TRON_NOGROW|TRON_NODIE) | (parts[i].tmp&0xF800);
- if (np > i)
- parts[np].tmp |= TRON_WAIT;
-
- parts[np].ctype = parts[i].ctype;
- parts[np].tmp2 = parts[i].tmp2;
- parts[np].life = parts[i].life + 2;
- return 1;
-}
-int trymovetron(int x, int y, int dir, int i, int len)
-{
- int k,j,r,rx,ry,tx,ty,count;
- count = 0;
- rx = x;
- ry = y;
- for (k = 1; k <= len; k ++)
- {
- rx += tron_rx[dir];
- ry += tron_ry[dir];
- r = pmap[ry][rx];
- if (!r && !bmap[(ry)/CELL][(rx)/CELL] && ry > CELL && rx > CELL && ry < YRES-CELL && rx < XRES-CELL)
- {
- count++;
- for (tx = rx - tron_ry[dir] , ty = ry - tron_rx[dir], j=1; abs(tx-rx) < (len-k) && abs(ty-ry) < (len-k); tx-=tron_ry[dir],ty-=tron_rx[dir],j++)
- {
- r = pmap[ty][tx];
- if (!r && !bmap[(ty)/CELL][(tx)/CELL] && ty > CELL && tx > CELL && ty < YRES-CELL && tx < XRES-CELL)
- {
- if (j == (len-k))//there is a safe path, so we can break out
- return len+1;
- count++;
- }
- else //we hit a block so no need to check farther here
- break;
- }
- for (tx = rx + tron_ry[dir] , ty = ry + tron_rx[dir], j=1; abs(tx-rx) < (len-k) && abs(ty-ry) < (len-k); tx+=tron_ry[dir],ty+=tron_rx[dir],j++)
- {
- r = pmap[ty][tx];
- if (!r && !bmap[(ty)/CELL][(tx)/CELL] && ty > CELL && tx > CELL && ty < YRES-CELL && tx < XRES-CELL)
- {
- if (j == (len-k))
- return len+1;
- count++;
- }
- else
- break;
- }
- }
- else //a block infront, no need to continue
- break;
- }
- return count;
-}
-int update_TRON(UPDATE_FUNC_ARGS) {
- int r, rx, ry, np;
- if (parts[i].tmp&TRON_WAIT)
- {
- parts[i].tmp &= ~TRON_WAIT;
- return 0;
- }
- if (parts[i].tmp&TRON_HEAD)
- {
- int firstdircheck = 0,seconddir,seconddircheck = 0,lastdir,lastdircheck = 0;
- int direction = (parts[i].tmp>>5 & 0x3);
- int originaldir = direction;
-
- //random turn
- int random = rand()%340;
- if (random==1 || random==3)
- {
- //randomly turn left(3) or right(1)
- direction = (direction + random)%4;
- }
-
- //check infront
- //do sight check
- firstdircheck = trymovetron(x,y,direction,i,parts[i].tmp2);
- if (firstdircheck < parts[i].tmp2)
- {
- if (originaldir != direction) //if we just tried a random turn, don't pick random again
- {
- seconddir = originaldir;
- lastdir = (direction + 2)%4;
- }
- else
- {
- seconddir = (direction + ((rand()%2)*2)+1)% 4;
- lastdir = (seconddir + 2)%4;
- }
- seconddircheck = trymovetron(x,y,seconddir,i,parts[i].tmp2);
- lastdircheck = trymovetron(x,y,lastdir,i,parts[i].tmp2);
- }
- //find the best move
- if (seconddircheck > firstdircheck)
- direction = seconddir;
- if (lastdircheck > seconddircheck && lastdircheck > firstdircheck)
- direction = lastdir;
- //now try making new head, even if it fails
- if (new_tronhead(x + tron_rx[direction],y + tron_ry[direction],i,direction) == -1)
- {
- //ohgod crash
- parts[i].tmp |= TRON_DEATH;
- //trigger tail death for TRON_NODIE, or is that mode even needed? just set a high tail length(but it still won't start dying when it crashes)
- }
-
- //set own life and clear .tmp (it dies if it can't move anyway)
- parts[i].life = parts[i].tmp2;
- parts[i].tmp &= parts[i].tmp&0xF818;
- }
- else // fade tail deco, or prevent tail from dieing
- {
- if (parts[i].tmp&TRON_NODIE)
- parts[i].life++;
- //parts[i].dcolour = clamp_flt((float)parts[i].life/(float)parts[i].tmp2,0,1.0f) << 24 | parts[i].dcolour&0x00FFFFFF;
- }
- return 0;
-}
-
-int graphics_TRON(GRAPHICS_FUNC_ARGS) {
- unsigned int col = tron_colours[(cpart->tmp&0xF800)>>11];
- if(cpart->tmp & TRON_HEAD)
- *pixel_mode |= PMODE_GLOW;
- *colr = (col & 0xFF0000)>>16;
- *colg = (col & 0x00FF00)>>8;
- *colb = (col & 0x0000FF);
- if(cpart->tmp & TRON_DEATH)
- {
- *pixel_mode |= FIRE_ADD | PMODE_FLARE;
- *firer = *colr;
- *fireg = *colg;
- *fireb = *colb;
- *firea = 255;
- }
- if(cpart->life < cpart->tmp2 && !(cpart->tmp & TRON_HEAD))
- {
- *pixel_mode |= PMODE_BLEND;
- *pixel_mode &= ~PMODE_FLAT;
- *cola = (int)((((float)cpart->life)/((float)cpart->tmp2))*255.0f);
- }
- return 0;
-}
-
-void TRON_init_graphics()
-{
- int i;
- int r, g, b;
- for (i=0; i<32; i++)
- {
- HSV_to_RGB(i<<4,255,255,&r,&g,&b);
- tron_colours[i] = r<<16 | g<<8 | b;
- }
-}
diff --git a/src/elements/ttan.c b/src/elements/ttan.c
deleted file mode 100644
index 9023939..0000000
--- a/src/elements/ttan.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_TTAN(UPDATE_FUNC_ARGS) {
- int nx, ny, ttan = 0;
- if(nt<=2)
- ttan = 2;
- else if(parts[i].tmp)
- ttan = 2;
- else if(nt<=6)
- for (nx=-1; nx<2; nx++) {
- for (ny=-1; ny<2; ny++) {
- if ((!nx != !ny) && x+nx>=0 && y+ny>=0 && x+nx<XRES && y+ny<YRES) {
- if((pmap[y+ny][x+nx]&0xFF)==PT_TTAN)
- ttan++;
- }
- }
- }
-
- if(ttan>=2) {
- bmap_blockair[y/CELL][x/CELL] = 1;
- bmap_blockairh[y/CELL][x/CELL] = 1;
- }
- return 0;
-}
diff --git a/src/elements/uran.c b/src/elements/uran.c
deleted file mode 100644
index e5b971b..0000000
--- a/src/elements/uran.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_URAN(UPDATE_FUNC_ARGS) {
- if (!legacy_enable && pv[y/CELL][x/CELL]>0.0f)
- {
- float atemp = parts[i].temp + (-MIN_TEMP);
- parts[i].temp = restrict_flt((atemp*(1+(pv[y/CELL][x/CELL]/2000)))+MIN_TEMP, MIN_TEMP, MAX_TEMP);
- }
- return 0;
-}
diff --git a/src/elements/vine.c b/src/elements/vine.c
deleted file mode 100644
index 5af5d48..0000000
--- a/src/elements/vine.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_VINE(UPDATE_FUNC_ARGS) {
- int r, np, rx =(rand()%3)-1, ry=(rand()%3)-1;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (1>rand()%15)
- part_change_type(i,x,y,PT_PLNT);
- else if (!r)
- {
- np = create_part(-1,x+rx,y+ry,PT_VINE);
- if (np<0) return 0;
- parts[np].temp = parts[i].temp;
- parts[i].tmp = 1;
- part_change_type(i,x,y,PT_PLNT);
- }
- }
- return 0;
-}
diff --git a/src/elements/warp.c b/src/elements/warp.c
deleted file mode 100644
index 42f2d3a..0000000
--- a/src/elements/warp.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_WARP(UPDATE_FUNC_ARGS) {
- int trade, r, rx, ry;
-
- if (parts[i].tmp2>2000)
- {
- parts[i].temp = 10000;
- pv[y/CELL][x/CELL] += (parts[i].tmp2/5000) * CFDS;
- if (2>rand()%100)
- create_part(-3, x, y, PT_ELEC);
- }
- for ( trade = 0; trade<5; trade ++)
- {
- rx = rand()%3-1;
- ry = rand()%3-1;
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)!=PT_WARP&&(r&0xFF)!=PT_STKM&&(r&0xFF)!=PT_STKM2&&(r&0xFF)!=PT_DMND&&(r&0xFF)!=PT_CLNE&&(r&0xFF)!=PT_BCLN&&(r&0xFF)!=PT_PCLN)
- {
- parts[i].x = parts[r>>8].x;
- parts[i].y = parts[r>>8].y;
- parts[r>>8].x = x;
- parts[r>>8].y = y;
- parts[r>>8].vx = (rand()%4)-1.5;
- parts[r>>8].vy = (rand()%4)-2;
- parts[i].life += 4;
- pmap[y][x] = r;
- pmap[y+ry][x+rx] = (i<<8)|parts[i].type;
- trade = 5;
- }
- }
- }
- return 0;
-}
-int graphics_WARP(GRAPHICS_FUNC_ARGS)
-{
- *colr = *colg = *colb = *cola = 0;
- *pixel_mode &= ~PMODE;
- return 0;
-}
diff --git a/src/elements/watr.c b/src/elements/watr.c
deleted file mode 100644
index ecf96aa..0000000
--- a/src/elements/watr.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_WATR(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_SALT && 1>(rand()%250))
- {
- part_change_type(i,x,y,PT_SLTW);
- // on average, convert 3 WATR to SLTW before SALT turns into SLTW
- if (rand()%3==0)
- part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
- }
- if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (legacy_enable||parts[i].temp>(273.15f+12.0f)) && 1>(rand()%500))
- {
- part_change_type(i,x,y,PT_FIRE);
- parts[i].life = 4;
- parts[i].ctype = PT_WATR;
- }
- if ((r&0xFF)==PT_FIRE && parts[r>>8].ctype!=PT_WATR){
- kill_part(r>>8);
- if(1>(rand()%150)){
- kill_part(i);
- return 1;
- }
- }
- if ((r&0xFF)==PT_SLTW && 1>(rand()%10000))
- {
- part_change_type(i,x,y,PT_SLTW);
- }
- /*if ((r&0xFF)==PT_CNCT && 1>(rand()%500)) Concrete+Water to paste, not very popular
- {
- part_change_type(i,x,y,PT_PSTE);
- kill_part(r>>8);
- }*/
- }
- return 0;
-}
diff --git a/src/elements/wifi.c b/src/elements/wifi.c
deleted file mode 100644
index 40e1f96..0000000
--- a/src/elements/wifi.c
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_WIFI(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- parts[i].tmp = (int)((parts[i].temp-73.15f)/100+1);
- if (parts[i].tmp>=CHANNELS) parts[i].tmp = CHANNELS-1;
- else if (parts[i].tmp<0) parts[i].tmp = 0;
- for (rx=-1; rx<2; rx++)
- for (ry=-1; ry<2; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- // wireless[][0] - whether channel is active on this frame
- // wireless[][1] - whether channel should be active on next frame
- if (wireless[parts[i].tmp][0])
- {
- if (((r&0xFF)==PT_NSCN||(r&0xFF)==PT_PSCN||(r&0xFF)==PT_INWR)&&parts[r>>8].life==0 && wireless[parts[i].tmp][0])
- {
- parts[r>>8].ctype = r&0xFF;
- part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
- parts[r>>8].life = 4;
- }
- }
- else
- {
- if ((r&0xFF)==PT_SPRK && parts[r>>8].ctype!=PT_NSCN && parts[r>>8].life>=3)
- {
- wireless[parts[i].tmp][1] = 1;
- ISWIRE = 2;
- }
- }
- }
- return 0;
-}
diff --git a/src/elements/wire.c b/src/elements/wire.c
deleted file mode 100644
index 81b1d5f..0000000
--- a/src/elements/wire.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_WIRE(UPDATE_FUNC_ARGS) {
- int s,r,rx,ry,count;
- /*
- 0: wire
- 1: spark head
- 2: spark tail
-
- tmp is previous state, ctype is current state
- */
- //parts[i].tmp=parts[i].ctype;
- parts[i].ctype=0;
- if(parts[i].tmp==1)
- {
- parts[i].ctype=2;
- }
- if(parts[i].tmp==2)
- {
- parts[i].ctype=0;
- }
-
- count=0;
- for(rx=-1; rx<2; rx++)
- for(ry=-1; ry<2; ry++)
- {
- if(x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if((r&0xFF)==PT_SPRK && parts[r>>8].life==3 && parts[r>>8].ctype==PT_PSCN)
- {
- parts[i].ctype=1;
- return 0;
- }
- else if((r&0xFF)==PT_NSCN && parts[i].tmp==1){create_part(-1, x+rx, y+ry, PT_SPRK);}
- else if((r&0xFF)==PT_WIRE && parts[r>>8].tmp==1 && !parts[i].tmp){count++;}
- }
- }
- if(count==1 || count==2)
- parts[i].ctype=1;
- return 0;
-}
-
-int graphics_WIRE(GRAPHICS_FUNC_ARGS)
-{
- if (cpart->ctype==0)
- {
- *colr = 255;
- *colg = 204;
- *colb = 0;
- return 0;
- }
- if (cpart->ctype==1)
- {
- *colr = 50;
- *colg = 100;
- *colb = 255;
- //*pixel_mode |= PMODE_GLOW;
- return 0;
- }
- if (cpart->ctype==2)
- {
- *colr = 255;
- *colg = 100;
- *colb = 50;
- //*pixel_mode |= PMODE_GLOW;
- return 0;
- }
-}
diff --git a/src/elements/wood.c b/src/elements/wood.c
deleted file mode 100644
index e5fec9a..0000000
--- a/src/elements/wood.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_WOOD(UPDATE_FUNC_ARGS) {
- if (parts[i].temp > 550 && parts[i].temp > parts[i].tmp)
- parts[i].tmp = (int)parts[i].temp;
- return 0;
-}
-
-int graphics_WOOD(GRAPHICS_FUNC_ARGS)
-{
- float maxtemp = fmax(cpart->tmp,cpart->temp);
- if (maxtemp > 400)
- {
- *colr -= (int)restrict_flt((maxtemp-400)/3,0,172);
- *colg -= (int)restrict_flt((maxtemp-400)/4,0,140);
- *colb -= (int)restrict_flt((maxtemp-400)/20,0,44);
- }
- if (maxtemp < 273)
- {
- *colr -= (int)restrict_flt((273-maxtemp)/5,0,40);
- *colg += (int)restrict_flt((273-maxtemp)/4,0,40);
- *colb += (int)restrict_flt((273-maxtemp)/1.5,0,150);
- }
- return 0;
-}
diff --git a/src/elements/wtrv.c b/src/elements/wtrv.c
deleted file mode 100644
index b7f94cf..0000000
--- a/src/elements/wtrv.c
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_WTRV(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && !legacy_enable && parts[i].temp>(273.15f+12.0f) && 1>(rand()%500))
- {
- part_change_type(i,x,y,PT_FIRE);
- parts[i].life = 4;
- parts[i].ctype = PT_WATR;
- }
- }
- if(parts[i].temp>1273&&parts[i].ctype==PT_FIRE)
- parts[i].temp-=parts[i].temp/1000;
- return 0;
-}
diff --git a/src/elements/yest.c b/src/elements/yest.c
deleted file mode 100644
index afd6243..0000000
--- a/src/elements/yest.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <element.h>
-
-int update_YEST(UPDATE_FUNC_ARGS) {
- int r, rx, ry;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
- {
- r = pmap[y+ry][x+rx];
- if (!r)
- continue;
- if ((r&0xFF)==PT_DYST && 1>(rand()%30) && !legacy_enable)
- {
- part_change_type(i,x,y,PT_DYST);
- }
- }
- if (parts[i].temp>303&&parts[i].temp<317) {
- create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_YEST);
- }
- return 0;
-}
diff --git a/src/graphics.c b/src/graphics.c
deleted file mode 100644
index 72cf11c..0000000
--- a/src/graphics.c
+++ /dev/null
@@ -1,4534 +0,0 @@
-/**
- * Powder Toy - graphics
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <math.h>
-#include <SDL/SDL.h>
-#include <bzlib.h>
-#ifdef WIN32
-#include <SDL/SDL_syswm.h>
-#endif
-
-#if defined(OGLR)
-#ifdef MACOSX
-#include <OpenGL/gl3.h>
-#include <OpenGL/glu.h>
-#elif defined(WIN32)
-#include <GL/glew.h>
-#include <GL/gl.h>
-#include <GL/glu.h>
-#else
-#include <GL/gl.h>
-#include <GL/glu.h>
-#endif
-#endif
-
-#include <defines.h>
-#include <air.h>
-#include "gravity.h"
-#include <powder.h>
-#define INCLUDE_SHADERS
-#include <graphics.h>
-#include <powdergraphics.h>
-#define INCLUDE_FONTDATA
-#include <font.h>
-#include <misc.h>
-#include "hmap.h"
-#ifdef LUACONSOLE
-#include <luaconsole.h>
-#endif
-
-#if defined(LIN32) || defined(LIN64)
-#include "icon.h"
-#endif
-
-
-#ifdef WIN32
-IMAGE_DOS_HEADER __ImageBase;
-#endif
-
-//unsigned cmode = CM_FIRE;
-unsigned int *render_modes;
-unsigned int render_mode;
-unsigned int colour_mode;
-unsigned int *display_modes;
-unsigned int display_mode;
-
-SDL_Surface *sdl_scrn;
-int sdl_scale = 1;
-
-#ifdef OGLR
-GLuint zoomTex, vidBuf, airBuf, fireAlpha, glowAlpha, blurAlpha, partsFboTex, partsFbo, partsTFX, partsTFY, airPV, airVY, airVX;
-GLuint fireProg, airProg_Pressure, airProg_Velocity, airProg_Cracker, lensProg;
-#endif
-
-int emp_decor = 0;
-int sandcolour_r = 0;
-int sandcolour_g = 0;
-int sandcolour_b = 0;
-int sandcolour_frame = 0;
-
-unsigned char fire_r[YRES/CELL][XRES/CELL];
-unsigned char fire_g[YRES/CELL][XRES/CELL];
-unsigned char fire_b[YRES/CELL][XRES/CELL];
-
-unsigned int fire_alpha[CELL*3][CELL*3];
-pixel *pers_bg;
-
-char * flm_data;
-int flm_data_points = 4;
-pixel flm_data_colours[] = {PIXPACK(0xAF9F0F), PIXPACK(0xDFBF6F), PIXPACK(0x60300F), PIXPACK(0x000000)};
-float flm_data_pos[] = {1.0f, 0.9f, 0.5f, 0.0f};
-
-char * plasma_data;
-int plasma_data_points = 5;
-pixel plasma_data_colours[] = {PIXPACK(0xAFFFFF), PIXPACK(0xAFFFFF), PIXPACK(0x301060), PIXPACK(0x301040), PIXPACK(0x000000)};
-float plasma_data_pos[] = {1.0f, 0.9f, 0.5f, 0.25, 0.0f};
-
-void init_display_modes()
-{
- int i;
- display_modes = calloc(1, sizeof(unsigned int));
- render_modes = calloc(2, sizeof(unsigned int));
-
- display_modes[0] = 0;
- render_modes[0] = RENDER_FIRE;
- render_modes[1] = 0;
-
- update_display_modes();
-}
-
-// Combine all elements of the display_modes and render_modes arrays into single variables using bitwise or
-void update_display_modes()
-{
- int i;
- display_mode = 0;
- i = 0;
- while(display_modes[i])
- {
- display_mode |= display_modes[i];
- i++;
- }
- render_mode = 0;
- i = 0;
- while(render_modes[i])
- {
- render_mode |= render_modes[i];
- i++;
- }
-}
-
-char * generate_gradient(pixel * colours, float * points, int pointcount, int size)
-{
- int cp, i, j;
- pixel ptemp;
- char * newdata = malloc(size * 3);
- float poss, pose, temp;
- memset(newdata, 0, size*3);
- //Sort the Colours and Points
- for (i = (pointcount - 1); i > 0; i--)
- {
- for (j = 1; j <= i; j++)
- {
- if (points[j-1] > points[j])
- {
- temp = points[j-1];
- points[j-1] = points[j];
- points[j] = temp;
-
- ptemp = colours[j-1];
- colours[j-1] = colours[j];
- colours[j] = ptemp;
- }
- }
- }
- i = 0;
- j = 1;
- poss = points[i];
- pose = points[j];
- for (cp = 0; cp < size; cp++)
- {
- float cpos = (float)cp / (float)size, ccpos, cccpos;
- if(cpos > pose && j+1 < pointcount)
- {
- poss = points[++i];
- pose = points[++j];
- }
- ccpos = cpos - poss;
- cccpos = ccpos / (pose - poss);
- if(cccpos > 1.0f)
- cccpos = 1.0f;
- newdata[(cp*3)] = PIXR(colours[i])*(1.0f-cccpos) + PIXR(colours[j])*(cccpos);
- newdata[(cp*3)+1] = PIXG(colours[i])*(1.0f-cccpos) + PIXG(colours[j])*(cccpos);
- newdata[(cp*3)+2] = PIXB(colours[i])*(1.0f-cccpos) + PIXB(colours[j])*(cccpos);
- }
- return newdata;
-}
-
-void *ptif_pack(pixel *src, int w, int h, int *result_size){
- int i = 0, datalen = (w*h)*3, cx = 0, cy = 0;
- unsigned char *red_chan = calloc(1, w*h);
- unsigned char *green_chan = calloc(1, w*h);
- unsigned char *blue_chan = calloc(1, w*h);
- unsigned char *data = malloc(((w*h)*3)+8);
- unsigned char *result = malloc(((w*h)*3)+8);
-
- for(cx = 0; cx<w; cx++){
- for(cy = 0; cy<h; cy++){
- red_chan[w*(cy)+(cx)] = PIXR(src[w*(cy)+(cx)]);
- green_chan[w*(cy)+(cx)] = PIXG(src[w*(cy)+(cx)]);
- blue_chan[w*(cy)+(cx)] = PIXB(src[w*(cy)+(cx)]);
- }
- }
-
- memcpy(data, red_chan, w*h);
- memcpy(data+(w*h), green_chan, w*h);
- memcpy(data+((w*h)*2), blue_chan, w*h);
- free(red_chan);
- free(green_chan);
- free(blue_chan);
-
- result[0] = 'P';
- result[1] = 'T';
- result[2] = 'i';
- result[3] = 1;
- result[4] = w;
- result[5] = w>>8;
- result[6] = h;
- result[7] = h>>8;
-
- i -= 8;
-
- if(BZ2_bzBuffToBuffCompress((char *)(result+8), (unsigned *)&i, (char *)data, datalen, 9, 0, 0) != BZ_OK){
- free(data);
- free(result);
- return NULL;
- }
-
- *result_size = i+8;
- free(data);
- return result;
-}
-
-pixel *ptif_unpack(void *datain, int size, int *w, int *h){
- int width, height, i, cx, cy, resCode;
- unsigned char *red_chan;
- unsigned char *green_chan;
- unsigned char *blue_chan;
- unsigned char *data = datain;
- unsigned char *undata;
- pixel *result;
- if(size<16){
- printf("Image empty\n");
- return NULL;
- }
- if(!(data[0]=='P' && data[1]=='T' && data[2]=='i')){
- printf("Image header invalid\n");
- return NULL;
- }
- width = data[4]|(data[5]<<8);
- height = data[6]|(data[7]<<8);
-
- i = (width*height)*3;
- undata = calloc(1, (width*height)*3);
- red_chan = calloc(1, width*height);
- green_chan = calloc(1, width*height);
- blue_chan = calloc(1, width*height);
- result = calloc(width*height, PIXELSIZE);
-
- resCode = BZ2_bzBuffToBuffDecompress((char *)undata, (unsigned *)&i, (char *)(data+8), size-8, 0, 0);
- if (resCode){
- printf("Decompression failure, %d\n", resCode);
- free(red_chan);
- free(green_chan);
- free(blue_chan);
- free(undata);
- free(result);
- return NULL;
- }
- if(i != (width*height)*3){
- printf("Result buffer size mismatch, %d != %d\n", i, (width*height)*3);
- free(red_chan);
- free(green_chan);
- free(blue_chan);
- free(undata);
- free(result);
- return NULL;
- }
- memcpy(red_chan, undata, width*height);
- memcpy(green_chan, undata+(width*height), width*height);
- memcpy(blue_chan, undata+((width*height)*2), width*height);
-
- for(cx = 0; cx<width; cx++){
- for(cy = 0; cy<height; cy++){
- result[width*(cy)+(cx)] = PIXRGB(red_chan[width*(cy)+(cx)], green_chan[width*(cy)+(cx)], blue_chan[width*(cy)+(cx)]);
- }
- }
-
- *w = width;
- *h = height;
- free(red_chan);
- free(green_chan);
- free(blue_chan);
- free(undata);
- return result;
-}
-
-pixel *resample_img_nn(pixel * src, int sw, int sh, int rw, int rh)
-{
- int y, x;
- pixel *q = NULL;
- q = malloc(rw*rh*PIXELSIZE);
- for (y=0; y<rh; y++)
- for (x=0; x<rw; x++){
- q[rw*y+x] = src[sw*(y*sh/rh)+(x*sw/rw)];
- }
- return q;
-}
-
-pixel *resample_img(pixel *src, int sw, int sh, int rw, int rh)
-{
- int y, x, fxceil, fyceil;
- //int i,j,x,y,w,h,r,g,b,c;
- pixel *q = NULL;
- //TODO: Actual resampling, this is just cheap nearest pixel crap
- if(rw == sw && rh == sh){
- //Don't resample
- q = malloc(rw*rh*PIXELSIZE);
- memcpy(q, src, rw*rh*PIXELSIZE);
- } else if(rw > sw && rh > sh){
- float fx, fy, fyc, fxc;
- double intp;
- pixel tr, tl, br, bl;
- q = malloc(rw*rh*PIXELSIZE);
- //Bilinear interpolation for upscaling
- for (y=0; y<rh; y++)
- for (x=0; x<rw; x++)
- {
- fx = ((float)x)*((float)sw)/((float)rw);
- fy = ((float)y)*((float)sh)/((float)rh);
- fxc = modf(fx, &intp);
- fyc = modf(fy, &intp);
- fxceil = (int)ceil(fx);
- fyceil = (int)ceil(fy);
- if (fxceil>=sw) fxceil = sw-1;
- if (fyceil>=sh) fyceil = sh-1;
- tr = src[sw*(int)floor(fy)+fxceil];
- tl = src[sw*(int)floor(fy)+(int)floor(fx)];
- br = src[sw*fyceil+fxceil];
- bl = src[sw*fyceil+(int)floor(fx)];
- q[rw*y+x] = PIXRGB(
- (int)(((((float)PIXR(tl))*(1.0f-fxc))+(((float)PIXR(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXR(bl))*(1.0f-fxc))+(((float)PIXR(br))*(fxc)))*(fyc)),
- (int)(((((float)PIXG(tl))*(1.0f-fxc))+(((float)PIXG(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXG(bl))*(1.0f-fxc))+(((float)PIXG(br))*(fxc)))*(fyc)),
- (int)(((((float)PIXB(tl))*(1.0f-fxc))+(((float)PIXB(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXB(bl))*(1.0f-fxc))+(((float)PIXB(br))*(fxc)))*(fyc))
- );
- }
- } else {
- //Stairstepping
- float fx, fy, fyc, fxc;
- double intp;
- pixel tr, tl, br, bl;
- int rrw = rw, rrh = rh;
- pixel * oq;
- oq = malloc(sw*sh*PIXELSIZE);
- memcpy(oq, src, sw*sh*PIXELSIZE);
- rw = sw;
- rh = sh;
- while(rrw != rw && rrh != rh){
- rw *= 0.7;
- rh *= 0.7;
- if(rw <= rrw || rh <= rrh){
- rw = rrw;
- rh = rrh;
- }
- q = malloc(rw*rh*PIXELSIZE);
- //Bilinear interpolation for upscaling
- for (y=0; y<rh; y++)
- for (x=0; x<rw; x++)
- {
- fx = ((float)x)*((float)sw)/((float)rw);
- fy = ((float)y)*((float)sh)/((float)rh);
- fxc = modf(fx, &intp);
- fyc = modf(fy, &intp);
- fxceil = (int)ceil(fx);
- fyceil = (int)ceil(fy);
- if (fxceil>=sw) fxceil = sw-1;
- if (fyceil>=sh) fyceil = sh-1;
- tr = oq[sw*(int)floor(fy)+fxceil];
- tl = oq[sw*(int)floor(fy)+(int)floor(fx)];
- br = oq[sw*fyceil+fxceil];
- bl = oq[sw*fyceil+(int)floor(fx)];
- q[rw*y+x] = PIXRGB(
- (int)(((((float)PIXR(tl))*(1.0f-fxc))+(((float)PIXR(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXR(bl))*(1.0f-fxc))+(((float)PIXR(br))*(fxc)))*(fyc)),
- (int)(((((float)PIXG(tl))*(1.0f-fxc))+(((float)PIXG(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXG(bl))*(1.0f-fxc))+(((float)PIXG(br))*(fxc)))*(fyc)),
- (int)(((((float)PIXB(tl))*(1.0f-fxc))+(((float)PIXB(tr))*(fxc)))*(1.0f-fyc) + ((((float)PIXB(bl))*(1.0f-fxc))+(((float)PIXB(br))*(fxc)))*(fyc))
- );
- }
- free(oq);
- oq = q;
- sw = rw;
- sh = rh;
- }
- }
- return q;
-}
-
-pixel *rescale_img(pixel *src, int sw, int sh, int *qw, int *qh, int f)
-{
- int i,j,x,y,w,h,r,g,b,c;
- pixel p, *q;
- w = (sw+f-1)/f;
- h = (sh+f-1)/f;
- q = malloc(w*h*PIXELSIZE);
- for (y=0; y<h; y++)
- for (x=0; x<w; x++)
- {
- r = g = b = c = 0;
- for (j=0; j<f; j++)
- for (i=0; i<f; i++)
- if (x*f+i<sw && y*f+j<sh)
- {
- p = src[(y*f+j)*sw + (x*f+i)];
- if (p)
- {
- r += PIXR(p);
- g += PIXG(p);
- b += PIXB(p);
- c ++;
- }
- }
- if (c>1)
- {
- r = (r+c/2)/c;
- g = (g+c/2)/c;
- b = (b+c/2)/c;
- }
- q[y*w+x] = PIXRGB(r, g, b);
- }
- *qw = w;
- *qh = h;
- return q;
-}
-
-#ifdef OGLR
-void clearScreen(float alpha)
-{
- if(alpha > 0.999f)
- {
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
- glClear(GL_COLOR_BUFFER_BIT);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
- }
- else
- {
- glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
- glColor4f(1.0f, 1.0f, 1.0f, alpha);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
- glBegin(GL_QUADS);
- glVertex2f(0, 0);
- glVertex2f(XRES, 0);
- glVertex2f(XRES, YRES);
- glVertex2f(0, YRES);
- glEnd();
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
- glBlendEquation(GL_FUNC_ADD);
- }
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
-}
-
-void clearScreenNP(float alpha)
-{
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
-}
-
-void ogl_blit(int x, int y, int w, int h, pixel *src, int pitch, int scale)
-{
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- //glDrawPixels(w,h,GL_BGRA,GL_UNSIGNED_BYTE,src); //Why does this still think it's ABGR?
- glEnable( GL_TEXTURE_2D );
- glBindTexture(GL_TEXTURE_2D, vidBuf);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES+BARSIZE, YRES+MENUSIZE, GL_BGRA, GL_UNSIGNED_BYTE, src);
- glBegin(GL_QUADS);
- glTexCoord2d(1, 0);
- glVertex3f((XRES+BARSIZE)*sdl_scale, (YRES+MENUSIZE)*sdl_scale, 1.0);
- glTexCoord2d(0, 0);
- glVertex3f(0, (YRES+MENUSIZE)*sdl_scale, 1.0);
- glTexCoord2d(0, 1);
- glVertex3f(0, 0, 1.0);
- glTexCoord2d(1, 1);
- glVertex3f((XRES+BARSIZE)*sdl_scale, 0, 1.0);
- glEnd();
-
- glDisable( GL_TEXTURE_2D );
- glBlendFunc(GL_ONE, GL_ONE);
- glFlush();
- SDL_GL_SwapBuffers ();
-}
-#endif
-
-void sdl_blit_1(int x, int y, int w, int h, pixel *src, int pitch)
-{
- pixel *dst;
- int j;
- if (SDL_MUSTLOCK(sdl_scrn))
- if (SDL_LockSurface(sdl_scrn)<0)
- return;
- dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x;
- if (SDL_MapRGB(sdl_scrn->format,0x33,0x55,0x77)!=PIXPACK(0x335577))
- {
- //pixel format conversion
- int i;
- pixel px;
- SDL_PixelFormat *fmt = sdl_scrn->format;
- for (j=0; j<h; j++)
- {
- for (i=0; i<w; i++)
- {
- px = src[i];
- dst[i] = ((PIXR(px)>>fmt->Rloss)<<fmt->Rshift)|
- ((PIXG(px)>>fmt->Gloss)<<fmt->Gshift)|
- ((PIXB(px)>>fmt->Bloss)<<fmt->Bshift);
- }
- dst+=sdl_scrn->pitch/PIXELSIZE;
- src+=pitch;
- }
- }
- else
- {
- for (j=0; j<h; j++)
- {
- memcpy(dst, src, w*PIXELSIZE);
- dst+=sdl_scrn->pitch/PIXELSIZE;
- src+=pitch;
- }
- }
- if (SDL_MUSTLOCK(sdl_scrn))
- SDL_UnlockSurface(sdl_scrn);
- SDL_UpdateRect(sdl_scrn,0,0,0,0);
-}
-
-void sdl_blit_2(int x, int y, int w, int h, pixel *src, int pitch)
-{
- pixel *dst;
- int j;
- int i,k;
- if (SDL_MUSTLOCK(sdl_scrn))
- if (SDL_LockSurface(sdl_scrn)<0)
- return;
- dst=(pixel *)sdl_scrn->pixels+y*sdl_scrn->pitch/PIXELSIZE+x;
- if (SDL_MapRGB(sdl_scrn->format,0x33,0x55,0x77)!=PIXPACK(0x335577))
- {
- //pixel format conversion
- pixel px;
- SDL_PixelFormat *fmt = sdl_scrn->format;
- for (j=0; j<h; j++)
- {
- for (k=0; k<sdl_scale; k++)
- {
- for (i=0; i<w; i++)
- {
- px = src[i];
- px = ((PIXR(px)>>fmt->Rloss)<<fmt->Rshift)|
- ((PIXG(px)>>fmt->Gloss)<<fmt->Gshift)|
- ((PIXB(px)>>fmt->Bloss)<<fmt->Bshift);
- dst[i*2]=px;
- dst[i*2+1]=px;
- }
- dst+=sdl_scrn->pitch/PIXELSIZE;
- }
- src+=pitch;
- }
- }
- else
- {
- for (j=0; j<h; j++)
- {
- for (k=0; k<sdl_scale; k++)
- {
- for (i=0; i<w; i++)
- {
- dst[i*2]=src[i];
- dst[i*2+1]=src[i];
- }
- dst+=sdl_scrn->pitch/PIXELSIZE;
- }
- src+=pitch;
- }
- }
- if (SDL_MUSTLOCK(sdl_scrn))
- SDL_UnlockSurface(sdl_scrn);
- SDL_UpdateRect(sdl_scrn,0,0,0,0);
-}
-
-void sdl_blit(int x, int y, int w, int h, pixel *src, int pitch)
-{
-#if defined(OGLR)
- ogl_blit(x, y, w, h, src, pitch, sdl_scale);
-#else
- if (sdl_scale == 2)
- sdl_blit_2(x, y, w, h, src, pitch);
- else
- sdl_blit_1(x, y, w, h, src, pitch);
-#endif
-}
-
-//an easy way to draw a blob
-void drawblob(pixel *vid, int x, int y, unsigned char cr, unsigned char cg, unsigned char cb)
-{
- blendpixel(vid, x+1, y, cr, cg, cb, 112);
- blendpixel(vid, x-1, y, cr, cg, cb, 112);
- blendpixel(vid, x, y+1, cr, cg, cb, 112);
- blendpixel(vid, x, y-1, cr, cg, cb, 112);
-
- blendpixel(vid, x+1, y-1, cr, cg, cb, 64);
- blendpixel(vid, x-1, y-1, cr, cg, cb, 64);
- blendpixel(vid, x+1, y+1, cr, cg, cb, 64);
- blendpixel(vid, x-1, y+1, cr, cg, cb, 64);
-}
-
-//draws walls and elements for menu
-int draw_tool_xy(pixel *vid_buf, int x, int y, int b, unsigned pc)
-{
- int i, j, c;
- pixel gc;
- if (x > XRES-26 || x < 0)
- return 26;
- if ((b&0xFF) == PT_LIFE)
- {
- for (j=1; j<15; j++)
- {
- for (i=1; i<27; i++)
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- }
- }
- c = PIXB(pc) + 3*PIXG(pc) + 2*PIXR(pc);
- if (c<544)
- {
- c = 255;
- }
- else
- {
- c = 0;
- }
- drawtext(vid_buf, x+14-textwidth((char *)gmenu[(b>>8)&0xFF].name)/2, y+4, (char *)gmenu[(b>>8)&0xFF].name, c, c, c, 255);
- }
- else if (b>=UI_WALLSTART)
- {
- int ds = 0;
- if (b-UI_WALLSTART>=0 && b-UI_WALLSTART<UI_WALLCOUNT)
- {
- ds = wtypes[b-UI_WALLSTART].drawstyle;
- gc = wtypes[b-UI_WALLSTART].eglow;
- }
- //x = (2+32*((b-22)/1));
- //y = YRES+2+40;
- if (ds==1)
- {
- for (j=1; j<15; j+=2)
- for (i=1+(1&(j>>1)); i<27; i+=2)
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- }
- else if (ds==2)
- {
- for (j=1; j<15; j+=2)
- for (i=1; i<27; i+=2)
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- }
- else if (ds==3)
- {
- for (j=1; j<15; j++)
- for (i=1; i<27; i++)
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- }
- else if (ds==4)
- {
- for (j=1; j<15; j++)
- for (i=1; i<27; i++)
- if(i%CELL == j%CELL)
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- else if (i%CELL == (j%CELL)+1 || (i%CELL == 0 && j%CELL == CELL-1))
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = gc;
- else
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = PIXPACK(0x202020);
- }
- else
- switch (b)
- {
- case WL_WALLELEC+100:
- for (j=1; j<15; j++)
- {
- for (i=1; i<27; i++)
- {
- if (!(i%2) && !(j%2))
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- }
- else
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = PIXPACK(0x808080);
- }
- }
- }
- break;
- case WL_EWALL+100:
- for (j=1; j<15; j++)
- {
- for (i=1; i<6+j; i++)
- {
- if (!(i&j&1))
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- }
- }
- for (; i<27; i++)
- {
- if (i&j&1)
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- }
- }
- }
- break;
- case WL_STREAM+100:
- for (j=1; j<15; j++)
- {
- for (i=1; i<27; i++)
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = i==1||i==26||j==1||j==14 ? PIXPACK(0xA0A0A0) : PIXPACK(0x000000);
- drawtext(vid_buf, x+4, y+3, "\x8D", 255, 255, 255, 255);
- }
- }
- for (i=9; i<27; i++)
- {
- drawpixel(vid_buf, x+i, y+8+(int)(3.9f*cos(i*0.3f)), 255, 255, 255, 255);
- }
- break;
- case WL_SIGN+100:
- for (j=1; j<15; j++)
- {
- for (i=1; i<27; i++)
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = i==1||i==26||j==1||j==14 ? PIXPACK(0xA0A0A0) : PIXPACK(0x000000);
- }
- }
- drawtext(vid_buf, x+9, y+3, "\xA1", 32, 64, 128, 255);
- drawtext(vid_buf, x+9, y+3, "\xA0", 255, 255, 255, 255);
- break;
- case WL_ERASE+100:
- for (j=1; j<15; j+=2)
- {
- for (i=1+(1&(j>>1)); i<13; i+=2)
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- }
- }
- for (j=1; j<15; j++)
- {
- for (i=14; i<27; i++)
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- }
- }
- break;
- case SPC_AIR:
- case SPC_HEAT:
- case SPC_COOL:
- case SPC_VACUUM:
- case SPC_WIND:
- case SPC_PGRV:
- case SPC_NGRV:
- case SPC_PROP:
- for (j=1; j<15; j++)
- for (i=1; i<27; i++)
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- c = PIXR(pc) + 3*PIXG(pc) + 2*PIXB(pc);
- if (c<544)
- {
- c = 255;
- }
- else
- {
- c = 0;
- }
- if (b==SPC_AIR)
- drawtext(vid_buf, x+14-textwidth("AIR")/2, y+4, "AIR", c, c, c, 255);
- else if (b==SPC_HEAT)
- drawtext(vid_buf, x+14-textwidth("HEAT")/2, y+4, "HEAT", c, c, c, 255);
- else if (b==SPC_COOL)
- drawtext(vid_buf, x+14-textwidth("COOL")/2, y+4, "COOL", c, c, c, 255);
- else if (b==SPC_VACUUM)
- drawtext(vid_buf, x+14-textwidth("VAC")/2, y+4, "VAC", c, c, c, 255);
- else if (b==SPC_WIND)
- drawtext(vid_buf, x+14-textwidth("WIND")/2, y+4, "WIND", c, c, c, 255);
- else if (b==SPC_PGRV)
- drawtext(vid_buf, x+14-textwidth("PGRV")/2, y+4, "PGRV", c, c, c, 255);
- else if (b==SPC_NGRV)
- drawtext(vid_buf, x+14-textwidth("NGRV")/2, y+4, "NGRV", c, c, c, 255);
- else if (b==SPC_PROP)
- drawtext(vid_buf, x+14-textwidth("PROP")/2, y+4, "PROP", c, c, c, 255);
- break;
- default:
- for (j=1; j<15; j++)
- for (i=1; i<27; i++)
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- }
- if (b==WL_ERASE+100)
- {
- for (j=4; j<12; j++)
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+j+6)] = PIXPACK(0xFF0000);
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+j+7)] = PIXPACK(0xFF0000);
- vid_buf[(XRES+BARSIZE)*(y+j)+(x-j+21)] = PIXPACK(0xFF0000);
- vid_buf[(XRES+BARSIZE)*(y+j)+(x-j+22)] = PIXPACK(0xFF0000);
- }
- }
- }
- else
- {
- //x = 2+32*(b/2);
- //y = YRES+2+20*(b%2);
- for (j=1; j<15; j++)
- {
- for (i=1; i<27; i++)
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+i)] = pc;
- }
- }
- if (b==0)
- {
- for (j=4; j<12; j++)
- {
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+j+6)] = PIXPACK(0xFF0000);
- vid_buf[(XRES+BARSIZE)*(y+j)+(x+j+7)] = PIXPACK(0xFF0000);
- vid_buf[(XRES+BARSIZE)*(y+j)+(x-j+21)] = PIXPACK(0xFF0000);
- vid_buf[(XRES+BARSIZE)*(y+j)+(x-j+22)] = PIXPACK(0xFF0000);
- }
- }
- c = PIXB(ptypes[b].pcolors) + 3*PIXG(ptypes[b].pcolors) + 2*PIXR(ptypes[b].pcolors);
- if (c<544)
- {
- c = 255;
- }
- else
- {
- c = 0;
- }
- drawtext(vid_buf, x+14-textwidth((char *)ptypes[b].name)/2, y+4, (char *)ptypes[b].name, c, c, c, 255);
- }
- return 26;
-}
-
-void draw_menu(pixel *vid_buf, int i, int hover)
-{
- if (i==SEC&&SEC!=0)
- drawrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16), 14, 14, 0, 255, 255, 255);
- else
- drawrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16), 14, 14, 255, 255, 255, 255);
- if (hover==i)
- {
- fillrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16), 14, 14, 255, 255, 255, 255);
- drawtext(vid_buf, (XRES+BARSIZE)-13, (i*16)+YRES+MENUSIZE-14-(SC_TOTAL*16), msections[i].icon, 0, 0, 0, 255);
- }
- else
- {
- drawtext(vid_buf, (XRES+BARSIZE)-13, (i*16)+YRES+MENUSIZE-14-(SC_TOTAL*16), msections[i].icon, 255, 255, 255, 255);
- }
-}
-
-void draw_color_menu(pixel *vid_buf, int i, int hover)
-{
- drawrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+YRES+MENUSIZE-16-(DECO_SECTIONS*16), 14, 14, 255, 255, 255, 255);
- if (hover==i)
- {
- fillrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+YRES+MENUSIZE-16-(DECO_SECTIONS*16), 14, 14, 255, 255, 255, 255);
- drawtext(vid_buf, (XRES+BARSIZE)-13, (i*16)+YRES+MENUSIZE-14-(DECO_SECTIONS*16), colorsections[i].icon, 0, 0, 0, 255);
- }
- else
- {
- drawtext(vid_buf, (XRES+BARSIZE)-13, (i*16)+YRES+MENUSIZE-14-(DECO_SECTIONS*16), colorsections[i].icon, 255, 255, 255, 255);
- }
-}
-
-//draws a pixel, identical to blendpixel(), except blendpixel has OpenGL support
-#if defined(WIN32) && !defined(__GNUC__)
-_inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
-#else
-inline void drawpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
-#endif
-{
-#ifdef PIXALPHA
- pixel t;
- if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
- return;
- if (a!=255)
- {
- t = vid[y*(XRES+BARSIZE)+x];
- r = (a*r + (255-a)*PIXR(t)) >> 8;
- g = (a*g + (255-a)*PIXG(t)) >> 8;
- b = (a*b + (255-a)*PIXB(t)) >> 8;
- a = a > PIXA(t) ? a : PIXA(t);
- }
- vid[y*(XRES+BARSIZE)+x] = PIXRGBA(r,g,b,a);
-#else
- pixel t;
- if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
- return;
- if (a!=255)
- {
- t = vid[y*(XRES+BARSIZE)+x];
- r = (a*r + (255-a)*PIXR(t)) >> 8;
- g = (a*g + (255-a)*PIXG(t)) >> 8;
- b = (a*b + (255-a)*PIXB(t)) >> 8;
- }
- vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b);
-#endif
-}
-
-#if defined(WIN32) && !defined(__GNUC__)
-_inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a)
-#else
-inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a)
-#endif
-{
- int i, j, w, bn = 0, ba = 0;
- char *rp = font_data + font_ptrs[c];
- w = *(rp++);
- for (j=0; j<FONT_H; j++)
- for (i=0; i<w; i++)
- {
- if (!bn)
- {
- ba = *(rp++);
- bn = 8;
- }
- drawpixel(vid, x+i, y+j, r, g, b, ((ba&3)*a)/3);
- ba >>= 2;
- bn -= 2;
- }
- return x + w;
-}
-
-int addchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a)
-{
- int i, j, w, bn = 0, ba = 0;
- char *rp = font_data + font_ptrs[c];
- w = *(rp++);
- for (j=0; j<FONT_H; j++)
- for (i=0; i<w; i++)
- {
- if (!bn)
- {
- ba = *(rp++);
- bn = 8;
- }
- {
- addpixel(vid, x+i, y+j, r, g, b, ((ba&3)*a)/3);
- }
- ba >>= 2;
- bn -= 2;
- }
- return x + w;
-}
-
-int drawtext(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a)
-{
- int sx = x;
- for (; *s; s++)
- {
- if (*s == '\n')
- {
- x = sx;
- y += FONT_H+2;
- }
- else if (*s == '\b')
- {
- switch (s[1])
- {
- case 'w':
- r = g = b = 255;
- break;
- case 'g':
- r = g = b = 192;
- break;
- case 'o':
- r = 255;
- g = 216;
- b = 32;
- break;
- case 'r':
- r = 255;
- g = b = 0;
- break;
- case 'l':
- r = 255;
- g = b = 75;
- break;
- case 'b':
- r = g = 0;
- b = 255;
- break;
- case 't':
- b = 255;
- g = 170;
- r = 32;
- break;
- }
- s++;
- }
- else
- x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a);
- }
- return x;
-}
-
-//Draw text with an outline
-int drawtext_outline(pixel *vid, int x, int y, const char *s, int r, int g, int b, int a, int or, int og, int ob, int oa)
-{
- drawtext(vid, x-1, y-1, s, or, og, ob, oa);
- drawtext(vid, x+1, y+1, s, or, og, ob, oa);
-
- drawtext(vid, x-1, y+1, s, or, og, ob, oa);
- drawtext(vid, x+1, y-1, s, or, og, ob, oa);
-
- return drawtext(vid, x, y, s, r, g, b, a);
-}
-int drawtextwrap(pixel *vid, int x, int y, int w, const char *s, int r, int g, int b, int a)
-{
- int sx = x;
- int rh = 12;
- int rw = 0;
- int cw = x;
- int wordlen;
- int charspace;
- while (*s)
- {
- wordlen = strcspn(s," .,!?\n");
- charspace = textwidthx((char *)s, w-(x-cw));
- if (charspace<wordlen && wordlen && w-(x-cw)<w/3)
- {
- x = sx;
- rw = 0;
- y+=FONT_H+2;
- rh+=FONT_H+2;
- }
- for (; *s && --wordlen>=-1; s++)
- {
- if (*s == '\n')
- {
- x = sx;
- rw = 0;
- y += FONT_H+2;
- }
- else if (*s == '\b')
- {
- switch (s[1])
- {
- case 'w':
- r = g = b = 255;
- break;
- case 'g':
- r = g = b = 192;
- break;
- case 'o':
- r = 255;
- g = 216;
- b = 32;
- break;
- case 'r':
- r = 255;
- g = b = 0;
- break;
- case 'l':
- r = 255;
- g = b = 75;
- break;
- case 'b':
- r = g = 0;
- b = 255;
- break;
- case 't':
- b = 255;
- g = 170;
- r = 32;
- break;
- }
- s++;
- }
- else
- {
-
- if (x-cw>=w)
- {
- x = sx;
- rw = 0;
- y+=FONT_H+2;
- rh+=FONT_H+2;
- if (*s==' ')
- continue;
- }
- x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a);
- }
- }
- }
-
- return rh;
-}
-
-//draws a rectange, (x,y) are the top left coords.
-void drawrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a)
-{
- int i;
- for (i=0; i<=w; i++)
- {
- drawpixel(vid, x+i, y, r, g, b, a);
- drawpixel(vid, x+i, y+h, r, g, b, a);
- }
- for (i=1; i<h; i++)
- {
- drawpixel(vid, x, y+i, r, g, b, a);
- drawpixel(vid, x+w, y+i, r, g, b, a);
- }
-}
-
-//draws a rectangle and fills it in as well.
-void fillrect(pixel *vid, int x, int y, int w, int h, int r, int g, int b, int a)
-{
- int i,j;
- for (j=1; j<h; j++)
- for (i=1; i<w; i++)
- drawpixel(vid, x+i, y+j, r, g, b, a);
-}
-
-void clearrect(pixel *vid, int x, int y, int w, int h)
-{
-#ifdef OGLR
- fillrect(vid, x, y, w, h, 0, 0, 0, 255);
-#else
- int i;
- for (i=1; i<h; i++)
- memset(vid+(x+1+(XRES+BARSIZE)*(y+i)), 0, PIXELSIZE*(w-1));
-#endif
-}
-//draws a line of dots, where h is the height. (why is this even here)
-void drawdots(pixel *vid, int x, int y, int h, int r, int g, int b, int a)
-{
- int i;
- for (i=0; i<=h; i+=2)
- drawpixel(vid, x, y+i, r, g, b, a);
-}
-
-int textwidth(char *s)
-{
- int x = 0;
- for (; *s; s++)
- x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
- return x-1;
-}
-
-int drawtextmax(pixel *vid, int x, int y, int w, char *s, int r, int g, int b, int a)
-{
- int i;
- w += x-5;
- for (; *s; s++)
- {
- if (x+font_data[font_ptrs[(int)(*(unsigned char *)s)]]>=w && x+textwidth(s)>=w+5)
- break;
- x = drawchar(vid, x, y, *(unsigned char *)s, r, g, b, a);
- }
- if (*s)
- for (i=0; i<3; i++)
- x = drawchar(vid, x, y, '.', r, g, b, a);
- return x;
-}
-
-int textnwidth(char *s, int n)
-{
- int x = 0;
- for (; *s; s++)
- {
- if (!n)
- break;
- x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
- n--;
- }
- return x-1;
-}
-void textnpos(char *s, int n, int w, int *cx, int *cy)
-{
- int x = 0;
- int y = 0;
- int wordlen, charspace;
- while (*s&&n)
- {
- wordlen = strcspn(s," .,!?\n");
- charspace = textwidthx(s, w-x);
- if (charspace<wordlen && wordlen && w-x<w/3)
- {
- x = 0;
- y += FONT_H+2;
- }
- for (; *s && --wordlen>=-1; s++)
- {
- if (!n) {
- break;
- }
- x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
- if (x>=w)
- {
- x = 0;
- y += FONT_H+2;
- if (*(s+1)==' ')
- x -= font_data[font_ptrs[(int)(' ')]];
- }
- n--;
- }
- }
- *cx = x-1;
- *cy = y;
-}
-
-int textwidthx(char *s, int w)
-{
- int x=0,n=0,cw;
- for (; *s; s++)
- {
- cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
- if (x+(cw/2) >= w)
- break;
- x += cw;
- n++;
- }
- return n;
-}
-int textposxy(char *s, int width, int w, int h)
-{
- int x=0,y=0,n=0,cw, wordlen, charspace;
- while (*s)
- {
- wordlen = strcspn(s," .,!?\n");
- charspace = textwidthx(s, width-x);
- if (charspace<wordlen && wordlen && width-x<width/3)
- {
- x = 0;
- y += FONT_H+2;
- }
- for (; *s && --wordlen>=-1; s++)
- {
- cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
- if ((x+(cw/2) >= w && y+6 >= h)||(y+6 >= h+FONT_H+2))
- return n++;
- x += cw;
- if (x>=width) {
- x = 0;
- y += FONT_H+2;
- if (*(s+1)==' ')
- x -= font_data[font_ptrs[(int)(' ')]];
- }
- n++;
- }
- }
- return n;
-}
-int textwrapheight(char *s, int width)
-{
- int x=0, height=FONT_H+2, cw;
- int wordlen;
- int charspace;
- while (*s)
- {
- wordlen = strcspn(s," .,!?\n");
- charspace = textwidthx(s, width-x);
- if (charspace<wordlen && wordlen && width-x<width/3)
- {
- x = 0;
- height += FONT_H+2;
- }
- for (; *s && --wordlen>=-1; s++)
- {
- if (*s == '\n')
- {
- x = 0;
- height += FONT_H+2;
- }
- else if (*s == '\b')
- {
- s++;
- }
- else
- {
- cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
- if (x+cw>=width)
- {
- x = 0;
- height += FONT_H+2;
- if (*s==' ')
- continue;
- }
- x += cw;
- }
- }
- }
- return height;
-}
-
-//the most used function for drawing a pixel, because it has OpenGL support, which is not fully implemented.
-#if defined(WIN32) && !defined(__GNUC__)
-_inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
-#else
-inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
-#endif
-{
-#ifdef PIXALPHA
- pixel t;
- if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
- return;
- if (a!=255)
- {
- t = vid[y*(XRES+BARSIZE)+x];
- r = (a*r + (255-a)*PIXR(t)) >> 8;
- g = (a*g + (255-a)*PIXG(t)) >> 8;
- b = (a*b + (255-a)*PIXB(t)) >> 8;
- a = a > PIXA(t) ? a : PIXA(t);
- }
- vid[y*(XRES+BARSIZE)+x] = PIXRGBA(r,g,b,a);
-#else
- pixel t;
- if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
- return;
- if (a!=255)
- {
- t = vid[y*(XRES+BARSIZE)+x];
- r = (a*r + (255-a)*PIXR(t)) >> 8;
- g = (a*g + (255-a)*PIXG(t)) >> 8;
- b = (a*b + (255-a)*PIXB(t)) >> 8;
- }
- vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b);
-#endif
-}
-
-void draw_icon(pixel *vid_buf, int x, int y, char ch, int flag)
-{
- char t[2];
- t[0] = ch;
- t[1] = 0;
- if (flag)
- {
- fillrect(vid_buf, x-1, y-1, 17, 17, 255, 255, 255, 255);
- drawtext(vid_buf, x+3, y+2, t, 0, 0, 0, 255);
- }
- else
- {
- drawrect(vid_buf, x, y, 15, 15, 255, 255, 255, 255);
- drawtext(vid_buf, x+3, y+2, t, 255, 255, 255, 255);
- }
-}
-void draw_air(pixel *vid)
-{
-#ifndef OGLR
- int x, y, i, j;
- pixel c;
- for (y=0; y<YRES/CELL; y++)
- for (x=0; x<XRES/CELL; x++)
- {
- if (display_mode & DISPLAY_AIRP)
- {
- if (pv[y][x] > 0.0f)
- c = PIXRGB(clamp_flt(pv[y][x], 0.0f, 8.0f), 0, 0);//positive pressure is red!
- else
- c = PIXRGB(0, 0, clamp_flt(-pv[y][x], 0.0f, 8.0f));//negative pressure is blue!
- }
- else if (display_mode & DISPLAY_AIRV)
- {
- c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red
- clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green
- clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue
- }
- else if ((display_mode & DISPLAY_AIRH))
- {
- if (aheat_enable)
- {
- float ttemp = hv[y][x]+(-MIN_TEMP);
- int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3);
- c = PIXRGB((int)((unsigned char)color_data[caddress]*0.7f), (int)((unsigned char)color_data[caddress+1]*0.7f), (int)((unsigned char)color_data[caddress+2]*0.7f));
- //c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red
- // clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green
- // clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue
- }
- else
- c = PIXRGB(0,0,0);
- }
- else if (display_mode & DISPLAY_AIRC)
- {
- int r;
- int g;
- int b;
- // velocity adds grey
- r = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f);
- g = clamp_flt(fabsf(vx[y][x]), 0.0f, 20.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 24.0f);
- b = clamp_flt(fabsf(vx[y][x]), 0.0f, 24.0f) + clamp_flt(fabsf(vy[y][x]), 0.0f, 20.0f);
- if (pv[y][x] > 0.0f)
- {
- r += clamp_flt(pv[y][x], 0.0f, 16.0f);//pressure adds red!
- if (r>255)
- r=255;
- if (g>255)
- g=255;
- if (b>255)
- b=255;
- c = PIXRGB(r, g, b);
- }
- else
- {
- b += clamp_flt(-pv[y][x], 0.0f, 16.0f);//pressure adds blue!
- if (r>255)
- r=255;
- if (g>255)
- g=255;
- if (b>255)
- b=255;
- c = PIXRGB(r, g, b);
- }
- }
- for (j=0; j<CELL; j++)//draws the colors
- for (i=0; i<CELL; i++)
- vid[(x*CELL+i) + (y*CELL+j)*(XRES+BARSIZE)] = c;
- }
-#else
- GLuint airProg;
- if(display_mode & DISPLAY_AIRC)
- {
- airProg = airProg_Cracker;
- }
- else if(display_mode & DISPLAY_AIRV)
- {
- airProg = airProg_Velocity;
- }
- else if(display_mode & DISPLAY_AIRP)
- {
- airProg = airProg_Pressure;
- }
- else
- {
- return;
- }
-
- glEnable( GL_TEXTURE_2D );
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
-
- glUseProgram(airProg);
-
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, airVX);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_RED, GL_FLOAT, vx);
- glUniform1i(glGetUniformLocation(airProg, "airX"), 0);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, airVY);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_GREEN, GL_FLOAT, vy);
- glUniform1i(glGetUniformLocation(airProg, "airY"), 1);
- glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, airPV);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_BLUE, GL_FLOAT, pv);
- glUniform1i(glGetUniformLocation(airProg, "airP"), 2);
- glActiveTexture(GL_TEXTURE0);
-
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glBegin(GL_QUADS);
- glTexCoord2d(1, 1);
- glVertex3f(XRES*sdl_scale, YRES*sdl_scale, 1.0);
- glTexCoord2d(0, 1);
- glVertex3f(0, YRES*sdl_scale, 1.0);
- glTexCoord2d(0, 0);
- glVertex3f(0, 0, 1.0);
- glTexCoord2d(1, 0);
- glVertex3f(XRES*sdl_scale, 0, 1.0);
- glEnd();
-
- glUseProgram(0);
- glBindTexture(GL_TEXTURE_2D, 0);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
- glDisable( GL_TEXTURE_2D );
-#endif
-}
-
-void draw_grav_zones(pixel * vid)
-{
- int x, y, i, j;
- for (y=0; y<YRES/CELL; y++)
- {
- for (x=0; x<XRES/CELL; x++)
- {
- if(gravmask[y*(XRES/CELL)+x])
- {
- for (j=0; j<CELL; j++)//draws the colors
- for (i=0; i<CELL; i++)
- if(i == j)
- drawpixel(vid, x*CELL+i, y*CELL+j, 255, 200, 0, 120);
- else
- drawpixel(vid, x*CELL+i, y*CELL+j, 32, 32, 32, 120);
- }
- }
- }
-}
-
-void draw_grav(pixel *vid)
-{
- int x, y, i, ca;
- float nx, ny, dist;
-
- for (y=0; y<YRES/CELL; y++)
- {
- for (x=0; x<XRES/CELL; x++)
- {
- ca = y*(XRES/CELL)+x;
- if(fabsf(gravx[ca]) <= 0.001f && fabsf(gravy[ca]) <= 0.001f)
- continue;
- nx = x*CELL;
- ny = y*CELL;
- dist = fabsf(gravy[ca])+fabsf(gravx[ca]);
- for(i = 0; i < 4; i++)
- {
- nx -= gravx[ca]*0.5f;
- ny -= gravy[ca]*0.5f;
- addpixel(vid, (int)(nx+0.5f), (int)(ny+0.5f), 255, 255, 255, (int)(dist*20.0f));
- }
- }
- }
-}
-
-void draw_line(pixel *vid, int x1, int y1, int x2, int y2, int r, int g, int b, int a) //Draws a line
-{
- int dx, dy, i, sx, sy, check, e, x, y;
-
- dx = abs(x1-x2);
- dy = abs(y1-y2);
- sx = isign(x2-x1);
- sy = isign(y2-y1);
- x = x1;
- y = y1;
- check = 0;
-
- if (dy>dx)
- {
- dx = dx+dy;
- dy = dx-dy;
- dx = dx-dy;
- check = 1;
- }
-
- e = (dy<<2)-dx;
- for (i=0; i<=dx; i++)
- {
- if (x>=0 && y>=0 && x<a && y<YRES+MENUSIZE)
- vid[x+y*a] =PIXRGB(r, g, b);
- if (e>=0)
- {
- if (check==1)
- x = x+sx;
- else
- y = y+sy;
- e = e-(dx<<2);
- }
- if (check==1)
- y = y+sy;
- else
- x = x+sx;
- e = e+(dy<<2);
- }
-}
-
-//adds color to a pixel, does not overwrite.
-void addpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
-{
- pixel t;
- if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
- return;
- t = vid[y*(XRES+BARSIZE)+x];
- r = (a*r + 255*PIXR(t)) >> 8;
- g = (a*g + 255*PIXG(t)) >> 8;
- b = (a*b + 255*PIXB(t)) >> 8;
- if (r>255)
- r = 255;
- if (g>255)
- g = 255;
- if (b>255)
- b = 255;
- vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b);
-}
-
-//draws one of two colors, so that it is always clearly visible
-void xor_pixel(int x, int y, pixel *vid)
-{
- int c;
- if (x<0 || y<0 || x>=XRES || y>=YRES)
- return;
- c = vid[y*(XRES+BARSIZE)+x];
- c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c);
- if (c<512)
- vid[y*(XRES+BARSIZE)+x] = PIXPACK(0xC0C0C0);
- else
- vid[y*(XRES+BARSIZE)+x] = PIXPACK(0x404040);
-}
-
-//same as xor_pixel, but draws a line of it
-void xor_line(int x1, int y1, int x2, int y2, pixel *vid)
-{
- int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
- float e, de;
- if (cp)
- {
- y = x1;
- x1 = y1;
- y1 = y;
- y = x2;
- x2 = y2;
- y2 = y;
- }
- if (x1 > x2)
- {
- y = x1;
- x1 = x2;
- x2 = y;
- y = y1;
- y1 = y2;
- y2 = y;
- }
- dx = x2 - x1;
- dy = abs(y2 - y1);
- e = 0.0f;
- if (dx)
- de = dy/(float)dx;
- else
- de = 0.0f;
- y = y1;
- sy = (y1<y2) ? 1 : -1;
- for (x=x1; x<=x2; x++)
- {
- if (cp)
- xor_pixel(y, x, vid);
- else
- xor_pixel(x, y, vid);
- e += de;
- if (e >= 0.5f)
- {
- y += sy;
- e -= 1.0f;
- }
- }
-}
-
-//same as blend_pixel, but draws a line of it
-void blend_line(pixel *vid, int x1, int y1, int x2, int y2, int r, int g, int b, int a)
-{
- int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
- float e, de;
- if (cp)
- {
- y = x1;
- x1 = y1;
- y1 = y;
- y = x2;
- x2 = y2;
- y2 = y;
- }
- if (x1 > x2)
- {
- y = x1;
- x1 = x2;
- x2 = y;
- y = y1;
- y1 = y2;
- y2 = y;
- }
- dx = x2 - x1;
- dy = abs(y2 - y1);
- e = 0.0f;
- if (dx)
- de = dy/(float)dx;
- else
- de = 0.0f;
- y = y1;
- sy = (y1<y2) ? 1 : -1;
- for (x=x1; x<=x2; x++)
- {
- if (cp)
- blendpixel(vid, y, x, r, g, b, a);
- else
- blendpixel(vid, x, y, r, g, b, a);
- e += de;
- if (e >= 0.5f)
- {
- y += sy;
- e -= 1.0f;
- }
- }
-}
-
-//same as xor_pixel, but draws a rectangle
-void xor_rect(pixel *vid, int x, int y, int w, int h)
-{
- int i;
- for (i=0; i<w; i+=2)
- {
- xor_pixel(x+i, y, vid);
- }
- if (h != 1)
- {
- if (h%2 == 1) i = 2;
- else i = 1;
- for (; i<w; i+=2)
- {
- xor_pixel(x+i, y+h-1, vid);
- }
- }
-
- for (i=2; i<h; i+=2)
- {
- xor_pixel(x, y+i, vid);
- }
- if (w != 1)
- {
- if (w%2 == 1) i = 2;
- else i = 1;
- for (; i<h-1; i+=2)
- {
- xor_pixel(x+w-1, y+i, vid);
- }
- }
-}
-
-void draw_other(pixel *vid) // EMP effect
-{
- int i, j;
- if (emp_decor>0 && !sys_pause) emp_decor-=emp_decor/25+2;
- if (emp_decor>40) emp_decor=40;
- if (emp_decor<0) emp_decor = 0;
- if (!(render_mode & EFFECT)) // not in nothing mode
- return;
- if (emp_decor>0)
- {
-#ifdef OGLR
- float femp_decor = ((float)emp_decor)/255.0f;
- /*int r=emp_decor*2.5, g=100+emp_decor*1.5, b=255;
- int a=(1.0*emp_decor/110)*255;
- if (r>255) r=255;
- if (g>255) g=255;
- if (b>255) g=255;
- if (a>255) a=255;*/
- glBegin(GL_QUADS);
- glColor4f(femp_decor*2.5f, 0.4f+femp_decor*1.5f, 1.0f+femp_decor*1.5f, femp_decor/0.44f);
- glVertex2f(0, MENUSIZE);
- glVertex2f(XRES, MENUSIZE);
- glVertex2f(XRES, YRES+MENUSIZE);
- glVertex2f(0, YRES+MENUSIZE);
- glEnd();
-#else
- int r=emp_decor*2.5, g=100+emp_decor*1.5, b=255;
- int a=(1.0*emp_decor/110)*255;
- if (r>255) r=255;
- if (g>255) g=255;
- if (b>255) g=255;
- if (a>255) a=255;
- for (j=0; j<YRES; j++)
- for (i=0; i<XRES; i++)
- {
- drawpixel(vid, i, j, r, g, b, a);
- }
-#endif
- }
-}
-
-void prepare_graphicscache()
-{
- graphicscache = malloc(sizeof(gcache_item)*PT_NUM);
- memset(graphicscache, 0, sizeof(gcache_item)*PT_NUM);
-}
-//New function for drawing particles
-#ifdef OGLR
-GLuint fireV[(YRES*XRES)*2];
-GLfloat fireC[(YRES*XRES)*4];
-GLuint smokeV[(YRES*XRES)*2];
-GLfloat smokeC[(YRES*XRES)*4];
-GLuint blobV[(YRES*XRES)*2];
-GLfloat blobC[(YRES*XRES)*4];
-GLuint blurV[(YRES*XRES)*2];
-GLfloat blurC[(YRES*XRES)*4];
-GLuint glowV[(YRES*XRES)*2];
-GLfloat glowC[(YRES*XRES)*4];
-GLuint flatV[(YRES*XRES)*2];
-GLfloat flatC[(YRES*XRES)*4];
-GLuint addV[(YRES*XRES)*2];
-GLfloat addC[(YRES*XRES)*4];
-GLfloat lineV[(((YRES*XRES)*2)*6)];
-GLfloat lineC[(((YRES*XRES)*2)*6)];
-GLfloat blurLineV[(((YRES*XRES)*2))];
-GLfloat blurLineC[(((YRES*XRES)*2)*4)];
-GLfloat ablurLineV[(((YRES*XRES)*2))];
-GLfloat ablurLineC[(((YRES*XRES)*2)*4)];
-#endif
-void render_parts(pixel *vid)
-{
- int deca, decr, decg, decb, cola, colr, colg, colb, firea, firer, fireg, fireb, pixel_mode, q, i, t, nx, ny, x, y, caddress;
- int orbd[4] = {0, 0, 0, 0}, orbl[4] = {0, 0, 0, 0};
- float gradv, flicker, fnx, fny, flx, fly;
-#ifdef OGLR
- int cfireV = 0, cfireC = 0, cfire = 0;
- int csmokeV = 0, csmokeC = 0, csmoke = 0;
- int cblobV = 0, cblobC = 0, cblob = 0;
- int cblurV = 0, cblurC = 0, cblur = 0;
- int cglowV = 0, cglowC = 0, cglow = 0;
- int cflatV = 0, cflatC = 0, cflat = 0;
- int caddV = 0, caddC = 0, cadd = 0;
- int clineV = 0, clineC = 0, cline = 0;
- int cblurLineV = 0, cblurLineC = 0, cblurLine = 0;
- int cablurLineV = 0, cablurLineC = 0, cablurLine = 0;
- GLuint origBlendSrc, origBlendDst;
-
- glGetIntegerv(GL_BLEND_SRC, &origBlendSrc);
- glGetIntegerv(GL_BLEND_DST, &origBlendDst);
- //Render to the particle FBO
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
-#else
- if (GRID_MODE)//draws the grid
- {
- for (ny=0; ny<YRES; ny++)
- for (nx=0; nx<XRES; nx++)
- {
- if (ny%(4*GRID_MODE)==0)
- blendpixel(vid, nx, ny, 100, 100, 100, 80);
- if (nx%(4*GRID_MODE)==0)
- blendpixel(vid, nx, ny, 100, 100, 100, 80);
- }
- }
-#endif
- for(i = 0; i<=parts_lastActiveIndex; i++) {
- if (parts[i].type) {
- t = parts[i].type;
-
- nx = (int)(parts[i].x+0.5f);
- ny = (int)(parts[i].y+0.5f);
- fnx = parts[i].x;
- fny = parts[i].y;
-#ifdef OGLR
- flx = parts[i].lastX;
- fly = parts[i].lastY;
-#endif
-
-
- if(photons[ny][nx]&0xFF && !(ptypes[t].properties & TYPE_ENERGY) && t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH)
- continue;
-
- //Defaults
- pixel_mode = 0 | PMODE_FLAT;
- cola = 255;
- colr = PIXR(ptypes[t].pcolors);
- colg = PIXG(ptypes[t].pcolors);
- colb = PIXB(ptypes[t].pcolors);
- firea = 0;
-
- deca = (parts[i].dcolour>>24)&0xFF;
- decr = (parts[i].dcolour>>16)&0xFF;
- decg = (parts[i].dcolour>>8)&0xFF;
- decb = (parts[i].dcolour)&0xFF;
-
- /*if(display_mode == RENDER_NONE)
- {
- if(decorations_enable)
- {
- colr = (deca*decr + (255-deca)*colr) >> 8;
- colg = (deca*decg + (255-deca)*colg) >> 8;
- colb = (deca*decb + (255-deca)*colb) >> 8;
- }
-#ifdef OGLR
- flatV[cflatV++] = nx;
- flatV[cflatV++] = ny;
- flatC[cflatC++] = ((float)colr)/255.0f;
- flatC[cflatC++] = ((float)colg)/255.0f;
- flatC[cflatC++] = ((float)colb)/255.0f;
- flatC[cflatC++] = 1.0f;
- cflat++;
-#else
- vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(colr,colg,colb);
-#endif
- }
- else*/
- {
- if (graphicscache[t].isready)
- {
- pixel_mode = graphicscache[t].pixel_mode;
- cola = graphicscache[t].cola;
- colr = graphicscache[t].colr;
- colg = graphicscache[t].colg;
- colb = graphicscache[t].colb;
- firea = graphicscache[t].firea;
- firer = graphicscache[t].firer;
- fireg = graphicscache[t].fireg;
- fireb = graphicscache[t].fireb;
- }
- else if(!(colour_mode & COLOUR_BASC)) //Don't get special effects for BASIC colour mode
- {
-#ifdef LUACONSOLE
- if (lua_gr_func[t])
- {
- if (luacon_graphics_update(t,i, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb))
- {
- graphicscache[t].isready = 1;
- graphicscache[t].pixel_mode = pixel_mode;
- graphicscache[t].cola = cola;
- graphicscache[t].colr = colr;
- graphicscache[t].colg = colg;
- graphicscache[t].colb = colb;
- graphicscache[t].firea = firea;
- graphicscache[t].firer = firer;
- graphicscache[t].fireg = fireg;
- graphicscache[t].fireb = fireb;
- }
- }
- else if (ptypes[t].graphics_func)
- {
-#else
- if (ptypes[t].graphics_func)
- {
-#endif
- if ((*(ptypes[t].graphics_func))(&(parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb)) //That's a lot of args, a struct might be better
- {
- graphicscache[t].isready = 1;
- graphicscache[t].pixel_mode = pixel_mode;
- graphicscache[t].cola = cola;
- graphicscache[t].colr = colr;
- graphicscache[t].colg = colg;
- graphicscache[t].colb = colb;
- graphicscache[t].firea = firea;
- graphicscache[t].firer = firer;
- graphicscache[t].fireg = fireg;
- graphicscache[t].fireb = fireb;
- }
- }
- else
- {
- if(graphics_DEFAULT(&(parts[i]), nx, ny, &pixel_mode, &cola, &colr, &colg, &colb, &firea, &firer, &fireg, &fireb))
- {
- graphicscache[t].isready = 1;
- graphicscache[t].pixel_mode = pixel_mode;
- graphicscache[t].cola = cola;
- graphicscache[t].colr = colr;
- graphicscache[t].colg = colg;
- graphicscache[t].colb = colb;
- graphicscache[t].firea = firea;
- graphicscache[t].firer = firer;
- graphicscache[t].fireg = fireg;
- graphicscache[t].fireb = fireb;
- }
- }
- }
- if(ptypes[t].properties & PROP_HOT_GLOW && parts[i].temp>(ptransitions[t].thv-800.0f))
- {
- gradv = 3.1415/(2*ptransitions[t].thv-(ptransitions[t].thv-800.0f));
- caddress = (parts[i].temp>ptransitions[t].thv)?ptransitions[t].thv-(ptransitions[t].thv-800.0f):parts[i].temp-(ptransitions[t].thv-800.0f);
- colr += sin(gradv*caddress) * 226;;
- colg += sin(gradv*caddress*4.55 +3.14) * 34;
- colb += sin(gradv*caddress*2.22 +3.14) * 64;
- }
-
- if(pixel_mode & FIRE_ADD && !(render_mode & FIRE_ADD))
- pixel_mode |= PMODE_GLOW;
- if(pixel_mode & FIRE_BLEND && !(render_mode & FIRE_BLEND))
- pixel_mode |= PMODE_BLUR;
- if(pixel_mode & PMODE_BLUR && !(render_mode & PMODE_BLUR))
- pixel_mode |= PMODE_FLAT;
- if(pixel_mode & PMODE_GLOW && !(render_mode & PMODE_GLOW))
- pixel_mode |= PMODE_BLEND;
- if (render_mode & PMODE_BLOB)
- pixel_mode |= PMODE_BLOB;
-
- pixel_mode &= render_mode;
-
- //Alter colour based on display mode
- if(colour_mode & COLOUR_HEAT)
- {
- caddress = restrict_flt((int)( restrict_flt((float)(parts[i].temp+(-MIN_TEMP)), 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3);
- firea = 255;
- firer = colr = (unsigned char)color_data[caddress];
- fireg = colg = (unsigned char)color_data[caddress+1];
- fireb = colb = (unsigned char)color_data[caddress+2];
- cola = 255;
- if(pixel_mode & (FIREMODE | PMODE_GLOW)) pixel_mode = (pixel_mode & ~(FIREMODE|PMODE_GLOW)) | PMODE_BLUR;
- }
- else if(colour_mode & COLOUR_LIFE)
- {
- gradv = 0.4f;
- if (!(parts[i].life<5))
- q = sqrt(parts[i].life);
- else
- q = parts[i].life;
- colr = colg = colb = sin(gradv*q) * 100 + 128;
- cola = 255;
- if(pixel_mode & (FIREMODE | PMODE_GLOW)) pixel_mode = (pixel_mode & ~(FIREMODE|PMODE_GLOW)) | PMODE_BLUR;
- }
- else if (colour_mode & COLOUR_BASC)
- {
- colr = PIXR(ptypes[t].pcolors);
- colg = PIXG(ptypes[t].pcolors);
- colb = PIXB(ptypes[t].pcolors);
- pixel_mode = PMODE_FLAT;
- }
-
- //Apply decoration colour
- if(!(colour_mode & ~COLOUR_GRAD))
- {
- if(!(pixel_mode & NO_DECO) && decorations_enable)
- {
- colr = (deca*decr + (255-deca)*colr) >> 8;
- colg = (deca*decg + (255-deca)*colg) >> 8;
- colb = (deca*decb + (255-deca)*colb) >> 8;
- }
-
- if(pixel_mode & DECO_FIRE && decorations_enable)
- {
- firer = (deca*decr + (255-deca)*firer) >> 8;
- fireg = (deca*decg + (255-deca)*fireg) >> 8;
- fireb = (deca*decb + (255-deca)*fireb) >> 8;
- }
- }
-
- if (colour_mode & COLOUR_GRAD)
- {
- float frequency = 0.05;
- int q = parts[i].temp-40;
- colr = sin(frequency*q) * 16 + colr;
- colg = sin(frequency*q) * 16 + colg;
- colb = sin(frequency*q) * 16 + colb;
- if(pixel_mode & (FIREMODE | PMODE_GLOW)) pixel_mode = (pixel_mode & ~(FIREMODE|PMODE_GLOW)) | PMODE_BLUR;
- }
-
- #ifndef OGLR
- //All colours are now set, check ranges
- if(colr>255) colr = 255;
- else if(colr<0) colr = 0;
- if(colg>255) colg = 255;
- else if(colg<0) colg = 0;
- if(colb>255) colb = 255;
- else if(colb<0) colb = 0;
- if(cola>255) cola = 255;
- else if(cola<0) cola = 0;
-
- if(firer>255) firer = 255;
- else if(firer<0) firer = 0;
- if(fireg>255) fireg = 255;
- else if(fireg<0) fireg = 0;
- if(fireb>255) fireb = 255;
- else if(fireb<0) fireb = 0;
- if(firea>255) firea = 255;
- else if(firea<0) firea = 0;
- #endif
-
- //Pixel rendering
- if (t==PT_SOAP)
- {
- if ((parts[i].ctype&7) == 7)
- draw_line(vid, nx, ny, (int)(parts[parts[i].tmp].x+0.5f), (int)(parts[parts[i].tmp].y+0.5f), colr, colg, colb, XRES+BARSIZE);
- }
- if(pixel_mode & PSPEC_STICKMAN)
- {
- char buff[20]; //Buffer for HP
- int s;
- int legr, legg, legb;
- playerst *cplayer;
- if(t==PT_STKM)
- cplayer = &player;
- else if(t==PT_STKM2)
- cplayer = &player2;
- else if(t==PT_FIGH)
- cplayer = &fighters[(unsigned char)parts[i].tmp];
- else
- continue;
-
- if (mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mouse is in the head
- {
- sprintf(buff, "%3d", parts[i].life); //Show HP
- drawtext(vid, mousex-8-2*(parts[i].life<100)-2*(parts[i].life<10), mousey-12, buff, 255, 255, 255, 255);
- }
-
- if (colour_mode!=COLOUR_HEAT)
- {
- if (cplayer->elem<PT_NUM)
- {
- colr = PIXR(ptypes[cplayer->elem].pcolors);
- colg = PIXG(ptypes[cplayer->elem].pcolors);
- colb = PIXB(ptypes[cplayer->elem].pcolors);
- }
- else
- {
- colr = 0x80;
- colg = 0x80;
- colb = 0xFF;
- }
- }
-#ifdef OGLR
- glColor4f(((float)colr)/255.0f, ((float)colg)/255.0f, ((float)colb)/255.0f, 1.0f);
- glBegin(GL_LINE_STRIP);
- if(t==PT_FIGH)
- {
- glVertex2f(fnx, fny+2);
- glVertex2f(fnx+2, fny);
- glVertex2f(fnx, fny-2);
- glVertex2f(fnx-2, fny);
- glVertex2f(fnx, fny+2);
- }
- else
- {
- glVertex2f(fnx-2, fny-2);
- glVertex2f(fnx+2, fny-2);
- glVertex2f(fnx+2, fny+2);
- glVertex2f(fnx-2, fny+2);
- glVertex2f(fnx-2, fny-2);
- }
- glEnd();
- glBegin(GL_LINES);
-
- if (colour_mode!=COLOUR_HEAT)
- {
- if (t==PT_STKM2)
- glColor4f(100.0f/255.0f, 100.0f/255.0f, 1.0f, 1.0f);
- else
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- }
-
- glVertex2f(nx, ny+3);
- glVertex2f(cplayer->legs[0], cplayer->legs[1]);
-
- glVertex2f(cplayer->legs[0], cplayer->legs[1]);
- glVertex2f(cplayer->legs[4], cplayer->legs[5]);
-
- glVertex2f(nx, ny+3);
- glVertex2f(cplayer->legs[8], cplayer->legs[9]);
-
- glVertex2f(cplayer->legs[8], cplayer->legs[9]);
- glVertex2f(cplayer->legs[12], cplayer->legs[13]);
- glEnd();
-#else
- s = XRES+BARSIZE;
-
- if (t==PT_STKM2)
- {
- legr = 100;
- legg = 100;
- legb = 255;
- }
- else
- {
- legr = 255;
- legg = 255;
- legb = 255;
- }
-
- if (colour_mode==COLOUR_HEAT)
- {
- legr = colr;
- legg = colg;
- legb = colb;
- }
-
- //head
- if(t==PT_FIGH)
- {
- draw_line(vid , nx, ny+2, nx+2, ny, colr, colg, colb, s);
- draw_line(vid , nx+2, ny, nx, ny-2, colr, colg, colb, s);
- draw_line(vid , nx, ny-2, nx-2, ny, colr, colg, colb, s);
- draw_line(vid , nx-2, ny, nx, ny+2, colr, colg, colb, s);
- }
- else
- {
- draw_line(vid , nx-2, ny+2, nx+2, ny+2, colr, colg, colb, s);
- draw_line(vid , nx-2, ny-2, nx+2, ny-2, colr, colg, colb, s);
- draw_line(vid , nx-2, ny-2, nx-2, ny+2, colr, colg, colb, s);
- draw_line(vid , nx+2, ny-2, nx+2, ny+2, colr, colg, colb, s);
- }
- //legs
- draw_line(vid , nx, ny+3, cplayer->legs[0], cplayer->legs[1], legr, legg, legb, s);
- draw_line(vid , cplayer->legs[0], cplayer->legs[1], cplayer->legs[4], cplayer->legs[5], legr, legg, legb, s);
- draw_line(vid , nx, ny+3, cplayer->legs[8], cplayer->legs[9], legr, legg, legb, s);
- draw_line(vid , cplayer->legs[8], cplayer->legs[9], cplayer->legs[12], cplayer->legs[13], legr, legg, legb, s);
-#endif
- }
-#ifdef OGLR
- if((display_mode & DISPLAY_EFFE) && (fabs(fnx-flx)>1.5f || fabs(fny-fly)>1.5f))
- {
- if(pixel_mode & PMODE_FLAT)
- {
- blurLineV[cblurLineV++] = nx;
- blurLineV[cblurLineV++] = ny;
- blurLineC[cblurLineC++] = ((float)colr)/255.0f;
- blurLineC[cblurLineC++] = ((float)colg)/255.0f;
- blurLineC[cblurLineC++] = ((float)colb)/255.0f;
- blurLineC[cblurLineC++] = 1.0f;
- cblurLine++;
-
- blurLineV[cblurLineV++] = flx;
- blurLineV[cblurLineV++] = fly;
- blurLineC[cblurLineC++] = ((float)colr)/255.0f;
- blurLineC[cblurLineC++] = ((float)colg)/255.0f;
- blurLineC[cblurLineC++] = ((float)colb)/255.0f;
- blurLineC[cblurLineC++] = 0.0f;
- cblurLine++;
- }
- else if(pixel_mode & PMODE_BLEND)
- {
- blurLineV[cblurLineV++] = nx;
- blurLineV[cblurLineV++] = ny;
- blurLineC[cblurLineC++] = ((float)colr)/255.0f;
- blurLineC[cblurLineC++] = ((float)colg)/255.0f;
- blurLineC[cblurLineC++] = ((float)colb)/255.0f;
- blurLineC[cblurLineC++] = ((float)cola)/255.0f;
- cblurLine++;
-
- blurLineV[cblurLineV++] = flx;
- blurLineV[cblurLineV++] = fly;
- blurLineC[cblurLineC++] = ((float)colr)/255.0f;
- blurLineC[cblurLineC++] = ((float)colg)/255.0f;
- blurLineC[cblurLineC++] = ((float)colb)/255.0f;
- blurLineC[cblurLineC++] = 0.0f;
- cblurLine++;
- }
- else if(pixel_mode & PMODE_ADD)
- {
- ablurLineV[cablurLineV++] = nx;
- ablurLineV[cablurLineV++] = ny;
- ablurLineC[cablurLineC++] = ((float)colr)/255.0f;
- ablurLineC[cablurLineC++] = ((float)colg)/255.0f;
- ablurLineC[cablurLineC++] = ((float)colb)/255.0f;
- ablurLineC[cablurLineC++] = ((float)cola)/255.0f;
- cablurLine++;
-
- ablurLineV[cablurLineV++] = flx;
- ablurLineV[cablurLineV++] = fly;
- ablurLineC[cablurLineC++] = ((float)colr)/255.0f;
- ablurLineC[cablurLineC++] = ((float)colg)/255.0f;
- ablurLineC[cablurLineC++] = ((float)colb)/255.0f;
- ablurLineC[cablurLineC++] = 0.0f;
- cablurLine++;
- }
- }
-#endif
- if(pixel_mode & PMODE_FLAT)
- {
-#ifdef OGLR
- flatV[cflatV++] = nx;
- flatV[cflatV++] = ny;
- flatC[cflatC++] = ((float)colr)/255.0f;
- flatC[cflatC++] = ((float)colg)/255.0f;
- flatC[cflatC++] = ((float)colb)/255.0f;
- flatC[cflatC++] = 1.0f;
- cflat++;
-#else
- vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(colr,colg,colb);
-#endif
- }
- if(pixel_mode & PMODE_BLEND)
- {
-#ifdef OGLR
- flatV[cflatV++] = nx;
- flatV[cflatV++] = ny;
- flatC[cflatC++] = ((float)colr)/255.0f;
- flatC[cflatC++] = ((float)colg)/255.0f;
- flatC[cflatC++] = ((float)colb)/255.0f;
- flatC[cflatC++] = ((float)cola)/255.0f;
- cflat++;
-#else
- blendpixel(vid, nx, ny, colr, colg, colb, cola);
-#endif
- }
- if(pixel_mode & PMODE_ADD)
- {
-#ifdef OGLR
- addV[caddV++] = nx;
- addV[caddV++] = ny;
- addC[caddC++] = ((float)colr)/255.0f;
- addC[caddC++] = ((float)colg)/255.0f;
- addC[caddC++] = ((float)colb)/255.0f;
- addC[caddC++] = ((float)cola)/255.0f;
- cadd++;
-#else
- addpixel(vid, nx, ny, colr, colg, colb, cola);
-#endif
- }
- if(pixel_mode & PMODE_BLOB)
- {
-#ifdef OGLR
- blobV[cblobV++] = nx;
- blobV[cblobV++] = ny;
- blobC[cblobC++] = ((float)colr)/255.0f;
- blobC[cblobC++] = ((float)colg)/255.0f;
- blobC[cblobC++] = ((float)colb)/255.0f;
- blobC[cblobC++] = 1.0f;
- cblob++;
-#else
- vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(colr,colg,colb);
-
- blendpixel(vid, nx+1, ny, colr, colg, colb, 223);
- blendpixel(vid, nx-1, ny, colr, colg, colb, 223);
- blendpixel(vid, nx, ny+1, colr, colg, colb, 223);
- blendpixel(vid, nx, ny-1, colr, colg, colb, 223);
-
- blendpixel(vid, nx+1, ny-1, colr, colg, colb, 112);
- blendpixel(vid, nx-1, ny-1, colr, colg, colb, 112);
- blendpixel(vid, nx+1, ny+1, colr, colg, colb, 112);
- blendpixel(vid, nx-1, ny+1, colr, colg, colb, 112);
-#endif
- }
- if(pixel_mode & PMODE_GLOW)
- {
- int cola1 = (5*cola)/255;
-#ifdef OGLR
- glowV[cglowV++] = nx;
- glowV[cglowV++] = ny;
- glowC[cglowC++] = ((float)colr)/255.0f;
- glowC[cglowC++] = ((float)colg)/255.0f;
- glowC[cglowC++] = ((float)colb)/255.0f;
- glowC[cglowC++] = 1.0f;
- cglow++;
-#else
- addpixel(vid, nx, ny, colr, colg, colb, (192*cola)/255);
- addpixel(vid, nx+1, ny, colr, colg, colb, (96*cola)/255);
- addpixel(vid, nx-1, ny, colr, colg, colb, (96*cola)/255);
- addpixel(vid, nx, ny+1, colr, colg, colb, (96*cola)/255);
- addpixel(vid, nx, ny-1, colr, colg, colb, (96*cola)/255);
-
- for (x = 1; x < 6; x++) {
- addpixel(vid, nx, ny-x, colr, colg, colb, cola1);
- addpixel(vid, nx, ny+x, colr, colg, colb, cola1);
- addpixel(vid, nx-x, ny, colr, colg, colb, cola1);
- addpixel(vid, nx+x, ny, colr, colg, colb, cola1);
- for (y = 1; y < 6; y++) {
- if(x + y > 7)
- continue;
- addpixel(vid, nx+x, ny-y, colr, colg, colb, cola1);
- addpixel(vid, nx-x, ny+y, colr, colg, colb, cola1);
- addpixel(vid, nx+x, ny+y, colr, colg, colb, cola1);
- addpixel(vid, nx-x, ny-y, colr, colg, colb, cola1);
- }
- }
-#endif
- }
- if(pixel_mode & PMODE_BLUR)
- {
-#ifdef OGLR
- blurV[cblurV++] = nx;
- blurV[cblurV++] = ny;
- blurC[cblurC++] = ((float)colr)/255.0f;
- blurC[cblurC++] = ((float)colg)/255.0f;
- blurC[cblurC++] = ((float)colb)/255.0f;
- blurC[cblurC++] = 1.0f;
- cblur++;
-#else
- for (x=-3; x<4; x++)
- {
- for (y=-3; y<4; y++)
- {
- if (abs(x)+abs(y) <2 && !(abs(x)==2||abs(y)==2))
- blendpixel(vid, x+nx, y+ny, colr, colg, colb, 30);
- if (abs(x)+abs(y) <=3 && abs(x)+abs(y))
- blendpixel(vid, x+nx, y+ny, colr, colg, colb, 20);
- if (abs(x)+abs(y) == 2)
- blendpixel(vid, x+nx, y+ny, colr, colg, colb, 10);
- }
- }
-#endif
- }
- if(pixel_mode & PMODE_SPARK)
- {
- flicker = rand()%20;
-#ifdef OGLR
- //Oh god, this is awful
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx-5;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 1.0f - ((float)flicker)/30;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx+5;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny-5;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 1.0f - ((float)flicker)/30;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny+5;
- cline++;
-#else
- gradv = 4*parts[i].life + flicker;
- for (x = 0; gradv>0.5; x++) {
- addpixel(vid, nx+x, ny, colr, colg, colb, gradv);
- addpixel(vid, nx-x, ny, colr, colg, colb, gradv);
-
- addpixel(vid, nx, ny+x, colr, colg, colb, gradv);
- addpixel(vid, nx, ny-x, colr, colg, colb, gradv);
- gradv = gradv/1.5f;
- }
-#endif
- }
- if(pixel_mode & PMODE_FLARE)
- {
- flicker = rand()%20;
-#ifdef OGLR
- //Oh god, this is awful
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx-10;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 1.0f - ((float)flicker)/40;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx+10;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny-10;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 1.0f - ((float)flicker)/30;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny+10;
- cline++;
-#else
- gradv = flicker + fabs(parts[i].vx)*17 + fabs(parts[i].vy)*17;
- blendpixel(vid, nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) );
- blendpixel(vid, nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) );
- blendpixel(vid, nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) );
- blendpixel(vid, nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) );
- blendpixel(vid, nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) );
- if (gradv>255) gradv=255;
- blendpixel(vid, nx+1, ny-1, colr, colg, colb, gradv);
- blendpixel(vid, nx-1, ny-1, colr, colg, colb, gradv);
- blendpixel(vid, nx+1, ny+1, colr, colg, colb, gradv);
- blendpixel(vid, nx-1, ny+1, colr, colg, colb, gradv);
- for (x = 1; gradv>0.5; x++) {
- addpixel(vid, nx+x, ny, colr, colg, colb, gradv);
- addpixel(vid, nx-x, ny, colr, colg, colb, gradv);
- addpixel(vid, nx, ny+x, colr, colg, colb, gradv);
- addpixel(vid, nx, ny-x, colr, colg, colb, gradv);
- gradv = gradv/1.2f;
- }
-#endif
- }
- if(pixel_mode & PMODE_LFLARE)
- {
- flicker = rand()%20;
-#ifdef OGLR
- //Oh god, this is awful
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx-70;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 1.0f - ((float)flicker)/30;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx+70;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny-70;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 1.0f - ((float)flicker)/50;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny;
- cline++;
-
- lineC[clineC++] = ((float)colr)/255.0f;
- lineC[clineC++] = ((float)colg)/255.0f;
- lineC[clineC++] = ((float)colb)/255.0f;
- lineC[clineC++] = 0.0f;
- lineV[clineV++] = fnx;
- lineV[clineV++] = fny+70;
- cline++;
-#else
- gradv = flicker + fabs(parts[i].vx)*17 + fabs(parts[i].vy)*17;
- blendpixel(vid, nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) );
- blendpixel(vid, nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) );
- blendpixel(vid, nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) );
- blendpixel(vid, nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) );
- blendpixel(vid, nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) );
- if (gradv>255) gradv=255;
- blendpixel(vid, nx+1, ny-1, colr, colg, colb, gradv);
- blendpixel(vid, nx-1, ny-1, colr, colg, colb, gradv);
- blendpixel(vid, nx+1, ny+1, colr, colg, colb, gradv);
- blendpixel(vid, nx-1, ny+1, colr, colg, colb, gradv);
- for (x = 1; gradv>0.5; x++) {
- addpixel(vid, nx+x, ny, colr, colg, colb, gradv);
- addpixel(vid, nx-x, ny, colr, colg, colb, gradv);
- addpixel(vid, nx, ny+x, colr, colg, colb, gradv);
- addpixel(vid, nx, ny-x, colr, colg, colb, gradv);
- gradv = gradv/1.01f;
- }
-#endif
- }
- if (pixel_mode & EFFECT_GRAVIN)
- {
- int nxo = 0;
- int nyo = 0;
- int r;
- int fire_rv = 0;
- float drad = 0.0f;
- float ddist = 0.0f;
- orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl);
- for (r = 0; r < 4; r++) {
- ddist = ((float)orbd[r])/16.0f;
- drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f;
- nxo = (int)(ddist*cos(drad));
- nyo = (int)(ddist*sin(drad));
- if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES && (pmap[ny+nyo][nx+nxo]&0xFF) != PT_PRTI)
- addpixel(vid, nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]);
- }
- }
- if (pixel_mode & EFFECT_GRAVOUT)
- {
- int nxo = 0;
- int nyo = 0;
- int r;
- int fire_bv = 0;
- float drad = 0.0f;
- float ddist = 0.0f;
- orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl);
- for (r = 0; r < 4; r++) {
- ddist = ((float)orbd[r])/16.0f;
- drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f;
- nxo = (int)(ddist*cos(drad));
- nyo = (int)(ddist*sin(drad));
- if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES && (pmap[ny+nyo][nx+nxo]&0xFF) != PT_PRTO)
- addpixel(vid, nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]);
- }
- }
- if ((pixel_mode & EFFECT_LINES) && DEBUG_MODE)
- {
- if (mousex==(nx) && mousey==(ny))//draw lines connecting wifi/portal channels
- {
- int z;
- int type = parts[i].type;
- if (type == PT_PRTI)
- type = PT_PRTO;
- else if (type == PT_PRTO)
- type = PT_PRTI;
- for (z = 0; z<NPART; z++) {
- if (parts[z].type)
- {
- if (parts[z].type==type&&parts[z].tmp==parts[i].tmp)
- xor_line(nx,ny,(int)(parts[z].x+0.5f),(int)(parts[z].y+0.5f),vid);
- }
- }
- }
- }
- //Fire effects
- if(firea && (pixel_mode & FIRE_BLEND))
- {
-#ifdef OGLR
- smokeV[csmokeV++] = nx;
- smokeV[csmokeV++] = ny;
- smokeC[csmokeC++] = ((float)firer)/255.0f;
- smokeC[csmokeC++] = ((float)fireg)/255.0f;
- smokeC[csmokeC++] = ((float)fireb)/255.0f;
- smokeC[csmokeC++] = ((float)firea)/255.0f;
- csmoke++;
-#else
- firea /= 2;
- fire_r[ny/CELL][nx/CELL] = (firea*firer + (255-firea)*fire_r[ny/CELL][nx/CELL]) >> 8;
- fire_g[ny/CELL][nx/CELL] = (firea*fireg + (255-firea)*fire_g[ny/CELL][nx/CELL]) >> 8;
- fire_b[ny/CELL][nx/CELL] = (firea*fireb + (255-firea)*fire_b[ny/CELL][nx/CELL]) >> 8;
-#endif
- }
- if(firea && (pixel_mode & FIRE_ADD))
- {
-#ifdef OGLR
- fireV[cfireV++] = nx;
- fireV[cfireV++] = ny;
- fireC[cfireC++] = ((float)firer)/255.0f;
- fireC[cfireC++] = ((float)fireg)/255.0f;
- fireC[cfireC++] = ((float)fireb)/255.0f;
- fireC[cfireC++] = ((float)firea)/255.0f;
- cfire++;
-#else
- firea /= 8;
- firer = ((firea*firer) >> 8) + fire_r[ny/CELL][nx/CELL];
- fireg = ((firea*fireg) >> 8) + fire_g[ny/CELL][nx/CELL];
- fireb = ((firea*fireb) >> 8) + fire_b[ny/CELL][nx/CELL];
-
- if(firer>255)
- firer = 255;
- if(fireg>255)
- fireg = 255;
- if(fireb>255)
- fireb = 255;
-
- fire_r[ny/CELL][nx/CELL] = firer;
- fire_g[ny/CELL][nx/CELL] = fireg;
- fire_b[ny/CELL][nx/CELL] = fireb;
-#endif
- }
- }
- }
- }
-#ifdef OGLR
-
- //Go into array mode
- glEnableClientState(GL_COLOR_ARRAY);
- glEnableClientState(GL_VERTEX_ARRAY);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
-
- if(cablurLine)
- {
- // -- BEGIN LINES -- //
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- glEnable( GL_LINE_SMOOTH );
- glColorPointer(4, GL_FLOAT, 0, &ablurLineC[0]);
- glVertexPointer(2, GL_FLOAT, 0, &ablurLineV[0]);
-
- glDrawArrays(GL_LINES, 0, cablurLine);
-
- //Clear some stuff we set
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_LINE_SMOOTH);
- // -- END LINES -- //
- }
- if(cblurLine)
- {
- // -- BEGIN LINES -- //
- glEnable( GL_LINE_SMOOTH );
- glColorPointer(4, GL_FLOAT, 0, &blurLineC[0]);
- glVertexPointer(2, GL_FLOAT, 0, &blurLineV[0]);
-
- glDrawArrays(GL_LINES, 0, cblurLine);
-
- //Clear some stuff we set
- glDisable(GL_LINE_SMOOTH);
- // -- END LINES -- //
- }
-
- if(cflat)
- {
- // -- BEGIN FLAT -- //
- //Set point size (size of fire texture)
- glPointSize(1.0f);
-
- glColorPointer(4, GL_FLOAT, 0, &flatC[0]);
- glVertexPointer(2, GL_INT, 0, &flatV[0]);
-
- glDrawArrays(GL_POINTS, 0, cflat);
-
- //Clear some stuff we set
- // -- END FLAT -- //
- }
-
- if(cblob)
- {
- // -- BEGIN BLOB -- //
- glEnable( GL_POINT_SMOOTH ); //Blobs!
- glPointSize(2.5f);
-
- glColorPointer(4, GL_FLOAT, 0, &blobC[0]);
- glVertexPointer(2, GL_INT, 0, &blobV[0]);
-
- glDrawArrays(GL_POINTS, 0, cblob);
-
- //Clear some stuff we set
- glDisable( GL_POINT_SMOOTH );
- // -- END BLOB -- //
- }
-
- if(cglow || cblur)
- {
- // -- BEGIN GLOW -- //
- //Start and prepare fire program
- glEnable(GL_TEXTURE_2D);
- glUseProgram(fireProg);
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, glowAlpha);
- glUniform1i(glGetUniformLocation(fireProg, "fireAlpha"), 0);
-
- glPointParameteri(GL_POINT_SPRITE_COORD_ORIGIN, GL_LOWER_LEFT);
-
- //Make sure we can use texture coords on points
- glEnable(GL_POINT_SPRITE);
- glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
- glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
-
- //Set point size (size of fire texture)
- glPointSize(11.0f);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
-
- if(cglow)
- {
- glColorPointer(4, GL_FLOAT, 0, &glowC[0]);
- glVertexPointer(2, GL_INT, 0, &glowV[0]);
-
- glDrawArrays(GL_POINTS, 0, cglow);
- }
-
- glPointSize(7.0f);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- if(cblur)
- {
- glBindTexture(GL_TEXTURE_2D, blurAlpha);
-
- glColorPointer(4, GL_FLOAT, 0, &blurC[0]);
- glVertexPointer(2, GL_INT, 0, &blurV[0]);
-
- glDrawArrays(GL_POINTS, 0, cblur);
- }
-
- //Clear some stuff we set
- glDisable(GL_POINT_SPRITE);
- glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
- glUseProgram(0);
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
- // -- END GLOW -- //
- }
-
- if(cadd)
- {
- // -- BEGIN ADD -- //
- //Set point size (size of fire texture)
- glPointSize(1.0f);
-
- glColorPointer(4, GL_FLOAT, 0, &addC[0]);
- glVertexPointer(2, GL_INT, 0, &addV[0]);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- glDrawArrays(GL_POINTS, 0, cadd);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- //Clear some stuff we set
- // -- END ADD -- //
- }
-
- if(cline)
- {
- // -- BEGIN LINES -- //
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- glEnable( GL_LINE_SMOOTH );
- glColorPointer(4, GL_FLOAT, 0, &lineC[0]);
- glVertexPointer(2, GL_FLOAT, 0, &lineV[0]);
-
- glDrawArrays(GL_LINE_STRIP, 0, cline);
-
- //Clear some stuff we set
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_LINE_SMOOTH);
- // -- END LINES -- //
- }
-
- if(cfire || csmoke)
- {
- // -- BEGIN FIRE -- //
- //Start and prepare fire program
- glEnable(GL_TEXTURE_2D);
- glUseProgram(fireProg);
- //glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, fireAlpha);
- glUniform1i(glGetUniformLocation(fireProg, "fireAlpha"), 0);
-
- //Make sure we can use texture coords on points
- glEnable(GL_POINT_SPRITE);
- glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
- glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
-
- //Set point size (size of fire texture)
- glPointSize(CELL*3);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
-
- if(cfire)
- {
- glColorPointer(4, GL_FLOAT, 0, &fireC[0]);
- glVertexPointer(2, GL_INT, 0, &fireV[0]);
-
- glDrawArrays(GL_POINTS, 0, cfire);
- }
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- if(csmoke)
- {
- glColorPointer(4, GL_FLOAT, 0, &smokeC[0]);
- glVertexPointer(2, GL_INT, 0, &smokeV[0]);
-
- glDrawArrays(GL_POINTS, 0, csmoke);
- }
-
- //Clear some stuff we set
- glDisable(GL_POINT_SPRITE);
- glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
- glUseProgram(0);
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
- // -- END FIRE -- //
- }
-
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
-
- //Reset FBO
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
-
- //Drawing the FBO onto the screen sounds like a cool idea now
-
- glBlendFunc(origBlendSrc, origBlendDst);
-#endif
-}
-
-#ifdef OGLR
-void draw_parts_fbo()
-{
- glEnable( GL_TEXTURE_2D );
- if(display_mode & DISPLAY_WARP)
- {
- float xres = XRES, yres = YRES;
- glUseProgram(lensProg);
- glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, partsFboTex);
- glUniform1i(glGetUniformLocation(lensProg, "pTex"), 0);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, partsTFX);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_RED, GL_FLOAT, gravx);
- glUniform1i(glGetUniformLocation(lensProg, "tfX"), 1);
- glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, partsTFY);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_GREEN, GL_FLOAT, gravy);
- glUniform1i(glGetUniformLocation(lensProg, "tfY"), 2);
- glActiveTexture(GL_TEXTURE0);
- glUniform1fv(glGetUniformLocation(lensProg, "xres"), 1, &xres);
- glUniform1fv(glGetUniformLocation(lensProg, "yres"), 1, &yres);
- }
- else
- {
- glBindTexture(GL_TEXTURE_2D, partsFboTex);
- glBlendFunc(GL_ONE, GL_ONE);
- }
-
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glBegin(GL_QUADS);
- glTexCoord2d(1, 0);
- glVertex3f(XRES*sdl_scale, (YRES+MENUSIZE)*sdl_scale, 1.0);
- glTexCoord2d(0, 0);
- glVertex3f(0, (YRES+MENUSIZE)*sdl_scale, 1.0);
- glTexCoord2d(0, 1);
- glVertex3f(0, MENUSIZE*sdl_scale, 1.0);
- glTexCoord2d(1, 1);
- glVertex3f(XRES*sdl_scale, MENUSIZE*sdl_scale, 1.0);
- glEnd();
-
- if(display_mode & DISPLAY_WARP)
- {
- glUseProgram(0);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- glDisable( GL_TEXTURE_2D );
-}
-#endif
-
-// draw the graphics that appear before update_particles is called
-void render_before(pixel *part_vbuf)
-{
-#ifdef OGLR
- if (display_mode & DISPLAY_PERS)//save background for persistent, then clear
- {
- clearScreen(0.01f);
- memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- }
- else //clear screen every frame
- {
- clearScreen(1.0f);
- memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- if (display_mode & DISPLAY_AIR)//air only gets drawn in these modes
- {
- draw_air(part_vbuf);
- }
- }
-#else
- if (display_mode & DISPLAY_AIR)//air only gets drawn in these modes
- {
- draw_air(part_vbuf);
- }
- else if (display_mode & DISPLAY_PERS)//save background for persistent, then clear
- {
- memcpy(part_vbuf, pers_bg, (XRES+BARSIZE)*YRES*PIXELSIZE);
- memset(part_vbuf+((XRES+BARSIZE)*YRES), 0, ((XRES+BARSIZE)*YRES*PIXELSIZE)-((XRES+BARSIZE)*YRES*PIXELSIZE));
- }
- else //clear screen every frame
- {
- memset(part_vbuf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- }
-#endif
- if(ngrav_enable && drawgrav_enable)
- draw_grav(part_vbuf);
- draw_walls(part_vbuf);
-}
-
-int persist_counter = 0;
-// draw the graphics that appear after update_particles is called
-void render_after(pixel *part_vbuf, pixel *vid_buf)
-{
- render_parts(part_vbuf); //draw particles
- draw_other(part_vbuf);
- //if(su == WL_GRAV+100)
- // draw_grav_zones(part_vbuf);
- if (vid_buf && (display_mode & DISPLAY_PERS))
- {
- if (!persist_counter)
- {
- dim_copy_pers(pers_bg, vid_buf);
- }
- else
- {
- memcpy(pers_bg, vid_buf, (XRES+BARSIZE)*YRES*PIXELSIZE);
- }
- persist_counter = (persist_counter+1) % 3;
- }
-#ifndef OGLR
- if (render_mode & FIREMODE)
- render_fire(part_vbuf);
-#endif
-
- render_signs(part_vbuf);
-
-#ifndef OGLR
- if(vid_buf && ngrav_enable && (display_mode & DISPLAY_WARP))
- render_gravlensing(part_vbuf, vid_buf);
-#endif
-}
-
-void draw_walls(pixel *vid)
-{
- int x, y, i, j, cr, cg, cb, nx, ny, t;
- unsigned char wt;
- float lx, ly;
- pixel pc;
- pixel gc;
- for (y=0; y<YRES/CELL; y++)
- for (x=0; x<XRES/CELL; x++)
- if (bmap[y][x])
- {
- wt = bmap[y][x]-UI_ACTUALSTART;
- if (wt<0 || wt>=UI_WALLCOUNT)
- continue;
- pc = wtypes[wt].colour;
- gc = wtypes[wt].eglow;
-
- // standard wall patterns
- if (wtypes[wt].drawstyle==1)
- {
- for (j=0; j<CELL; j+=2)
- for (i=(j>>1)&1; i<CELL; i+=2)
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
- }
- else if (wtypes[wt].drawstyle==2)
- {
- for (j=0; j<CELL; j+=2)
- for (i=0; i<CELL; i+=2)
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
- }
- else if (wtypes[wt].drawstyle==3)
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
- }
- else if (wtypes[wt].drawstyle==4)
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- if(i == j)
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
- else if (i == j+1 || (i == 0 && j == CELL-1))
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = gc;
- else
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x202020);
- }
-
- // special rendering for some walls
- if (bmap[y][x]==WL_EWALL)
- {
- if (emap[y][x])
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- if (i&j&1)
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
- }
- else
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- if (!(i&j&1))
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
- }
- }
- else if (bmap[y][x]==WL_WALLELEC)
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- {
- if (!((y*CELL+j)%2) && !((x*CELL+i)%2))
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
- else
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
- }
- }
- else if (bmap[y][x]==WL_EHOLE)
- {
- if (emap[y][x])
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x242424);
- for (j=0; j<CELL; j+=2)
- for (i=0; i<CELL; i+=2)
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x000000);
- }
- else
- {
- for (j=0; j<CELL; j+=2)
- for (i=0; i<CELL; i+=2)
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x242424);
- }
- }
- if (render_mode & PMODE_BLOB)
- {
- // when in blob view, draw some blobs...
- if (wtypes[wt].drawstyle==1)
- {
- for (j=0; j<CELL; j+=2)
- for (i=(j>>1)&1; i<CELL; i+=2)
- drawblob(vid, (x*CELL+i), (y*CELL+j), PIXR(pc), PIXG(pc), PIXB(pc));
- }
- else if (wtypes[wt].drawstyle==2)
- {
- for (j=0; j<CELL; j+=2)
- for (i=0; i<CELL; i+=2)
- drawblob(vid, (x*CELL+i), (y*CELL+j), PIXR(pc), PIXG(pc), PIXB(pc));
- }
- else if (wtypes[wt].drawstyle==3)
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- drawblob(vid, (x*CELL+i), (y*CELL+j), PIXR(pc), PIXG(pc), PIXB(pc));
- }
- else if (wtypes[wt].drawstyle==4)
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- if(i == j)
- drawblob(vid, (x*CELL+i), (y*CELL+j), PIXR(pc), PIXG(pc), PIXB(pc));
- else if (i == j+1 || (i == 0 && j == CELL-1))
- drawblob(vid, (x*CELL+i), (y*CELL+j), PIXR(gc), PIXG(gc), PIXB(gc));
- else
- drawblob(vid, (x*CELL+i), (y*CELL+j), 0x20, 0x20, 0x20);
- }
- if (bmap[y][x]==WL_EWALL)
- {
- if (emap[y][x])
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- if (i&j&1)
- drawblob(vid, (x*CELL+i), (y*CELL+j), 0x80, 0x80, 0x80);
- }
- else
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- if (!(i&j&1))
- drawblob(vid, (x*CELL+i), (y*CELL+j), 0x80, 0x80, 0x80);
- }
- }
- else if (bmap[y][x]==WL_WALLELEC)
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- {
- if (!((y*CELL+j)%2) && !((x*CELL+i)%2))
- drawblob(vid, (x*CELL+i), (y*CELL+j), PIXR(pc), PIXG(pc), PIXB(pc));
- else
- drawblob(vid, (x*CELL+i), (y*CELL+j), 0x80, 0x80, 0x80);
- }
- }
- else if (bmap[y][x]==WL_EHOLE)
- {
- if (emap[y][x])
- {
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- drawblob(vid, (x*CELL+i), (y*CELL+j), 0x24, 0x24, 0x24);
- for (j=0; j<CELL; j+=2)
- for (i=0; i<CELL; i+=2)
- vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x000000);
- }
- else
- {
- for (j=0; j<CELL; j+=2)
- for (i=0; i<CELL; i+=2)
- drawblob(vid, (x*CELL+i), (y*CELL+j), 0x24, 0x24, 0x24);
- }
- }
- }
- if (wtypes[wt].eglow && emap[y][x])
- {
- // glow if electrified
- pc = wtypes[wt].eglow;
- cr = fire_r[y][x] + PIXR(pc);
- if (cr > 255) cr = 255;
- fire_r[y][x] = cr;
- cg = fire_g[y][x] + PIXG(pc);
- if (cg > 255) cg = 255;
- fire_g[y][x] = cg;
- cb = fire_b[y][x] + PIXB(pc);
- if (cb > 255) cb = 255;
- fire_b[y][x] = cb;
-
- }
- }
-
- // draw streamlines
- 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 create_decorations(int x, int y, int rx, int ry, int r, int g, int b, int click, int tool)
-{
- int i,j,rp;
- if (rx==0 && ry==0)
- {
- create_decoration(x,y,r,g,b,click,tool);
- return;
- }
- for (j=-ry; j<=ry; j++)
- for (i=-rx; i<=rx; i++)
- if(y+j>=0 && x+i>=0 && x+i<XRES && y+j<YRES)
- if (InCurrentBrush(i, j, rx, ry)){
- create_decoration(x+i,y+j,r,g,b,click,tool);
- }
-}
-void create_decoration(int x, int y, int r, int g, int b, int click, int tool)
-{
- int rp, tr = 0, tg = 0, tb = 0;
- rp = pmap[y][x];
- if (!rp)
- return;
- if (tool == DECO_DRAW)
- {
- if (click == 4)
- parts[rp>>8].dcolour = 0;
- else
- parts[rp>>8].dcolour = ((255<<24)|(r<<16)|(g<<8)|b);
- }
- else if (tool == DECO_LIGHTEN)
- {//maybe get a better lighten/darken?
- if (parts[rp>>8].dcolour == 0)
- return;
- tr = (parts[rp>>8].dcolour>>16)&0xFF;
- tg = (parts[rp>>8].dcolour>>8)&0xFF;
- tb = (parts[rp>>8].dcolour)&0xFF;
- parts[rp>>8].dcolour = ((parts[rp>>8].dcolour&0xFF000000)|(clamp_flt(tr+(255-tr)*0.02+1, 0,255)<<16)|(clamp_flt(tg+(255-tg)*0.02+1, 0,255)<<8)|clamp_flt(tb+(255-tb)*0.02+1, 0,255));
- }
- else if (tool == DECO_DARKEN)
- {
- if (parts[rp>>8].dcolour == 0)
- return;
- tr = (parts[rp>>8].dcolour>>16)&0xFF;
- tg = (parts[rp>>8].dcolour>>8)&0xFF;
- tb = (parts[rp>>8].dcolour)&0xFF;
- parts[rp>>8].dcolour = ((parts[rp>>8].dcolour&0xFF000000)|(clamp_flt(tr-(tr)*0.02, 0,255)<<16)|(clamp_flt(tg-(tg)*0.02, 0,255)<<8)|clamp_flt(tb-(tb)*0.02, 0,255));
- }
- else if (tool == DECO_SMUDGE)
- {
- int rx, ry, num = 0, ta = 0;
- for (rx=-2; rx<3; rx++)
- for (ry=-2; ry<3; ry++)
- {
- if ((pmap[y+ry][x+rx]&0xFF) && parts[pmap[y+ry][x+rx]>>8].dcolour)
- {
- num++;
- ta += (parts[pmap[y+ry][x+rx]>>8].dcolour>>24)&0xFF;
- tr += (parts[pmap[y+ry][x+rx]>>8].dcolour>>16)&0xFF;
- tg += (parts[pmap[y+ry][x+rx]>>8].dcolour>>8)&0xFF;
- tb += (parts[pmap[y+ry][x+rx]>>8].dcolour)&0xFF;
- }
- }
- if (num == 0)
- return;
- ta = fminf(255,(int)((float)ta/num+.5));
- tr = fminf(255,(int)((float)tr/num+.5));
- tg = fminf(255,(int)((float)tg/num+.5));
- tb = fminf(255,(int)((float)tb/num+.5));
- if (!parts[rp>>8].dcolour)
- ta = fmaxf(0,ta-3);
- parts[rp>>8].dcolour = ((ta<<24)|(tr<<16)|(tg<<8)|tb);
- }
-}
-void line_decorations(int x1, int y1, int x2, int y2, int rx, int ry, int r, int g, int b, int click, int tool)
-{
- int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy;
- float e, de;
- if (cp)
- {
- y = x1;
- x1 = y1;
- y1 = y;
- y = x2;
- x2 = y2;
- y2 = y;
- }
- if (x1 > x2)
- {
- y = x1;
- x1 = x2;
- x2 = y;
- y = y1;
- y1 = y2;
- y2 = y;
- }
- dx = x2 - x1;
- dy = abs(y2 - y1);
- e = 0.0f;
- if (dx)
- de = dy/(float)dx;
- else
- de = 0.0f;
- y = y1;
- sy = (y1<y2) ? 1 : -1;
- for (x=x1; x<=x2; x++)
- {
- if (cp)
- create_decorations(y, x, rx, ry, r, g, b, click, tool);
- else
- create_decorations(x, y, rx, ry, r, g, b, click, tool);
- e += de;
- if (e >= 0.5f)
- {
- y += sy;
- if (!(rx+ry))
- {
- if (cp)
- create_decorations(y, x, rx, ry, r, g, b, click, tool);
- else
- create_decorations(x, y, rx, ry, r, g, b, click, tool);
- }
- e -= 1.0f;
- }
- }
-}
-void box_decorations(int x1, int y1, int x2, int y2, int r, int g, int b, int click, int tool)
-{
- int i, j;
- if (x1>x2)
- {
- i = x2;
- x2 = x1;
- x1 = i;
- }
- if (y1>y2)
- {
- j = y2;
- y2 = y1;
- y1 = j;
- }
- for (j=y1; j<=y2; j++)
- for (i=x1; i<=x2; i++)
- create_decorations(i, j, 0, 0, r, g, b, click, tool);
-}
-
-//draws the photon colors in the HUD
-void draw_wavelengths(pixel *vid, int x, int y, int h, int wl)
-{
- int i,cr,cg,cb,j;
- int tmp;
- fillrect(vid,x-1,y-1,30+1,h+1,64,64,64,255); // coords -1 size +1 to work around bug in fillrect - TODO: fix fillrect
- for (i=0; i<30; i++)
- {
- if ((wl>>i)&1)
- {
- // Need a spread of wavelengths to get a smooth spectrum, 5 bits seems to work reasonably well
- if (i>2) tmp = 0x1F << (i-2);
- else tmp = 0x1F >> (2-i);
- cg = 0;
- cb = 0;
- cr = 0;
- for (j=0; j<12; j++) {
- cr += (tmp >> (j+18)) & 1;
- cb += (tmp >> j) & 1;
- }
- for (j=0; j<13; j++)
- cg += (tmp >> (j+9)) & 1;
- tmp = 624/(cr+cg+cb+1);
- cr *= tmp;
- cg *= tmp;
- cb *= tmp;
- for (j=0; j<h; j++) blendpixel(vid,x+29-i,y+j,cr>255?255:cr,cg>255?255:cg,cb>255?255:cb,255);
- }
- }
-}
-
-void render_signs(pixel *vid_buf)
-{
- int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq;
- for (i=0; i<MAXSIGNS; i++)
- if (signs[i].text[0])
- {
- char buff[256]; //Buffer
- get_sign_pos(i, &x, &y, &w, &h);
- clearrect(vid_buf, x, y, w, h);
- drawrect(vid_buf, x, y, w, h, 192, 192, 192, 255);
-
- //Displaying special information
- if (strcmp(signs[i].text, "{p}")==0)
- {
- float pressure = 0.0f;
- if (signs[i].x>=0 && signs[i].x<XRES && signs[i].y>=0 && signs[i].y<YRES)
- pressure = pv[signs[i].y/CELL][signs[i].x/CELL];
- sprintf(buff, "Pressure: %3.2f", pressure); //...pressure
- drawtext(vid_buf, x+3, y+3, buff, 255, 255, 255, 255);
- }
- if (strcmp(signs[i].text, "{t}")==0)
- {
- if (signs[i].x>=0 && signs[i].x<XRES && signs[i].y>=0 && signs[i].y<YRES && pmap[signs[i].y][signs[i].x])
- sprintf(buff, "Temp: %4.2f", parts[pmap[signs[i].y][signs[i].x]>>8].temp-273.15); //...temperature
- else
- sprintf(buff, "Temp: 0.00"); //...temperature
- drawtext(vid_buf, x+3, y+3, buff, 255, 255, 255, 255);
- }
-
- if (sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0)
- {
- int sldr, startm;
- memset(buff, 0, sizeof(buff));
- for (sldr=3; signs[i].text[sldr-1] != '|'; sldr++)
- startm = sldr + 1;
- sldr = startm;
- while (signs[i].text[sldr] != '}')
- {
- buff[sldr - startm] = signs[i].text[sldr];
- sldr++;
- }
- drawtext(vid_buf, x+3, y+3, buff, 0, 191, 255, 255);
- }
-
- //Usual text
- if (strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}") && sregexp(signs[i].text, "^{c:[0-9]*|.*}$"))
- drawtext(vid_buf, x+3, y+3, signs[i].text, 255, 255, 255, 255);
-
- x = signs[i].x;
- y = signs[i].y;
- dx = 1 - signs[i].ju;
- dy = (signs[i].y > 18) ? -1 : 1;
- for (j=0; j<4; j++)
- {
- drawpixel(vid_buf, x, y, 192, 192, 192, 255);
- x+=dx;
- y+=dy;
- }
- if (MSIGN==i)
- {
- bq = b;
- mouse_get_state(&mx, &my);
- mouse_coords_window_to_sim(&mx, &my, mx, my);
- signs[i].x = mx;
- signs[i].y = my;
- }
- }
-}
-
-void render_gravlensing(pixel *src, pixel * dst)
-{
- int nx, ny, rx, ry, gx, gy, bx, by, co;
- int r, g, b;
- pixel t;
- for(nx = 0; nx < XRES; nx++)
- {
- for(ny = 0; ny < YRES; ny++)
- {
- co = (ny/CELL)*(XRES/CELL)+(nx/CELL);
- rx = (int)(nx-gravx[co]*0.75f+0.5f);
- ry = (int)(ny-gravy[co]*0.75f+0.5f);
- gx = (int)(nx-gravx[co]*0.875f+0.5f);
- gy = (int)(ny-gravy[co]*0.875f+0.5f);
- bx = (int)(nx-gravx[co]+0.5f);
- by = (int)(ny-gravy[co]+0.5f);
- if(rx > 0 && rx < XRES && ry > 0 && ry < YRES && gx > 0 && gx < XRES && gy > 0 && gy < YRES && bx > 0 && bx < XRES && by > 0 && by < YRES)
- {
- t = dst[ny*(XRES+BARSIZE)+nx];
- r = PIXR(src[ry*(XRES+BARSIZE)+rx]) + PIXR(t);
- g = PIXG(src[gy*(XRES+BARSIZE)+gx]) + PIXG(t);
- b = PIXB(src[by*(XRES+BARSIZE)+bx]) + PIXB(t);
- if (r>255)
- r = 255;
- if (g>255)
- g = 255;
- if (b>255)
- b = 255;
- dst[ny*(XRES+BARSIZE)+nx] = PIXRGB(r,g,b);
- // addpixel(dst, nx, ny, PIXR(src[ry*(XRES+BARSIZE)+rx]), PIXG(src[gy*(XRES+BARSIZE)+gx]), PIXB(src[by*(XRES+BARSIZE)+bx]), 255);
- }
-
- /*rx = nx+(gravxf[(ny*XRES)+nx]*0.5f);
- ry = ny+(gravyf[(ny*XRES)+nx]*0.5f);
- gx = nx+(gravxf[(ny*XRES)+nx]*0.75f);
- gy = ny+(gravyf[(ny*XRES)+nx]*0.75f);
- bx = nx+(gravxf[(ny*XRES)+nx]);
- by = ny+(gravyf[(ny*XRES)+nx]);
- if(rx > 0 && rx < XRES && ry > 0 && ry < YRES && gravp[ny/CELL][nx/CELL]*0.5f > -8.0f)
- addpixel(dst, rx, ry, PIXR(src[ry*(XRES+BARSIZE)+rx]), 0, 0, 255);
- if(gx > 0 && gx < XRES && gy > 0 && gy < YRES && gravp[ny/CELL][nx/CELL]*0.75f > -8.0f)
- addpixel(dst, gx, gy, 0, PIXG(src[ry*(XRES+BARSIZE)+rx]), 0, 255);
- if(bx > 0 && bx < XRES && by > 0 && by < YRES && gravp[ny/CELL][nx/CELL] > -8.0f)
- addpixel(dst, bx, by, 0, 0, PIXB(src[ry*(XRES+BARSIZE)+rx]), 255);*/
- }
- }
-}
-
-void render_fire(pixel *vid)
-{
- int i,j,x,y,r,g,b,nx,ny;
- for (j=0; j<YRES/CELL; j++)
- for (i=0; i<XRES/CELL; i++)
- {
- r = fire_r[j][i];
- g = fire_g[j][i];
- b = fire_b[j][i];
- if (r || g || b)
- for (y=-CELL; y<2*CELL; y++)
- for (x=-CELL; x<2*CELL; x++)
- addpixel(vid, i*CELL+x, j*CELL+y, r, g, b, fire_alpha[y+CELL][x+CELL]);
- r *= 8;
- g *= 8;
- b *= 8;
- for (y=-1; y<2; y++)
- for (x=-1; x<2; x++)
- if ((x || y) && i+x>=0 && j+y>=0 && i+x<XRES/CELL && j+y<YRES/CELL)
- {
- r += fire_r[j+y][i+x];
- g += fire_g[j+y][i+x];
- b += fire_b[j+y][i+x];
- }
- r /= 16;
- g /= 16;
- b /= 16;
- fire_r[j][i] = r>4 ? r-4 : 0;
- fire_g[j][i] = g>4 ? g-4 : 0;
- fire_b[j][i] = b>4 ? b-4 : 0;
- }
-}
-
-void prepare_alpha(int size, float intensity)
-{
- //TODO: implement size
- int x,y,i,j,c;
- float multiplier = 255.0f*intensity;
- float temp[CELL*3][CELL*3];
- float fire_alphaf[CELL*3][CELL*3];
- float glow_alphaf[11][11];
- float blur_alphaf[7][7];
- memset(temp, 0, sizeof(temp));
- for (x=0; x<CELL; x++)
- for (y=0; y<CELL; y++)
- for (i=-CELL; i<CELL; i++)
- for (j=-CELL; j<CELL; j++)
- temp[y+CELL+j][x+CELL+i] += expf(-0.1f*(i*i+j*j));
- for (x=0; x<CELL*3; x++)
- for (y=0; y<CELL*3; y++)
- fire_alpha[y][x] = (int)(multiplier*temp[y][x]/(CELL*CELL));
-
-#ifdef OGLR
- for (x=0; x<CELL*3; x++)
- for (y=0; y<CELL*3; y++)
- {
- fire_alphaf[y][x] = (intensity*temp[y][x]/((float)(CELL*CELL)))/2.0f;
- }
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, fireAlpha);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, CELL*3, CELL*3, GL_ALPHA, GL_FLOAT, fire_alphaf);
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
-
- memset(glow_alphaf, 0, sizeof(glow_alphaf));
-
- c = 5;
-
- glow_alphaf[c][c] = 0.8f;
- glow_alphaf[c][c-1] = 0.4f;
- glow_alphaf[c][c+1] = 0.4f;
- glow_alphaf[c-1][c] = 0.4f;
- glow_alphaf[c+1][c] = 0.4f;
- for (x = 1; x < 6; x++) {
- glow_alphaf[c][c-x] += 0.02f;
- glow_alphaf[c][c+x] += 0.02f;
- glow_alphaf[c-x][c] += 0.02f;
- glow_alphaf[c+x][c] += 0.02f;
- for (y = 1; y < 6; y++) {
- if(x + y > 7)
- continue;
- glow_alphaf[c+x][c-y] += 0.02f;
- glow_alphaf[c-x][c+y] += 0.02f;
- glow_alphaf[c+x][c+y] += 0.02f;
- glow_alphaf[c-x][c-y] += 0.02f;
- }
- }
-
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, glowAlpha);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 11, 11, GL_ALPHA, GL_FLOAT, glow_alphaf);
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
-
- c = 3;
-
- for (x=-3; x<4; x++)
- {
- for (y=-3; y<4; y++)
- {
- if (abs(x)+abs(y) <2 && !(abs(x)==2||abs(y)==2))
- blur_alphaf[c+x][c-y] = 0.11f;
- if (abs(x)+abs(y) <=3 && abs(x)+abs(y))
- blur_alphaf[c+x][c-y] = 0.08f;
- if (abs(x)+abs(y) == 2)
- blur_alphaf[c+x][c-y] = 0.04f;
- }
- }
-
- glEnable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, blurAlpha);
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 7, 7, GL_ALPHA, GL_FLOAT, blur_alphaf);
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
-#endif
-}
-
-pixel *render_packed_rgb(void *image, int width, int height, int cmp_size)
-{
- unsigned char *tmp;
- pixel *res;
- int i;
-
- tmp = malloc(width*height*3);
- if (!tmp)
- return NULL;
- res = malloc(width*height*PIXELSIZE);
- if (!res)
- {
- free(tmp);
- return NULL;
- }
-
- i = width*height*3;
- if (BZ2_bzBuffToBuffDecompress((char *)tmp, (unsigned *)&i, (char *)image, cmp_size, 0, 0))
- {
- free(res);
- free(tmp);
- return NULL;
- }
-
- for (i=0; i<width*height; i++)
- res[i] = PIXRGB(tmp[3*i], tmp[3*i+1], tmp[3*i+2]);
-
- free(tmp);
- return res;
-}
-
-void draw_rgba_image(pixel *vid, unsigned char *data, int x, int y, float alpha)
-{
- unsigned char w, h;
- int i, j;
- unsigned char r, g, b, a;
- if (!data) return;
- w = *(data++)&0xFF;
- h = *(data++)&0xFF;
- for (j=0; j<h; j++)
- {
- for (i=0; i<w; i++)
- {
- r = *(data++)&0xFF;
- g = *(data++)&0xFF;
- b = *(data++)&0xFF;
- a = *(data++)&0xFF;
- drawpixel(vid, x+i, y+j, r, g, b, a*alpha);
- }
- }
-}
-
-void draw_image(pixel *vid, pixel *img, int x, int y, int w, int h, int a)
-{
- int i, j, r, g, b;
- if (!img) return;
- for (j=0; j<h; j++)
- for (i=0; i<w; i++)
- {
- r = PIXR(*img);
- g = PIXG(*img);
- b = PIXB(*img);
- drawpixel(vid, x+i, y+j, r, g, b, a);
- img++;
- }
-}
-
-void dim_copy(pixel *dst, pixel *src) //old persistent, unused
-{
- int i,r,g,b;
- for (i=0; i<XRES*YRES; i++)
- {
- r = PIXR(src[i]);
- g = PIXG(src[i]);
- b = PIXB(src[i]);
- if (r>0)
- r--;
- if (g>0)
- g--;
- if (b>0)
- b--;
- dst[i] = PIXRGB(r,g,b);
- }
-}
-
-void dim_copy_pers(pixel *dst, pixel *src) //for persistent view, reduces rgb slowly
-{
- int i,r,g,b;
- for (i=0; i<(XRES+BARSIZE)*YRES; i++)
- {
- r = PIXR(src[i]);
- g = PIXG(src[i]);
- b = PIXB(src[i]);
- if (r>0)
- r--;
- if (g>0)
- g--;
- if (b>0)
- b--;
- dst[i] = PIXRGB(r,g,b);
- }
-}
-
-void render_zoom(pixel *img) //draws the zoom box
-{
-#ifdef OGLR
- int origBlendSrc, origBlendDst;
- float zcx1, zcx0, zcy1, zcy0, yfactor, xfactor, i; //X-Factor is shit, btw
- xfactor = 1.0f/(float)XRES;
- yfactor = 1.0f/(float)YRES;
-
- zcx0 = (zoom_x)*xfactor;
- zcx1 = (zoom_x+ZSIZE)*xfactor;
- zcy0 = (zoom_y)*yfactor;
- zcy1 = ((zoom_y+ZSIZE))*yfactor;
-
- glGetIntegerv(GL_BLEND_SRC, &origBlendSrc);
- glGetIntegerv(GL_BLEND_DST, &origBlendDst);
- glBlendFunc(GL_ONE, GL_ZERO);
-
- glEnable( GL_TEXTURE_2D );
- //glReadBuffer(GL_AUX0);
- glBindTexture(GL_TEXTURE_2D, partsFboTex);
-
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glBegin(GL_QUADS);
- glTexCoord2d(zcx1, zcy1);
- glVertex3f((zoom_wx+ZSIZE*ZFACTOR)*sdl_scale, (YRES+MENUSIZE-(zoom_wy+ZSIZE*ZFACTOR))*sdl_scale, 1.0);
- glTexCoord2d(zcx0, zcy1);
- glVertex3f(zoom_wx*sdl_scale, (YRES+MENUSIZE-(zoom_wy+ZSIZE*ZFACTOR))*sdl_scale, 1.0);
- glTexCoord2d(zcx0, zcy0);
- glVertex3f(zoom_wx*sdl_scale, (YRES+MENUSIZE-zoom_wy)*sdl_scale, 1.0);
- glTexCoord2d(zcx1, zcy0);
- glVertex3f((zoom_wx+ZSIZE*ZFACTOR)*sdl_scale, (YRES+MENUSIZE-zoom_wy)*sdl_scale, 1.0);
- glEnd();
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable( GL_TEXTURE_2D );
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glLineWidth(sdl_scale);
- glEnable(GL_LINE_SMOOTH);
- glBegin(GL_LINES);
- glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
- for(i = 0; i < ZSIZE; i++)
- {
- glVertex2f((zoom_wx+ZSIZE*ZFACTOR)*sdl_scale, (YRES+MENUSIZE-(zoom_wy+ZSIZE*ZFACTOR)+i*ZFACTOR)*sdl_scale);
- glVertex2f(zoom_wx*sdl_scale, (YRES+MENUSIZE-(zoom_wy+ZSIZE*ZFACTOR)+i*ZFACTOR)*sdl_scale);
- glVertex2f((zoom_wx+i*ZFACTOR)*sdl_scale, (YRES+MENUSIZE-(zoom_wy+ZSIZE*ZFACTOR))*sdl_scale);
- glVertex2f((zoom_wx+i*ZFACTOR)*sdl_scale, (YRES+MENUSIZE-zoom_wy)*sdl_scale);
- }
- glEnd();
-
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glBegin(GL_LINE_STRIP);
- glVertex3i((zoom_wx-1)*sdl_scale, (YRES+MENUSIZE-zoom_wy)*sdl_scale, 0);
- glVertex3i((zoom_wx-1)*sdl_scale, (YRES+MENUSIZE-(zoom_wy+ZSIZE*ZFACTOR))*sdl_scale, 0);
- glVertex3i((zoom_wx+ZSIZE*ZFACTOR)*sdl_scale, (YRES+MENUSIZE-(zoom_wy+ZSIZE*ZFACTOR))*sdl_scale, 0);
- glVertex3i((zoom_wx+ZSIZE*ZFACTOR)*sdl_scale, (YRES+MENUSIZE-zoom_wy)*sdl_scale, 0);
- glVertex3i((zoom_wx-1)*sdl_scale, (YRES+MENUSIZE-zoom_wy)*sdl_scale, 0);
- glEnd();
- glDisable(GL_LINE_SMOOTH);
-
- glDisable(GL_LINE_SMOOTH);
-
- if(zoom_en)
- {
- glEnable(GL_COLOR_LOGIC_OP);
- //glEnable(GL_LINE_SMOOTH);
- glLogicOp(GL_XOR);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glBegin(GL_LINE_STRIP);
- glVertex3i((zoom_x-1)*sdl_scale, (YRES+MENUSIZE-(zoom_y-1))*sdl_scale, 0);
- glVertex3i((zoom_x-1)*sdl_scale, (YRES+MENUSIZE-(zoom_y+ZSIZE))*sdl_scale, 0);
- glVertex3i((zoom_x+ZSIZE)*sdl_scale, (YRES+MENUSIZE-(zoom_y+ZSIZE))*sdl_scale, 0);
- glVertex3i((zoom_x+ZSIZE)*sdl_scale, (YRES+MENUSIZE-(zoom_y-1))*sdl_scale, 0);
- glVertex3i((zoom_x-1)*sdl_scale, (YRES+MENUSIZE-(zoom_y-1))*sdl_scale, 0);
- glEnd();
- glDisable(GL_COLOR_LOGIC_OP);
- }
- glLineWidth(1);
- glBlendFunc(origBlendSrc, origBlendDst);
-#else
- int x, y, i, j;
- pixel pix;
- drawrect(img, zoom_wx-2, zoom_wy-2, ZSIZE*ZFACTOR+2, ZSIZE*ZFACTOR+2, 192, 192, 192, 255);
- drawrect(img, zoom_wx-1, zoom_wy-1, ZSIZE*ZFACTOR, ZSIZE*ZFACTOR, 0, 0, 0, 255);
- clearrect(img, zoom_wx, zoom_wy, ZSIZE*ZFACTOR, ZSIZE*ZFACTOR);
- for (j=0; j<ZSIZE; j++)
- for (i=0; i<ZSIZE; i++)
- {
- pix = img[(j+zoom_y)*(XRES+BARSIZE)+(i+zoom_x)];
- for (y=0; y<ZFACTOR-1; y++)
- for (x=0; x<ZFACTOR-1; x++)
- img[(j*ZFACTOR+y+zoom_wy)*(XRES+BARSIZE)+(i*ZFACTOR+x+zoom_wx)] = pix;
- }
- if (zoom_en)
- {
- for (j=-1; j<=ZSIZE; j++)
- {
- xor_pixel(zoom_x+j, zoom_y-1, img);
- xor_pixel(zoom_x+j, zoom_y+ZSIZE, img);
- }
- for (j=0; j<ZSIZE; j++)
- {
- xor_pixel(zoom_x-1, zoom_y+j, img);
- xor_pixel(zoom_x+ZSIZE, zoom_y+j, img);
- }
- }
-#endif
-}
-
-int render_thumb(void *thumb, int size, int bzip2, pixel *vid_buf, int px, int py, int scl)
-{
- unsigned char *d,*c=thumb;
- int i,j,x,y,a,t,r,g,b,sx,sy;
-
- if (bzip2)
- {
- if (size<16)
- return 1;
- if (c[3]!=0x74 || c[2]!=0x49 || c[1]!=0x68 || c[0]!=0x53)
- return 1;
- if (c[4]>PT_NUM)
- return 2;
- if (c[5]!=CELL || c[6]!=XRES/CELL || c[7]!=YRES/CELL)
- return 3;
- i = XRES*YRES;
- d = malloc(i);
- if (!d)
- return 1;
-
- if (BZ2_bzBuffToBuffDecompress((char *)d, (unsigned *)&i, (char *)(c+8), size-8, 0, 0))
- return 1;
- size = i;
- }
- else
- d = c;
-
- if (size < XRES*YRES)
- {
- if (bzip2)
- free(d);
- return 1;
- }
-
- sy = 0;
- for (y=0; y+scl<=YRES; y+=scl)
- {
- sx = 0;
- for (x=0; x+scl<=XRES; x+=scl)
- {
- a = 0;
- r = g = b = 0;
- for (j=0; j<scl; j++)
- for (i=0; i<scl; i++)
- {
- t = d[(y+j)*XRES+(x+i)];
- if (t==0xFF)
- {
- r += 256;
- g += 256;
- b += 256;
- a += 2;
- }
- else if (t)
- {
- if (t>=PT_NUM)
- goto corrupt;
- r += PIXR(ptypes[t].pcolors);
- g += PIXG(ptypes[t].pcolors);
- b += PIXB(ptypes[t].pcolors);
- a ++;
- }
- }
- if (a)
- {
- a = 256/a;
- r = (r*a)>>8;
- g = (g*a)>>8;
- b = (b*a)>>8;
- }
-
- drawpixel(vid_buf, px+sx, py+sy, r, g, b, 255);
- sx++;
- }
- sy++;
- }
-
- if (bzip2)
- free(d);
- return 0;
-
-corrupt:
- if (bzip2)
- free(d);
- return 1;
-}
-
-//draws the cursor
-void render_cursor(pixel *vid, int x, int y, int t, int rx, int ry)
-{
-#ifdef OGLR
- int i;
- if (t<PT_NUM||(t&0xFF)==PT_LIFE||t==SPC_AIR||t==SPC_HEAT||t==SPC_COOL||t==SPC_VACUUM||t==SPC_WIND||t==SPC_PGRV||t==SPC_NGRV||t==SPC_PROP)
- {
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
- glEnable(GL_COLOR_LOGIC_OP);
- glLogicOp(GL_XOR);
- glBegin(GL_LINE_LOOP);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- y *= sdl_scale;
- x *= sdl_scale;
- ry *= sdl_scale;
- rx *= sdl_scale;
- if (CURRENT_BRUSH==SQUARE_BRUSH)
- {
- glVertex2f(x-rx+1, (/*(YRES+MENUSIZE)*sdl_scale-*/y)-ry+1);
- glVertex2f(x+rx+1, (/*(YRES+MENUSIZE)*sdl_scale-*/y)-ry+1);
- glVertex2f(x+rx+1, (/*(YRES+MENUSIZE)*sdl_scale-*/y)+ry+1);
- glVertex2f(x-rx+1, (/*(YRES+MENUSIZE)*sdl_scale-*/y)+ry+1);
- glVertex2f(x-rx+1, (/*(YRES+MENUSIZE)*sdl_scale-*/y)-ry+1);
- }
- else if (CURRENT_BRUSH==CIRCLE_BRUSH)
- {
- for (i = 0; i < 360; i++)
- {
- float degInRad = i*(M_PI/180.0f);
- glVertex2f((cos(degInRad)*rx)+x, (sin(degInRad)*ry)+/*(YRES+MENUSIZE)*sdl_scale-*/y);
- }
- }
- else if (CURRENT_BRUSH==TRI_BRUSH)
- {
- glVertex2f(x+1, (/*(YRES+MENUSIZE)*sdl_scale-*/y)+ry+1);
- glVertex2f(x+rx+1, (/*(YRES+MENUSIZE)*sdl_scale-*/y)-ry+1);
- glVertex2f(x-rx+1, (/*(YRES+MENUSIZE)*sdl_scale-*/y)-ry+1);
- glVertex2f(x+1, (/*(YRES+MENUSIZE)*sdl_scale-*/y)+ry+1);
- }
- glEnd();
- glDisable(GL_COLOR_LOGIC_OP);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
- }
-#else
- int i,j,c;
- if (t<PT_NUM||(t&0xFF)==PT_LIFE||t==SPC_AIR||t==SPC_HEAT||t==SPC_COOL||t==SPC_VACUUM||t==SPC_WIND||t==SPC_PGRV||t==SPC_NGRV||t==SPC_PROP)
- {
- if (rx<=0)
- for (j = y - ry; j <= y + ry; j++)
- xor_pixel(x, j, vid);
- else
- {
- int tempy = y, i, j, oldy;
- if (CURRENT_BRUSH == TRI_BRUSH)
- tempy = y + ry;
- for (i = x - rx; i <= x; i++) {
- oldy = tempy;
- if (!InCurrentBrush(i-x,tempy-y,rx,ry))
- continue;
- while (InCurrentBrush(i-x,tempy-y,rx,ry))
- tempy = tempy - 1;
- tempy = tempy + 1;
- if (oldy != tempy && CURRENT_BRUSH != SQUARE_BRUSH)
- oldy--;
- if (CURRENT_BRUSH == TRI_BRUSH)
- oldy = tempy;
- for (j = tempy; j <= oldy; j++) {
- int i2 = 2*x-i, j2 = 2*y-j;
- if (CURRENT_BRUSH == TRI_BRUSH)
- j2 = y+ry;
- xor_pixel(i, j, vid);
- if (i2 != i)
- xor_pixel(i2, j, vid);
- if (j2 != j)
- xor_pixel(i, j2, vid);
- if (i2 != i && j2 != j)
- xor_pixel(i2, j2, vid);
- }
- }
- }
- }
- else //wall cursor
- {
- int tc;
- c = (rx/CELL) * CELL;
- x = (x/CELL) * CELL;
- y = (y/CELL) * CELL;
-
- tc = !((c%(CELL*2))==0);
-
- x -= c/2;
- y -= c/2;
-
- x += tc*(CELL/2);
- y += tc*(CELL/2);
-
- for (i=0; i<CELL+c; i++)
- {
- xor_pixel(x+i, y, vid);
- xor_pixel(x+i, y+CELL+c-1, vid);
- }
- for (i=1; i<CELL+c-1; i++)
- {
- xor_pixel(x, y+i, vid);
- xor_pixel(x+CELL+c-1, y+i, vid);
- }
- }
-#endif
-}
-
-SDL_VideoInfo info;
-int sdl_opened = 0;
-int sdl_open(void)
-{
- char screen_err = 0;
-#ifdef WIN32
- SDL_SysWMinfo SysInfo;
- HWND WindowHandle;
- HICON hIconSmall;
- HICON hIconBig;
-#elif defined(LIN32) || defined(LIN64)
- SDL_Surface *icon;
-#endif
- int status;
- if (SDL_Init(SDL_INIT_VIDEO)<0)
- {
- fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError());
- return 0;
- }
-
-#ifdef WIN32
- SDL_VERSION(&SysInfo.version);
- if(SDL_GetWMInfo(&SysInfo) <= 0) {
- printf("%s : %d\n", SDL_GetError(), SysInfo.window);
- exit(-1);
- }
- WindowHandle = SysInfo.window;
- hIconSmall = (HICON)LoadImage(&__ImageBase, MAKEINTRESOURCE(101), IMAGE_ICON, 16, 16, LR_SHARED);
- hIconBig = (HICON)LoadImage(&__ImageBase, MAKEINTRESOURCE(101), IMAGE_ICON, 32, 32, LR_SHARED);
- SendMessage(WindowHandle, WM_SETICON, ICON_SMALL, (LPARAM)hIconSmall);
- SendMessage(WindowHandle, WM_SETICON, ICON_BIG, (LPARAM)hIconBig);
-#elif defined(LIN32) || defined(LIN64)
- icon = SDL_CreateRGBSurfaceFrom(app_icon, 16, 16, 32, 64, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
- SDL_WM_SetIcon(icon, NULL);
-#endif
- SDL_WM_SetCaption("The Powder Toy", "Powder Toy");
-
- atexit(SDL_Quit);
-
- if(!sdl_opened)
- info = *SDL_GetVideoInfo();
-
- if (info.current_w<((XRES+BARSIZE)*sdl_scale) || info.current_h<((YRES+MENUSIZE)*sdl_scale))
- {
- sdl_scale = 1;
- screen_err = 1;
- fprintf(stderr, "Can't change scale factor, because screen resolution is too small");
- }
-#if defined(OGLR)
- sdl_scrn=SDL_SetVideoMode(XRES*sdl_scale + BARSIZE*sdl_scale,YRES*sdl_scale + MENUSIZE*sdl_scale,32,SDL_OPENGL);
- SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
-
- if(sdl_opened)
- {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- glOrtho(0, (XRES+BARSIZE)*sdl_scale, 0, (YRES+MENUSIZE)*sdl_scale, -1, 1);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- else
- {
-#ifdef WIN32
- status = glewInit();
- if(status != GLEW_OK)
- {
- fprintf(stderr, "Initializing Glew: %d\n", status);
- return 0;
- }
-#endif
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- glOrtho(0, (XRES+BARSIZE)*sdl_scale, 0, (YRES+MENUSIZE)*sdl_scale, -1, 1);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- glRasterPos2i(0, (YRES+MENUSIZE));
- glPixelZoom(1, -1);
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- //FBO Texture
- glEnable(GL_TEXTURE_2D);
- glGenTextures(1, &partsFboTex);
- glBindTexture(GL_TEXTURE_2D, partsFboTex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, XRES, YRES, 0, GL_RGBA, GL_FLOAT, NULL);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
- //FBO
- glGenFramebuffers(1, &partsFbo);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
- glEnable(GL_BLEND);
- glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, partsFboTex, 0);
- glBindTexture(GL_TEXTURE_2D, 0);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); // Reset framebuffer binding
- glDisable(GL_TEXTURE_2D);
-
- //Texture for main UI
- glEnable(GL_TEXTURE_2D);
- glGenTextures(1, &vidBuf);
- glBindTexture(GL_TEXTURE_2D, vidBuf);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, XRES+BARSIZE, YRES+MENUSIZE, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
-
- //Texture for air to be drawn
- glEnable(GL_TEXTURE_2D);
- glGenTextures(1, &airBuf);
- glBindTexture(GL_TEXTURE_2D, airBuf);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
-
- //Zoom texture
- glEnable(GL_TEXTURE_2D);
- glGenTextures(1, &zoomTex);
- glBindTexture(GL_TEXTURE_2D, zoomTex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
-
- //Texture for velocity maps for gravity
- glEnable(GL_TEXTURE_2D);
- glGenTextures(1, &partsTFX);
- glBindTexture(GL_TEXTURE_2D, partsTFX);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glGenTextures(1, &partsTFY);
- glBindTexture(GL_TEXTURE_2D, partsTFY);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
-
- //Texture for velocity maps for air
- //TODO: Combine all air maps into 3D array or structs
- glEnable(GL_TEXTURE_2D);
- glGenTextures(1, &airVX);
- glBindTexture(GL_TEXTURE_2D, airVX);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glGenTextures(1, &airVY);
- glBindTexture(GL_TEXTURE_2D, airVY);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glGenTextures(1, &airPV);
- glBindTexture(GL_TEXTURE_2D, airPV);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, XRES/CELL, YRES/CELL, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
-
- //Fire alpha texture
- glEnable(GL_TEXTURE_2D);
- glGenTextures(1, &fireAlpha);
- glBindTexture(GL_TEXTURE_2D, fireAlpha);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, CELL*3, CELL*3, 0, GL_ALPHA, GL_FLOAT, NULL);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
-
- //Glow alpha texture
- glEnable(GL_TEXTURE_2D);
- glGenTextures(1, &glowAlpha);
- glBindTexture(GL_TEXTURE_2D, glowAlpha);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 11, 11, 0, GL_ALPHA, GL_FLOAT, NULL);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
-
-
- //Blur Alpha texture
- glEnable(GL_TEXTURE_2D);
- glGenTextures(1, &blurAlpha);
- glBindTexture(GL_TEXTURE_2D, blurAlpha);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 7, 7, 0, GL_ALPHA, GL_FLOAT, NULL);
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
-
- glBindTexture(GL_TEXTURE_2D, 0);
- glDisable(GL_TEXTURE_2D);
-
- loadShaders();
- }
-#else
-#ifdef PIX16
- if (kiosk_enable)
- sdl_scrn=SDL_SetVideoMode(XRES*sdl_scale + BARSIZE*sdl_scale,YRES*sdl_scale + MENUSIZE*sdl_scale,16,SDL_FULLSCREEN|SDL_SWSURFACE);
- else
- sdl_scrn=SDL_SetVideoMode(XRES*sdl_scale + BARSIZE*sdl_scale,YRES*sdl_scale + MENUSIZE*sdl_scale,16,SDL_SWSURFACE);
-#else
- if (kiosk_enable)
- sdl_scrn=SDL_SetVideoMode(XRES*sdl_scale + BARSIZE*sdl_scale,YRES*sdl_scale + MENUSIZE*sdl_scale,32,SDL_FULLSCREEN|SDL_SWSURFACE);
- else
- sdl_scrn=SDL_SetVideoMode(XRES*sdl_scale + BARSIZE*sdl_scale,YRES*sdl_scale + MENUSIZE*sdl_scale,32,SDL_SWSURFACE);
-#endif
-#endif
- if (!sdl_scrn)
- {
- fprintf(stderr, "Creating window: %s\n", SDL_GetError());
- return 0;
- }
- SDL_EnableUNICODE(1);
- //SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-#if (defined(LIN32) || defined(LIN64)) && defined(SDL_VIDEO_DRIVER_X11)
- SDL_EventState(SDL_SYSWMEVENT, SDL_ENABLE);
- SDL_VERSION(&sdl_wminfo.version);
- SDL_GetWMInfo(&sdl_wminfo);
- sdl_wminfo.info.x11.lock_func();
- XA_CLIPBOARD = XInternAtom(sdl_wminfo.info.x11.display, "CLIPBOARD", 1);
- XA_TARGETS = XInternAtom(sdl_wminfo.info.x11.display, "TARGETS", 1);
- sdl_wminfo.info.x11.unlock_func();
-#endif
-
- if (screen_err)
- error_ui(vid_buf, 0, "Can't change scale factor, because screen resolution is too small");
- sdl_opened = 1;
- return 1;
-}
-#ifdef OGLR
-void checkShader(GLuint shader, char * shname)
-{
- GLuint status;
- glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
- if (status == GL_FALSE)
- {
- char errorBuf[ GL_INFO_LOG_LENGTH];
- int errLen;
- glGetShaderInfoLog(shader, GL_INFO_LOG_LENGTH, &errLen, errorBuf);
- fprintf(stderr, "Failed to compile %s shader:\n%s\n", shname, errorBuf);
- exit(1);
- }
-}
-void checkProgram(GLuint program, char * progname)
-{
- GLuint status;
- glGetProgramiv(program, GL_LINK_STATUS, &status);
- if (status == GL_FALSE)
- {
- char errorBuf[ GL_INFO_LOG_LENGTH];
- int errLen;
- glGetShaderInfoLog(program, GL_INFO_LOG_LENGTH, &errLen, errorBuf);
- fprintf(stderr, "Failed to link %s program:\n%s\n", progname, errorBuf);
- exit(1);
- }
-}
-void loadShaders()
-{
- GLuint vertexShader, fragmentShader;
-
- //Particle texture
- vertexShader = glCreateShader(GL_VERTEX_SHADER);
- fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
-
- glShaderSource( vertexShader, 1, &fireVertex, NULL);
- glShaderSource( fragmentShader, 1, &fireFragment, NULL);
-
- glCompileShader( vertexShader );
- checkShader(vertexShader, "FV");
- glCompileShader( fragmentShader );
- checkShader(fragmentShader, "FF");
-
- fireProg = glCreateProgram();
- glAttachShader( fireProg, vertexShader );
- glAttachShader( fireProg, fragmentShader );
- glLinkProgram( fireProg );
- checkProgram(fireProg, "F");
-
- //Lensing
- vertexShader = glCreateShader(GL_VERTEX_SHADER);
- fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
-
- glShaderSource( vertexShader, 1, &lensVertex, NULL);
- glShaderSource( fragmentShader, 1, &lensFragment, NULL);
-
- glCompileShader( vertexShader );
- checkShader(vertexShader, "LV");
- glCompileShader( fragmentShader );
- checkShader(fragmentShader, "LF");
-
- lensProg = glCreateProgram();
- glAttachShader( lensProg, vertexShader );
- glAttachShader( lensProg, fragmentShader );
- glLinkProgram( lensProg );
- checkProgram(lensProg, "L");
-
- //Air Velocity
- vertexShader = glCreateShader(GL_VERTEX_SHADER);
- fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
-
- glShaderSource( vertexShader, 1, &airVVertex, NULL);
- glShaderSource( fragmentShader, 1, &airVFragment, NULL);
-
- glCompileShader( vertexShader );
- checkShader(vertexShader, "AVX");
- glCompileShader( fragmentShader );
- checkShader(fragmentShader, "AVF");
-
- airProg_Velocity = glCreateProgram();
- glAttachShader( airProg_Velocity, vertexShader );
- glAttachShader( airProg_Velocity, fragmentShader );
- glLinkProgram( airProg_Velocity );
- checkProgram(airProg_Velocity, "AV");
-
- //Air Pressure
- vertexShader = glCreateShader(GL_VERTEX_SHADER);
- fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
-
- glShaderSource( vertexShader, 1, &airPVertex, NULL);
- glShaderSource( fragmentShader, 1, &airPFragment, NULL);
-
- glCompileShader( vertexShader );
- checkShader(vertexShader, "APV");
- glCompileShader( fragmentShader );
- checkShader(fragmentShader, "APF");
-
- airProg_Pressure = glCreateProgram();
- glAttachShader( airProg_Pressure, vertexShader );
- glAttachShader( airProg_Pressure, fragmentShader );
- glLinkProgram( airProg_Pressure );
- checkProgram(airProg_Pressure, "AP");
-
- //Air cracker
- vertexShader = glCreateShader(GL_VERTEX_SHADER);
- fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
-
- glShaderSource( vertexShader, 1, &airCVertex, NULL);
- glShaderSource( fragmentShader, 1, &airCFragment, NULL);
-
- glCompileShader( vertexShader );
- checkShader(vertexShader, "ACV");
- glCompileShader( fragmentShader );
- checkShader(fragmentShader, "ACF");
-
- airProg_Cracker = glCreateProgram();
- glAttachShader( airProg_Cracker, vertexShader );
- glAttachShader( airProg_Cracker, fragmentShader );
- glLinkProgram( airProg_Cracker );
- checkProgram(airProg_Cracker, "AC");
-}
-#endif
-int draw_debug_info(pixel* vid, int lm, int lx, int ly, int cx, int cy, int line_x, int line_y)
-{
- char infobuf[256];
- if(debug_flags & DEBUG_PERFORMANCE_FRAME || debug_flags & DEBUG_PERFORMANCE_CALC)
- {
- int t1, t2, x = 0, i = debug_perf_istart;
- float partiavg = 0, frameavg = 0;
- while(i != debug_perf_iend)
- {
- partiavg += abs(debug_perf_partitime[i]/100000);
- frameavg += abs(debug_perf_frametime[i]/100000);
- if(debug_flags & DEBUG_PERFORMANCE_CALC)
- t1 = abs(debug_perf_partitime[i]/100000);
- else
- t1 = 0;
-
- if(debug_flags & DEBUG_PERFORMANCE_FRAME)
- t2 = abs(debug_perf_frametime[i]/100000);
- else
- t2 = 0;
-
- if(t1 > YRES)
- t1 = YRES;
- if(t1+t2 > YRES)
- t2 = YRES-t1;
-
- if(t1>0)
- draw_line(vid, x, YRES, x, YRES-t1, 0, 255, 120, XRES+BARSIZE);
- if(t2>0)
- draw_line(vid, x, YRES-t1, x, YRES-(t1+t2), 255, 120, 0, XRES+BARSIZE);
-
- i++;
- x++;
- i %= DEBUG_PERF_FRAMECOUNT;
- }
-
- if(debug_flags & DEBUG_PERFORMANCE_CALC)
- t1 = abs(partiavg / x);
- else
- t1 = 0;
-
- if(debug_flags & DEBUG_PERFORMANCE_FRAME)
- t2 = abs(frameavg / x);
- else
- t2 = 0;
-
- if(t1 > YRES)
- t1 = YRES;
- if(t1+t2 > YRES)
- t2 = YRES-t1;
-
- if(t1>0)
- fillrect(vid, x, YRES-t1-1, 5, t1+2, 0, 255, 0, 255);
- if(t2>0)
- fillrect(vid, x, (YRES-t1)-t2-1, 5, t2+1, 255, 0, 0, 255);
- }
- if(debug_flags & DEBUG_DRAWTOOL)
- {
- if(lm == 1) //Line tool
- {
- blend_line(vid, 0, line_y, XRES, line_y, 255, 255, 255, 120);
- blend_line(vid, line_x, 0, line_x, YRES, 255, 255, 255, 120);
-
- blend_line(vid, 0, ly, XRES, ly, 255, 255, 255, 120);
- blend_line(vid, lx, 0, lx, YRES, 255, 255, 255, 120);
-
- sprintf(infobuf, "%d x %d", lx, ly);
- drawtext_outline(vid, lx+(lx>line_x?3:-textwidth(infobuf)-3), ly+(ly<line_y?-10:3), infobuf, 255, 255, 255, 200, 0, 0, 0, 120);
-
- sprintf(infobuf, "%d x %d", line_x, line_y);
- drawtext_outline(vid, line_x+(lx<line_x?3:-textwidth(infobuf)-2), line_y+(ly>line_y?-10:3), infobuf, 255, 255, 255, 200, 0, 0, 0, 120);
-
- sprintf(infobuf, "%d", abs(line_x-lx));
- drawtext_outline(vid, (line_x+lx)/2-textwidth(infobuf)/2, line_y+(ly>line_y?-10:3), infobuf, 255, 255, 255, 200, 0, 0, 0, 120);
-
- sprintf(infobuf, "%d", abs(line_y-ly));
- drawtext_outline(vid, line_x+(lx<line_x?3:-textwidth(infobuf)-2), (line_y+ly)/2-3, infobuf, 255, 255, 255, 200, 0, 0, 0, 120);
- }
- }
- if(debug_flags & DEBUG_PARTS)
- {
- int i = 0, x = 0, y = 0, lpx = 0, lpy = 0;
- sprintf(infobuf, "%d/%d (%.2f%%)", parts_lastActiveIndex, NPART, (((float)parts_lastActiveIndex)/((float)NPART))*100.0f);
- for(i = 0; i < NPART; i++){
- if(parts[i].type){
- drawpixel(vid, x, y, 255, 255, 255, 180);
- } else {
- drawpixel(vid, x, y, 0, 0, 0, 180);
- }
- if(i == parts_lastActiveIndex)
- {
- lpx = x;
- lpy = y;
- }
- x++;
- if(x>=XRES){
- y++;
- x = 0;
- }
- }
- draw_line(vid, 0, lpy, XRES, lpy, 0, 255, 120, XRES+BARSIZE);
- draw_line(vid, lpx, 0, lpx, YRES, 0, 255, 120, XRES+BARSIZE);
- drawpixel(vid, lpx, lpy, 255, 50, 50, 220);
-
- drawpixel(vid, lpx+1, lpy, 255, 50, 50, 120);
- drawpixel(vid, lpx-1, lpy, 255, 50, 50, 120);
- drawpixel(vid, lpx, lpy+1, 255, 50, 50, 120);
- drawpixel(vid, lpx, lpy-1, 255, 50, 50, 120);
-
- fillrect(vid, 7, YRES-26, textwidth(infobuf)+5, 14, 0, 0, 0, 180);
- drawtext(vid, 10, YRES-22, infobuf, 255, 255, 255, 255);
- }
-}
diff --git a/src/gravity.c b/src/gravity.c
deleted file mode 100644
index 7b70ee5..0000000
--- a/src/gravity.c
+++ /dev/null
@@ -1,525 +0,0 @@
-/**
- * Powder Toy - Newtonian gravity
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <math.h>
-#include <sys/types.h>
-#include <pthread.h>
-#include "defines.h"
-#include "gravity.h"
-#include "powder.h"
-
-#ifdef GRAVFFT
-#include <fftw3.h>
-#endif
-
-
-float *gravmap = NULL;//Maps to be used by the main thread
-float *gravp = NULL;
-float *gravy = NULL;
-float *gravx = NULL;
-unsigned *gravmask = NULL;
-
-float *th_ogravmap = NULL;// Maps to be processed by the gravity thread
-float *th_gravmap = NULL;
-float *th_gravx = NULL;
-float *th_gravy = NULL;
-float *th_gravp = NULL;
-
-int gravwl_timeout = 0;
-int gravityMode = 0; // starts enabled in "vertical" mode...
-int ngrav_enable = 0; //Newtonian gravity
-int th_gravchanged = 0;
-
-pthread_t gravthread;
-pthread_mutex_t gravmutex;
-pthread_cond_t gravcv;
-int grav_ready = 0;
-int gravthread_done = 0;
-
-void bilinear_interpolation(float *src, float *dst, int sw, int sh, int rw, int rh)
-{
- int y, x, fxceil, fyceil;
- float fx, fy, fyc, fxc;
- double intp;
- float tr, tl, br, bl;
- //Bilinear interpolation for upscaling
- for (y=0; y<rh; y++)
- for (x=0; x<rw; x++)
- {
- fx = ((float)x)*((float)sw)/((float)rw);
- fy = ((float)y)*((float)sh)/((float)rh);
- fxc = modf(fx, &intp);
- fyc = modf(fy, &intp);
- fxceil = (int)ceil(fx);
- fyceil = (int)ceil(fy);
- if (fxceil>=sw) fxceil = sw-1;
- if (fyceil>=sh) fyceil = sh-1;
- tr = src[sw*(int)floor(fy)+fxceil];
- tl = src[sw*(int)floor(fy)+(int)floor(fx)];
- br = src[sw*fyceil+fxceil];
- bl = src[sw*fyceil+(int)floor(fx)];
- dst[rw*y+x] = ((tl*(1.0f-fxc))+(tr*(fxc)))*(1.0f-fyc) + ((bl*(1.0f-fxc))+(br*(fxc)))*(fyc);
- }
-}
-
-void gravity_init()
-{
- //Allocate full size Gravmaps
- th_ogravmap = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
- th_gravmap = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
- th_gravy = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
- th_gravx = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
- th_gravp = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
- gravmap = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
- gravy = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
- gravx = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
- gravp = calloc((XRES/CELL)*(YRES/CELL), sizeof(float));
- gravmask = calloc((XRES/CELL)*(YRES/CELL), sizeof(unsigned));
-}
-
-void gravity_cleanup()
-{
-#ifdef GRAVFFT
- grav_fft_cleanup();
-#endif
-}
-
-void gravity_update_async()
-{
- int result;
- if(ngrav_enable)
- {
- pthread_mutex_lock(&gravmutex);
- result = grav_ready;
- if(result) //Did the gravity thread finish?
- {
- if (!sys_pause||framerender){ //Only update if not paused
- //Switch the full size gravmaps, we don't really need the two above any more
- float *tmpf;
-
- if(th_gravchanged)
- {
- #if !defined(GRAVFFT) && defined(GRAV_DIFF)
- memcpy(gravy, th_gravy, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- memcpy(gravx, th_gravx, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- memcpy(gravp, th_gravp, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- #else
- tmpf = gravy;
- gravy = th_gravy;
- th_gravy = tmpf;
-
- tmpf = gravx;
- gravx = th_gravx;
- th_gravx = tmpf;
-
- tmpf = gravp;
- gravp = th_gravp;
- th_gravp = tmpf;
- #endif
- }
-
- tmpf = gravmap;
- gravmap = th_gravmap;
- th_gravmap = tmpf;
-
- grav_ready = 0; //Tell the other thread that we're ready for it to continue
- pthread_cond_signal(&gravcv);
- }
- }
- pthread_mutex_unlock(&gravmutex);
- //Apply the gravity mask
- membwand(gravy, gravmask, (XRES/CELL)*(YRES/CELL)*sizeof(float), (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
- membwand(gravx, gravmask, (XRES/CELL)*(YRES/CELL)*sizeof(float), (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
- memset(gravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- }
-}
-
-void* update_grav_async(void* unused)
-{
- int done = 0;
- int thread_done = 0;
- memset(th_ogravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- memset(th_gravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- memset(th_gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- memset(th_gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- memset(th_gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- //memset(th_gravy, 0, XRES*YRES*sizeof(float));
- //memset(th_gravx, 0, XRES*YRES*sizeof(float));
- //memset(th_gravp, 0, XRES*YRES*sizeof(float));
-#ifdef GRAVFFT
- grav_fft_init();
-#endif
- while(!thread_done){
- if(!done){
- update_grav();
- done = 1;
- pthread_mutex_lock(&gravmutex);
-
- grav_ready = done;
- thread_done = gravthread_done;
-
- pthread_mutex_unlock(&gravmutex);
- } else {
- pthread_mutex_lock(&gravmutex);
- pthread_cond_wait(&gravcv, &gravmutex);
-
- done = grav_ready;
- thread_done = gravthread_done;
-
- pthread_mutex_unlock(&gravmutex);
- }
- }
- pthread_exit(NULL);
-}
-
-void start_grav_async()
-{
- if(!ngrav_enable){
- gravthread_done = 0;
- grav_ready = 0;
- pthread_mutex_init (&gravmutex, NULL);
- pthread_cond_init(&gravcv, NULL);
- pthread_create(&gravthread, NULL, update_grav_async, NULL); //Start asynchronous gravity simulation
- ngrav_enable = 1;
- }
- memset(gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- memset(gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- memset(gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
-}
-
-void stop_grav_async()
-{
- if(ngrav_enable){
- pthread_mutex_lock(&gravmutex);
- gravthread_done = 1;
- pthread_cond_signal(&gravcv);
- pthread_mutex_unlock(&gravmutex);
- pthread_join(gravthread, NULL);
- pthread_mutex_destroy(&gravmutex); //Destroy the mutex
- ngrav_enable = 0;
- }
- //Clear the grav velocities
- memset(gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- memset(gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- memset(gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
-}
-
-#ifdef GRAVFFT
-int grav_fft_status = 0;
-float *th_ptgravx, *th_ptgravy, *th_gravmapbig, *th_gravxbig, *th_gravybig;
-fftwf_complex *th_ptgravxt, *th_ptgravyt, *th_gravmapbigt, *th_gravxbigt, *th_gravybigt;
-fftwf_plan plan_gravmap, plan_gravx_inverse, plan_gravy_inverse;
-
-void grav_fft_init()
-{
- int xblock2 = XRES/CELL*2;
- int yblock2 = YRES/CELL*2;
- int x, y, fft_tsize = (xblock2/2+1)*yblock2;
- float distance, scaleFactor;
- fftwf_plan plan_ptgravx, plan_ptgravy;
- if (grav_fft_status) return;
-
- //use fftw malloc function to ensure arrays are aligned, to get better performance
- th_ptgravx = fftwf_malloc(xblock2*yblock2*sizeof(float));
- th_ptgravy = fftwf_malloc(xblock2*yblock2*sizeof(float));
- th_ptgravxt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
- th_ptgravyt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
- th_gravmapbig = fftwf_malloc(xblock2*yblock2*sizeof(float));
- th_gravmapbigt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
- th_gravxbig = fftwf_malloc(xblock2*yblock2*sizeof(float));
- th_gravybig = fftwf_malloc(xblock2*yblock2*sizeof(float));
- th_gravxbigt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
- th_gravybigt = fftwf_malloc(fft_tsize*sizeof(fftwf_complex));
-
- //select best algorithm, could use FFTW_PATIENT or FFTW_EXHAUSTIVE but that increases the time taken to plan, and I don't see much increase in execution speed
- plan_ptgravx = fftwf_plan_dft_r2c_2d(yblock2, xblock2, th_ptgravx, th_ptgravxt, FFTW_MEASURE);
- plan_ptgravy = fftwf_plan_dft_r2c_2d(yblock2, xblock2, th_ptgravy, th_ptgravyt, FFTW_MEASURE);
- plan_gravmap = fftwf_plan_dft_r2c_2d(yblock2, xblock2, th_gravmapbig, th_gravmapbigt, FFTW_MEASURE);
- plan_gravx_inverse = fftwf_plan_dft_c2r_2d(yblock2, xblock2, th_gravxbigt, th_gravxbig, FFTW_MEASURE);
- plan_gravy_inverse = fftwf_plan_dft_c2r_2d(yblock2, xblock2, th_gravybigt, th_gravybig, FFTW_MEASURE);
-
- //(XRES/CELL)*(YRES/CELL)*4 is size of data array, scaling needed because FFTW calculates an unnormalized DFT
- scaleFactor = -M_GRAV/((XRES/CELL)*(YRES/CELL)*4);
- //calculate velocity map caused by a point mass
- for (y=0; y<yblock2; y++)
- {
- for (x=0; x<xblock2; x++)
- {
- if (x==XRES/CELL && y==YRES/CELL) continue;
- distance = sqrtf(pow(x-(XRES/CELL), 2) + pow(y-(YRES/CELL), 2));
- th_ptgravx[y*xblock2+x] = scaleFactor*(x-(XRES/CELL)) / pow(distance, 3);
- th_ptgravy[y*xblock2+x] = scaleFactor*(y-(YRES/CELL)) / pow(distance, 3);
- }
- }
- th_ptgravx[yblock2*xblock2/2+xblock2/2] = 0.0f;
- th_ptgravy[yblock2*xblock2/2+xblock2/2] = 0.0f;
-
- //transform point mass velocity maps
- fftwf_execute(plan_ptgravx);
- fftwf_execute(plan_ptgravy);
- fftwf_destroy_plan(plan_ptgravx);
- fftwf_destroy_plan(plan_ptgravy);
- fftwf_free(th_ptgravx);
- fftwf_free(th_ptgravy);
-
- //clear padded gravmap
- memset(th_gravmapbig,0,xblock2*yblock2*sizeof(float));
-
- grav_fft_status = 1;
-}
-
-void grav_fft_cleanup()
-{
- if (!grav_fft_status) return;
- fftwf_free(th_ptgravxt);
- fftwf_free(th_ptgravyt);
- fftwf_free(th_gravmapbig);
- fftwf_free(th_gravmapbigt);
- fftwf_free(th_gravxbig);
- fftwf_free(th_gravybig);
- fftwf_free(th_gravxbigt);
- fftwf_free(th_gravybigt);
- fftwf_destroy_plan(plan_gravmap);
- fftwf_destroy_plan(plan_gravx_inverse);
- fftwf_destroy_plan(plan_gravy_inverse);
- grav_fft_status = 0;
-}
-
-void update_grav()
-{
- int x, y, changed = 0;
- int xblock2 = XRES/CELL*2, yblock2 = YRES/CELL*2;
- int i, fft_tsize = (xblock2/2+1)*yblock2;
- float mr, mc, pr, pc, gr, gc;
- for (y=0; y<YRES/CELL; y++)
- {
- if(changed)
- break;
- for (x=0; x<XRES/CELL; x++)
- {
- if(th_ogravmap[y*(XRES/CELL)+x]!=th_gravmap[y*(XRES/CELL)+x]){
- changed = 1;
- break;
- }
- }
- }
- if(changed)
- {
- th_gravchanged = 1;
- if (!grav_fft_status) grav_fft_init();
-
- //copy gravmap into padded gravmap array
- for (y=0; y<YRES/CELL; y++)
- {
- for (x=0; x<XRES/CELL; x++)
- {
- th_gravmapbig[(y+YRES/CELL)*xblock2+XRES/CELL+x] = th_gravmap[y*(XRES/CELL)+x];
- }
- }
- //transform gravmap
- fftwf_execute(plan_gravmap);
- //do convolution (multiply the complex numbers)
- for (i=0; i<fft_tsize; i++)
- {
- mr = th_gravmapbigt[i][0];
- mc = th_gravmapbigt[i][1];
- pr = th_ptgravxt[i][0];
- pc = th_ptgravxt[i][1];
- gr = mr*pr-mc*pc;
- gc = mr*pc+mc*pr;
- th_gravxbigt[i][0] = gr;
- th_gravxbigt[i][1] = gc;
- pr = th_ptgravyt[i][0];
- pc = th_ptgravyt[i][1];
- gr = mr*pr-mc*pc;
- gc = mr*pc+mc*pr;
- th_gravybigt[i][0] = gr;
- th_gravybigt[i][1] = gc;
- }
- //inverse transform, and copy from padded arrays into normal velocity maps
- fftwf_execute(plan_gravx_inverse);
- fftwf_execute(plan_gravy_inverse);
- for (y=0; y<YRES/CELL; y++)
- {
- for (x=0; x<XRES/CELL; x++)
- {
- th_gravx[y*(XRES/CELL)+x] = th_gravxbig[y*xblock2+x];
- th_gravy[y*(XRES/CELL)+x] = th_gravybig[y*xblock2+x];
- th_gravp[y*(XRES/CELL)+x] = sqrtf(pow(th_gravxbig[y*xblock2+x],2)+pow(th_gravybig[y*xblock2+x],2));
- }
- }
- }
- else
- {
- th_gravchanged = 0;
- }
- memcpy(th_ogravmap, th_gravmap, (XRES/CELL)*(YRES/CELL)*sizeof(float));
-}
-
-#else
-// gravity without fast Fourier transforms
-
-void update_grav(void)
-{
- int x, y, i, j, changed = 0;
- float val, distance;
- th_gravchanged = 0;
-#ifndef GRAV_DIFF
- //Find any changed cells
- for (i=0; i<YRES/CELL; i++)
- {
- if(changed)
- break;
- for (j=0; j<XRES/CELL; j++)
- {
- if(th_ogravmap[i*(XRES/CELL)+j]!=th_gravmap[i*(XRES/CELL)+j]){
- changed = 1;
- break;
- }
- }
- }
- if(!changed)
- goto fin;
- memset(th_gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- memset(th_gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
-#endif
- th_gravchanged = 1;
- for (i = 0; i < YRES / CELL; i++) {
- for (j = 0; j < XRES / CELL; j++) {
-#ifdef GRAV_DIFF
- if (th_ogravmap[i*(XRES/CELL)+j] != th_gravmap[i*(XRES/CELL)+j])
- {
-#else
- if (th_gravmap[i*(XRES/CELL)+j] > 0.0001f || th_gravmap[i*(XRES/CELL)+j]<-0.0001f) //Only calculate with populated or changed cells.
- {
-#endif
- for (y = 0; y < YRES / CELL; y++) {
- for (x = 0; x < XRES / CELL; x++) {
- if (x == j && y == i)//Ensure it doesn't calculate with itself
- continue;
- distance = sqrt(pow(j - x, 2) + pow(i - y, 2));
-#ifdef GRAV_DIFF
- val = th_gravmap[i*(XRES/CELL)+j] - th_ogravmap[i*(XRES/CELL)+j];
-#else
- val = th_gravmap[i*(XRES/CELL)+j];
-#endif
- th_gravx[y*(XRES/CELL)+x] += M_GRAV * val * (j - x) / pow(distance, 3);
- th_gravy[y*(XRES/CELL)+x] += M_GRAV * val * (i - y) / pow(distance, 3);
- th_gravp[y*(XRES/CELL)+x] += M_GRAV * val / pow(distance, 2);
- }
- }
- }
- }
- }
-fin:
- memcpy(th_ogravmap, th_gravmap, (XRES/CELL)*(YRES/CELL)*sizeof(float));
-}
-#endif
-
-
-
-void grav_mask_r(int x, int y, char checkmap[YRES/CELL][XRES/CELL], char shape[YRES/CELL][XRES/CELL], char *shapeout)
-{
- if(x < 0 || x >= XRES/CELL || y < 0 || y >= YRES/CELL)
- return;
- if(x == 0 || y ==0 || y == (YRES/CELL)-1 || x == (XRES/CELL)-1)
- *shapeout = 1;
- checkmap[y][x] = 1;
- shape[y][x] = 1;
- if(x-1 >= 0 && !checkmap[y][x-1] && bmap[y][x-1]!=WL_GRAV)
- grav_mask_r(x-1, y, checkmap, shape, shapeout);
- if(y-1 >= 0 && !checkmap[y-1][x] && bmap[y-1][x]!=WL_GRAV)
- grav_mask_r(x, y-1, checkmap, shape, shapeout);
- if(x+1 < XRES/CELL && !checkmap[y][x+1] && bmap[y][x+1]!=WL_GRAV)
- grav_mask_r(x+1, y, checkmap, shape, shapeout);
- if(y+1 < YRES/CELL && !checkmap[y+1][x] && bmap[y+1][x]!=WL_GRAV)
- grav_mask_r(x, y+1, checkmap, shape, shapeout);
- return;
-}
-struct mask_el {
- char *shape;
- char shapeout;
- void *next;
-};
-typedef struct mask_el mask_el;
-void mask_free(mask_el *c_mask_el){
- if(c_mask_el==NULL)
- return;
- if(c_mask_el->next!=NULL)
- mask_free(c_mask_el->next);
- free(c_mask_el->shape);
- free(c_mask_el);
-}
-void gravity_mask()
-{
- char checkmap[YRES/CELL][XRES/CELL];
- int x = 0, y = 0, i, j;
- unsigned maskvalue;
- mask_el *t_mask_el = NULL;
- mask_el *c_mask_el = NULL;
- if(!gravmask)
- return;
- memset(checkmap, 0, sizeof(checkmap));
- for(x = 0; x < XRES/CELL; x++)
- {
- for(y = 0; y < YRES/CELL; y++)
- {
- if(bmap[y][x]!=WL_GRAV && checkmap[y][x] == 0)
- {
- //Create a new shape
- if(t_mask_el==NULL){
- t_mask_el = malloc(sizeof(mask_el));
- t_mask_el->shape = malloc((XRES/CELL)*(YRES/CELL));
- memset(t_mask_el->shape, 0, (XRES/CELL)*(YRES/CELL));
- t_mask_el->shapeout = 0;
- t_mask_el->next = NULL;
- c_mask_el = t_mask_el;
- } else {
- c_mask_el->next = malloc(sizeof(mask_el));
- c_mask_el = c_mask_el->next;
- c_mask_el->shape = malloc((XRES/CELL)*(YRES/CELL));
- memset(c_mask_el->shape, 0, (XRES/CELL)*(YRES/CELL));
- c_mask_el->shapeout = 0;
- c_mask_el->next = NULL;
- }
- //Fill the shape
- grav_mask_r(x, y, checkmap, c_mask_el->shape, &c_mask_el->shapeout);
- }
- }
- }
- c_mask_el = t_mask_el;
- memset(gravmask, 0, (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
- while(c_mask_el!=NULL)
- {
- char *cshape = c_mask_el->shape;
- for(x = 0; x < XRES/CELL; x++)
- {
- for(y = 0; y < YRES/CELL; y++)
- {
- if(cshape[y*(XRES/CELL)+x]){
- if(c_mask_el->shapeout)
- maskvalue = 0xFFFFFFFF;
- else
- maskvalue = 0x00000000;
- gravmask[y*(XRES/CELL)+x] = maskvalue;
- }
- }
- }
- c_mask_el = c_mask_el->next;
- }
- mask_free(t_mask_el);
-}
diff --git a/src/http.c b/src/http.c
deleted file mode 100644
index b188a16..0000000
--- a/src/http.c
+++ /dev/null
@@ -1,1079 +0,0 @@
-/**
- * Powder Toy - HTTP Library
- *
- * Copyright (c) 2008 - 2010 Stanislaw Skowronek.
- * Copyright (c) 2010 Simon Robertshaw
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#ifndef WIN32
-#include <sys/param.h>
-#endif
-#if !defined(MACOSX) && !defined(BSD)
-#include <malloc.h>
-#endif
-#include <time.h>
-#ifdef WIN32
-#define _WIN32_WINNT 0x0501
-//#include <iphlpapi.h>
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#else
-#include <sys/types.h>
-#include <unistd.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <sys/socket.h>
-#include <netdb.h>
-#include <netinet/in.h>
-#endif
-
-#include <defines.h>
-#include <http.h>
-#include <md5.h>
-
-#ifdef WIN32
-#define PERROR SOCKET_ERROR
-#define PERRNO WSAGetLastError()
-#define PEAGAIN WSAEWOULDBLOCK
-#define PEINTR WSAEINTR
-#define PEINPROGRESS WSAEINPROGRESS
-#define PEALREADY WSAEALREADY
-#define PCLOSE closesocket
-#else
-#define PERROR -1
-#define PERRNO errno
-#define PEAGAIN EAGAIN
-#define PEINTR EINTR
-#define PEINPROGRESS EINPROGRESS
-#define PEALREADY EALREADY
-#define PCLOSE close
-#endif
-
-static int http_up = 0;
-static long http_timeout = 15;
-static int http_use_proxy = 0;
-static struct sockaddr_in http_proxy;
-
-static char *mystrdup(char *s)
-{
- char *x;
- if (s)
- {
- x = malloc(strlen(s)+1);
- strcpy(x, s);
- return x;
- }
- return s;
-}
-
-static int splituri(char *uri, char **host, char **path)
-{
- char *p=uri,*q,*x,*y;
- if (!strncmp(p, "http://", 7))
- p += 7;
- q = strchr(p, '/');
- if (!q)
- q = p + strlen(p);
- x = malloc(q-p+1);
- if (*q)
- y = mystrdup(q);
- else
- y = mystrdup("/");
- strncpy(x, p, q-p);
- x[q-p] = 0;
- if (q==p || x[q-p-1]==':')
- {
- free(x);
- free(y);
- return 1;
- }
- *host = x;
- *path = y;
- return 0;
-}
-
-static char *getserv(char *host)
-{
- char *q, *x = mystrdup(host);
- q = strchr(x, ':');
- if (q)
- *q = 0;
- return x;
-}
-
-static char *getport(char *host)
-{
- char *p, *q;
- q = strchr(host, ':');
- if (q)
- p = mystrdup(q+1);
- else
- p = mystrdup("80");
- return p;
-}
-
-static int resolve(char *dns, char *srv, struct sockaddr_in *addr)
-{
- struct addrinfo hnt, *res = 0;
- if (http_use_proxy)
- {
- memcpy(addr, &http_proxy, sizeof(struct sockaddr_in));
- return 0;
- }
- memset(&hnt, 0, sizeof(hnt));
- hnt.ai_family = AF_INET;
- hnt.ai_socktype = SOCK_STREAM;
- if (getaddrinfo(dns, srv, &hnt, &res))
- return 1;
- if (res)
- {
- if (res->ai_family != AF_INET)
- {
- freeaddrinfo(res);
- return 1;
- }
- memcpy(addr, res->ai_addr, res->ai_addrlen);
- freeaddrinfo(res);
- return 0;
- }
- return 1;
-}
-
-void http_init(char *proxy)
-{
- char *host, *port;
-#ifdef WIN32
- WSADATA wsadata;
- if (!WSAStartup(MAKEWORD(2,2), &wsadata))
- http_up = 1;
-#else
- signal(SIGPIPE, SIG_IGN);
- http_up = 1;
-#endif
- if (proxy)
- {
- host = getserv(proxy);
- port = getport(proxy);
- if (resolve(host, port, &http_proxy))
- http_up = 0;
- else
- http_use_proxy = 1;
- free(host);
- free(port);
- }
-}
-
-void http_done(void)
-{
-#ifdef WIN32
- WSACleanup();
-#endif
- http_up = 0;
-}
-
-#define CHUNK 4096
-
-#define HTS_STRT 0
-#define HTS_RSLV 1
-#define HTS_CONN 2
-#define HTS_IDLE 3
-#define HTS_XMIT 4
-#define HTS_RECV 5
-#define HTS_DONE 6
-struct http_ctx
-{
- int state;
- time_t last;
- int keep;
- int ret;
- char *host, *path;
- char *thdr;
- int thlen;
- char *txd;
- int txdl;
- struct sockaddr_in addr;
- char *tbuf;
- int tlen, tptr;
- char *hbuf;
- int hlen, hptr;
- char *rbuf;
- int rlen, rptr;
- int chunked, chunkhdr, rxtogo, contlen, cclose;
- int fd;
- char *fdhost;
-};
-void *http_async_req_start(void *ctx, char *uri, char *data, int dlen, int keep)
-{
- struct http_ctx *cx = ctx;
- if (!ctx)
- {
- ctx = calloc(1, sizeof(struct http_ctx));
- cx = ctx;
- cx->fd = PERROR;
- }
-
- if (!cx->hbuf)
- {
- cx->hbuf = malloc(256);
- cx->hlen = 256;
- }
-
- if (!http_up)
- {
- cx->ret = 604;
- cx->state = HTS_DONE;
- return ctx;
- }
-
- if (cx->state!=HTS_STRT && cx->state!=HTS_IDLE)
- {
- fprintf(stderr, "HTTP: unclean request restart state.\n");
- exit(1);
- }
-
- cx->keep = keep;
- cx->ret = 600;
- if (splituri(uri, &cx->host, &cx->path))
- {
- cx->ret = 601;
- cx->state = HTS_DONE;
- return ctx;
- }
- if (http_use_proxy)
- {
- free(cx->path);
- cx->path = mystrdup(uri);
- }
- if (cx->fdhost && strcmp(cx->host, cx->fdhost))
- {
- free(cx->fdhost);
- cx->fdhost = NULL;
- PCLOSE(cx->fd);
- cx->fd = PERROR;
- cx->state = HTS_STRT;
- }
- if (data)
- {
- if (!dlen)
- dlen = strlen(data);
- cx->txd = malloc(dlen);
- memcpy(cx->txd, data, dlen);
- cx->txdl = dlen;
- }
- else
- cx->txdl = 0;
-
- cx->contlen = 0;
- cx->chunked = 0;
- cx->chunkhdr = 0;
- cx->rxtogo = 0;
- cx->cclose = 0;
-
- cx->tptr = 0;
- cx->tlen = 0;
-
- cx->last = time(NULL);
-
- return ctx;
-}
-
-void http_async_add_header(void *ctx, char *name, char *data)
-{
- struct http_ctx *cx = ctx;
- cx->thdr = realloc(cx->thdr, cx->thlen + strlen(name) + strlen(data) + 5);
- cx->thlen += sprintf(cx->thdr+cx->thlen, "%s: %s\r\n", name, data);
-}
-
-static void process_header(struct http_ctx *cx, char *str)
-{
- char *p;
- if (cx->chunkhdr)
- {
- p = strchr(str, ';');
- if (p)
- *p = 0;
- cx->rxtogo = strtoul(str, NULL, 16);
- cx->chunkhdr = 0;
- if (!cx->rxtogo)
- cx->chunked = 0;
- }
- if (!str[0])
- {
- cx->rxtogo = cx->contlen;
- cx->chunkhdr = cx->chunked;
- if (!cx->contlen && !cx->chunked && cx->ret!=100)
- cx->state = HTS_DONE;
- return;
- }
- if (!strncmp(str, "HTTP/", 5))
- {
- p = strchr(str, ' ');
- if (!p)
- {
- cx->ret = 603;
- cx->state = HTS_DONE;
- return;
- }
- p++;
- cx->ret = atoi(p);
- return;
- }
- if (!strncmp(str, "Content-Length: ", 16))
- {
- cx->contlen = atoi(str+16);
- return;
- }
- if (!strcmp(str, "Transfer-Encoding: chunked"))
- {
- cx->chunked = 1;
- return;
- }
- if (!strcmp(str, "Connection: close"))
- {
- cx->cclose = 1;
- return;
- }
-}
-
-static void process_byte(struct http_ctx *cx, char ch)
-{
- if (cx->rxtogo)
- {
- cx->rxtogo--;
-
- if (!cx->rbuf)
- {
- cx->rbuf = malloc(256);
- cx->rlen = 256;
- }
- if (cx->rptr >= cx->rlen-1)
- {
- cx->rlen *= 2;
- cx->rbuf = realloc(cx->rbuf, cx->rlen);
- }
- cx->rbuf[cx->rptr++] = ch;
-
- if (!cx->rxtogo && !cx->chunked)
- cx->state = HTS_DONE;
- }
- else
- {
- if (ch == '\n')
- {
- cx->hbuf[cx->hptr] = 0;
- process_header(cx, cx->hbuf);
- cx->hptr = 0;
- }
- else if (ch != '\r')
- {
- if (cx->hptr >= cx->hlen-1)
- {
- cx->hlen *= 2;
- cx->hbuf = realloc(cx->hbuf, cx->hlen);
- }
- cx->hbuf[cx->hptr++] = ch;
- }
- }
-}
-
-int http_async_req_status(void *ctx)
-{
- struct http_ctx *cx = ctx;
- char *dns,*srv,buf[CHUNK];
- int tmp, i;
- time_t now = time(NULL);
-#ifdef WIN32
- unsigned long tmp2;
-#endif
-
- switch (cx->state)
- {
- case HTS_STRT:
- dns = getserv(cx->host);
- srv = getport(cx->host);
- if (resolve(dns, srv, &cx->addr))
- {
- free(dns);
- free(srv);
- cx->state = HTS_DONE;
- cx->ret = 602;
- return 1;
- }
- free(dns);
- free(srv);
- cx->state = HTS_RSLV;
- return 0;
- case HTS_RSLV:
- cx->state = HTS_CONN;
- cx->last = now;
- return 0;
- case HTS_CONN:
- if (cx->fd == PERROR)
- {
- cx->fd = socket(AF_INET, SOCK_STREAM, 0);
- if (cx->fd == PERROR)
- goto fail;
- cx->fdhost = mystrdup(cx->host);
-#ifdef WIN32
- tmp2 = 1;
- if (ioctlsocket(cx->fd, FIONBIO, &tmp2) == SOCKET_ERROR)
- goto fail;
-#else
- tmp = fcntl(cx->fd, F_GETFL);
- if (tmp < 0)
- goto fail;
- if (fcntl(cx->fd, F_SETFL, tmp|O_NONBLOCK) < 0)
- goto fail;
-#endif
- }
- if (!connect(cx->fd, (struct sockaddr *)&cx->addr, sizeof(cx->addr)))
- cx->state = HTS_IDLE;
-#ifdef WIN32
- else if (PERRNO==WSAEISCONN)
- cx->state = HTS_IDLE;
-#endif
-#if defined(MACOSX) || defined(BSD)
- else if (PERRNO==EISCONN)
- cx->state = HTS_IDLE;
-#endif
- else if (PERRNO!=PEINPROGRESS && PERRNO!=PEALREADY
-#ifdef WIN32
- && PERRNO!=PEAGAIN && PERRNO!=WSAEINVAL
-#endif
- )
- goto fail;
- if (now-cx->last>http_timeout)
- goto timeout;
- return 0;
- case HTS_IDLE:
- if (cx->txdl)
- {
- // generate POST
- cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) + 126 + cx->txdl + cx->thlen);
- cx->tptr = 0;
- cx->tlen = 0;
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "POST %s HTTP/1.1\r\n", cx->path);
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\r\n", cx->host);
- if (!cx->keep)
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n");
- if (cx->thdr)
- {
- memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
- cx->tlen += cx->thlen;
- free(cx->thdr);
- cx->thdr = NULL;
- cx->thlen = 0;
- }
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "Content-Length: %d\r\n", cx->txdl);
-#ifdef BETA
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
-#else
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
-#endif
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n");
- memcpy(cx->tbuf+cx->tlen, cx->txd, cx->txdl);
- cx->tlen += cx->txdl;
- free(cx->txd);
- cx->txd = NULL;
- cx->txdl = 0;
- }
- else
- {
- // generate GET
- cx->tbuf = malloc(strlen(cx->host) + strlen(cx->path) +93 + cx->thlen);
- cx->tptr = 0;
- cx->tlen = 0;
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "GET %s HTTP/1.1\r\n", cx->path);
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "Host: %s\r\n", cx->host);
- if (cx->thdr)
- {
- memcpy(cx->tbuf+cx->tlen, cx->thdr, cx->thlen);
- cx->tlen += cx->thlen;
- free(cx->thdr);
- cx->thdr = NULL;
- cx->thlen = 0;
- }
- if (!cx->keep)
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "Connection: close\r\n");
-#ifdef BETA
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dB%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
-#else
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "X-Powder-Version: %s%dS%d\r\n", IDENT_VERSION, SAVE_VERSION, MINOR_VERSION);
-#endif
- cx->tlen += sprintf(cx->tbuf+cx->tlen, "\r\n");
- }
- cx->state = HTS_XMIT;
- cx->last = now;
- return 0;
- case HTS_XMIT:
- tmp = send(cx->fd, cx->tbuf+cx->tptr, cx->tlen-cx->tptr, 0);
- if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
- goto fail;
- if (tmp!=PERROR)
- {
- cx->tptr += tmp;
- if (cx->tptr == cx->tlen)
- {
- cx->tptr = 0;
- cx->tlen = 0;
- if (cx->tbuf)
- free(cx->tbuf);
- cx->state = HTS_RECV;
- }
- cx->last = now;
- }
- if (now-cx->last>http_timeout)
- goto timeout;
- return 0;
- case HTS_RECV:
- tmp = recv(cx->fd, buf, CHUNK, 0);
- if (tmp==PERROR && PERRNO!=PEAGAIN && PERRNO!=PEINTR)
- goto fail;
- if (tmp!=PERROR)
- {
- for (i=0; i<tmp; i++)
- {
- process_byte(cx, buf[i]);
- if (cx->state == HTS_DONE)
- return 1;
- }
- cx->last = now;
- }
- if (now-cx->last>http_timeout)
- goto timeout;
- return 0;
- case HTS_DONE:
- return 1;
- }
- return 0;
-
-fail:
- cx->ret = 600;
- cx->state = HTS_DONE;
- return 1;
-
-timeout:
- cx->ret = 605;
- cx->state = HTS_DONE;
- return 1;
-}
-
-char *http_async_req_stop(void *ctx, int *ret, int *len)
-{
- struct http_ctx *cx = ctx;
- char *rxd;
-
- if (cx->state != HTS_DONE)
- while (!http_async_req_status(ctx)) ;
-
- if (cx->host)
- {
- free(cx->host);
- cx->host = NULL;
- }
- if (cx->path)
- {
- free(cx->path);
- cx->path = NULL;
- }
- if (cx->txd)
- {
- free(cx->txd);
- cx->txd = NULL;
- cx->txdl = 0;
- }
- if (cx->hbuf)
- {
- free(cx->hbuf);
- cx->hbuf = NULL;
- }
- if (cx->thdr)
- {
- free(cx->thdr);
- cx->thdr = NULL;
- cx->thlen = 0;
- }
-
- if (ret)
- *ret = cx->ret;
- if (len)
- *len = cx->rptr;
- if (cx->rbuf)
- cx->rbuf[cx->rptr] = 0;
- rxd = cx->rbuf;
- cx->rbuf = NULL;
- cx->rlen = 0;
- cx->rptr = 0;
- cx->contlen = 0;
-
- if (!cx->keep)
- http_async_req_close(ctx);
- else if (cx->cclose)
- {
- PCLOSE(cx->fd);
- cx->fd = PERROR;
- if (cx->fdhost)
- {
- free(cx->fdhost);
- cx->fdhost = NULL;
- }
- cx->state = HTS_STRT;
- }
- else
- cx->state = HTS_IDLE;
-
- return rxd;
-}
-
-void http_async_get_length(void *ctx, int *total, int *done)
-{
- struct http_ctx *cx = ctx;
- if (done)
- *done = cx->rptr;
- if (total)
- *total = cx->contlen;
-}
-
-void http_async_req_close(void *ctx)
-{
- struct http_ctx *cx = ctx;
- void *tmp;
- if (cx->host)
- {
- cx->keep = 1;
- tmp = http_async_req_stop(ctx, NULL, NULL);
- if (tmp)
- free(tmp);
- }
- if (cx->fdhost)
- free(cx->fdhost);
- PCLOSE(cx->fd);
- free(ctx);
-}
-
-char *http_simple_get(char *uri, int *ret, int *len)
-{
- void *ctx = http_async_req_start(NULL, uri, NULL, 0, 0);
- if (!ctx)
- {
- if (ret)
- *ret = 600;
- if (len)
- *len = 0;
- return NULL;
- }
- return http_async_req_stop(ctx, ret, len);
-}
-static char hex[] = "0123456789abcdef";
-void http_auth_headers(void *ctx, char *user, char *pass, char *session_id)
-{
- char *tmp;
- int i;
- unsigned char hash[16];
- unsigned int m;
- struct md5_context md5;
-
- if (user)
- {
- if (pass)
- {
- md5_init(&md5);
- md5_update(&md5, (unsigned char *)user, strlen(user));
- md5_update(&md5, (unsigned char *)"-", 1);
- m = 0;
-
- md5_update(&md5, (unsigned char *)pass, strlen(pass));
- md5_final(hash, &md5);
- tmp = malloc(33);
- for (i=0; i<16; i++)
- {
- tmp[i*2] = hex[hash[i]>>4];
- tmp[i*2+1] = hex[hash[i]&15];
- }
- tmp[32] = 0;
- http_async_add_header(ctx, "X-Auth-Hash", tmp);
- free(tmp);
- }
- if (session_id)
- {
- http_async_add_header(ctx, "X-Auth-User-Id", user);
- http_async_add_header(ctx, "X-Auth-Session-Key", session_id);
- }
- else
- {
- http_async_add_header(ctx, "X-Auth-User", user);
- }
- }
-}
-char *http_auth_get(char *uri, char *user, char *pass, char *session_id, int *ret, int *len)
-{
- void *ctx = http_async_req_start(NULL, uri, NULL, 0, 0);
-
- if (!ctx)
- {
- if (ret)
- *ret = 600;
- if (len)
- *len = 0;
- return NULL;
- }
- return http_async_req_stop(ctx, ret, len);
-}
-
-char *http_simple_post(char *uri, char *data, int dlen, int *ret, int *len)
-{
- void *ctx = http_async_req_start(NULL, uri, data, dlen, 0);
- if (!ctx)
- {
- if (ret)
- *ret = 600;
- if (len)
- *len = 0;
- return NULL;
- }
- return http_async_req_stop(ctx, ret, len);
-}
-
-char *http_ret_text(int ret)
-{
- switch (ret)
- {
- case 100:
- return "Continue";
- case 101:
- return "Switching Protocols";
- case 102:
- return "Processing";
-
- case 200:
- return "OK";
- case 201:
- return "Created";
- case 202:
- return "Accepted";
- case 203:
- return "Non-Authoritative Information";
- case 204:
- return "No Content";
- case 205:
- return "Reset Content";
- case 206:
- return "Partial Content";
- case 207:
- return "Multi-Status";
-
- case 300:
- return "Multiple Choices";
- case 301:
- return "Moved Permanently";
- case 302:
- return "Found";
- case 303:
- return "See Other";
- case 304:
- return "Not Modified";
- case 305:
- return "Use Proxy";
- case 306:
- return "Switch Proxy";
- case 307:
- return "Temporary Redirect";
-
- case 400:
- return "Bad Request";
- case 401:
- return "Unauthorized";
- case 402:
- return "Payment Required";
- case 403:
- return "Forbidden";
- case 404:
- return "Not Found";
- case 405:
- return "Method Not Allowed";
- case 406:
- return "Not Acceptable";
- case 407:
- return "Proxy Authentication Required";
- case 408:
- return "Request Timeout";
- case 409:
- return "Conflict";
- case 410:
- return "Gone";
- case 411:
- return "Length Required";
- case 412:
- return "Precondition Failed";
- case 413:
- return "Request Entity Too Large";
- case 414:
- return "Request URI Too Long";
- case 415:
- return "Unsupported Media Type";
- case 416:
- return "Requested Range Not Satisfiable";
- case 417:
- return "Expectation Failed";
- case 418:
- return "I'm a teapot";
- case 422:
- return "Unprocessable Entity";
- case 423:
- return "Locked";
- case 424:
- return "Failed Dependency";
- case 425:
- return "Unordered Collection";
- case 426:
- return "Upgrade Required";
- case 444:
- return "No Response";
- case 450:
- return "Blocked by Windows Parental Controls";
- case 499:
- return "Client Closed Request";
-
- case 500:
- return "Internal Server Error";
- case 501:
- return "Not Implemented";
- case 502:
- return "Bad Gateway";
- case 503:
- return "Service Unavailable";
- case 504:
- return "Gateway Timeout";
- case 505:
- return "HTTP Version Not Supported";
- case 506:
- return "Variant Also Negotiates";
- case 507:
- return "Insufficient Storage";
- case 509:
- return "Bandwidth Limit Exceeded";
- case 510:
- return "Not Extended";
-
- case 600:
- return "Internal Client Error";
- case 601:
- return "Unsupported Protocol";
- case 602:
- return "Server Not Found";
- case 603:
- return "Malformed Response";
- case 604:
- return "Network Not Available";
- case 605:
- return "Request Timed Out";
- default:
- return "Unknown Status Code";
- }
-}
-char *http_multipart_post(char *uri, char **names, char **parts, int *plens, char *user, char *pass, char *session_id, int *ret, int *len)
-{
- void *ctx;
- char *data = NULL, *tmp, *p;
- int dlen = 0, i, j;
- unsigned char hash[16];
- unsigned char boundary[32], ch;
- int blen = 0;
- unsigned int map[62], m;
- struct md5_context md5;
- //struct md5_context md52;
- int own_plen = 0;
-
- if (names)
- {
- if (!plens)
- {
- own_plen = 1;
- for (i=0; names[i]; i++) ;
- plens = calloc(i, sizeof(int));
- for (i=0; names[i]; i++)
- plens[i] = strlen(parts[i]);
- }
-
-retry:
- if (blen >= 31)
- goto fail;
- memset(map, 0, 62*sizeof(int));
- for (i=0; names[i]; i++)
- {
- for (j=0; j<plens[i]-blen; j++)
- if (!blen || !memcmp(parts[i]+j, boundary, blen))
- {
- ch = parts[i][j+blen];
- if (ch>='0' && ch<='9')
- map[ch-'0']++;
- else if (ch>='A' && ch<='Z')
- map[ch-'A'+10]++;
- else if (ch>='a' && ch<='z')
- map[ch-'a'+36]++;
- }
- }
- m = ~0;
- j = 61;
- for (i=0; i<62; i++)
- if (map[i]<m)
- {
- m = map[i];
- j = i;
- }
- if (j<10)
- boundary[blen] = '0'+j;
- else if (j<36)
- boundary[blen] = 'A'+(j-10);
- else
- boundary[blen] = 'a'+(j-36);
- blen++;
- if (map[j])
- goto retry;
- boundary[blen] = 0;
-
- for (i=0; names[i]; i++)
- dlen += blen+strlen(names[i])+plens[i]+128;
- dlen += blen+8;
- data = malloc(dlen);
- dlen = 0;
- for (i=0; names[i]; i++)
- {
- dlen += sprintf(data+dlen, "--%s\r\n", boundary);
- dlen += sprintf(data+dlen, "Content-transfer-encoding: binary\r\n");
- if (strchr(names[i], ':'))
- {
- tmp = mystrdup(names[i]);
- p = strchr(tmp, ':');
- *p = 0;
- dlen += sprintf(data+dlen, "content-disposition: form-data; name=\"%s\"; ", tmp);
- free(tmp);
- p = strchr(names[i], ':');
- dlen += sprintf(data+dlen, "filename=\"%s\"\r\n\r\n", p+1);
- }
- else
- dlen += sprintf(data+dlen, "content-disposition: form-data; name=\"%s\"\r\n\r\n", names[i]);
- memcpy(data+dlen, parts[i], plens[i]);
- dlen += plens[i];
- dlen += sprintf(data+dlen, "\r\n");
- }
- dlen += sprintf(data+dlen, "--%s--\r\n", boundary);
- }
-
- ctx = http_async_req_start(NULL, uri, data, dlen, 0);
- if (!ctx)
- goto fail;
-
- if (user)
- {
- //http_async_add_header(ctx, "X-Auth-User", user);
- if (pass)
- {
- md5_init(&md5);
- md5_update(&md5, (unsigned char *)user, strlen(user));
- md5_update(&md5, (unsigned char *)"-", 1);
- m = 0;
- if (names)
- {
- for (i=0; names[i]; i++)
- {
- //md5_update(&md5, (unsigned char *)parts[i], plens[i]); //WHY?
- //md5_update(&md5, (unsigned char *)"-", 1);
- p = strchr(names[i], ':');
- if (p)
- m += (p - names[i]) + 1;
- else
- m += strlen(names[i])+1;
- }
-
- tmp = malloc(m);
- m = 0;
- for (i=0; names[i]; i++)
- {
- p = strchr(names[i], ':');
- if (m)
- {
- tmp[m] = ' ';
- m ++;
- }
- if (p)
- {
- memcpy(tmp+m, names[i], p-names[i]);
- m += p - names[i];
- }
- else
- {
- strcpy(tmp+m, names[i]);
- m += strlen(names[i]);
- }
- }
- tmp[m] = 0;
- http_async_add_header(ctx, "X-Auth-Objects", tmp);
- free(tmp);
- }
-
- md5_update(&md5, (unsigned char *)pass, strlen(pass));
- md5_final(hash, &md5);
- tmp = malloc(33);
- for (i=0; i<16; i++)
- {
- tmp[i*2] = hex[hash[i]>>4];
- tmp[i*2+1] = hex[hash[i]&15];
- }
- tmp[32] = 0;
- http_async_add_header(ctx, "X-Auth-Hash", tmp);
- free(tmp);
- }
- if (session_id)
- {
- http_async_add_header(ctx, "X-Auth-User-Id", user);
- http_async_add_header(ctx, "X-Auth-Session-Key", session_id);
- }
- else
- {
- http_async_add_header(ctx, "X-Auth-User", user);
- }
- }
-
- if (data)
- {
- tmp = malloc(32+strlen((char *)boundary));
- sprintf(tmp, "multipart/form-data, boundary=%s", boundary);
- http_async_add_header(ctx, "Content-type", tmp);
- free(tmp);
- free(data);
- }
-
- if (own_plen)
- free(plens);
- return http_async_req_stop(ctx, ret, len);
-
-fail:
- if (data)
- free(data);
- if (own_plen)
- free(plens);
- if (ret)
- *ret = 600;
- if (len)
- *len = 0;
- return NULL;
-}
diff --git a/src/interface.c b/src/interface.c
deleted file mode 100644
index 742272b..0000000
--- a/src/interface.c
+++ /dev/null
@@ -1,7243 +0,0 @@
-/**
- * Powder Toy - user interface
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifdef MACOSX
-#include <CoreFoundation/CFString.h>
-#endif
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <bzlib.h>
-#include <math.h>
-#include <time.h>
-#include <http.h>
-#include <md5.h>
-#include <font.h>
-#include <defines.h>
-#include <powder.h>
-#include <interface.h>
-#include <misc.h>
-#include <console.h>
-#include "gravity.h"
-#include <images.h>
-#if defined(WIN32) && !defined(__GNUC__)
-#include <io.h>
-#else
-#include <dirent.h>
-#endif
-#ifdef PYCONSOLE
-#include <pythonconsole.h>
-#endif
-#include <powdergraphics.h>
-#include "save.h"
-
-SDLMod sdl_mod;
-int sdl_key, sdl_rkey, sdl_wheel, sdl_ascii, sdl_zoom_trig=0;
-#if (defined(LIN32) || defined(LIN64)) && defined(SDL_VIDEO_DRIVER_X11)
-SDL_SysWMinfo sdl_wminfo;
-Atom XA_CLIPBOARD, XA_TARGETS;
-#endif
-
-char *shift_0="`1234567890-=[]\\;',./";
-char *shift_1="~!@#$%^&*()_+{}|:\"<>?";
-
-int svf_messages = 0;
-int svf_login = 0;
-int svf_admin = 0;
-int svf_mod = 0;
-char svf_user[64] = "";
-char svf_user_id[64] = "";
-char svf_pass[64] = "";
-char svf_session_id[64] = "";
-
-int svf_open = 0;
-int svf_own = 0;
-int svf_myvote = 0;
-int svf_publish = 0;
-char svf_filename[255] = "";
-int svf_fileopen = 0;
-char svf_id[16] = "";
-char svf_name[64] = "";
-char svf_description[255] = "";
-char svf_tags[256] = "";
-void *svf_last = NULL;
-int svf_lsize;
-
-char *search_ids[GRID_X*GRID_Y];
-char *search_dates[GRID_X*GRID_Y];
-int search_votes[GRID_X*GRID_Y];
-int search_publish[GRID_X*GRID_Y];
-int search_scoredown[GRID_X*GRID_Y];
-int search_scoreup[GRID_X*GRID_Y];
-char *search_names[GRID_X*GRID_Y];
-char *search_owners[GRID_X*GRID_Y];
-void *search_thumbs[GRID_X*GRID_Y];
-int search_thsizes[GRID_X*GRID_Y];
-
-int search_own = 0;
-int search_fav = 0;
-int search_date = 0;
-int search_page = 0;
-char search_expr[256] = "";
-
-char server_motd[512] = "";
-
-char *tag_names[TAG_MAX];
-int tag_votes[TAG_MAX];
-
-int zoom_en = 0;
-int zoom_x=(XRES-ZSIZE_D)/2, zoom_y=(YRES-ZSIZE_D)/2;
-int zoom_wx=0, zoom_wy=0;
-unsigned char ZFACTOR = 256/ZSIZE_D;
-unsigned char ZSIZE = ZSIZE_D;
-
-int drawgrav_enable = 0;
-
-void menu_count(void)//puts the number of elements in each section into .itemcount
-{
- int i=0;
- for (i=0;i<SC_TOTAL;i++)
- {
- msections[i].itemcount = 0;
- }
- msections[SC_LIFE].itemcount = NGOLALT;
- msections[SC_WALL].itemcount = UI_WALLCOUNT-4;
- for (i=0; i<PT_NUM; i++)
- {
- if (ptypes[i].menusection<SC_TOTAL)
- {
- msections[ptypes[i].menusection].itemcount+=ptypes[i].menu;
- }
- }
-
-}
-
-void get_sign_pos(int i, int *x0, int *y0, int *w, int *h)
-{
- //Changing width if sign have special content
- if (strcmp(signs[i].text, "{p}")==0)
- *w = textwidth("Pressure: -000.00");
-
- if (strcmp(signs[i].text, "{t}")==0)
- *w = textwidth("Temp: 0000.00");
-
- if (sregexp(signs[i].text, "^{c:[0-9]*|.*}$")==0)
- {
- int sldr, startm;
- char buff[256];
- memset(buff, 0, sizeof(buff));
- for (sldr=3; signs[i].text[sldr-1] != '|'; sldr++)
- startm = sldr + 1;
-
- sldr = startm;
- while (signs[i].text[sldr] != '}')
- {
- buff[sldr - startm] = signs[i].text[sldr];
- sldr++;
- }
- *w = textwidth(buff) + 5;
- }
-
- //Ususal width
- if (strcmp(signs[i].text, "{p}") && strcmp(signs[i].text, "{t}") && sregexp(signs[i].text, "^{c:[0-9]*|.*}$"))
- *w = textwidth(signs[i].text) + 5;
- *h = 14;
- *x0 = (signs[i].ju == 2) ? signs[i].x - *w :
- (signs[i].ju == 1) ? signs[i].x - *w/2 : signs[i].x;
- *y0 = (signs[i].y > 18) ? signs[i].y - 18 : signs[i].y + 4;
-}
-
-void add_sign_ui(pixel *vid_buf, int mx, int my)
-{
- int i, w, h, x, y, nm=0, ju;
- int x0=(XRES-192)/2,y0=(YRES-80)/2,b=1,bq;
- ui_edit ed;
-
- // if currently moving a sign, stop doing so
- if (MSIGN!=-1)
- {
- MSIGN = -1;
- return;
- }
-
- // check if it is an existing sign
- for (i=0; i<MAXSIGNS; i++)
- if (signs[i].text[0])
- {
- get_sign_pos(i, &x, &y, &w, &h);
- if (mx>=x && mx<=x+w && my>=y && my<=y+h)
- break;
- }
- // else look for empty spot
- if (i >= MAXSIGNS)
- {
- nm = 1;
- for (i=0; i<MAXSIGNS; i++)
- if (!signs[i].text[0])
- break;
- }
- if (i >= MAXSIGNS)
- return;
- if (nm)
- {
- signs[i].x = mx;
- signs[i].y = my;
- signs[i].ju = 1;
- }
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- ed.x = x0+25;
- ed.y = y0+25;
- ed.w = 158;
- ed.nx = 1;
- ed.def = "[message]";
- ed.focus = 1;
- ed.hide = 0;
- ed.cursor = strlen(signs[i].text);
- ed.multiline = 0;
- strcpy(ed.str, signs[i].text);
- ju = signs[i].ju;
-
- fillrect(vid_buf, -1, -1, XRES, YRES+MENUSIZE, 0, 0, 0, 192);
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- drawrect(vid_buf, x0, y0, 192, 80, 192, 192, 192, 255);
- clearrect(vid_buf, x0, y0, 192, 80);
- drawtext(vid_buf, x0+8, y0+8, nm ? "New sign:" : "Edit sign:", 255, 255, 255, 255);
- drawtext(vid_buf, x0+12, y0+23, "\xA1", 32, 64, 128, 255);
- drawtext(vid_buf, x0+12, y0+23, "\xA0", 255, 255, 255, 255);
- drawrect(vid_buf, x0+8, y0+20, 176, 16, 192, 192, 192, 255);
- ui_edit_draw(vid_buf, &ed);
- drawtext(vid_buf, x0+8, y0+46, "Justify:", 255, 255, 255, 255);
- draw_icon(vid_buf, x0+50, y0+42, 0x9D, ju == 0);
- draw_icon(vid_buf, x0+68, y0+42, 0x9E, ju == 1);
- draw_icon(vid_buf, x0+86, y0+42, 0x9F, ju == 2);
-
-
-
-
-
- if (!nm)
- {
- drawtext(vid_buf, x0+138, y0+45, "\x86", 160, 48, 32, 255);
- drawtext(vid_buf, x0+138, y0+45, "\x85", 255, 255, 255, 255);
- drawtext(vid_buf, x0+152, y0+46, "Delete", 255, 255, 255, 255);
- drawrect(vid_buf, x0+134, y0+42, 50, 15, 255, 255, 255, 255);
- drawrect(vid_buf,x0+104,y0+42,26,15,255,255,255,255);
- drawtext(vid_buf, x0+110, y0+48, "Mv.", 255, 255, 255, 255);
- }
-
- drawtext(vid_buf, x0+5, y0+69, "OK", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+64, 192, 16, 192, 192, 192, 255);
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- ui_edit_process(mx, my, b, &ed);
-
- if (b && !bq && mx>=x0+50 && mx<=x0+67 && my>=y0+42 && my<=y0+59)
- ju = 0;
- if (b && !bq && mx>=x0+68 && mx<=x0+85 && my>=y0+42 && my<=y0+59)
- ju = 1;
- if (b && !bq && mx>=x0+86 && mx<=x0+103 && my>=y0+42 && my<=y0+59)
- ju = 2;
-
- if (!nm && b && !bq && mx>=x0+104 && mx<=x0+130 && my>=y0+42 && my<=y0+59)
- {
- MSIGN = i;
- break;
- }
- if (b && !bq && mx>=x0+9 && mx<x0+23 && my>=y0+22 && my<y0+36)
- break;
- if (b && !bq && mx>=x0 && mx<x0+192 && my>=y0+64 && my<=y0+80)
- break;
-
- if (!nm && b && !bq && mx>=x0+134 && my>=y0+42 && mx<=x0+184 && my<=y0+59)
- {
- signs[i].text[0] = 0;
- return;
- }
-
- if (sdl_key==SDLK_RETURN)
- break;
- if (sdl_key==SDLK_ESCAPE)
- {
- if (!ed.focus)
- return;
- ed.focus = 0;
- }
- }
-
- strcpy(signs[i].text, ed.str);
- signs[i].ju = ju;
-}
-//TODO: Finish text wrapping in text edits
-void ui_edit_draw(pixel *vid_buf, ui_edit *ed)
-{
- int cx, i, cy;
- char echo[256], *str;
-
- if (ed->hide)
- {
- for (i=0; ed->str[i]; i++)
- echo[i] = 0x8D;
- echo[i] = 0;
- str = echo;
- }
- else
- str = ed->str;
-
- if (ed->str[0])
- {
- if (ed->multiline) {
- drawtextwrap(vid_buf, ed->x, ed->y, ed->w-14, str, 255, 255, 255, 255);
- drawtext(vid_buf, ed->x+ed->w-11, ed->y-1, "\xAA", 128, 128, 128, 255);
- } else {
- drawtext(vid_buf, ed->x, ed->y, str, 255, 255, 255, 255);
- drawtext(vid_buf, ed->x+ed->w-11, ed->y-1, "\xAA", 128, 128, 128, 255);
- }
- }
- else if (!ed->focus)
- drawtext(vid_buf, ed->x, ed->y, ed->def, 128, 128, 128, 255);
- if (ed->focus)
- {
- if (ed->multiline) {
- textnpos(str, ed->cursor, ed->w-14, &cx, &cy);
- } else {
- cx = textnwidth(str, ed->cursor);
- cy = 0;
- }
-
- for (i=-3; i<9; i++)
- drawpixel(vid_buf, ed->x+cx, ed->y+i+cy, 255, 255, 255, 255);
- }
-}
-
-void ui_edit_process(int mx, int my, int mb, ui_edit *ed)
-{
- char ch, ts[2], echo[256], *str;
- int l, i;
-#ifdef RAWINPUT
- char *p;
-#endif
-
- if (mb)
- {
- if (ed->hide)
- {
- for (i=0; ed->str[i]; i++)
- echo[i] = 0x8D;
- echo[i] = 0;
- str = echo;
- }
- else
- str = ed->str;
-
- if (ed->multiline) {
- if (mx>=ed->x+ed->w-11 && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+11)
- {
- ed->focus = 1;
- ed->cursor = 0;
- ed->str[0] = 0;
- }
- else if (mx>=ed->x-ed->nx && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+ed->h)
- {
- ed->focus = 1;
- ed->cursor = textposxy(str, ed->w-14, mx-ed->x, my-ed->y);
- }
- else
- ed->focus = 0;
- } else {
- if (mx>=ed->x+ed->w-11 && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+11)
- {
- ed->focus = 1;
- ed->cursor = 0;
- ed->str[0] = 0;
- }
- else if (mx>=ed->x-ed->nx && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+11)
- {
- ed->focus = 1;
- ed->cursor = textwidthx(str, mx-ed->x);
- }
- else
- ed->focus = 0;
- }
- }
- if (ed->focus && sdl_key)
- {
- if (ed->hide)
- {
- for (i=0; ed->str[i]; i++)
- echo[i] = 0x8D;
- echo[i] = 0;
- str = echo;
- }
- else
- str = ed->str;
-
- l = strlen(ed->str);
- switch (sdl_key)
- {
- case SDLK_HOME:
- ed->cursor = 0;
- break;
- case SDLK_END:
- ed->cursor = l;
- break;
- case SDLK_LEFT:
- if (ed->cursor > 0)
- ed->cursor --;
- break;
- case SDLK_RIGHT:
- if (ed->cursor < l)
- ed->cursor ++;
- break;
- case SDLK_DELETE:
- if (sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))
- ed->str[ed->cursor] = 0;
- else if (ed->cursor < l)
- memmove(ed->str+ed->cursor, ed->str+ed->cursor+1, l-ed->cursor);
- break;
- case SDLK_BACKSPACE:
- if (sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))
- {
- if (ed->cursor > 0)
- memmove(ed->str, ed->str+ed->cursor, l-ed->cursor+1);
- ed->cursor = 0;
- }
- else if (ed->cursor > 0)
- {
- ed->cursor--;
- memmove(ed->str+ed->cursor, ed->str+ed->cursor+1, l-ed->cursor);
- }
- break;
- default:
- if(sdl_mod & (KMOD_CTRL) && sdl_key=='c')//copy
- {
- clipboard_push_text(ed->str);
- break;
- }
- else if(sdl_mod & (KMOD_CTRL) && sdl_key=='v')//paste
- {
- char *paste = clipboard_pull_text();
- int pl = strlen(paste);
- if ((textwidth(str)+textwidth(paste) > ed->w-14 && !ed->multiline) || (pl+strlen(ed->str)>255) || (float)(((textwidth(str)+textwidth(paste))/(ed->w-14)*12) > ed->h && ed->multiline))
- break;
- memmove(ed->str+ed->cursor+pl, ed->str+ed->cursor, l-ed->cursor+1);
- memcpy(ed->str+ed->cursor,paste,pl);
- ed->cursor += pl;
- break;
- }
-#ifdef RAWINPUT
- if (sdl_key>=SDLK_SPACE && sdl_key<=SDLK_z && l<255)
- {
- ch = sdl_key;
- if ((sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT|KMOD_CAPS)))
- {
- if (ch>='a' && ch<='z')
- ch &= ~0x20;
- p = strchr(shift_0, ch);
- if (p)
- ch = shift_1[p-shift_0];
- }
- ts[0]=ed->hide?0x8D:ch;
- ts[1]=0;
- if ((textwidth(str)+textwidth(ts) > ed->w-14 && !ed->multiline) || (float)(((textwidth(str)+textwidth(ts))/(ed->w-14)*12) > ed->h && ed->multiline))
- break;
- memmove(ed->str+ed->cursor+1, ed->str+ed->cursor, l+1-ed->cursor);
- ed->str[ed->cursor] = ch;
- ed->cursor++;
- }
-#else
- if (sdl_ascii>=' ' && sdl_ascii<127 && l<255)
- {
- ch = sdl_ascii;
- ts[0]=ed->hide?0x8D:ch;
- ts[1]=0;
- if ((textwidth(str)+textwidth(ts) > ed->w-14 && !ed->multiline) || (float)(((textwidth(str)+textwidth(ts))/(ed->w-14)*12) > ed->h && ed->multiline))
- break;
- memmove(ed->str+ed->cursor+1, ed->str+ed->cursor, l+1-ed->cursor);
- ed->str[ed->cursor] = ch;
- ed->cursor++;
- }
-#endif
- break;
- }
- }
-}
-
-void ui_list_process(pixel * vid_buf, int mx, int my, int mb, ui_list *ed)
-{
- int i, ystart, selected = 0;
- if(ed->selected > ed->count || ed->selected < -1)
- {
- ed->selected = -1;
- }
- if(mx > ed->x && mx < ed->x+ed->w && my > ed->y && my < ed->y+ed->h)
- {
- ed->focus = 1;
- if(mb)
- {
- ystart = ed->y-(ed->count*8);
- if(ystart < 5)
- ystart = 5;
- while (!sdl_poll())
- {
- mb = mouse_get_state(&mx, &my);
- if (!mb)
- break;
- }
-
- while (!sdl_poll() && !selected)
- {
- mb = mouse_get_state(&mx, &my);
- for(i = 0; i < ed->count; i++)
- {
- if(mx > ed->x && mx < ed->x+ed->w && my > (ystart + i*16) && my < (ystart + i * 16) + 16)
- {
- if(mb){
- ed->selected = i;
- selected = 1;
- }
- fillrect(vid_buf, ed->x, ystart + i * 16, ed->w, 16, 255, 255, 255, 25);
- drawtext(vid_buf, ed->x + 4, ystart + i * 16 + 5, ed->items[i], 255, 255, 255, 255);
- }
- else
- {
- drawtext(vid_buf, ed->x + 4, ystart + i * 16 + 5, ed->items[i], 192, 192, 192, 255);
- }
- draw_line(vid_buf, ed->x, ystart + i * 16, ed->x+ed->w, ystart + i * 16, 128, 128, 128, XRES+BARSIZE);
- }
- drawrect(vid_buf, ed->x, ystart, ed->w, ed->count*16, 255, 255, 255, 255);
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
- clearrect(vid_buf, ed->x-2, ystart-2, ed->w+4, (ed->count*16)+4);
-
- if(!selected && mb)
- break;
- }
- while (!sdl_poll())
- {
- mb = mouse_get_state(&mx, &my);
- if (!mb)
- break;
- }
-
- if(ed->selected!=-1)
- strcpy(ed->str, ed->items[ed->selected]);
- }
- }
- else
- {
- ed->focus = 0;
- }
-}
-
-void ui_list_draw(pixel *vid_buf, ui_list *ed)
-{
- if(ed->selected > ed->count || ed->selected < -1)
- {
- ed->selected = -1;
- }
- if (ed->focus)
- {
- drawrect(vid_buf, ed->x, ed->y, ed->w, ed->h, 255, 255, 255, 255);
- }
- else
- {
- drawrect(vid_buf, ed->x, ed->y, ed->w, ed->h, 192, 192, 192, 255);
- }
- if(ed->selected!=-1)
- {
- drawtext(vid_buf, ed->x+4, ed->y+5, ed->items[ed->selected], 255, 255, 255, 255);
- }
- else
- {
- drawtext(vid_buf, ed->x+4, ed->y+5, ed->def, 192, 192, 192, 255);
- }
-}
-
-void ui_checkbox_draw(pixel *vid_buf, ui_checkbox *ed)
-{
- int w = 12;
- if (ed->checked)
- {
- drawtext(vid_buf, ed->x+2, ed->y+2, "\xCF", 128, 128, 128, 255);
- }
- if (ed->focus)
- {
- drawrect(vid_buf, ed->x, ed->y, w, w, 255, 255, 255, 255);
- }
- else
- {
- drawrect(vid_buf, ed->x, ed->y, w, w, 128, 128, 128, 255);
- }
-}
-
-void ui_checkbox_process(int mx, int my, int mb, int mbq, ui_checkbox *ed)
-{
- int w = 12;
-
- if (mb && !mbq)
- {
- if (mx>=ed->x && mx<=ed->x+w && my>=ed->y && my<=ed->y+w)
- {
- ed->checked = (ed->checked)?0:1;
- }
- }
- else
- {
- if (mx>=ed->x && mx<=ed->x+w && my>=ed->y && my<=ed->y+w)
- {
- ed->focus = 1;
- }
- else
- {
- ed->focus = 0;
- }
- }
-}
-
-void ui_radio_draw(pixel *vid_buf, ui_checkbox *ed)
-{
- if (ed->checked)
- {
- int nx, ny;
- for(nx=-6; nx<=6; nx++)
- for(ny=-6; ny<=6; ny++)
- if((nx*nx+ny*ny)<10)
- blendpixel(vid_buf, ed->x+6+nx, ed->y+6+ny, 128, 128, 128, 255);
- }
- if (ed->focus)
- {
- int nx, ny;
- for(nx=-6; nx<=6; nx++)
- for(ny=-6; ny<=6; ny++)
- if((nx*nx+ny*ny)<40 && (nx*nx+ny*ny)>28)
- blendpixel(vid_buf, ed->x+6+nx, ed->y+6+ny, 255, 255, 255, 255);
- }
- else
- {
- int nx, ny;
- for(nx=-6; nx<=6; nx++)
- for(ny=-6; ny<=6; ny++)
- if((nx*nx+ny*ny)<40 && (nx*nx+ny*ny)>28)
- blendpixel(vid_buf, ed->x+6+nx, ed->y+6+ny, 128, 128, 128, 255);
- }
-}
-
-void ui_radio_process(int mx, int my, int mb, int mbq, ui_checkbox *ed)
-{
- int w = 12;
-
- if (mb && !mbq)
- {
- if (mx>=ed->x && mx<=ed->x+w && my>=ed->y && my<=ed->y+w)
- {
- ed->checked = (ed->checked)?0:1;
- }
- }
- else
- {
- if (mx>=ed->x && mx<=ed->x+w && my>=ed->y && my<=ed->y+w)
- {
- ed->focus = 1;
- }
- else
- {
- ed->focus = 0;
- }
- }
-}
-
-void ui_copytext_draw(pixel *vid_buf, ui_copytext *ed)
-{
- int g = 180, i = 0;
- if (!ed->state) {
- if (ed->hover) {
- i = 0;
- } else {
- i = 100;
- }
- g = 255;
- drawtext(vid_buf, (ed->x+(ed->width/2))-(textwidth("Click the box to copy the text")/2), ed->y-12, "Click the box to copy the text", 255, 255, 255, 255-i);
- } else {
- i = 0;
- drawtext(vid_buf, (ed->x+(ed->width/2))-(textwidth("Copied!")/2), ed->y-12, "Copied!", 255, 255, 255, 255-i);
- g = 190;
- }
-
- drawrect(vid_buf, ed->x, ed->y, ed->width, ed->height, g, 255, g, 255-i);
- drawrect(vid_buf, ed->x+1, ed->y+1, ed->width-2, ed->height-2, g, 255, g, 100-i);
- drawtext(vid_buf, ed->x+6, ed->y+5, ed->text, g, 255, g, 230-i);
-}
-
-void ui_copytext_process(int mx, int my, int mb, int mbq, ui_copytext *ed)
-{
- if (my>=ed->y && my<=ed->y+ed->height && mx>=ed->x && mx<=ed->x+ed->width && !ed->state) {
- if (mb && !mbq) {
- clipboard_push_text(ed->text);
- ed->state = 1;
- }
- ed->hover = 1;
- } else {
- ed->hover = 0;
- }
-}
-
-void ui_richtext_draw(pixel *vid_buf, ui_richtext *ed)
-{
- ed->str[511] = 0;
- ed->printstr[511] = 0;
- drawtext(vid_buf, ed->x, ed->y, ed->printstr, 255, 255, 255, 255);
-}
-
-int markup_getregion(char *text, char *action, char *data, char *atext){
- int datamarker = 0;
- int terminator = 0;
- int minit;
- if (sregexp(text, "^{a:.*|.*}")==0)
- {
- *action = text[1];
- for (minit=3; text[minit-1] != '|'; minit++)
- datamarker = minit + 1;
- for (minit=datamarker; text[minit-1] != '}'; minit++)
- terminator = minit + 1;
- strncpy(data, text+3, datamarker-4);
- strncpy(atext, text+datamarker, terminator-datamarker-1);
- return terminator;
- }
- else
- {
- return 0;
- }
-}
-
-void ui_richtext_settext(char *text, ui_richtext *ed)
-{
- int pos = 0, action = 0, ppos = 0, ipos = 0;
- memset(ed->printstr, 0, 512);
- memset(ed->str, 0, 512);
- strcpy(ed->str, text);
- //strcpy(ed->printstr, text);
- for(action = 0; action < 6; action++){
- ed->action[action] = 0;
- memset(ed->actiondata[action], 0, 256);
- memset(ed->actiontext[action], 0, 256);
- }
- action = 0;
- for(pos = 0; pos<512; ){
- if(!ed->str[pos])
- break;
- if(ed->str[pos] == '{'){
- int mulen = 0;
- mulen = markup_getregion(ed->str+pos, &ed->action[action], ed->actiondata[action], ed->actiontext[action]);
- if(mulen){
- ed->regionss[action] = ipos;
- ed->regionsf[action] = ipos + strlen(ed->actiontext[action]);
- //printf("%c, %s, %s [%d, %d]\n", ed->action[action], ed->actiondata[action], ed->actiontext[action], ed->regionss[action], ed->regionsf[action]);
- strcpy(ed->printstr+ppos, ed->actiontext[action]);
- ppos+=strlen(ed->actiontext[action]);
- ipos+=strlen(ed->actiontext[action]);
- pos+=mulen;
- action++;
- }
- else
- {
- pos++;
- }
- } else {
- ed->printstr[ppos] = ed->str[pos];
- ppos++;
- pos++;
- ipos++;
- if(ed->str[pos] == '\b'){
- ipos-=2;
- }
- }
- }
- ed->printstr[ppos] = 0;
- //printf("%s\n", ed->printstr);
-}
-
-void ui_richtext_process(int mx, int my, int mb, int mbq, ui_richtext *ed)
-{
- int action = 0;
- int currentpos = 0;
- if(mx>ed->x && mx < ed->x+textwidth(ed->printstr) && my > ed->y && my < ed->y + 10 && mb && !mbq){
- currentpos = textwidthx(ed->printstr, mx-ed->x);
- for(action = 0; action < 6; action++){
- if(currentpos >= ed->regionss[action] && currentpos <= ed->regionsf[action])
- {
- //Do action
- if(ed->action[action]=='a'){
- //Open link
- open_link(ed->actiondata[action]);
- }
- break;
- }
- }
- }
-}
-
-void draw_svf_ui(pixel *vid_buf, int alternate)// all the buttons at the bottom
-{
- int c;
-
- //the open browser button
- if(alternate)
- {
- fillrect(vid_buf, 0, YRES+(MENUSIZE-16)-1, 18, 16, 255, 255, 255, 255);
- drawtext(vid_buf, 4, YRES+(MENUSIZE-14), "\x81", 0, 0, 0, 255);
- } else {
- drawtext(vid_buf, 4, YRES+(MENUSIZE-14), "\x81", 255, 255, 255, 255);
- drawrect(vid_buf, 1, YRES+(MENUSIZE-16), 16, 14, 255, 255, 255, 255);
- }
-
- // the reload button
- c = (svf_last) ? 255 : 128;
- drawtext(vid_buf, 23, YRES+(MENUSIZE-14), "\x91", c, c, c, 255);
- drawrect(vid_buf, 19, YRES+(MENUSIZE-16), 16, 14, c, c, c, 255);
-
- // the save sim button
- if(alternate)
- {
- fillrect(vid_buf, 36, YRES+(MENUSIZE-16)-1, 152, 16, 255, 255, 255, 255);
- drawtext(vid_buf, 40, YRES+(MENUSIZE-14), "\x82", 0, 0, 0, 255);
- if(svf_fileopen)
- drawtext(vid_buf, 58, YRES+(MENUSIZE-12), svf_filename, 0, 0, 0, 255);
- else
- drawtext(vid_buf, 58, YRES+(MENUSIZE-12), "[save to disk]", 0, 0, 0, 255);
- } else {
- c = svf_login ? 255 : 128;
- drawtext(vid_buf, 40, YRES+(MENUSIZE-14), "\x82", c, c, c, 255);
- if (svf_open)
- drawtextmax(vid_buf, 58, YRES+(MENUSIZE-12), 125, svf_name, c, c, c, 255);
- else
- drawtext(vid_buf, 58, YRES+(MENUSIZE-12), "[untitled simulation]", c, c, c, 255);
- drawrect(vid_buf, 37, YRES+(MENUSIZE-16), 150, 14, c, c, c, 255);
- if (svf_open && svf_own)
- drawdots(vid_buf, 55, YRES+(MENUSIZE-15), 12, c, c, c, 255);
- }
-
- c = (svf_login && svf_open) ? 255 : 128;
-
- //the vote buttons
- drawrect(vid_buf, 189, YRES+(MENUSIZE-16), 14, 14, c, c, c, 255);
- drawrect(vid_buf, 203, YRES+(MENUSIZE-16), 14, 14, c, c, c, 255);
-
- if (svf_myvote==1 && (svf_login && svf_open))
- {
- fillrect(vid_buf, 189, YRES+(MENUSIZE-16), 14, 14, 0, 108, 10, 255);
- }
- else if (svf_myvote==-1 && (svf_login && svf_open))
- {
- fillrect(vid_buf, 203, YRES+(MENUSIZE-16), 14, 14, 108, 10, 0, 255);
- }
- drawtext(vid_buf, 192, YRES+(MENUSIZE-12), "\xCB", 0, 187, 18, c);
- drawtext(vid_buf, 205, YRES+(MENUSIZE-14), "\xCA", 187, 40, 0, c);
-
- //the tags button
- drawtext(vid_buf, 222, YRES+(MENUSIZE-15), "\x83", c, c, c, 255);
- if (svf_tags[0])
- drawtextmax(vid_buf, 240, YRES+(MENUSIZE-12), XRES+BARSIZE-405, svf_tags, c, c, c, 255);
- else
- drawtext(vid_buf, 240, YRES+(MENUSIZE-12), "[no tags set]", c, c, c, 255);
-
- drawrect(vid_buf, 219, YRES+(MENUSIZE-16), XRES+BARSIZE-380, 14, c, c, c, 255);
-
- //the clear sim button------------some of the commented values are wrong
- drawtext(vid_buf, XRES-139+BARSIZE/*371*/, YRES+(MENUSIZE-14), "\x92", 255, 255, 255, 255);
- drawrect(vid_buf, XRES-143+BARSIZE/*367*/, YRES+(MENUSIZE-16), 16, 14, 255, 255, 255, 255);
-
- //the login button
- drawtext(vid_buf, XRES-122+BARSIZE/*388*/, YRES+(MENUSIZE-13), "\x84", 255, 255, 255, 255);
- if (svf_login)
- drawtextmax(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), 66, svf_user, 255, 255, 255, 255);
- else
- drawtext(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), "[sign in]", 255, 255, 255, 255);
- drawrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14, 255, 255, 255, 255);
-
- //te pause button
- if (sys_pause)
- {
- fillrect(vid_buf, XRES-17+BARSIZE/*493*/, YRES+(MENUSIZE-17), 16, 16, 255, 255, 255, 255);
- drawtext(vid_buf, XRES-14+BARSIZE/*496*/, YRES+(MENUSIZE-14), "\x90", 0, 0, 0, 255);
- }
- else
- {
- drawtext(vid_buf, XRES-14+BARSIZE/*496*/, YRES+(MENUSIZE-14), "\x90", 255, 255, 255, 255);
- drawrect(vid_buf, XRES-16+BARSIZE/*494*/, YRES+(MENUSIZE-16), 14, 14, 255, 255, 255, 255);
- }
-
- //The simulation options button, used to be the heat sim button
- {
- drawtext(vid_buf, XRES-156+BARSIZE/*481*/, YRES+(MENUSIZE-13), "\xCF", 255, 255, 255, 255);
- drawrect(vid_buf, XRES-159+BARSIZE/*494*/, YRES+(MENUSIZE-16), 14, 14, 255, 255, 255, 255);
- }
-
- //the view mode button
- addchar(vid_buf, XRES-29+BARSIZE, YRES+(MENUSIZE-13), 0xD8, 255, 0, 0, 255);
- addchar(vid_buf, XRES-29+BARSIZE, YRES+(MENUSIZE-13), 0xD9, 0, 255, 0, 255);
- addchar(vid_buf, XRES-29+BARSIZE, YRES+(MENUSIZE-13), 0xDA, 0, 0, 255, 255);
- drawrect(vid_buf, XRES-32+BARSIZE/*478*/, YRES+(MENUSIZE-16), 14, 14, 255, 255, 255, 255);
-
- // special icons for admin/mods
- if (svf_admin)
- {
- drawtext(vid_buf, XRES-45+BARSIZE/*463*/, YRES+(MENUSIZE-14), "\xC9", 232, 127, 35, 255);
- drawtext(vid_buf, XRES-45+BARSIZE/*463*/, YRES+(MENUSIZE-14), "\xC7", 255, 255, 255, 255);
- drawtext(vid_buf, XRES-45+BARSIZE/*463*/, YRES+(MENUSIZE-14), "\xC8", 255, 255, 255, 255);
- }
- else if (svf_mod)
- {
- drawtext(vid_buf, XRES-45+BARSIZE/*463*/, YRES+(MENUSIZE-14), "\xC9", 35, 127, 232, 255);
- drawtext(vid_buf, XRES-45+BARSIZE/*463*/, YRES+(MENUSIZE-14), "\xC7", 255, 255, 255, 255);
- }//else if(amd)
- // drawtext(vid_buf, XRES-45/*465*/, YRES+(MENUSIZE-15), "\x97", 0, 230, 153, 255); Why is this here?
-}
-
-void error_ui(pixel *vid_buf, int err, char *txt)
-{
- int x0=(XRES-240)/2,y0=YRES/2,b=1,bq,mx,my,textheight;
- char *msg;
-
- msg = malloc(strlen(txt)+16);
- if (err)
- sprintf(msg, "%03d %s", err, txt);
- else
- sprintf(msg, "%s", txt);
- textheight = textwrapheight(msg, 240);
- y0 -= (52+textheight)/2;
- if (y0<2)
- y0 = 2;
- if (y0+50+textheight>YRES)
- textheight = YRES-50-y0;
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- clearrect(vid_buf, x0-2, y0-2, 244, 52+textheight);
- drawrect(vid_buf, x0, y0, 240, 48+textheight, 192, 192, 192, 255);
- if (err)
- drawtext(vid_buf, x0+8, y0+8, "HTTP error:", 255, 64, 32, 255);
- else
- drawtext(vid_buf, x0+8, y0+8, "Error:", 255, 64, 32, 255);
- drawtextwrap(vid_buf, x0+8, y0+26, 224, msg, 255, 255, 255, 255);
- drawtext(vid_buf, x0+5, y0+textheight+37, "Dismiss", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+textheight+32, 240, 16, 192, 192, 192, 255);
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- if (b && !bq && mx>=x0 && mx<x0+240 && my>=y0+textheight+32 && my<=y0+textheight+48)
- break;
-
- if (sdl_key==SDLK_RETURN)
- break;
- if (sdl_key==SDLK_ESCAPE)
- break;
- }
-
- free(msg);
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-}
-
-typedef struct int_pair
-{
- int first, second;
-} int_pair;
-
-int int_pair_cmp (const void * a, const void * b)
-{
- int_pair *ap = a;
- int_pair *bp = a;
- return ( ap->first - bp->first );
-}
-
-void element_search_ui(pixel *vid_buf, int * slp, int * srp)
-{
- int windowHeight = 300, windowWidth = 240;
- int x0 = (XRES-windowWidth)/2, y0 = (YRES-windowHeight)/2, b = 1, bq, mx, my;
- int toolx = 0, tooly = 0, i, xoff, yoff, c, found;
- char tempCompare[512];
- char tempString[512];
- int_pair tempInts[PT_NUM];
- ui_edit ed;
- int selectedl = -1;
- int selectedr = -1;
- int firstResult = -1, hover = -1;
-
- ed.x = x0+12;
- ed.y = y0+30;
- ed.w = windowWidth - 20;
- ed.nx = 1;
- ed.def = "[element name]";
- ed.focus = 1;
- ed.hide = 0;
- ed.cursor = 0;
- ed.multiline = 0;
- ed.str[0] = 0;
-
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- clearrect(vid_buf, x0-2, y0-2, windowWidth+4, windowHeight+4);
- drawrect(vid_buf, x0, y0, windowWidth, windowHeight, 192, 192, 192, 255);
-
- drawtext(vid_buf, x0+8, y0+8, "Element Search", 255, 255, 255, 255);
-
- drawrect(vid_buf, ed.x-4, ed.y-5, ed.w+4, 16, 192, 192, 192, 255);
- ui_edit_draw(vid_buf, &ed);
- ui_edit_process(mx, my, b, &ed);
-
- drawrect(vid_buf, ed.x-4, (ed.y-5)+20, ed.w+4, windowHeight-((ed.y-5)), 192, 192, 192, 255);
- xoff = (ed.x-4)+6;
- yoff = ((ed.y-5)+20)+4;
- toolx = 0;
- tooly = 0;
-
- drawtext(vid_buf, xoff+toolx+4, yoff+tooly+3, "Matches:", 255, 255, 255, 180);
- draw_line(vid_buf, xoff+toolx+2, yoff+tooly+14, xoff+toolx+5+(ed.w-16), yoff+tooly+14, 180, 180, 180, XRES+BARSIZE);
- tooly += 17;
-
- //Covert input to lower case
- c = 0;
- while (ed.str[c]) { tempString[c] = tolower(ed.str[c]); c++; } tempString[c] = 0;
-
- firstResult = -1;
- hover = -1;
- for(i = 0; i < PT_NUM; i++)
- {
- c = 0;
- while (ptypes[i].name[c]) { tempCompare[c] = tolower(ptypes[i].name[c]); c++; } tempCompare[c] = 0;
- if(strstr(tempCompare, tempString)!=0 && ptypes[i].enabled)
- {
- if(firstResult==-1)
- firstResult = i;
- toolx += draw_tool_xy(vid_buf, toolx+xoff, tooly+yoff, i, ptypes[i].pcolors)+5;
- if (!bq && mx>=xoff+toolx-32 && mx<xoff+toolx && my>=yoff+tooly && my<yoff+tooly+15)
- {
- drawrect(vid_buf, xoff+toolx-32, yoff+tooly-1, 29, 17, 255, 55, 55, 255);
- hover = i;
- }
- else if (i==selectedl || i==*slp)
- {
- drawrect(vid_buf, xoff+toolx-32, yoff+tooly-1, 29, 17, 255, 55, 55, 255);
- }
- else if (i==selectedr || i==*srp)
- {
- drawrect(vid_buf, xoff+toolx-32, yoff+tooly-1, 29, 17, 55, 55, 255, 255);
- }
- if(toolx > ed.w-4)
- {
- tooly += 18;
- toolx = 0;
- }
- if(tooly>windowHeight-((ed.y-5)+20))
- break;;
- }
- }
-
- if(toolx>0)
- {
- toolx = 0;
- tooly += 18;
- }
-
- if(tooly<windowHeight-((ed.y-5)+20))
- {
- drawtext(vid_buf, xoff+toolx+4, yoff+tooly+3, "Related:", 255, 255, 255, 180);
- draw_line(vid_buf, xoff+toolx+2, yoff+tooly+14, xoff+toolx+5+(ed.w-16), yoff+tooly+14, 180, 180, 180, XRES+BARSIZE);
- tooly += 17;
-
- found = 0;
- for(i = 0; i < PT_NUM; i++)
- {
- c = 0;
- while (ptypes[i].descs[c]) { tempCompare[c] = tolower(ptypes[i].descs[c]); c++; } tempCompare[c] = 0;
- if(strstr(tempCompare, tempString)!=0 && ptypes[i].enabled)
- {
- tempInts[found].first = strstr(tempCompare, tempString);
- tempInts[found++].second = i;
- }
- }
-
- qsort(tempInts, found, sizeof(int_pair), int_pair_cmp);
-
- for(i = 0; i < found; i++)
- {
- if(firstResult==-1)
- firstResult = tempInts[i].second;
- toolx += draw_tool_xy(vid_buf, toolx+xoff, tooly+yoff, tempInts[i].second, ptypes[tempInts[i].second].pcolors)+5;
- if (!bq && mx>=xoff+toolx-32 && mx<xoff+toolx && my>=yoff+tooly && my<yoff+tooly+15)
- {
- drawrect(vid_buf, xoff+toolx-32, yoff+tooly-1, 29, 17, 255, 55, 55, 255);
- hover = tempInts[i].second;
- }
- else if (tempInts[i].second==selectedl || tempInts[i].second==*slp)
- {
- drawrect(vid_buf, xoff+toolx-32, yoff+tooly-1, 29, 17, 255, 55, 55, 255);
- }
- else if (tempInts[i].second==selectedr || tempInts[i].second==*srp)
- {
- drawrect(vid_buf, xoff+toolx-32, yoff+tooly-1, 29, 17, 55, 55, 255, 255);
- }
- if(toolx > ed.w-4)
- {
- tooly += 18;
- toolx = 0;
- }
- if(tooly>windowHeight-((ed.y-5)+18))
- break;
- }
- }
-
- if(b==1 && hover!=-1)
- {
- selectedl = hover;
- break;
- }
- if(b==4 && hover!=-1)
- {
- selectedr = hover;
- break;
- }
-
- drawtext(vid_buf, x0+5, y0+windowHeight-12, "Dismiss", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+windowHeight-16, windowWidth, 16, 192, 192, 192, 255);
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- if (b && !bq && mx>=x0 && mx<x0+windowWidth && my>=y0+windowHeight-16 && my<=y0+windowHeight)
- break;
-
- if (sdl_key==SDLK_RETURN)
- {
- if(selectedl==-1)
- selectedl = firstResult;
- break;
- }
- if (sdl_key==SDLK_ESCAPE)
- {
- selectedl = -1;
- selectedr = -1;
- break;
- }
- }
-
- if(selectedl!=-1)
- *slp = selectedl;
- if(selectedr!=-1)
- *srp = selectedr;
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-}
-
-char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shadow)
-{
- int xsize = 244;
- int ysize = 90;
- int edity, editx;
- int x0=(XRES-xsize)/2,y0=(YRES-MENUSIZE-ysize)/2,b=1,bq,mx,my;
- ui_edit ed;
-
- edity = y0+50;
- editx = x0+12;
-
- ed.x = editx;
- ed.y = edity;
- ed.w = xsize - 20;
- ed.nx = 1;
- ed.def = shadow;
- ed.focus = 0;
- ed.hide = 0;
- ed.cursor = 0;
- ed.multiline = 0;
- strncpy(ed.str, text, 254);
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
- drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
- drawtext(vid_buf, x0+8, y0+8, title, 160, 160, 255, 255);
- drawtext(vid_buf, x0+8, y0+26, prompt, 255, 255, 255, 255);
-
- drawrect(vid_buf, ed.x-4, ed.y-5, ed.w+4, 16, 192, 192, 192, 255);
-
- ui_edit_draw(vid_buf, &ed);
- ui_edit_process(mx, my, b, &ed);
-
- drawtext(vid_buf, x0+5, y0+ysize-11, "OK", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+ysize-16, xsize, 16, 192, 192, 192, 255);
-
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- if (b && !bq && mx>=x0 && mx<x0+xsize && my>=y0+ysize-16 && my<=y0+ysize)
- break;
-
- if (sdl_key==SDLK_RETURN)
- break;
- if (sdl_key==SDLK_ESCAPE)
- break;
- }
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
- return mystrdup(ed.str);
-}
-
-void prop_edit_ui(pixel *vid_buf, int x, int y)
-{
- pixel * o_vid_buf;
- float valuef;
- unsigned char valuec;
- int valuei;
- int format;
- size_t propoffset;
- char *listitems[] = {"type", "life", "ctype", "temp", "tmp", "tmp2", "vy", "vx", "x", "y", "dcolour"};
- int listitemscount = 11;
- int xsize = 244;
- int ysize = 87;
- int edity, editx, edit2y, edit2x;
- int x0=(XRES-xsize)/2,y0=(YRES-MENUSIZE-ysize)/2,b=1,bq,mx,my;
- ui_list ed;
- ui_edit ed2;
-
- edity = y0+25;
- editx = x0+8;
-
- edit2y = y0+50;
- edit2x = x0+12;
-
- ed.x = editx;
- ed.y = edity;
- ed.w = xsize - 16;
- ed.h = 16;
- ed.def = "[property]";
- ed.selected = -1;
- ed.items = listitems;
- ed.count = listitemscount;
-
- ed2.x = edit2x;
- ed2.y = edit2y;
- ed2.w = xsize - 20;
- ed2.nx = 1;
- ed2.def = "[value]";
- ed2.focus = 0;
- ed2.hide = 0;
- ed2.cursor = 0;
- ed2.multiline = 0;
- ed2.str[0] = 0;
- strncpy(ed2.str, "0", 254);
- strncpy(ed.str, "ctype", 254);
-
- o_vid_buf = (pixel*)calloc((YRES+MENUSIZE) * (XRES+BARSIZE), PIXELSIZE);
- if (o_vid_buf)
- memcpy(o_vid_buf, vid_buf, ((YRES+MENUSIZE) * (XRES+BARSIZE)) * PIXELSIZE);
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- if (o_vid_buf)
- memcpy(vid_buf, o_vid_buf, ((YRES+MENUSIZE) * (XRES+BARSIZE)) * PIXELSIZE);
- clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
- drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
- drawtext(vid_buf, x0+8, y0+8, "Change particle property", 160, 160, 255, 255);
- //drawtext(vid_buf, x0+8, y0+26, prompt, 255, 255, 255, 255);
-
- //drawrect(vid_buf, ed.x-4, ed.y-5, ed.w+4, 16, 192, 192, 192, 255);
- drawrect(vid_buf, ed2.x-4, ed2.y-5, ed2.w+4, 16, 192, 192, 192, 255);
-
- ui_list_draw(vid_buf, &ed);
- ui_list_process(vid_buf, mx, my, b, &ed);
- ui_edit_draw(vid_buf, &ed2);
- ui_edit_process(mx, my, b, &ed2);
-
- drawtext(vid_buf, x0+5, y0+ysize-11, "OK", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+ysize-16, xsize, 16, 192, 192, 192, 255);
-
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- if (b && !bq && mx>=x0 && mx<x0+xsize && my>=y0+ysize-16 && my<=y0+ysize)
- break;
-
- if (sdl_key==SDLK_RETURN)
- break;
- if (sdl_key==SDLK_ESCAPE)
- goto exit;
- }
-
- if(ed.selected!=-1)
- {
- if (strcmp(ed.str,"type")==0){
- propoffset = offsetof(particle, type);
- format = 1;
- } else if (strcmp(ed.str,"life")==0){
- propoffset = offsetof(particle, life);
- format = 0;
- } else if (strcmp(ed.str,"ctype")==0){
- propoffset = offsetof(particle, ctype);
- format = 1;
- } else if (strcmp(ed.str,"temp")==0){
- propoffset = offsetof(particle, temp);
- format = 2;
- } else if (strcmp(ed.str,"tmp")==0){
- propoffset = offsetof(particle, tmp);
- format = 0;
- } else if (strcmp(ed.str,"tmp2")==0){
- propoffset = offsetof(particle, tmp2);
- format = 0;
- } else if (strcmp(ed.str,"vy")==0){
- propoffset = offsetof(particle, vy);
- format = 2;
- } else if (strcmp(ed.str,"vx")==0){
- propoffset = offsetof(particle, vx);
- format = 2;
- } else if (strcmp(ed.str,"x")==0){
- propoffset = offsetof(particle, x);
- format = 2;
- } else if (strcmp(ed.str,"y")==0){
- propoffset = offsetof(particle, y);
- format = 2;
- } else if (strcmp(ed.str,"dcolour")==0){
- propoffset = offsetof(particle, dcolour);
- format = 3;
- }
- } else {
- error_ui(vid_buf, 0, "Invalid property");
- goto exit;
- }
-
- if(format==0){
- sscanf(ed2.str, "%d", &valuei);
- flood_prop(x, y, propoffset, &valuei, format);
- }
- if(format==1){
- int isint = 1, i;
- //Check if it's an element name
- for(i = 0; i < strlen(ed2.str); i++)
- {
- if(!(ed2.str[i] >= '0' && ed2.str[i] <= '9'))
- {
- isint = 0;
- break;
- }
- }
- if(isint)
- {
- sscanf(ed2.str, "%u", &valuei);
- }
- else
- {
- if(!console_parse_type(ed2.str, &valuei, NULL))
- {
- error_ui(vid_buf, 0, "Invalid element name");
- goto exit;
- }
- }
- valuec = (unsigned char)valuei;
- flood_prop(x, y, propoffset, &valuec, format);
- }
- if(format==2){
- sscanf(ed2.str, "%f", &valuef);
- flood_prop(x, y, propoffset, &valuef, format);
- }
- if(format==3){
- int j;
- unsigned int valueui;
- if(ed2.str[0] == '#') // #FFFFFFFF
- {
- //Convert to lower case
- for(j = 0; j < strlen(ed2.str); j++)
- ed2.str[j] = tolower(ed2.str[j]);
- sscanf(ed2.str, "#%x", &valueui);
- printf("%s, %u\n", ed2.str, valueui);
- }
- else if(ed2.str[0] == '0' && ed2.str[1] == 'x') // 0xFFFFFFFF
- {
- //Convert to lower case
- for(j = 0; j < strlen(ed2.str); j++)
- ed2.str[j] = tolower(ed2.str[j]);
- sscanf(ed2.str, "0x%x", &valueui);
- printf("%s, %u\n", ed2.str, valueui);
- }
- else
- {
- sscanf(ed2.str, "%d", &valueui);
- }
- flood_prop(x, y, propoffset, &valueui, 0);
- }
-exit:
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-}
-
-void info_ui(pixel *vid_buf, char *top, char *txt)
-{
- int x0=(XRES-240)/2,y0=(YRES-MENUSIZE)/2,b=1,bq,mx,my;
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- clearrect(vid_buf, x0-2, y0-2, 244, 64);
- drawrect(vid_buf, x0, y0, 240, 60, 192, 192, 192, 255);
- drawtext(vid_buf, x0+8, y0+8, top, 160, 160, 255, 255);
- drawtext(vid_buf, x0+8, y0+26, txt, 255, 255, 255, 255);
- drawtext(vid_buf, x0+5, y0+49, "OK", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+44, 240, 16, 192, 192, 192, 255);
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- if (b && !bq && mx>=x0 && mx<x0+240 && my>=y0+44 && my<=y0+60)
- break;
-
- if (sdl_key==SDLK_RETURN)
- break;
- if (sdl_key==SDLK_ESCAPE)
- break;
- }
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-}
-
-void info_box(pixel *vid_buf, char *msg)
-{
- int w = textwidth(msg)+16;
- int x0=(XRES-w)/2,y0=(YRES-24)/2;
-
- clearrect(vid_buf, x0-2, y0-2, w+4, 28);
- drawrect(vid_buf, x0, y0, w, 24, 192, 192, 192, 255);
- drawtext(vid_buf, x0+8, y0+8, msg, 192, 192, 240, 255);
-#ifndef RENDERER
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-#endif
-}
-
-void info_box_overlay(pixel *vid_buf, char *msg)
-{
- int w = textwidth(msg)+16;
- int x0=(XRES-w)/2,y0=(YRES-24)/2;
-
- clearrect(vid_buf, x0-2, y0-2, w+4, 28);
- drawrect(vid_buf, x0, y0, w, 24, 192, 192, 192, 255);
- drawtext(vid_buf, x0+8, y0+8, msg, 192, 192, 240, 255);
-}
-
-void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt)
-{
- int state = 0;
- int i;
- int g = 255;
- int xsize = 244;
- int ysize = 90;
- int x0=(XRES-xsize)/2,y0=(YRES-MENUSIZE-ysize)/2,b=1,bq,mx,my;
- int buttonx = 0;
- int buttony = 0;
- int buttonwidth = 0;
- int buttonheight = 0;
- ui_copytext ed;
-
- buttonwidth = textwidth(copytxt)+12;
- buttonheight = 10+8;
- buttony = y0+50;
- buttonx = x0+(xsize/2)-(buttonwidth/2);
-
- ed.x = buttonx;
- ed.y = buttony;
- ed.width = buttonwidth;
- ed.height = buttonheight;
- ed.hover = 0;
- ed.state = 0;
- strcpy(ed.text, copytxt);
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
- drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
- drawtext(vid_buf, x0+8, y0+8, top, 160, 160, 255, 255);
- drawtext(vid_buf, x0+8, y0+26, txt, 255, 255, 255, 255);
-
- ui_copytext_draw(vid_buf, &ed);
- ui_copytext_process(mx, my, b, bq, &ed);
-
- drawtext(vid_buf, x0+5, y0+ysize-11, "OK", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+ysize-16, xsize, 16, 192, 192, 192, 255);
-
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- if (b && !bq && mx>=x0 && mx<x0+xsize && my>=y0+ysize-16 && my<=y0+ysize)
- break;
-
- if (sdl_key==SDLK_RETURN)
- break;
- if (sdl_key==SDLK_ESCAPE)
- break;
- }
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-}
-int confirm_ui(pixel *vid_buf, char *top, char *msg, char *btn)
-{
- int x0=(XRES-240)/2,y0=YRES/2,b=1,bq,mx,my,textheight;
- int ret = 0;
-
- textheight = textwrapheight(msg, 240);
- y0 -= (52+textheight)/2;
- if (y0<2)
- y0 = 2;
- if (y0+50+textheight>YRES)
- textheight = YRES-50-y0;
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- clearrect(vid_buf, x0-2, y0-2, 244, 52+textheight);
- drawrect(vid_buf, x0, y0, 240, 48+textheight, 192, 192, 192, 255);
- drawtext(vid_buf, x0+8, y0+8, top, 255, 216, 32, 255);
- drawtextwrap(vid_buf, x0+8, y0+26, 224, msg, 255, 255, 255, 255);
- drawtext(vid_buf, x0+5, y0+textheight+37, "Cancel", 255, 255, 255, 255);
- drawtext(vid_buf, x0+165, y0+textheight+37, btn, 255, 216, 32, 255);
- drawrect(vid_buf, x0, y0+textheight+32, 160, 16, 192, 192, 192, 255);
- drawrect(vid_buf, x0+160, y0+textheight+32, 80, 16, 192, 192, 192, 255);
-
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- if (b && !bq && mx>=x0+160 && mx<x0+240 && my>=y0+textheight+32 && my<=y0+textheight+48)
- {
- ret = 1;
- break;
- }
-
- if (b && !bq && mx>=x0 && mx<x0+160 && my>=y0+textheight+32 && my<=y0+textheight+48)
- break;
-
- if (sdl_key==SDLK_RETURN)
- {
- ret = 1;
- break;
- }
- if (sdl_key==SDLK_ESCAPE)
- break;
- }
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- return ret;
-}
-
-void login_ui(pixel *vid_buf)
-{
- int x0=(XRES+BARSIZE-192)/2,y0=(YRES+MENUSIZE-80)/2,b=1,bq,mx,my,err;
- ui_edit ed1,ed2;
- char *res;
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- ed1.x = x0+25;
- ed1.y = y0+25;
- ed1.w = 158;
- ed1.nx = 1;
- ed1.def = "[user name]";
- ed1.focus = 1;
- ed1.hide = 0;
- ed1.multiline = 0;
- ed1.cursor = strlen(svf_user);
- strcpy(ed1.str, svf_user);
- ed2.x = x0+25;
- ed2.y = y0+45;
- ed2.w = 158;
- ed2.nx = 1;
- ed2.def = "[password]";
- ed2.focus = 0;
- ed2.hide = 1;
- ed2.cursor = 0;
- ed2.multiline = 0;
- strcpy(ed2.str, "");
-
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- drawrect(vid_buf, x0, y0, 192, 80, 192, 192, 192, 255);
- clearrect(vid_buf, x0, y0, 192, 80);
- drawtext(vid_buf, x0+8, y0+8, "Server login:", 255, 255, 255, 255);
- drawtext(vid_buf, x0+12, y0+23, "\x8B", 32, 64, 128, 255);
- drawtext(vid_buf, x0+12, y0+23, "\x8A", 255, 255, 255, 255);
- drawrect(vid_buf, x0+8, y0+20, 176, 16, 192, 192, 192, 255);
- drawtext(vid_buf, x0+11, y0+44, "\x8C", 160, 144, 32, 255);
- drawtext(vid_buf, x0+11, y0+44, "\x84", 255, 255, 255, 255);
- drawrect(vid_buf, x0+8, y0+40, 176, 16, 192, 192, 192, 255);
- ui_edit_draw(vid_buf, &ed1);
- ui_edit_draw(vid_buf, &ed2);
- drawtext(vid_buf, x0+5, y0+69, "Sign out", 255, 255, 255, 255);
- drawtext(vid_buf, x0+187-textwidth("Sign in"), y0+69, "Sign in", 255, 255, 55, 255);
- drawrect(vid_buf, x0, y0+64, 192, 16, 192, 192, 192, 255);
- drawrect(vid_buf, x0, y0+64, 96, 16, 192, 192, 192, 255);
-
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- ui_edit_process(mx, my, b, &ed1);
- ui_edit_process(mx, my, b, &ed2);
-
- if (b && !bq && mx>=x0+9 && mx<x0+23 && my>=y0+22 && my<y0+36)
- break;
- if (b && !bq && mx>=x0+9 && mx<x0+23 && my>=y0+42 && my<y0+46)
- break;
- if (b && !bq && mx>=x0 && mx<x0+96 && my>=y0+64 && my<=y0+80)
- goto fail;
- if (b && !bq && mx>=x0+97 && mx<x0+192 && my>=y0+64 && my<=y0+80)
- break;
-
- if (sdl_key==SDLK_RETURN || sdl_key==SDLK_TAB)
- {
- if (!ed1.focus)
- break;
- ed1.focus = 0;
- ed2.focus = 1;
- }
- if (sdl_key==SDLK_ESCAPE)
- {
- if (!ed1.focus && !ed2.focus)
- return;
- ed1.focus = 0;
- ed2.focus = 0;
- }
- }
-
- strcpy(svf_user, ed1.str);
- md5_ascii(svf_pass, (unsigned char *)ed2.str, 0);
- res = http_multipart_post(
- "http://" SERVER "/Login.api",
- NULL, NULL, NULL,
- svf_user, svf_pass, NULL,
- &err, NULL);
- if (err != 200)
- {
- error_ui(vid_buf, err, http_ret_text(err));
- if (res)
- free(res);
- goto fail;
- }
- if (res && !strncmp(res, "OK ", 3))
- {
- char *s_id,*u_e,*nres,*u_m,*mres;
- s_id = strchr(res+3, ' ');
- if (!s_id)
- goto fail;
- *(s_id++) = 0;
-
- u_e = strchr(s_id, ' ');
- if (!u_e)
- goto fail;
- *(u_e++) = 0;
-
- u_m = strchr(u_e, ' ');
- if (!u_m) {
- u_m = malloc(1);
- memset(u_m, 0, 1);
- }
- else
- *(u_m++) = 0;
-
- strcpy(svf_user_id, res+3);
- strcpy(svf_session_id, s_id);
- mres = mystrdup(u_e);
- nres = mystrdup(u_m);
-
- #ifdef DEBUG
- printf("{%s} {%s} {%s} {%s}\n", svf_user_id, svf_session_id, nres, mres);
- #endif
-
- if (!strncmp(nres, "ADMIN", 5))
- {
- svf_admin = 1;
- svf_mod = 0;
- }
- else if (!strncmp(nres, "MOD", 3))
- {
- svf_admin = 0;
- svf_mod = 1;
- }
- else
- {
- svf_admin = 0;
- svf_mod = 0;
- }
- svf_messages = atoi(mres);
- free(res);
- svf_login = 1;
- return;
- }
- if (!res)
- res = mystrdup("Unspecified Error");
- error_ui(vid_buf, 0, res);
- free(res);
-
-fail:
- strcpy(svf_user, "");
- strcpy(svf_pass, "");
- strcpy(svf_user_id, "");
- strcpy(svf_session_id, "");
- svf_login = 0;
- svf_own = 0;
- svf_admin = 0;
- svf_mod = 0;
- svf_messages = 0;
- save_presets(0);
-}
-
-int stamp_ui(pixel *vid_buf)
-{
- int b=1,bq,mx,my,d=-1,i,j,k,x,gx,gy,y,w,h,r=-1,stamp_page=0,per_page=GRID_X*GRID_Y,page_count;
- char page_info[64];
- // stamp_count-1 to avoid an extra page when there are per_page stamps on each page
- page_count = (stamp_count-1)/per_page+1;
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- clearrect(vid_buf, -1, -1, XRES+BARSIZE+1, YRES+MENUSIZE+1);
- k = stamp_page*per_page;//0;
- r = -1;
- d = -1;
- for (j=0; j<GRID_Y; j++)
- for (i=0; i<GRID_X; i++)
- {
- if (stamps[k].name[0])
- {
- gx = ((XRES/GRID_X)*i) + (XRES/GRID_X-XRES/GRID_S)/2;
- gy = ((((YRES-MENUSIZE+20)+15)/GRID_Y)*j) + ((YRES-MENUSIZE+20)/GRID_Y-(YRES-MENUSIZE+20)/GRID_S+10)/2 + 18;
- x = (XRES*i)/GRID_X + XRES/(GRID_X*2);
- y = (YRES*j)/GRID_Y + YRES/(GRID_Y*2);
- gy -= 20;
- w = stamps[k].thumb_w;
- h = stamps[k].thumb_h;
- x -= w/2;
- y -= h/2;
- if (stamps[k].thumb)
- {
- draw_image(vid_buf, stamps[k].thumb, gx+(((XRES/GRID_S)/2)-(w/2)), gy+(((YRES/GRID_S)/2)-(h/2)), w, h, 255);
- xor_rect(vid_buf, gx+(((XRES/GRID_S)/2)-(w/2)), gy+(((YRES/GRID_S)/2)-(h/2)), w, h);
- }
- else
- {
- drawtext(vid_buf, gx+8, gy+((YRES/GRID_S)/2)-4, "Error loading stamp", 255, 255, 255, 255);
- }
- if (mx>=gx+XRES/GRID_S-4 && mx<(gx+XRES/GRID_S)+6 && my>=gy-6 && my<gy+4)
- {
- d = k;
- drawrect(vid_buf, gx-2, gy-2, XRES/GRID_S+3, YRES/GRID_S+3, 128, 128, 128, 255);
- drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x86", 255, 48, 32, 255);
- }
- else
- {
- if (mx>=gx && mx<gx+(XRES/GRID_S) && my>=gy && my<gy+(YRES/GRID_S) && stamps[k].thumb)
- {
- r = k;
- drawrect(vid_buf, gx-2, gy-2, XRES/GRID_S+3, YRES/GRID_S+3, 128, 128, 210, 255);
- }
- else
- {
- drawrect(vid_buf, gx-2, gy-2, XRES/GRID_S+3, YRES/GRID_S+3, 128, 128, 128, 255);
- }
- drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x86", 150, 48, 32, 255);
- }
- drawtext(vid_buf, gx+XRES/(GRID_S*2)-textwidth(stamps[k].name)/2, gy+YRES/GRID_S+7, stamps[k].name, 192, 192, 192, 255);
- drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x85", 255, 255, 255, 255);
- }
- k++;
- }
-
- sprintf(page_info, "Page %d of %d", stamp_page+1, page_count);
-
- drawtext(vid_buf, (XRES/2)-(textwidth(page_info)/2), YRES+MENUSIZE-14, page_info, 255, 255, 255, 255);
-
- if (stamp_page)
- {
- drawtext(vid_buf, 4, YRES+MENUSIZE-14, "\x96", 255, 255, 255, 255);
- drawrect(vid_buf, 1, YRES+MENUSIZE-18, 16, 16, 255, 255, 255, 255);
- }
- if (stamp_page<page_count-1)
- {
- drawtext(vid_buf, XRES-15, YRES+MENUSIZE-14, "\x95", 255, 255, 255, 255);
- drawrect(vid_buf, XRES-18, YRES+MENUSIZE-18, 16, 16, 255, 255, 255, 255);
- }
-
- if (b==1&&d!=-1)
- {
- if (confirm_ui(vid_buf, "Do you want to delete?", stamps[d].name, "Delete"))
- {
- del_stamp(d);
- }
- }
-
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- if (b==1&&r!=-1)
- break;
- if (b==4&&r!=-1)
- {
- r = -1;
- break;
- }
-
- if ((b && !bq && mx>=1 && mx<=17 && my>=YRES+MENUSIZE-18 && my<YRES+MENUSIZE-2) || sdl_wheel>0)
- {
- if (stamp_page)
- {
- stamp_page --;
- }
- sdl_wheel = 0;
- }
- if ((b && !bq && mx>=XRES-18 && mx<=XRES-1 && my>=YRES+MENUSIZE-18 && my<YRES+MENUSIZE-2) || sdl_wheel<0)
- {
- if (stamp_page<page_count-1)
- {
- stamp_page ++;
- }
- sdl_wheel = 0;
- }
-
- if (sdl_key==SDLK_RETURN)
- break;
- if (sdl_key==SDLK_ESCAPE)
- {
- r = -1;
- break;
- }
- }
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- return r;
-}
-
-void tag_list_ui(pixel *vid_buf)
-{
- int y,d,x0=(XRES-192)/2,y0=(YRES-256)/2,b=1,bq,mx,my,vp,vn;
- char *p,*q,s;
- char *tag=NULL, *op=NULL;
- ui_edit ed;
- struct strlist *vote=NULL,*down=NULL;
-
- ed.x = x0+25;
- ed.y = y0+221;
- ed.w = 158;
- ed.nx = 1;
- ed.def = "[new tag]";
- ed.focus = 0;
- ed.hide = 0;
- ed.cursor = 0;
- ed.multiline = 0;
- strcpy(ed.str, "");
-
- fillrect(vid_buf, -1, -1, XRES, YRES+MENUSIZE, 0, 0, 0, 192);
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- op = tag = NULL;
-
- drawrect(vid_buf, x0, y0, 192, 256, 192, 192, 192, 255);
- clearrect(vid_buf, x0, y0, 192, 256);
- drawtext(vid_buf, x0+8, y0+8, "Current tags:", 255, 255, 255, 255);
- p = svf_tags;
- s = svf_tags[0] ? ' ' : 0;
- y = 36 + y0;
- while (s)
- {
- q = strchr(p, ' ');
- if (!q)
- q = p+strlen(p);
- s = *q;
- *q = 0;
- if (svf_own || svf_admin || svf_mod)
- {
- drawtext(vid_buf, x0+20, y-1, "\x86", 160, 48, 32, 255);
- drawtext(vid_buf, x0+20, y-1, "\x85", 255, 255, 255, 255);
- d = 14;
- if (b && !bq && mx>=x0+18 && mx<x0+32 && my>=y-2 && my<y+12)
- {
- op = "delete";
- tag = mystrdup(p);
- }
- }
- else
- d = 0;
- vp = strlist_find(&vote, p);
- vn = strlist_find(&down, p);
- if ((!vp && !vn && !svf_own) || svf_admin || svf_mod)
- {
- drawtext(vid_buf, x0+d+20, y-1, "\x88", 32, 144, 32, 255);
- drawtext(vid_buf, x0+d+20, y-1, "\x87", 255, 255, 255, 255);
- if (b && !bq && mx>=x0+d+18 && mx<x0+d+32 && my>=y-2 && my<y+12)
- {
- op = "vote";
- tag = mystrdup(p);
- strlist_add(&vote, p);
- }
- drawtext(vid_buf, x0+d+34, y-1, "\x88", 144, 48, 32, 255);
- drawtext(vid_buf, x0+d+34, y-1, "\xA2", 255, 255, 255, 255);
- if (b && !bq && mx>=x0+d+32 && mx<x0+d+46 && my>=y-2 && my<y+12)
- {
- op = "down";
- tag = mystrdup(p);
- strlist_add(&down, p);
- }
- }
- if (vp)
- drawtext(vid_buf, x0+d+48+textwidth(p), y, " - voted!", 48, 192, 48, 255);
- if (vn)
- drawtext(vid_buf, x0+d+48+textwidth(p), y, " - voted.", 192, 64, 32, 255);
- drawtext(vid_buf, x0+d+48, y, p, 192, 192, 192, 255);
- *q = s;
- p = q+1;
- y += 16;
- }
- drawtext(vid_buf, x0+11, y0+219, "\x86", 32, 144, 32, 255);
- drawtext(vid_buf, x0+11, y0+219, "\x89", 255, 255, 255, 255);
- drawrect(vid_buf, x0+8, y0+216, 176, 16, 192, 192, 192, 255);
- ui_edit_draw(vid_buf, &ed);
- drawtext(vid_buf, x0+5, y0+245, "Close", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+240, 192, 16, 192, 192, 192, 255);
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- ui_edit_process(mx, my, b, &ed);
-
- if (b && mx>=x0 && mx<=x0+192 && my>=y0+240 && my<y0+256)
- break;
-
- if (op)
- {
- d = execute_tagop(vid_buf, op, tag);
- free(tag);
- op = tag = NULL;
- if (d)
- goto finish;
- }
-
- if (b && !bq && mx>=x0+9 && mx<x0+23 && my>=y0+218 && my<y0+232)
- {
- d = execute_tagop(vid_buf, "add", ed.str);
- strcpy(ed.str, "");
- ed.cursor = 0;
- if (d)
- goto finish;
- }
-
- if (sdl_key==SDLK_RETURN)
- {
- if (!ed.focus)
- break;
- d = execute_tagop(vid_buf, "add", ed.str);
- strcpy(ed.str, "");
- ed.cursor = 0;
- if (d)
- goto finish;
- }
- if (sdl_key==SDLK_ESCAPE)
- {
- if (!ed.focus)
- break;
- strcpy(ed.str, "");
- ed.cursor = 0;
- ed.focus = 0;
- }
- }
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
- sdl_key = 0;
-
-finish:
- strlist_free(&vote);
-}
-
-int save_name_ui(pixel *vid_buf)
-{
- int x0=(XRES-420)/2,y0=(YRES-68-YRES/4)/2,b=1,bq,mx,my,ths,idtxtwidth,nd=0;
- void *th;
- pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
- ui_edit ed;
- ui_edit ed2;
- ui_checkbox cb;
- ui_copytext ctb;
-
- th = build_thumb(&ths, 0);
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- ed.x = x0+25;
- ed.y = y0+25;
- ed.w = 158;
- ed.nx = 1;
- ed.def = "[simulation name]";
- ed.focus = 1;
- ed.hide = 0;
- ed.cursor = strlen(svf_name);
- ed.multiline = 0;
- strcpy(ed.str, svf_name);
-
- ed2.x = x0+13;
- ed2.y = y0+45;
- ed2.w = 166;
- ed2.h = 85;
- ed2.nx = 1;
- ed2.def = "[simulation description]";
- ed2.focus = 0;
- ed2.hide = 0;
- ed2.cursor = strlen(svf_description);
- ed2.multiline = 1;
- strcpy(ed2.str, svf_description);
-
- ctb.x = 0;
- ctb.y = YRES+MENUSIZE-20;
- ctb.width = textwidth(svf_id)+12;
- ctb.height = 10+7;
- ctb.hover = 0;
- ctb.state = 0;
- strcpy(ctb.text, svf_id);
-
-
- cb.x = x0+10;
- cb.y = y0+53+YRES/4;
- cb.focus = 0;
- cb.checked = svf_publish;
-
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- draw_rgba_image(vid_buf, save_to_server_image, 0, 0, 0.7);
-
- memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- drawrect(vid_buf, x0, y0, 420, 90+YRES/4, 192, 192, 192, 255);
- clearrect(vid_buf, x0, y0, 420, 90+YRES/4);
- drawtext(vid_buf, x0+8, y0+8, "New simulation name:", 255, 255, 255, 255);
- drawtext(vid_buf, x0+10, y0+23, "\x82", 192, 192, 192, 255);
- drawrect(vid_buf, x0+8, y0+20, 176, 16, 192, 192, 192, 255);
-
- drawrect(vid_buf, x0+8, y0+40, 176, 95, 192, 192, 192, 255);
-
- ui_edit_draw(vid_buf, &ed);
- ui_edit_draw(vid_buf, &ed2);
-
- drawrect(vid_buf, x0+(205-XRES/3)/2-2+205, y0+30, XRES/3+3, YRES/3+3, 128, 128, 128, 255);
- render_thumb(th, ths, 0, vid_buf, x0+(205-XRES/3)/2+205, y0+32, 3);
-
- ui_checkbox_draw(vid_buf, &cb);
- drawtext(vid_buf, x0+34, y0+50+YRES/4, "Publish? (Do not publish others'\nworks without permission)", 192, 192, 192, 255);
-
- drawtext(vid_buf, x0+5, y0+79+YRES/4, "Save simulation", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+74+YRES/4, 192, 16, 192, 192, 192, 255);
-
- draw_line(vid_buf, x0+192, y0, x0+192, y0+90+YRES/4, 150, 150, 150, XRES+BARSIZE);
-
- if (svf_id[0])
- {
- //Save ID text and copybox
- idtxtwidth = textwidth("Current save ID: ");
- idtxtwidth += ctb.width;
- ctb.x = textwidth("Current save ID: ")+(XRES+BARSIZE-idtxtwidth)/2;
- drawtext(vid_buf, (XRES+BARSIZE-idtxtwidth)/2, YRES+MENUSIZE-15, "Current save ID: ", 255, 255, 255, 255);
-
- ui_copytext_draw(vid_buf, &ctb);
- ui_copytext_process(mx, my, b, bq, &ctb);
- }
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- memcpy(vid_buf, old_vid, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
-
- ui_edit_process(mx, my, b, &ed);
- ui_edit_process(mx, my, b, &ed2);
- ui_checkbox_process(mx, my, b, bq, &cb);
-
- if ((b && !bq && ((mx>=x0+9 && mx<x0+23 && my>=y0+22 && my<y0+36) ||
- (mx>=x0 && mx<x0+192 && my>=y0+74+YRES/4 && my<y0+90+YRES/4)))
- || sdl_key==SDLK_RETURN)
- {
- if (th) free(th);
- if (!ed.str[0])
- return 0;
- nd = strcmp(svf_name, ed.str) || !svf_own;
- strncpy(svf_name, ed.str, 63);
- svf_name[63] = 0;
- strncpy(svf_description, ed2.str, 254);
- svf_description[254] = 0;
- if (nd)
- {
- strcpy(svf_id, "");
- strcpy(svf_tags, "");
- }
- svf_open = 1;
- svf_own = 1;
- svf_publish = cb.checked;
- svf_filename[0] = 0;
- svf_fileopen = 0;
- free(old_vid);
- return nd+1;
- }
- if (sdl_key==SDLK_ESCAPE)
- {
- if (!ed.focus)
- break;
- ed.focus = 0;
- }
- }
- if (th) free(th);
- free(old_vid);
- return 0;
-}
-
-//unused old function, with all the elements drawn at the bottom
-/*
-void menu_ui(pixel *vid_buf, int i, int *sl, int *sr)
-{
- int b=1,bq,mx,my,h,x,y,n=0,height,width,sy,rows=0;
- pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
- if (!old_vid)
- return;
- fillrect(vid_buf, -1, -1, XRES+1, YRES+MENUSIZE, 0, 0, 0, 192);
- memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
- rows = ceil((float)msections[i].itemcount/16.0f);
- height = (ceil((float)msections[i].itemcount/16.0f)*18);
- width = restrict_flt(msections[i].itemcount*31, 0, 16*31);
- //clearrect(vid_buf, -1, -1, XRES+1, YRES+MENUSIZE+1);
- h = -1;
- x = XRES-BARSIZE-26;
- y = (((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-(height/2)+(FONT_H/2)+1;
- sy = y;
- //clearrect(vid_buf, (XRES-BARSIZE-width)+1, y-4, width+4, height+4+rows);
- fillrect(vid_buf, (XRES-BARSIZE-width)-7, y-10, width+16, height+16+rows, 0, 0, 0, 100);
- drawrect(vid_buf, (XRES-BARSIZE-width)-7, y-10, width+16, height+16+rows, 255, 255, 255, 255);
- fillrect(vid_buf, (XRES-BARSIZE)+11, (((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-2, 15, FONT_H+3, 0, 0, 0, 100);
- drawrect(vid_buf, (XRES-BARSIZE)+10, (((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-2, 16, FONT_H+3, 255, 255, 255, 255);
- drawrect(vid_buf, (XRES-BARSIZE)+9, (((YRES/SC_TOTAL)*i)+((YRES/SC_TOTAL)/2))-1, 1, FONT_H+1, 0, 0, 0, 255);
- if (i==SC_WALL)
- {
- for (n = 122; n<122+UI_WALLCOUNT; n++)
- {
- if (n!=SPC_AIR&&n!=SPC_HEAT&&n!=SPC_COOL&&n!=SPC_VACUUM)
- {
- if (x-26<=60)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, mwalls[n-122].colour)+5;
- if (mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if (n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if (n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- }
- else if (i==SC_SPECIAL)
- {
- for (n = 122; n<122+UI_WALLCOUNT; n++)
- {
- if (n==SPC_AIR||n==SPC_HEAT||n==SPC_COOL||n==SPC_VACUUM)
- {
- if (x-26<=60)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, mwalls[n-122].colour)+5;
- if (mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if (n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if (n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- for (n = 0; n<PT_NUM; n++)
- {
- if (ptypes[n].menusection==i&&ptypes[n].menu==1)
- {
- if (x-26<=60)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, ptypes[n].pcolors)+5;
- if (mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if (n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if (n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- }
- else
- {
- for (n = 0; n<PT_NUM; n++)
- {
- if (ptypes[n].menusection==i&&ptypes[n].menu==1)
- {
- if (x-26<=60)
- {
- x = XRES-BARSIZE-26;
- y += 19;
- }
- x -= draw_tool_xy(vid_buf, x, y, n, ptypes[n].pcolors)+5;
- if (mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- h = n;
- }
- else if (n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 0, 0, 255);
- }
- else if (n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 0, 255, 255);
- }
- }
- }
- }
-
- if (h==-1)
- {
- drawtext(vid_buf, XRES-textwidth((char *)msections[i].name)-BARSIZE, sy+height+10, (char *)msections[i].name, 255, 255, 255, 255);
- }
- else if (i==SC_WALL||(i==SC_SPECIAL&&h>=122))
- {
- drawtext(vid_buf, XRES-textwidth((char *)mwalls[h-122].descs)-BARSIZE, sy+height+10, (char *)mwalls[h-122].descs, 255, 255, 255, 255);
- }
- else
- {
- drawtext(vid_buf, XRES-textwidth((char *)ptypes[h].descs)-BARSIZE, sy+height+10, (char *)ptypes[h].descs, 255, 255, 255, 255);
- }
-
-
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
- memcpy(vid_buf, old_vid, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
- if (!(mx>=(XRES-BARSIZE-width)-7 && my>=sy-10 && my<sy+height+9))
- {
- break;
- }
-
- if (b==1&&h!=-1)
- {
- *sl = h;
- break;
- }
- if (b==4&&h!=-1)
- {
- *sr = h;
- break;
- }
- //if(b==4&&h!=-1) {
- // h = -1;
- // break;
- //}
-
- if (sdl_key==SDLK_RETURN)
- break;
- if (sdl_key==SDLK_ESCAPE)
- break;
- }
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
- //drawtext(vid_buf, XRES+2, (12*i)+2, msections[i].icon, 255, 255, 255, 255);
-}
-*/
-//current menu function
-void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *su, int *dae, int b, int bq, int mx, int my)
-{
- int h,x,y,n=0,height,width,sy,rows=0,xoff=0,fwidth;
- SEC = SEC2;
- rows = ceil((float)msections[i].itemcount/16.0f);
- height = (ceil((float)msections[i].itemcount/16.0f)*18);
- width = restrict_flt(msections[i].itemcount*31, 0, 16*31);
- fwidth = msections[i].itemcount*31;
- h = -1;
- x = XRES-BARSIZE-18;
- y = YRES+1;
- sy = y;
- if (i==SC_WALL)//wall menu
- {
- for (n = UI_WALLSTART; n<UI_WALLSTART+UI_WALLCOUNT; n++)
- {
- if (n!=SPC_AIR&&n!=SPC_HEAT&&n!=SPC_COOL&&n!=SPC_VACUUM&&n!=SPC_WIND&&n!=SPC_PGRV&&n!=SPC_NGRV&&n!=SPC_PROP)
- {
- /*if (x-18<=2)
- {
- x = XRES-BARSIZE-18;
- y += 19;
- }*/
- x -= draw_tool_xy(vid_buf, x, y, n, wtypes[n-UI_WALLSTART].colour)+5;
- if (!bq && mx>=x+32 && mx<x+58 && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 55, 55, 255);
- h = n;
- }
- if (!bq && mx>=x+32 && mx<x+58 && my>=y && my< y+15&&(sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL)))
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 255, 255, 255);
- h = n;
- }
- else if (n==SLALT)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 0, 255, 255, 255);
- }
- else if (n==*sl)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 255, 55, 55, 255);
- }
- else if (n==*sr)
- {
- drawrect(vid_buf, x+30, y-1, 29, 17, 55, 55, 255, 255);
- }
- }
- }
- }
- else if (i==SC_TOOL)//tools menu
- {
- for (n = UI_WALLSTART; n<UI_WALLSTART+UI_WALLCOUNT; n++)
- {
- if (n==SPC_AIR||n==SPC_HEAT||n==SPC_COOL||n==SPC_VACUUM||n==SPC_WIND||n==SPC_PGRV||n==SPC_NGRV||n==SPC_PROP)
- {
- /*if (x-18<=0)
- {
- x = XRES-BARSIZE-18;
- y += 19;
- }*/
- x -= draw_tool_xy(vid_buf, x-xoff, y, n, wtypes[n-UI_WALLSTART].colour)+5;
- if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
- h = n;
- }
- if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15&&(sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL)))
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 0, 255, 255, 255);
- h = n;
- }
- else if (n==SLALT)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 0, 255, 255, 255);
- }
- else if (n==*sl)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
- }
- else if (n==*sr)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 55, 55, 255, 255);
- }
- }
- }
- }
- else if (i==SC_SPECIAL)//special menu
- {
- if (fwidth > XRES-BARSIZE) { //fancy scrolling
- float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE)));
- xoff = (int)(overflow / location);
- }
- for (n = 0; n<PT_NUM; n++)
- {
- if (ptypes[n].menusection==i&&ptypes[n].menu==1)
- {
- /*if (x-18<=0)
- {
- x = XRES-BARSIZE-18;
- y += 19;
- }*/
- x -= draw_tool_xy(vid_buf, x-xoff, y, n, ptypes[n].pcolors)+5;
- if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
- h = n;
- }
- if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15&&(sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL)))
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 0, 255, 255, 255);
- h = n;
- }
- else if (n==SLALT)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 0, 255, 255, 255);
- }
- else if (n==*sl)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
- }
- else if (n==*sr)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 55, 55, 255, 255);
- }
- }
- }
- }
- else if(i==SC_LIFE)
- {
- int n2;
- if (fwidth > XRES-BARSIZE) { //fancy scrolling
- float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE)));
- xoff = (int)(overflow / location);
- }
- for (n2 = 0; n2<NGOLALT; n2++)
- {
- n = PT_LIFE | (n2<<8);
- x -= draw_tool_xy(vid_buf, x-xoff, y, n, gmenu[n2].colour)+5;
- if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
- h = n;
- }
- if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15&&(sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_SHIFT)))
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 0, 255, 255, 255);
- h = n;
- }
- else if (n==SLALT)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 0, 255, 255, 255);
- }
- else if (n==*sl)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
- }
- else if (n==*sr)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 55, 55, 255, 255);
- }
- }
- }
- else //all other menus
- {
- if (fwidth > XRES-BARSIZE) { //fancy scrolling
- float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE)));
- xoff = (int)(overflow / location);
- }
- for (n = 0; n<PT_NUM; n++)
- {
- if (ptypes[n].menusection==i&&ptypes[n].menu==1)
- {
- x -= draw_tool_xy(vid_buf, x-xoff, y, n, ptypes[n].pcolors)+5;
- if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
- h = n;
- }
- if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15&&(sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL)))
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 0, 255, 255, 255);
- h = n;
- }
- else if (n==SLALT)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 0, 255, 255, 255);
- }
- else if (n==*sl)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
- }
- else if (n==*sr)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 55, 55, 255, 255);
- }
- }
- }
- }
- if (!bq && mx>=((XRES+BARSIZE)-16) ) //highlight menu section
- if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL))
- if (i>=0&&i<SC_TOTAL)
- SEC = i;
-
- if (h==-1)
- {
- drawtext(vid_buf, XRES-textwidth((char *)msections[i].name)-BARSIZE, sy-10, (char *)msections[i].name, 255, 255, 255, 255);
- }
- else if (i==SC_WALL||i==SC_TOOL)
- {
- drawtext(vid_buf, XRES-textwidth((char *)wtypes[h-UI_WALLSTART].descs)-BARSIZE, sy-10, (char *)wtypes[h-UI_WALLSTART].descs, 255, 255, 255, 255);
- }
- else if (i==SC_LIFE)
- {
- drawtext(vid_buf, XRES-textwidth((char *)gmenu[(h>>8)&0xFF].description)-BARSIZE, sy-10, (char *)gmenu[(h>>8)&0xFF].description, 255, 255, 255, 255);
- }
- else
- {
- drawtext(vid_buf, XRES-textwidth((char *)ptypes[h].descs)-BARSIZE, sy-10, (char *)ptypes[h].descs, 255, 255, 255, 255);
- }
- //these are click events, b=1 is left click, b=4 is right
- //h has the value of the element it is over, and -1 if not over an element
- if (b==1&&h==-1)
- {
- if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL) && SEC>=0)
- {
- SLALT = -1;
- SEC2 = SEC;
- }
- }
- if (b==1&&h!=-1)
- {
- if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL))
- {
- SLALT = h;
- SEC2 = -1;
- }
- else {
- *sl = *su = h;
- *dae = 51;
- }
- }
- if (b==4&&h==-1)
- {
- if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL) && SEC>=0)
- {
- SLALT = -1;
- SEC2 = SEC;
- }
- }
- if (b==4&&h!=-1)
- {
- if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL))
- {
- SLALT = h;
- SEC2 = -1;
- }
- else {
- *sr = *su = h;
- *dae = 51;
- }
- }
-}
-int color_menu_ui(pixel *vid_buf, int i, int *cr, int *cg, int *cb, int b, int bq, int mx, int my, int *tool)
-{
- int h,x,y,n=0,height,width,sy,rows=0,xoff=0,fwidth,a,c;
- fwidth = colorsections[i].itemcount*31;
- h = -1;
- x = XRES-BARSIZE-18;
- y = YRES+5;
- sy = y;
- if(i==0) //color menu
- {
- if (fwidth > XRES-BARSIZE) { //fancy scrolling
- float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE)));
- xoff = (int)(overflow / location);
- }
- for (n = 0; n<7; n++)
- {
- for (a=1; a<15; a++)
- {
- for (c=1; c<27; c++)
- {
- vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = colorlist[n].colour;
- }
- }
- x -= 26+5;
- if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
- h = n;
- }
- }
- if(h!=-1)
- {
- drawtext(vid_buf, XRES-textwidth((char *)colorlist[h].descs)-BARSIZE, sy+20, (char *)colorlist[h].descs, 255, 255, 255, 255);
- }
- else
- {
- drawtext(vid_buf, XRES-textwidth((char *)colorsections[i].name)-BARSIZE, sy+20, (char *)colorsections[i].name, 255, 255, 255, 255);
- }
- //these are click events, b=1 is left click, b=4 is right
- //h has the value of the element it is over, and -1 if not over an element
- if (b==1 && h!=-1)
- {
- *cr = PIXR(colorlist[h].colour);
- *cg = PIXG(colorlist[h].colour);
- *cb = PIXB(colorlist[h].colour);
- return 1;
- }
- }
- if(i==1) //deco tool menu
- {
- if (fwidth > XRES-BARSIZE) { //fancy scrolling
- float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE)));
- xoff = (int)(overflow / location);
- }
- for (n = 0; n<4; n++)
- {
- for (a=1; a<15; a++)
- {
- for (c=1; c<27; c++)
- {
- if (n == DECO_LIGHTEN)
- vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = PIXRGB(PIXR(toollist[n].colour)-10*a, PIXG(toollist[n].colour)-10*a, PIXB(toollist[n].colour)-10*a);
- else if (n == DECO_DARKEN)
- vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = PIXRGB(PIXR(toollist[n].colour)+10*a, PIXG(toollist[n].colour)+10*a, PIXB(toollist[n].colour)+10*a);
- else if (n == DECO_SMUDGE)
- vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = PIXRGB(PIXR(toollist[n].colour), PIXG(toollist[n].colour)-5*c, PIXB(toollist[n].colour)+5*c);
- else if (n == DECO_DRAW)
- vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = PIXRGB(*cr,*cg,*cb);
- else
- vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = toollist[n].colour;
- }
- }
- x -= 26+5;
- if (!bq && mx>=x+32-xoff && mx<x+58-xoff && my>=y && my< y+15)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
- h = n;
- }
- else if (n==*tool)
- {
- drawrect(vid_buf, x+30-xoff, y-1, 29, 17, 255, 55, 55, 255);
- }
- }
- if(h!=-1)
- {
- drawtext(vid_buf, XRES-textwidth((char *)toollist[h].descs)-BARSIZE, sy+20, (char *)toollist[h].descs, 255, 255, 255, 255);
- }
- else
- {
- drawtext(vid_buf, XRES-textwidth((char *)colorsections[i].name)-BARSIZE, sy+20, (char *)colorsections[i].name, 255, 255, 255, 255);
- }
- //these are click events, b=1 is left click, b=4 is right
- //h has the value of the element it is over, and -1 if not over an element
- if (b==1 && h!=-1)
- {
- *tool = h;
- return 0;
- }
- }
-
- return 0;
-}
-
-int quickoptions_tooltip_fade = 0;
-char * quickoptions_tooltip;
-int quickoptions_tooltip_y = 0;
-void quickoptions_menu(pixel *vid_buf, int b, int bq, int x, int y)
-{
- int i = 0;
- if(quickoptions_tooltip_fade && quickoptions_tooltip)
- {
- drawtext_outline(vid_buf, (XRES - 5) - textwidth(quickoptions_tooltip), quickoptions_tooltip_y, quickoptions_tooltip, 255, 255, 255, quickoptions_tooltip_fade*20, 0, 0, 0, quickoptions_tooltip_fade*15);
- quickoptions_tooltip_fade--;
- }
- while(quickmenu[i].icon!=NULL)
- {
- if(quickmenu[i].type == QM_TOGGLE)
- {
- drawrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+1, 14, 14, 255, 255, 255, 255);
- if(*(quickmenu[i].variable))
- {
- fillrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+1, 14, 14, 255, 255, 255, 255);
- drawtext(vid_buf, (XRES+BARSIZE)-11, (i*16)+5, quickmenu[i].icon, 0, 0, 0, 255);
- }
- else
- {
- fillrect(vid_buf, (XRES+BARSIZE)-16, (i*16)+1, 14, 14, 0, 0, 0, 255);
- drawtext(vid_buf, (XRES+BARSIZE)-11, (i*16)+5, quickmenu[i].icon, 255, 255, 255, 255);
- }
- if(x >= (XRES+BARSIZE)-16 && x <= (XRES+BARSIZE)-2 && y >= (i*16)+1 && y <= (i*16)+15)
- {
- quickoptions_tooltip_fade+=2;
- quickoptions_tooltip = quickmenu[i].name;
- quickoptions_tooltip_y = (i*16)+5;
- if(b && !bq)
- {
- if (!strcmp(quickmenu[i].name,"Newtonian gravity"))
- {
- if(!ngrav_enable)
- start_grav_async();
- else
- stop_grav_async();
- }
- else
- *(quickmenu[i].variable) = !(*(quickmenu[i].variable));
- }
- }
- }
- i++;
- }
- if(quickoptions_tooltip_fade > 12)
- quickoptions_tooltip_fade = 12;
- if(quickoptions_tooltip_fade < 0)
- quickoptions_tooltip_fade = 0;
-}
-
-int sdl_poll(void)
-{
- SDL_Event event;
- sdl_key=sdl_rkey=sdl_wheel=sdl_ascii=0;
- loop_time = SDL_GetTicks();
- while (SDL_PollEvent(&event))
- {
- switch (event.type)
- {
- case SDL_KEYDOWN:
- sdl_key=event.key.keysym.sym;
- sdl_ascii=event.key.keysym.unicode;
- if (event.key.keysym.sym == SDLK_PLUS)
- {
- sdl_wheel++;
- }
- if (event.key.keysym.sym == SDLK_MINUS)
- {
- sdl_wheel--;
- }
- break;
-
- case SDL_KEYUP:
- sdl_rkey=event.key.keysym.sym;
- break;
- case SDL_MOUSEBUTTONDOWN:
- if (event.button.button == SDL_BUTTON_WHEELUP)
- sdl_wheel++;
- if (event.button.button == SDL_BUTTON_WHEELDOWN)
- sdl_wheel--;
- break;
- case SDL_QUIT:
- return 1;
- case SDL_SYSWMEVENT:
-#if (defined(LIN32) || defined(LIN64)) && defined(SDL_VIDEO_DRIVER_X11)
- if (event.syswm.msg->subsystem != SDL_SYSWM_X11)
- break;
- sdl_wminfo.info.x11.lock_func();
- XEvent xe = event.syswm.msg->event.xevent;
- if (xe.type==SelectionClear)
- {
- if (clipboard_text!=NULL) {
- free(clipboard_text);
- clipboard_text = NULL;
- }
- }
- else if (xe.type==SelectionRequest)
- {
- XEvent xr;
- xr.xselection.type = SelectionNotify;
- xr.xselection.requestor = xe.xselectionrequest.requestor;
- xr.xselection.selection = xe.xselectionrequest.selection;
- xr.xselection.target = xe.xselectionrequest.target;
- xr.xselection.property = xe.xselectionrequest.property;
- xr.xselection.time = xe.xselectionrequest.time;
- if (xe.xselectionrequest.target==XA_TARGETS)
- {
- // send list of supported formats
- Atom targets[] = {XA_TARGETS, XA_STRING};
- xr.xselection.property = xe.xselectionrequest.property;
- XChangeProperty(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, xe.xselectionrequest.property, XA_ATOM, 32, PropModeReplace, (unsigned char*)targets, (int)(sizeof(targets)/sizeof(Atom)));
- }
- // TODO: Supporting more targets would be nice
- else if (xe.xselectionrequest.target==XA_STRING && clipboard_text)
- {
- XChangeProperty(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, xe.xselectionrequest.property, xe.xselectionrequest.target, 8, PropModeReplace, clipboard_text, strlen(clipboard_text)+1);
- }
- else
- {
- // refuse clipboard request
- xr.xselection.property = None;
- }
- XSendEvent(sdl_wminfo.info.x11.display, xe.xselectionrequest.requestor, 0, 0, &xr);
- }
- sdl_wminfo.info.x11.unlock_func();
-#endif
- continue;
- }
- }
- sdl_mod = SDL_GetModState();
- return 0;
-}
-
-void stickmen_keys()
-{
- // 4
- //1 8 2
- if (sdl_key == SDLK_RIGHT)
- {
- player.comm = (int)(player.comm)|0x02; //Go right command
- }
- if (sdl_key == SDLK_LEFT)
- {
- player.comm = (int)(player.comm)|0x01; //Go left command
- }
- if (sdl_key == SDLK_DOWN && ((int)(player.comm)&0x08)!=0x08)
- {
- player.comm = (int)(player.comm)|0x08; //Use element command
- }
- if (sdl_key == SDLK_UP && ((int)(player.comm)&0x04)!=0x04)
- {
- player.comm = (int)(player.comm)|0x04; //Jump command
- }
-
- if (sdl_key == SDLK_d)
- {
- player2.comm = (int)(player2.comm)|0x02; //Go right command
- }
- if (sdl_key == SDLK_a)
- {
- player2.comm = (int)(player2.comm)|0x01; //Go left command
- }
- if (sdl_key == SDLK_s && ((int)(player2.comm)&0x08)!=0x08)
- {
- player2.comm = (int)(player2.comm)|0x08; //Use element command
- }
- if (sdl_key == SDLK_w && ((int)(player2.comm)&0x04)!=0x04)
- {
- player2.comm = (int)(player2.comm)|0x04; //Jump command
- }
-
- if (sdl_rkey == SDLK_RIGHT || sdl_rkey == SDLK_LEFT)
- {
- player.pcomm = player.comm; //Saving last movement
- player.comm = (int)(player.comm)&12; //Stop command
- }
- if (sdl_rkey == SDLK_UP)
- {
- player.comm = (int)(player.comm)&11;
- }
- if (sdl_rkey == SDLK_DOWN)
- {
- player.comm = (int)(player.comm)&7;
- }
-
- if (sdl_rkey == SDLK_d || sdl_rkey == SDLK_a)
- {
- player2.pcomm = player2.comm; //Saving last movement
- player2.comm = (int)(player2.comm)&12; //Stop command
- }
- if (sdl_rkey == SDLK_w)
- {
- player2.comm = (int)(player2.comm)&11;
- }
- if (sdl_rkey == SDLK_s)
- {
- player2.comm = (int)(player2.comm)&7;
- }
-}
-
-void set_cmode(int cm) // sets to given view mode
-{
- int cmode = cm;
- colour_mode = COLOUR_DEFAULT;
-
- free(render_modes);
- render_modes = calloc(2, sizeof(unsigned int));
- render_modes[0] = RENDER_BASC;
- render_modes[1] = 0;
-
- free(display_modes);
- display_modes = calloc(1, sizeof(unsigned int));
- display_modes[0] = 0;
-
- itc = 51;
- if (cmode==CM_VEL)
- {
- free(render_modes);
- render_modes = calloc(3, sizeof(unsigned int));
- render_modes[0] = RENDER_EFFE;
- render_modes[1] = RENDER_BASC;
- render_modes[2] = 0;
- free(display_modes);
- display_modes = calloc(2, sizeof(unsigned int));
- display_modes[0] = DISPLAY_AIRV;
- display_modes[1] = 0;
- strcpy(itc_msg, "Velocity Display");
- }
- else if (cmode==CM_PRESS)
- {
- free(render_modes);
- render_modes = calloc(3, sizeof(unsigned int));
- render_modes[0] = RENDER_EFFE;
- render_modes[1] = RENDER_BASC;
- render_modes[2] = 0;
- free(display_modes);
- display_modes = calloc(2, sizeof(unsigned int));
- display_modes[0] = DISPLAY_AIRP;
- display_modes[1] = 0;
- strcpy(itc_msg, "Pressure Display");
- }
- else if (cmode==CM_PERS)
- {
- free(render_modes);
- render_modes = calloc(3, sizeof(unsigned int));
- render_modes[0] = RENDER_EFFE;
- render_modes[1] = RENDER_BASC;
- render_modes[2] = 0;
- free(display_modes);
- display_modes = calloc(2, sizeof(unsigned int));
- display_modes[0] = DISPLAY_PERS;
- display_modes[1] = 0;
- memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- strcpy(itc_msg, "Persistent Display");
- }
- else if (cmode==CM_FIRE)
- {
- free(render_modes);
- render_modes = calloc(3, sizeof(unsigned int));
- render_modes[0] = RENDER_FIRE;
- render_modes[1] = RENDER_EFFE;
- render_modes[2] = 0;
- memset(fire_r, 0, sizeof(fire_r));
- memset(fire_g, 0, sizeof(fire_g));
- memset(fire_b, 0, sizeof(fire_b));
- strcpy(itc_msg, "Fire Display");
- }
- else if (cmode==CM_BLOB)
- {
- free(render_modes);
- render_modes = calloc(4, sizeof(unsigned int));
- render_modes[0] = RENDER_FIRE;
- render_modes[1] = RENDER_BLOB;
- render_modes[2] = RENDER_EFFE;
- render_modes[3] = 0;
- memset(fire_r, 0, sizeof(fire_r));
- memset(fire_g, 0, sizeof(fire_g));
- memset(fire_b, 0, sizeof(fire_b));
- strcpy(itc_msg, "Blob Display");
- }
- else if (cmode==CM_HEAT)
- {
- colour_mode = COLOUR_HEAT;
- strcpy(itc_msg, "Heat Display");
- free(display_modes);
- display_modes = calloc(2, sizeof(unsigned int));
- display_modes[0] = DISPLAY_AIRH;
- display_modes[1] = 0;
- }
- else if (cmode==CM_FANCY)
- {
- free(render_modes);
- render_modes = calloc(5, sizeof(unsigned int));
- render_modes[0] = RENDER_FIRE;
- render_modes[1] = RENDER_GLOW;
- render_modes[2] = RENDER_BLUR;
- render_modes[3] = RENDER_EFFE;
- render_modes[4] = 0;
- free(display_modes);
- display_modes = calloc(2, sizeof(unsigned int));
- display_modes[0] = DISPLAY_WARP;
- display_modes[1] = 0;
- memset(fire_r, 0, sizeof(fire_r));
- memset(fire_g, 0, sizeof(fire_g));
- memset(fire_b, 0, sizeof(fire_b));
- strcpy(itc_msg, "Fancy Display");
- }
- else if (cmode==CM_NOTHING)
- {
- strcpy(itc_msg, "Nothing Display");
- }
- else if (cmode==CM_GRAD)
- {
- colour_mode = COLOUR_GRAD;
- strcpy(itc_msg, "Heat Gradient Display");
- }
- else if (cmode==CM_LIFE)
- {
- colour_mode = COLOUR_LIFE;
- strcpy(itc_msg, "Life Gradient Display");
- }
- else if (cmode==CM_CRACK)
- {
- free(render_modes);
- render_modes = calloc(3, sizeof(unsigned int));
- render_modes[0] = RENDER_EFFE;
- render_modes[1] = RENDER_BASC;
- render_modes[2] = 0;
- free(display_modes);
- display_modes = calloc(2, sizeof(unsigned int));
- display_modes[0] = DISPLAY_AIRC;
- display_modes[1] = 0;
- strcpy(itc_msg, "Alternate Velocity Display");
- }
- else //if no special text given, it will display this.
- {
- strcpy(itc_msg, "Error: Incorrect Display Number");
- }
-
- update_display_modes();// Update render_mode and display_mode from the relevant arrays
- save_presets(0);
-}
-
-char *download_ui(pixel *vid_buf, char *uri, int *len)
-{
- int dstate = 0;
- void *http = http_async_req_start(NULL, uri, NULL, 0, 0);
- int x0=(XRES-240)/2,y0=(YRES-MENUSIZE)/2;
- int done, total, i, ret, zlen, ulen;
- char str[16], *tmp, *res;
-
- if (svf_login) {
- http_auth_headers(http, svf_user_id, NULL, svf_session_id);
- }
-
- while (!http_async_req_status(http))
- {
- sdl_poll();
-
- http_async_get_length(http, &total, &done);
-
- clearrect(vid_buf, x0-2, y0-2, 244, 64);
- drawrect(vid_buf, x0, y0, 240, 60, 192, 192, 192, 255);
- drawtext(vid_buf, x0+8, y0+8, "Please wait", 255, 216, 32, 255);
- drawtext(vid_buf, x0+8, y0+26, "Downloading update...", 255, 255, 255, 255);
-
- if (total)
- {
- i = (236*done)/total;
- fillrect(vid_buf, x0+1, y0+45, i+1, 14, 255, 216, 32, 255);
- i = (100*done)/total;
- sprintf(str, "%d%%", i);
- if (i<50)
- drawtext(vid_buf, x0+120-textwidth(str)/2, y0+48, str, 192, 192, 192, 255);
- else
- drawtext(vid_buf, x0+120-textwidth(str)/2, y0+48, str, 0, 0, 0, 255);
- }
- else
- drawtext(vid_buf, x0+120-textwidth("Waiting...")/2, y0+48, "Waiting...", 255, 216, 32, 255);
-
- drawrect(vid_buf, x0, y0+44, 240, 16, 192, 192, 192, 255);
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
- }
-
- tmp = http_async_req_stop(http, &ret, &zlen);
- if (ret!=200)
- {
- error_ui(vid_buf, ret, http_ret_text(ret));
- if (tmp)
- free(tmp);
- return NULL;
- }
- if (!tmp)
- {
- error_ui(vid_buf, 0, "Server did not return data");
- return NULL;
- }
-
- if (zlen<16)
- {
- printf("ZLen is not 16!\n");
- goto corrupt;
- }
- if (tmp[0]!=0x42 || tmp[1]!=0x75 || tmp[2]!=0x54 || tmp[3]!=0x54)
- {
- printf("Tmperr %d, %d, %d, %d\n", tmp[0], tmp[1], tmp[2], tmp[3]);
- goto corrupt;
- }
-
- ulen = (unsigned char)tmp[4];
- ulen |= ((unsigned char)tmp[5])<<8;
- ulen |= ((unsigned char)tmp[6])<<16;
- ulen |= ((unsigned char)tmp[7])<<24;
-
- res = (char *)malloc(ulen);
- if (!res)
- {
- printf("No res!\n");
- goto corrupt;
- }
- dstate = BZ2_bzBuffToBuffDecompress((char *)res, (unsigned *)&ulen, (char *)(tmp+8), zlen-8, 0, 0);
- if (dstate)
- {
- printf("Decompression failure: %d!\n", dstate);
- free(res);
- goto corrupt;
- }
-
- free(tmp);
- if (len)
- *len = ulen;
- return res;
-
-corrupt:
- error_ui(vid_buf, 0, "Downloaded update is corrupted");
- free(tmp);
- return NULL;
-}
-
-int search_ui(pixel *vid_buf)
-{
- int nmp=-1,uih=0,nyu,nyd,b=1,bq,mx=0,my=0,mxq=0,myq=0,mmt=0,gi,gj,gx,gy,pos,i,mp,dp,dap,own,last_own=search_own,last_fav=search_fav,page_count=0,last_page=0,last_date=0,j,w,h,st=0,lv;
- int is_p1=0, exp_res=GRID_X*GRID_Y, tp, view_own=0;
- int thumb_drawn[GRID_X*GRID_Y];
- pixel *v_buf = (pixel *)malloc(((YRES+MENUSIZE)*(XRES+BARSIZE))*PIXELSIZE);
- pixel *bthumb_rsdata = NULL;
- float ry;
- time_t http_last_use=HTTP_TIMEOUT;
- ui_edit ed;
- ui_richtext motd;
-
-
- void *http = NULL;
- int active = 0;
- char *last = NULL;
- int search = 0;
- int lasttime = TIMEOUT;
- char *uri;
- int status;
- char *results;
- char *tmp, ts[64];
-
- void *img_http[IMGCONNS];
- char *img_id[IMGCONNS];
- void *thumb, *data;
- int thlen, dlen;
-
- if (!v_buf)
- return 0;
- memset(v_buf, 0, ((YRES+MENUSIZE)*(XRES+BARSIZE))*PIXELSIZE);
-
- memset(img_http, 0, sizeof(img_http));
- memset(img_id, 0, sizeof(img_id));
-
- memset(search_ids, 0, sizeof(search_ids));
- memset(search_dates, 0, sizeof(search_dates));
- memset(search_names, 0, sizeof(search_names));
- memset(search_scoreup, 0, sizeof(search_scoreup));
- memset(search_scoredown, 0, sizeof(search_scoredown));
- memset(search_publish, 0, sizeof(search_publish));
- memset(search_owners, 0, sizeof(search_owners));
- memset(search_thumbs, 0, sizeof(search_thumbs));
- memset(search_thsizes, 0, sizeof(search_thsizes));
-
- memset(thumb_drawn, 0, sizeof(thumb_drawn));
-
- do_open = 0;
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- ed.x = 65;
- ed.y = 13;
- ed.w = XRES-200;
- ed.nx = 1;
- ed.def = "[search terms]";
- ed.focus = 1;
- ed.hide = 0;
- ed.cursor = strlen(search_expr);
- ed.multiline = 0;
- strcpy(ed.str, search_expr);
-
- motd.x = 20;
- motd.y = 33;
- motd.str[0] = 0;
-
- sdl_wheel = 0;
-
- while (!sdl_poll())
- {
- uih = 0;
- bq = b;
- mxq = mx;
- myq = my;
- b = mouse_get_state(&mx, &my);
-
- if (mx!=mxq || my!=myq || sdl_wheel || b)
- mmt = 0;
- else if (mmt<TIMEOUT)
- mmt++;
-
- clearrect(vid_buf, -1, -1, (XRES+BARSIZE)+1, YRES+MENUSIZE+1);
-
- memcpy(vid_buf, v_buf, ((YRES+MENUSIZE)*(XRES+BARSIZE))*PIXELSIZE);
-
- drawtext(vid_buf, 11, 13, "Search:", 192, 192, 192, 255);
- if (!last || (!active && strcmp(last, ed.str)))
- drawtext(vid_buf, 51, 11, "\x8E", 192, 160, 32, 255);
- else
- drawtext(vid_buf, 51, 11, "\x8E", 32, 64, 160, 255);
- drawtext(vid_buf, 51, 11, "\x8F", 255, 255, 255, 255);
- drawrect(vid_buf, 48, 8, XRES-182, 16, 192, 192, 192, 255);
-
- if (!svf_login || search_fav)
- {
- search_own = 0;
- drawrect(vid_buf, XRES-64+16, 8, 56, 16, 96, 96, 96, 255);
- drawtext(vid_buf, XRES-61+16, 11, "\x94", 96, 80, 16, 255);
- drawtext(vid_buf, XRES-61+16, 11, "\x93", 128, 128, 128, 255);
- drawtext(vid_buf, XRES-46+16, 13, "My Own", 128, 128, 128, 255);
- }
- else if (search_own)
- {
- fillrect(vid_buf, XRES-65+16, 7, 58, 18, 255, 255, 255, 255);
- drawtext(vid_buf, XRES-61+16, 11, "\x94", 192, 160, 64, 255);
- drawtext(vid_buf, XRES-61+16, 11, "\x93", 32, 32, 32, 255);
- drawtext(vid_buf, XRES-46+16, 13, "My Own", 0, 0, 0, 255);
- }
- else
- {
- drawrect(vid_buf, XRES-64+16, 8, 56, 16, 192, 192, 192, 255);
- drawtext(vid_buf, XRES-61+16, 11, "\x94", 192, 160, 32, 255);
- 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(!svf_login)
- {
- search_fav = 0;
- drawrect(vid_buf, XRES-134, 8, 16, 16, 192, 192, 192, 255);
- drawtext(vid_buf, XRES-130, 11, "\xCC", 120, 120, 120, 255);
- }
- else 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);
- }
- else
- {
- drawrect(vid_buf, XRES-134, 8, 16, 16, 192, 192, 192, 255);
- drawtext(vid_buf, XRES-130, 11, "\xCC", 192, 160, 32, 255);
- }
-
- if(search_fav)
- {
- search_date = 0;
- drawrect(vid_buf, XRES-129+16, 8, 60, 16, 96, 96, 96, 255);
- drawtext(vid_buf, XRES-126+16, 11, "\xA9", 44, 48, 32, 255);
- drawtext(vid_buf, XRES-126+16, 11, "\xA8", 32, 44, 32, 255);
- drawtext(vid_buf, XRES-126+16, 11, "\xA7", 128, 128, 128, 255);
- drawtext(vid_buf, XRES-111+16, 13, "By votes", 128, 128, 128, 255);
- }
- else if (search_date)
- {
- fillrect(vid_buf, XRES-130+16, 7, 62, 18, 255, 255, 255, 255);
- drawtext(vid_buf, XRES-126+16, 11, "\xA6", 32, 32, 32, 255);
- drawtext(vid_buf, XRES-111+16, 13, "By date", 0, 0, 0, 255);
- }
- else
- {
- drawrect(vid_buf, XRES-129+16, 8, 60, 16, 192, 192, 192, 255);
- drawtext(vid_buf, XRES-126+16, 11, "\xA9", 144, 48, 32, 255);
- drawtext(vid_buf, XRES-126+16, 11, "\xA8", 32, 144, 32, 255);
- drawtext(vid_buf, XRES-126+16, 11, "\xA7", 255, 255, 255, 255);
- drawtext(vid_buf, XRES-111+16, 13, "By votes", 255, 255, 255, 255);
- }
-
- if (search_page)
- {
- drawtext(vid_buf, 4, YRES+MENUSIZE-16, "\x96", 255, 255, 255, 255);
- drawrect(vid_buf, 1, YRES+MENUSIZE-20, 16, 16, 255, 255, 255, 255);
- }
- if (page_count > 9)
- {
- drawtext(vid_buf, XRES-15, YRES+MENUSIZE-16, "\x95", 255, 255, 255, 255);
- drawrect(vid_buf, XRES-18, YRES+MENUSIZE-20, 16, 16, 255, 255, 255, 255);
- }
-
- ui_edit_draw(vid_buf, &ed);
-
- if ((b && !bq && mx>=1 && mx<=17 && my>=YRES+MENUSIZE-20 && my<YRES+MENUSIZE-4) || sdl_wheel>0)
- {
- if (search_page)
- {
- search_page --;
- lasttime = TIMEOUT;
- }
- sdl_wheel = 0;
- uih = 1;
- }
- if ((b && !bq && mx>=XRES-18 && mx<=XRES-1 && my>=YRES+MENUSIZE-20 && my<YRES+MENUSIZE-4) || sdl_wheel<0)
- {
- if (page_count>exp_res)
- {
- lasttime = TIMEOUT;
- search_page ++;
- page_count = exp_res;
- }
- sdl_wheel = 0;
- uih = 1;
- }
-
- tp = -1;
- if (is_p1)
- {
- //Message of the day
- ui_richtext_process(mx, my, b, bq, &motd);
- ui_richtext_draw(vid_buf, &motd);
- //Popular tags
- drawtext(vid_buf, (XRES-textwidth("Popular tags:"))/2, 49, "Popular tags:", 255, 192, 64, 255);
- for (gj=0; gj<((GRID_Y-GRID_P)*YRES)/(GRID_Y*14); gj++)
- for (gi=0; gi<(GRID_X+1); gi++)
- {
- pos = gi+(GRID_X+1)*gj;
- if (pos>TAG_MAX || !tag_names[pos])
- break;
- if (tag_votes[0])
- i = 127+(128*tag_votes[pos])/tag_votes[0];
- else
- i = 192;
- w = textwidth(tag_names[pos]);
- if (w>XRES/(GRID_X+1)-5)
- w = XRES/(GRID_X+1)-5;
- gx = (XRES/(GRID_X+1))*gi;
- gy = gj*13 + 62;
- if (mx>=gx && mx<gx+(XRES/((GRID_X+1)+1)) && my>=gy && my<gy+14)
- {
- j = (i*5)/6;
- tp = pos;
- }
- else
- j = i;
- drawtextmax(vid_buf, gx+(XRES/(GRID_X+1)-w)/2, gy, XRES/(GRID_X+1)-5, tag_names[pos], j, j, i, 255);
- }
- }
-
- mp = dp = -1;
- dap = -1;
- st = 0;
- for (gj=0; gj<GRID_Y; gj++)
- for (gi=0; gi<GRID_X; gi++)
- {
- if (is_p1)
- {
- pos = gi+GRID_X*(gj-GRID_Y+GRID_P);
- if (pos<0)
- break;
- }
- else
- pos = gi+GRID_X*gj;
- if (!search_ids[pos])
- break;
- gx = ((XRES/GRID_X)*gi) + (XRES/GRID_X-XRES/GRID_S)/2;
- gy = ((((YRES-(MENUSIZE-20))+15)/GRID_Y)*gj) + ((YRES-(MENUSIZE-20))/GRID_Y-(YRES-(MENUSIZE-20))/GRID_S+10)/2 + 18;
- if (textwidth(search_names[pos]) > XRES/GRID_X-10)
- {
- tmp = malloc(strlen(search_names[pos])+4);
- strcpy(tmp, search_names[pos]);
- j = textwidthx(tmp, XRES/GRID_X-15);
- strcpy(tmp+j, "...");
- drawtext(vid_buf, gx+XRES/(GRID_S*2)-textwidth(tmp)/2, gy+YRES/GRID_S+7, tmp, 192, 192, 192, 255);
- free(tmp);
- }
- else
- drawtext(vid_buf, gx+XRES/(GRID_S*2)-textwidth(search_names[pos])/2, gy+YRES/GRID_S+7, search_names[pos], 192, 192, 192, 255);
- j = textwidth(search_owners[pos]);
- if (mx>=gx+XRES/(GRID_S*2)-j/2 && mx<=gx+XRES/(GRID_S*2)+j/2 &&
- my>=gy+YRES/GRID_S+18 && my<=gy+YRES/GRID_S+31)
- {
- st = 1;
- drawtext(vid_buf, gx+XRES/(GRID_S*2)-j/2, gy+YRES/GRID_S+20, search_owners[pos], 128, 128, 160, 255);
- }
- else
- drawtext(vid_buf, gx+XRES/(GRID_S*2)-j/2, gy+YRES/GRID_S+20, search_owners[pos], 128, 128, 128, 255);
- if (search_thumbs[pos]&&thumb_drawn[pos]==0)
- {
- //render_thumb(search_thumbs[pos], search_thsizes[pos], 1, v_buf, gx, gy, GRID_S);
- int finh, finw;
- pixel *thumb_rsdata = NULL;
- pixel *thumb_imgdata = ptif_unpack(search_thumbs[pos], search_thsizes[pos], &finw, &finh);
- if(thumb_imgdata!=NULL){
- thumb_rsdata = resample_img_nn(thumb_imgdata, finw, finh, XRES/GRID_S, YRES/GRID_S);
- draw_image(v_buf, thumb_rsdata, gx, gy, XRES/GRID_S, YRES/GRID_S, 255);
- free(thumb_imgdata);
- free(thumb_rsdata);
- }
- thumb_drawn[pos] = 1;
- }
- own = svf_login && (!strcmp(svf_user, search_owners[pos]) || svf_admin || svf_mod);
- if (mx>=gx-2 && mx<=gx+XRES/GRID_S+3 && my>=gy-2 && my<=gy+YRES/GRID_S+30)
- mp = pos;
- if ((own || search_fav) && mx>=gx+XRES/GRID_S-4 && mx<=gx+XRES/GRID_S+6 && my>=gy-6 && my<=gy+4)
- {
- mp = -1;
- dp = pos;
- }
- if (own && !search_dates[pos] && mx>=gx-6 && mx<=gx+4 && my>=gy+YRES/GRID_S-4 && my<=gy+YRES/GRID_S+6)
- {
- mp = -1;
- dap = pos;
- }
- drawrect(vid_buf, gx-2+(XRES/GRID_S)+5, gy-2, 6, YRES/GRID_S+3, 128, 128, 128, 255);
- fillrect(vid_buf, gx-2+(XRES/GRID_S)+5, gy-2, 6, 1+(YRES/GRID_S+3)/2, 0, 107, 10, 255);
- fillrect(vid_buf, gx-2+(XRES/GRID_S)+5, gy-2+((YRES/GRID_S+3)/2), 6, 1+(YRES/GRID_S+3)/2, 107, 10, 0, 255);
-
- if (mp==pos && !st)
- drawrect(vid_buf, gx-2, gy-2, XRES/GRID_S+3, YRES/GRID_S+3, 160, 160, 192, 255);
- else
- drawrect(vid_buf, gx-2, gy-2, XRES/GRID_S+3, YRES/GRID_S+3, 128, 128, 128, 255);
- if (own || search_fav)
- {
- if (dp == pos)
- drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x86", 255, 48, 32, 255);
- else
- drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x86", 160, 48, 32, 255);
- drawtext(vid_buf, gx+XRES/GRID_S-4, gy-6, "\x85", 255, 255, 255, 255);
- }
- if (!search_publish[pos])
- {
- drawtext(vid_buf, gx-6, gy-6, "\xCD", 255, 255, 255, 255);
- drawtext(vid_buf, gx-6, gy-6, "\xCE", 212, 151, 81, 255);
- }
- if (!search_dates[pos] && own)
- {
- fillrect(vid_buf, gx-5, gy+YRES/GRID_S-3, 7, 8, 255, 255, 255, 255);
- if (dap == pos) {
- drawtext(vid_buf, gx-6, gy+YRES/GRID_S-4, "\xA6", 200, 100, 80, 255);
- } else {
- drawtext(vid_buf, gx-6, gy+YRES/GRID_S-4, "\xA6", 160, 70, 50, 255);
- }
- //drawtext(vid_buf, gx-6, gy-6, "\xCE", 212, 151, 81, 255);
- }
- if (view_own || svf_admin || svf_mod)
- {
- sprintf(ts+1, "%d", search_votes[pos]);
- ts[0] = 0xBB;
- for (j=1; ts[j]; j++)
- ts[j] = 0xBC;
- ts[j-1] = 0xB9;
- ts[j] = 0xBA;
- ts[j+1] = 0;
- w = gx+XRES/GRID_S-2-textwidth(ts);
- h = gy+YRES/GRID_S-11;
- drawtext(vid_buf, w, h, ts, 16, 72, 16, 255);
- for (j=0; ts[j]; j++)
- ts[j] -= 14;
- drawtext(vid_buf, w, h, ts, 192, 192, 192, 255);
- sprintf(ts, "%d", search_votes[pos]);
- for (j=0; ts[j]; j++)
- ts[j] += 127;
- drawtext(vid_buf, w+3, h, ts, 255, 255, 255, 255);
- }
- if (search_scoreup[pos]>0||search_scoredown[pos]>0)
- {
- lv = (search_scoreup[pos]>search_scoredown[pos]?search_scoreup[pos]:search_scoredown[pos]);
-
- if (((YRES/GRID_S+3)/2)>lv)
- {
- ry = ((float)((YRES/GRID_S+3)/2)/(float)lv);
- if (lv<8)
- {
- ry = ry/(8-lv);
- }
- nyu = search_scoreup[pos]*ry;
- nyd = search_scoredown[pos]*ry;
- }
- else
- {
- ry = ((float)lv/(float)((YRES/GRID_S+3)/2));
- nyu = search_scoreup[pos]/ry;
- nyd = search_scoredown[pos]/ry;
- }
-
-
- fillrect(vid_buf, gx-1+(XRES/GRID_S)+5, gy-1+((YRES/GRID_S+3)/2)-nyu, 4, nyu, 57, 187, 57, 255);
- fillrect(vid_buf, gx-1+(XRES/GRID_S)+5, gy-2+((YRES/GRID_S+3)/2), 4, nyd, 187, 57, 57, 255);
- //drawrect(vid_buf, gx-2+(XRES/GRID_S)+5, gy-2+((YRES/GRID_S+3)/2)-nyu, 4, nyu, 0, 107, 10, 255);
- //drawrect(vid_buf, gx-2+(XRES/GRID_S)+5, gy-2+((YRES/GRID_S+3)/2)+1, 4, nyd, 107, 10, 0, 255);
- }
- }
-
- if (mp!=-1 && mmt>=TIMEOUT/5 && !st)
- {
- gi = mp % GRID_X;
- gj = mp / GRID_X;
- if (is_p1)
- gj += GRID_Y-GRID_P;
- gx = ((XRES/GRID_X)*gi) + (XRES/GRID_X-XRES/GRID_S)/2;
- gy = (((YRES+15)/GRID_Y)*gj) + (YRES/GRID_Y-YRES/GRID_S+10)/2 + 18;
- i = w = textwidth(search_names[mp]);
- h = YRES/GRID_Z+30;
- if (w<XRES/GRID_Z) w=XRES/GRID_Z;
- gx += XRES/(GRID_S*2)-w/2;
- gy += YRES/(GRID_S*2)-h/2;
- if (gx<2) gx=2;
- if (gx+w>=XRES-2) gx=XRES-3-w;
- if (gy<32) gy=32;
- if (gy+h>=YRES+(MENUSIZE-2)) gy=YRES+(MENUSIZE-3)-h;
- clearrect(vid_buf, gx-2, gy-3, w+4, h);
- drawrect(vid_buf, gx-2, gy-3, w+4, h, 160, 160, 192, 255);
- if (search_thumbs[mp]){
- if(mp != nmp && bthumb_rsdata){
- free(bthumb_rsdata);
- bthumb_rsdata = NULL;
- }
- if(!bthumb_rsdata){
- int finh, finw;
- pixel *thumb_imgdata = ptif_unpack(search_thumbs[mp], search_thsizes[mp], &finw, &finh);
- if(thumb_imgdata!=NULL){
- bthumb_rsdata = resample_img(thumb_imgdata, finw, finh, XRES/GRID_Z, YRES/GRID_Z);
- free(thumb_imgdata);
- }
- }
- draw_image(vid_buf, bthumb_rsdata, gx+(w-(XRES/GRID_Z))/2, gy, XRES/GRID_Z, YRES/GRID_Z, 255);
- nmp = mp;
- }
- drawtext(vid_buf, gx+(w-i)/2, gy+YRES/GRID_Z+4, search_names[mp], 192, 192, 192, 255);
- drawtext(vid_buf, gx+(w-textwidth(search_owners[mp]))/2, gy+YRES/GRID_Z+16, search_owners[mp], 128, 128, 128, 255);
- }
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- ui_edit_process(mx, my, b, &ed);
-
- if (sdl_key==SDLK_RETURN)
- {
- if (!last || (!active && (strcmp(last, ed.str) || last_own!=search_own || last_date!=search_date || last_page!=search_page)))
- lasttime = TIMEOUT;
- else if (search_ids[0] && !search_ids[1])
- {
- bq = 0;
- b = 1;
- mp = 0;
- }
- }
- if (sdl_key==SDLK_ESCAPE)
- goto finish;
-
- if (b && !bq && mx>=XRES-64+16 && mx<=XRES-8+16 && my>=8 && my<=24 && svf_login && !search_fav)
- {
- search_own = !search_own;
- lasttime = TIMEOUT;
- }
- if (b && !bq && mx>=XRES-129+16 && mx<=XRES-65+16 && my>=8 && my<=24 && !search_fav)
- {
- search_date = !search_date;
- lasttime = TIMEOUT;
- }
- if (b && !bq && mx>=XRES-134 && mx<=XRES-134+16 && my>=8 && my<=24 && svf_login)
- {
- search_fav = !search_fav;
- search_own = 0;
- search_date = 0;
- lasttime = TIMEOUT;
- }
-
- if (b && !bq && dp!=-1)
- {
- if (search_fav){
- if(confirm_ui(vid_buf, "Remove from favourites?", search_names[dp], "Remove")){
- execute_unfav(vid_buf, search_ids[dp]);
- lasttime = TIMEOUT;
- if (last)
- {
- free(last);
- last = NULL;
- }
- }
- } else {
- if (confirm_ui(vid_buf, "Do you want to delete?", search_names[dp], "Delete"))
- {
- execute_delete(vid_buf, search_ids[dp]);
- lasttime = TIMEOUT;
- if (last)
- {
- free(last);
- last = NULL;
- }
- }
- }
- }
- if (b && !bq && dap!=-1)
- {
- sprintf(ed.str, "history:%s", search_ids[dap]);
- lasttime = TIMEOUT;
- }
-
- if (b && !bq && tp!=-1)
- {
- strncpy(ed.str, tag_names[tp], 255);
- lasttime = TIMEOUT;
- }
-
- if (b && !bq && mp!=-1 && st)
- {
- sprintf(ed.str, "user:%s", search_owners[mp]);
- lasttime = TIMEOUT;
- }
-
- if (do_open==1)
- {
- mp = 0;
- }
-
- 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 || do_open==1) {
- goto finish;
- }
- }
-
- if (!last)
- {
- search = 1;
- }
- else if (!active && (strcmp(last, ed.str) || last_own!=search_own || last_date!=search_date || last_page!=search_page || last_fav!=search_fav))
- {
- search = 1;
- if (strcmp(last, ed.str) || last_own!=search_own || last_fav!=search_fav || last_date!=search_date)
- {
- search_page = 0;
- page_count = 0;
- }
- free(last);
- last = NULL;
- }
- else
- search = 0;
-
- if (search && lasttime>=TIMEOUT)
- {
- lasttime = 0;
- last = mystrdup(ed.str);
- last_own = search_own;
- last_date = search_date;
- last_page = search_page;
- last_fav = search_fav;
- active = 1;
- 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
- if (search_own || svf_admin || svf_mod)
- tmp = "&ShowVotes=true";
- else
- tmp = "";
- if (!search_own && !search_date && !search_fav && !*last)
- {
- if (search_page)
- {
- exp_res = GRID_X*GRID_Y;
- sprintf(uri, "http://" SERVER "/Search.api?Start=%d&Count=%d%s&Query=", (search_page-1)*GRID_X*GRID_Y+GRID_X*GRID_P, exp_res+1, tmp);
- }
- else
- {
- exp_res = GRID_X*GRID_P;
- sprintf(uri, "http://" SERVER "/Search.api?Start=%d&Count=%d&t=%d%s&Query=", 0, exp_res+1, ((GRID_Y-GRID_P)*YRES)/(GRID_Y*14)*GRID_X, tmp);
- }
- }
- else
- {
- exp_res = GRID_X*GRID_Y;
- sprintf(uri, "http://" SERVER "/Search.api?Start=%d&Count=%d%s&Query=", search_page*GRID_X*GRID_Y, exp_res+1, tmp);
- }
- strcaturl(uri, last);
- if (search_own)
- {
- strcaturl(uri, " user:");
- strcaturl(uri, svf_user);
- }
- if (search_fav)
- {
- strcaturl(uri, " cat:favs");
- }
- if (search_date)
- strcaturl(uri, " sort:date");
-
- http = http_async_req_start(http, uri, NULL, 0, 1);
- if (svf_login)
- {
- //http_auth_headers(http, svf_user, svf_pass);
- http_auth_headers(http, svf_user_id, NULL, svf_session_id);
- }
- http_last_use = time(NULL);
- free(uri);
- }
-
- if (active && http_async_req_status(http))
- {
- http_last_use = time(NULL);
- results = http_async_req_stop(http, &status, NULL);
- view_own = last_own;
- if (status == 200)
- {
- page_count = search_results(results, last_own||svf_admin||svf_mod);
- memset(thumb_drawn, 0, sizeof(thumb_drawn));
- memset(v_buf, 0, ((YRES+MENUSIZE)*(XRES+BARSIZE))*PIXELSIZE);
- nmp = -1;
-
- ui_richtext_settext(server_motd, &motd);
- motd.x = (XRES-textwidth(motd.printstr))/2;
- }
- is_p1 = (exp_res < GRID_X*GRID_Y);
- if (results)
- free(results);
- active = 0;
- }
-
- if (http && !active && (time(NULL)>http_last_use+HTTP_TIMEOUT))
- {
- http_async_req_close(http);
- http = NULL;
- }
-
- for (i=0; i<IMGCONNS; i++)
- {
- if (img_http[i] && http_async_req_status(img_http[i]))
- {
- thumb = http_async_req_stop(img_http[i], &status, &thlen);
- if (status != 200)
- {
- if (thumb)
- free(thumb);
- thumb = calloc(1,4);
- thlen = 4;
- }
- thumb_cache_add(img_id[i], thumb, thlen);
- for (pos=0; pos<GRID_X*GRID_Y; pos++) {
- if (search_dates[pos]) {
- char *id_d_temp = malloc(strlen(search_ids[pos])+strlen(search_dates[pos])+2);
- if (id_d_temp == 0)
- {
- break;
- }
- strcpy(id_d_temp, search_ids[pos]);
- strappend(id_d_temp, "_");
- strappend(id_d_temp, search_dates[pos]);
- //img_id[i] = mystrdup(id_d_temp);
- if (!strcmp(id_d_temp, img_id[i]) && !search_thumbs[pos]) {
- break;
- }
- free(id_d_temp);
- } else {
- if (search_ids[pos] && !strcmp(search_ids[pos], img_id[i])) {
- break;
- }
- }
- }
- if (pos<GRID_X*GRID_Y)
- {
- search_thumbs[pos] = thumb;
- search_thsizes[pos] = thlen;
- }
- else
- free(thumb);
- free(img_id[i]);
- img_id[i] = NULL;
- }
- if (!img_id[i])
- {
- for (pos=0; pos<GRID_X*GRID_Y; pos++)
- if (search_ids[pos] && !search_thumbs[pos])
- {
- if (search_dates[pos])
- {
- char *id_d_temp = malloc(strlen(search_ids[pos])+strlen(search_dates[pos])+2);
- strcpy(id_d_temp, search_ids[pos]);
- strappend(id_d_temp, "_");
- strappend(id_d_temp, search_dates[pos]);
-
- for (gi=0; gi<IMGCONNS; gi++)
- if (img_id[gi] && !strcmp(id_d_temp, img_id[gi]))
- break;
-
- free(id_d_temp);
- }
- else
- {
- for (gi=0; gi<IMGCONNS; gi++)
- if (img_id[gi] && !strcmp(search_ids[pos], img_id[gi]))
- break;
- }
- if (gi<IMGCONNS)
- continue;
- break;
- }
- if (pos<GRID_X*GRID_Y)
- {
- if (search_dates[pos]) {
- char *id_d_temp = malloc(strlen(search_ids[pos])+strlen(search_dates[pos])+2);
- uri = malloc(strlen(search_ids[pos])*3+strlen(search_dates[pos])*3+strlen(STATICSERVER)+71);
- strcpy(uri, "http://" STATICSERVER "/");
- strcaturl(uri, search_ids[pos]);
- strappend(uri, "_");
- strcaturl(uri, search_dates[pos]);
- strappend(uri, "_small.pti");
-
- strcpy(id_d_temp, search_ids[pos]);
- strappend(id_d_temp, "_");
- strappend(id_d_temp, search_dates[pos]);
- img_id[i] = mystrdup(id_d_temp);
- free(id_d_temp);
- } else {
- uri = malloc(strlen(search_ids[pos])*3+strlen(SERVER)+64);
- strcpy(uri, "http://" STATICSERVER "/");
- strcaturl(uri, search_ids[pos]);
- strappend(uri, "_small.pti");
- img_id[i] = mystrdup(search_ids[pos]);
- }
- img_http[i] = http_async_req_start(img_http[i], uri, NULL, 0, 1);
- free(uri);
- }
- }
- if (!img_id[i] && img_http[i])
- {
- http_async_req_close(img_http[i]);
- img_http[i] = NULL;
- }
- }
-
- if (lasttime<TIMEOUT)
- lasttime++;
- }
-
-finish:
- if (last)
- free(last);
- if (http)
- http_async_req_close(http);
- for (i=0; i<IMGCONNS; i++)
- if (img_http[i])
- http_async_req_close(img_http[i]);
-
- if(bthumb_rsdata){
- free(bthumb_rsdata);
- bthumb_rsdata = NULL;
- }
-
- search_results("", 0);
-
- strcpy(search_expr, ed.str);
-
- free(v_buf);
- return 0;
-}
-
-int report_ui(pixel* vid_buf, char *save_id)
-{
- int b=1,bq,mx,my;
- ui_edit ed;
- ed.x = 209;
- ed.y = 159;
- ed.w = (XRES+BARSIZE-400)-18;
- ed.h = (YRES+MENUSIZE-300)-36;
- ed.nx = 1;
- ed.def = "Report details";
- ed.focus = 0;
- ed.hide = 0;
- ed.multiline = 1;
- ed.cursor = 0;
- strcpy(ed.str, "");
-
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
- while (!sdl_poll()) {
- fillrect(vid_buf, 200, 150, (XRES+BARSIZE-400), (YRES+MENUSIZE-300), 0,0,0, 255);
- drawrect(vid_buf, 200, 150, (XRES+BARSIZE-400), (YRES+MENUSIZE-300), 255, 255, 255, 255);
-
- drawrect(vid_buf, 205, 155, (XRES+BARSIZE-400)-10, (YRES+MENUSIZE-300)-28, 255, 255, 255, 170);
-
- bq = b;
- b = mouse_get_state(&mx, &my);
-
-
- drawrect(vid_buf, 200, (YRES+MENUSIZE-150)-18, 50, 18, 255, 255, 255, 255);
- drawtext(vid_buf, 213, (YRES+MENUSIZE-150)-13, "Cancel", 255, 255, 255, 255);
-
- drawrect(vid_buf, (XRES+BARSIZE-400)+150, (YRES+MENUSIZE-150)-18, 50, 18, 255, 255, 255, 255);
- drawtext(vid_buf, (XRES+BARSIZE-400)+163, (YRES+MENUSIZE-150)-13, "Report", 255, 255, 255, 255);
- if (mx>(XRES+BARSIZE-400)+150 && my>(YRES+MENUSIZE-150)-18 && mx<(XRES+BARSIZE-400)+200 && my<(YRES+MENUSIZE-150)) {
- fillrect(vid_buf, (XRES+BARSIZE-400)+150, (YRES+MENUSIZE-150)-18, 50, 18, 255, 255, 255, 40);
- if (b) {
- if (execute_report(vid_buf, save_id, ed.str)) {
- info_ui(vid_buf, "Success", "This save has been reported");
- return 1;
- } else {
- return 0;
- }
- }
- }
- if (mx>200 && my>(YRES+MENUSIZE-150)-18 && mx<250 && my<(YRES+MENUSIZE-150)) {
- fillrect(vid_buf, 200, (YRES+MENUSIZE-150)-18, 50, 18, 255, 255, 255, 40);
- if (b)
- return 0;
- }
- ui_edit_draw(vid_buf, &ed);
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
- ui_edit_process(mx, my, b, &ed);
- }
- return 0;
-}
-
-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,active_3=0,cc=0,ccy=0,cix=0,hasdrawninfo=0,hasdrawncthumb=0,hasdrawnthumb=0,authoritah=0,myown=0,queue_open=0,data_size=0,full_thumb_data_size=0,retval=0,bc=255,openable=1;
- int nyd,nyu,ry,lv;
- float ryf;
-
- char *uri, *uri_2, *o_uri, *uri_3;
- void *data = NULL, *info_data, *thumb_data_full;
- save_info *info = calloc(sizeof(save_info), 1);
- void *http = NULL, *http_2 = NULL, *http_3 = NULL;
- int lasttime = TIMEOUT, saveTotal, saveDone, infoTotal, infoDone, downloadDone, downloadTotal;
- int status, status_2, info_ready = 0, data_ready = 0, thumb_data_ready = 0;
- time_t http_last_use = HTTP_TIMEOUT, http_last_use_2 = HTTP_TIMEOUT, http_last_use_3 = HTTP_TIMEOUT;
- pixel *save_pic;// = malloc((XRES/2)*(YRES/2));
- pixel *save_pic_thumb = NULL;
- char *thumb_data = NULL;
- char viewcountbuffer[11];
- int thumb_data_size = 0;
- ui_edit ed;
- ui_copytext ctb;
-
- pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
- if (!old_vid || !info)
- return 0;
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- viewcountbuffer[0] = 0;
-
- 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);
-
- ed.x = 57+(XRES/2)+1;
- ed.y = YRES+MENUSIZE-118;
- ed.w = XRES+BARSIZE-114-((XRES/2)+1);
- ed.h = 48;
- ed.nx = 1;
- ed.def = "Add comment";
- ed.focus = 1;
- ed.hide = 0;
- ed.multiline = 1;
- ed.cursor = 0;
- strcpy(ed.str, "");
-
- ctb.x = 100;
- ctb.y = YRES+MENUSIZE-20;
- ctb.width = textwidth(save_id)+12;
- ctb.height = 10+7;
- ctb.hover = 0;
- ctb.state = 0;
- strcpy(ctb.text, save_id);
-
- memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- //Try to load the thumbnail from the cache
- if(save_date)
- {
- char * id_d_temp = malloc(strlen(save_id)+strlen(save_date)+2);
- strcpy(id_d_temp, save_id);
- strappend(id_d_temp, "_");
- strappend(id_d_temp, save_date);
-
- status = thumb_cache_find(id_d_temp, &thumb_data, &thumb_data_size);
- free(id_d_temp);
- }
- else
- {
- status = thumb_cache_find(save_id, &thumb_data, &thumb_data_size);
- }
- if(!status){
- thumb_data = NULL;
- } else {
- //We found a thumbnail in the cache, we'll draw this one while we wait for the full image to load.
- int finw, finh;
- pixel *thumb_imgdata = ptif_unpack(thumb_data, thumb_data_size, &finw, &finh);
- if(thumb_imgdata!=NULL){
- save_pic_thumb = resample_img(thumb_imgdata, finw, finh, XRES/2, YRES/2);
- //draw_image(vid_buf, save_pic_thumb, 51, 51, XRES/2, YRES/2, 255);
- }
- free(thumb_imgdata);
- //rescale_img(full_save, imgw, imgh, &thumb_w, &thumb_h, 2);
- }
-
- //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(STATICSERVER)+71);
- strcpy(uri, "http://" STATICSERVER "/");
- strcaturl(uri, save_id);
- strappend(uri, "_");
- strcaturl(uri, save_date);
- strappend(uri, ".cps");
-
- uri_2 = malloc(strlen(save_id)*3+strlen(save_date)*3+strlen(STATICSERVER)+71);
- strcpy(uri_2, "http://" STATICSERVER "/");
- strcaturl(uri_2, save_id);
- strappend(uri_2, "_");
- strcaturl(uri_2, save_date);
- strappend(uri_2, ".info");
-
- uri_3 = malloc(strlen(save_id)*3+strlen(save_date)*3+strlen(STATICSERVER)+71);
- strcpy(uri_3, "http://" STATICSERVER "/");
- strcaturl(uri_3, save_id);
- strappend(uri_3, "_");
- strcaturl(uri_3, save_date);
- strappend(uri_3, "_large.pti");
- } else {
- //We're loading a normal save
- uri = malloc(strlen(save_id)*3+strlen(STATICSERVER)+64);
- strcpy(uri, "http://" STATICSERVER "/");
- strcaturl(uri, save_id);
- strappend(uri, ".cps");
-
- uri_2 = malloc(strlen(save_id)*3+strlen(STATICSERVER)+64);
- strcpy(uri_2, "http://" STATICSERVER "/");
- strcaturl(uri_2, save_id);
- strappend(uri_2, ".info");
-
- uri_3 = malloc(strlen(save_id)*3+strlen(STATICSERVER)+64);
- strcpy(uri_3, "http://" STATICSERVER "/");
- strcaturl(uri_3, save_id);
- strappend(uri_3, "_large.pti");
- }
- http = http_async_req_start(http, uri, NULL, 0, 1);
- http_2 = http_async_req_start(http_2, uri_2, NULL, 0, 1);
- http_3 = http_async_req_start(http_3, uri_3, NULL, 0, 1);
- if (svf_login)
- {
- http_auth_headers(http, svf_user_id, NULL, svf_session_id);
- http_auth_headers(http_2, svf_user_id, NULL, svf_session_id);
- }
- http_last_use = time(NULL);
- http_last_use_2 = time(NULL);
- http_last_use_3 = time(NULL);
- free(uri);
- free(uri_2);
- free(uri_3);
- active = 1;
- active_2 = 1;
- active_3 = 1;
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- if (active)
- {
- http_async_get_length(http, &saveTotal, &saveDone);
- }
- if (active && http_async_req_status(http))
- {
- int imgh, imgw, nimgh, nimgw;
- http_last_use = time(NULL);
- data = http_async_req_stop(http, &status, &data_size);
- saveDone = data_size;
- saveTotal = data_size;
- if (status == 200)
- {
- pixel *full_save;
- if (!data||!data_size) {
- error_ui(vid_buf, 0, "Save data is empty (may be corrupt)");
- break;
- }
- full_save = prerender_save(data, data_size, &imgw, &imgh);
- if (full_save!=NULL) {
- //save_pic = rescale_img(full_save, imgw, imgh, &thumb_w, &thumb_h, 2);
- data_ready = 1;
- free(full_save);
- } else {
- error_ui(vid_buf, 0, "Save may be from a newer version");
- break;
- }
- }
- active = 0;
- free(http);
- http = NULL;
- }
- if (active_2)
- {
- http_async_get_length(http_2, &infoTotal, &infoDone);
- }
- 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, &infoTotal);
- infoDone = infoTotal;
- if (status_2 == 200 || !info_data)
- {
- info_ready = info_parse(info_data, info);
- sprintf(viewcountbuffer, "%d", info->downloadcount);
- if (info_ready<=0) {
- error_ui(vid_buf, 0, "Save info not found");
- break;
- }
- }
- if (info_data)
- free(info_data);
- active_2 = 0;
- free(http_2);
- http_2 = NULL;
- }
- if (active_3 && http_async_req_status(http_3))
- {
- int imgh, imgw, nimgh, nimgw;
- http_last_use_3 = time(NULL);
- thumb_data_full = http_async_req_stop(http_3, &status, &full_thumb_data_size);
- if (status == 200)
- {
- pixel *full_thumb;
- if (!thumb_data_full||!full_thumb_data_size) {
- //error_ui(vid_buf, 0, "Save data is empty (may be corrupt)");
- //break;
- } else {
- full_thumb = ptif_unpack(thumb_data_full, full_thumb_data_size, &imgw, &imgh);//prerender_save(data, data_size, &imgw, &imgh);
- if (full_thumb!=NULL) {
- save_pic = resample_img(full_thumb, imgw, imgh, XRES/2, YRES/2);
- thumb_data_ready = 1;
- free(full_thumb);
- }
- }
- }
- if(thumb_data_full)
- free(thumb_data_full);
- active_3 = 0;
- free(http_3);
- http_3 = NULL;
- }
- if (save_pic_thumb!=NULL && !hasdrawncthumb) {
- draw_image(vid_buf, save_pic_thumb, 51, 51, XRES/2, YRES/2, 255);
- free(save_pic_thumb);
- save_pic_thumb = NULL;
- hasdrawncthumb = 1;
- memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
- }
- if (thumb_data_ready && !hasdrawnthumb) {
- draw_image(vid_buf, save_pic, 51, 51, XRES/2, YRES/2, 255);
- free(save_pic);
- save_pic = NULL;
- hasdrawnthumb = 1;
- memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
- }
- if (info_ready && !hasdrawninfo) {
- //Render all the save information
- 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);
- if(info->downloadcount){
- drawtext(vid_buf, 48+(XRES/2)-textwidth(viewcountbuffer)-textwidth("Views:")-4, (YRES/2)+72, "Views:", 255, 255, 255, 155);
- drawtext(vid_buf, 48+(XRES/2)-textwidth(viewcountbuffer), (YRES/2)+72, viewcountbuffer, 255, 255, 255, 255);
- }
- drawtextwrap(vid_buf, 62, (YRES/2)+86, (XRES/2)-24, info->description, 255, 255, 255, 200);
-
- //Draw the score bars
- if (info->voteup>0||info->votedown>0)
- {
- lv = (info->voteup>info->votedown)?info->voteup:info->votedown;
- lv = (lv>10)?lv:10;
-
- if (50>lv)
- {
- ryf = 50.0f/((float)lv);
- //if(lv<8)
- //{
- // ry = ry/(8-lv);
- //}
- nyu = info->voteup*ryf;
- nyd = info->votedown*ryf;
- }
- else
- {
- ryf = ((float)lv)/50.0f;
- nyu = info->voteup/ryf;
- nyd = info->votedown/ryf;
- }
- nyu = nyu>50?50:nyu;
- nyd = nyd>50?50:nyd;
-
- fillrect(vid_buf, 48+(XRES/2)-51, (YRES/2)+53, 52, 6, 0, 107, 10, 255);
- fillrect(vid_buf, 48+(XRES/2)-51, (YRES/2)+59, 52, 6, 107, 10, 0, 255);
- drawrect(vid_buf, 48+(XRES/2)-51, (YRES/2)+53, 52, 6, 128, 128, 128, 255);
- drawrect(vid_buf, 48+(XRES/2)-51, (YRES/2)+59, 52, 6, 128, 128, 128, 255);
-
- fillrect(vid_buf, 48+(XRES/2)-nyu, (YRES/2)+54, nyu, 4, 57, 187, 57, 255);
- fillrect(vid_buf, 48+(XRES/2)-nyd, (YRES/2)+60, nyd, 4, 187, 57, 57, 255);
- }
-
- ccy = 0;
- for (cc=0; cc<info->comment_count; cc++) {
- if ((ccy + 72 + ((textwidth(info->comments[cc])/(XRES+BARSIZE-100-((XRES/2)+1)-20)))*12)<(YRES+MENUSIZE-50)) {
- 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;
- if (ccy+52<YRES+MENUSIZE-50) { //Try not to draw off the screen.
- draw_line(vid_buf, 50+(XRES/2)+2, ccy+52, XRES+BARSIZE-50, ccy+52, 100, 100, 100, XRES+BARSIZE);
- }
- }
- }
- hasdrawninfo = 1;
- myown = svf_login && !strcmp(info->author, svf_user);
- authoritah = svf_login && (!strcmp(info->author, svf_user) || svf_admin || svf_mod);
- memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
- }
- if (info_ready && svf_login) {
- //Render the comment box.
- fillrect(vid_buf, 50+(XRES/2)+1, YRES+MENUSIZE-125, XRES+BARSIZE-100-((XRES/2)+1), 75, 0, 0, 0, 255);
- drawrect(vid_buf, 50+(XRES/2)+1, YRES+MENUSIZE-125, XRES+BARSIZE-100-((XRES/2)+1), 75, 200, 200, 200, 255);
-
- drawrect(vid_buf, 54+(XRES/2)+1, YRES+MENUSIZE-121, XRES+BARSIZE-108-((XRES/2)+1), 48, 255, 255, 255, 200);
-
- ui_edit_draw(vid_buf, &ed);
-
- drawrect(vid_buf, XRES+BARSIZE-100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255);
- drawtext(vid_buf, XRES+BARSIZE-90, YRES+MENUSIZE-63, "Submit", 255, 255, 255, 255);
- }
-
- //Download completion
- downloadTotal = saveTotal+infoTotal;
- downloadDone = saveDone+infoDone;
- if(downloadTotal>downloadDone)
- {
- clearrect(vid_buf, 51, (YRES/2)+37, (XRES)/2, 14);
- fillrect(vid_buf, 51, (YRES/2)+38, (((float)XRES-2)/2.0f)*((float)downloadDone/(float)downloadTotal), 12, 255, 200, 0, 255);
- if(((float)downloadDone/(float)downloadTotal)>0.5f)
- drawtext(vid_buf, 51+(((XRES/2)-textwidth("Downloading"))/2), (YRES/2)+40, "Downloading", 0, 0, 0, 255);
- else
- drawtext(vid_buf, 51+(((XRES/2)-textwidth("Downloading"))/2), (YRES/2)+40, "Downloading", 255, 255, 255, 255);
- }
-
- //Save ID text and copybox
- cix = textwidth("Save ID: ");
- cix += ctb.width;
- ctb.x = textwidth("Save ID: ")+(XRES+BARSIZE-cix)/2;
- //ctb.x =
- drawtext(vid_buf, (XRES+BARSIZE-cix)/2, YRES+MENUSIZE-15, "Save ID: ", 255, 255, 255, 255);
- ui_copytext_draw(vid_buf, &ctb);
- ui_copytext_process(mx, my, b, bq, &ctb);
-
- //Open Button
- bc = openable?255:150;
- drawrect(vid_buf, 50, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, bc);
- drawtext(vid_buf, 73, YRES+MENUSIZE-63, "Open", 255, 255, 255, bc);
- drawtext(vid_buf, 58, YRES+MENUSIZE-64, "\x81", 255, 255, 255, bc);
- //Fav Button
- bc = svf_login?255:150;
- drawrect(vid_buf, 100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, bc);
- if(info->myfav && svf_login){
- drawtext(vid_buf, 122, YRES+MENUSIZE-63, "Unfav.", 255, 230, 230, bc);
- } else {
- drawtext(vid_buf, 122, YRES+MENUSIZE-63, "Fav.", 255, 255, 255, bc);
- }
- drawtext(vid_buf, 107, YRES+MENUSIZE-64, "\xCC", 255, 255, 255, bc);
- //Report Button
- bc = (svf_login && info_ready)?255:150;
- drawrect(vid_buf, 150, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, bc);
- drawtext(vid_buf, 168, YRES+MENUSIZE-63, "Report", 255, 255, 255, bc);
- drawtext(vid_buf, 155, YRES+MENUSIZE-64, "\xE3", 255, 255, 255, bc);
- //Delete Button
- bc = authoritah?255:150;
- drawrect(vid_buf, 200, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, bc);
- drawtext(vid_buf, 218, YRES+MENUSIZE-63, "Delete", 255, 255, 255, bc);
- drawtext(vid_buf, 206, YRES+MENUSIZE-64, "\xAA", 255, 255, 255, bc);
- //Open in browser button
- bc = 255;
- drawrect(vid_buf, 250, YRES+MENUSIZE-68, 107, 18, 255, 255, 255, bc);
- drawtext(vid_buf, 273, YRES+MENUSIZE-63, "Open in Browser", 255, 255, 255, bc);
- drawtext(vid_buf, 258, YRES+MENUSIZE-64, "\x81", 255, 255, 255, bc);
-
- //Open Button
- if (sdl_key==SDLK_RETURN && openable) {
- queue_open = 1;
- }
- if (mx > 50 && mx < 50+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && openable && !queue_open) {
- fillrect(vid_buf, 50, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
- if (b && !bq) {
- //Button Clicked
- queue_open = 1;
- }
- }
- //Fav Button
- if (mx > 100 && mx < 100+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login && !queue_open) {
- fillrect(vid_buf, 100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
- if (b && !bq) {
- //Button Clicked
- if(info->myfav){
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- info_box(vid_buf, "Removing from favourites...");
- execute_unfav(vid_buf, save_id);
- info->myfav = 0;
- } else {
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- info_box(vid_buf, "Adding to favourites...");
- execute_fav(vid_buf, save_id);
- info->myfav = 1;
- }
- }
- }
- //Report Button
- if (mx > 150 && mx < 150+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login && info_ready && !queue_open) {
- fillrect(vid_buf, 150, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
- if (b && !bq) {
- //Button Clicked
- if (report_ui(vid_buf, save_id)) {
- retval = 0;
- break;
- }
- }
- }
- //Delete Button
- if (mx > 200 && mx < 200+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && (authoritah || myown) && !queue_open) {
- fillrect(vid_buf, 200, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
- if (b && !bq) {
- //Button Clicked
- if (myown || !info->publish) {
- if (confirm_ui(vid_buf, "Are you sure you wish to delete this?", "You will not be able recover it.", "Delete")) {
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- info_box(vid_buf, "Deleting...");
- if (execute_delete(vid_buf, save_id)) {
- retval = 0;
- break;
- }
- }
- } else {
- if (confirm_ui(vid_buf, "Are you sure?", "This save will be removed from the search index.", "Remove")) {
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- info_box(vid_buf, "Removing...");
- if (execute_delete(vid_buf, save_id)) {
- retval = 0;
- break;
- }
- }
- }
- }
- }
- //Open in browser button
- if (mx > 250 && mx < 250+107 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && !queue_open) {
- fillrect(vid_buf, 250, YRES+MENUSIZE-68, 107, 18, 255, 255, 255, 40);
- if (b && !bq) {
- //Button Clicked
- o_uri = malloc(7+strlen(SERVER)+41+strlen(save_id)*3);
- strcpy(o_uri, "http://" SERVER "/Browse/View.html?ID=");
- strcaturl(o_uri, save_id);
- open_link(o_uri);
- free(o_uri);
- }
- }
- //Submit Button
- if (mx > XRES+BARSIZE-100 && mx < XRES+BARSIZE-100+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login && info_ready && !queue_open) {
- fillrect(vid_buf, XRES+BARSIZE-100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
- if (b && !bq) {
- //Button Clicked
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- info_box(vid_buf, "Submitting Comment...");
- execute_submit(vid_buf, save_id, ed.str);
- ed.str[0] = 0;
- }
- }
- //If mouse was clicked outsite of the window bounds.
- if (!(mx>50 && my>50 && mx<XRES+BARSIZE-50 && my<YRES+MENUSIZE-50) && b && !queue_open && my<YRES+MENUSIZE-21) {
- retval = 0;
- break;
- }
-
- //User opened the save, wait until we've got all the data first...
- if (queue_open) {
- if (info_ready && data_ready) {
- // Do Open!
- status = parse_save(data, data_size, 1, 0, 0, bmap, vx, vy, pv, fvx, fvy, signs, parts, pmap);
- if (!status) {
- if(svf_last)
- free(svf_last);
- svf_last = data;
- data = NULL; //so we don't free it when returning
- 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);
- strcpy(svf_description, info->description);
- if (info->tags)
- {
- strncpy(svf_tags, info->tags, 255);
- svf_tags[255] = 0;
- } else {
- svf_tags[0] = 0;
- }
- svf_myvote = info->myvote;
- svf_filename[0] = 0;
- svf_fileopen = 0;
- retval = 1;
- break;
- } else {
- queue_open = 0;
-
- svf_open = 0;
- svf_filename[0] = 0;
- svf_fileopen = 0;
- svf_publish = 0;
- svf_own = 0;
- svf_myvote = 0;
- svf_id[0] = 0;
- svf_name[0] = 0;
- svf_description[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, 50+(XRES/4)-textwidth("Loading...")/2, 50+(YRES/4), "Loading...", 255, 255, 255, 128);
- }
- }
- if (!info_ready || !data_ready) {
- info_box(vid_buf, "Loading");
- }
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
- memcpy(vid_buf, old_vid, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
- if (info_ready && svf_login) {
- ui_edit_process(mx, my, b, &ed);
- }
-
- if (sdl_key==SDLK_ESCAPE) {
- retval = 0;
- break;
- }
-
- if (lasttime<TIMEOUT)
- lasttime++;
- }
- //Prevent those mouse clicks being passed down.
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
- //Close open connections
- if (http)
- http_async_req_close(http);
- if (http_2)
- http_async_req_close(http_2);
- if (http_3)
- http_async_req_close(http_3);
- info_parse("", info);
- free(info);
- free(old_vid);
- if (data) free(data);
- return retval;
-}
-
-int info_parse(char *info_data, save_info *info)
-{
- int i,j;
- char *p,*q,*r,*s,*vu,*vd,*pu,*sd;
-
- if (info->title) free(info->title);
- if (info->name) free(info->name);
- if (info->author) free(info->author);
- if (info->date) free(info->date);
- if (info->description) free(info->description);
- if (info->tags) free(info->tags);
- for (i=0;i<6;i++)
- {
- if (info->comments[i]) free(info->comments[i]);
- if (info->commentauthors[i]) free(info->commentauthors[i]);
- }
- memset(info, 0, sizeof(save_info));
-
- if (!info_data || !*info_data)
- return 0;
-
- i = 0;
- j = 0;
- s = NULL;
- do_open = 0;
- while (1)
- {
- if (!*info_data)
- break;
- p = strchr(info_data, '\n');
- if (!p)
- p = info_data + strlen(info_data);
- else
- *(p++) = 0;
-
- if (!strncmp(info_data, "TITLE ", 6))
- {
- info->title = mystrdup(info_data+6);
- j++;
- }
- else if (!strncmp(info_data, "NAME ", 5))
- {
- info->name = mystrdup(info_data+5);
- j++;
- }
- else if (!strncmp(info_data, "AUTHOR ", 7))
- {
- info->author = mystrdup(info_data+7);
- j++;
- }
- else if (!strncmp(info_data, "DATE ", 5))
- {
- info->date = mystrdup(info_data+5);
- j++;
- }
- else if (!strncmp(info_data, "DESCRIPTION ", 12))
- {
- info->description = mystrdup(info_data+12);
- j++;
- }
- else if (!strncmp(info_data, "VOTEUP ", 7))
- {
- info->voteup = atoi(info_data+7);
- j++;
- }
- else if (!strncmp(info_data, "VOTEDOWN ", 9))
- {
- info->votedown = atoi(info_data+9);
- j++;
- }
- else if (!strncmp(info_data, "VOTE ", 5))
- {
- info->vote = atoi(info_data+5);
- j++;
- }
- else if (!strncmp(info_data, "MYVOTE ", 7))
- {
- info->myvote = atoi(info_data+7);
- j++;
- }
- else if (!strncmp(info_data, "DOWNLOADS ", 10))
- {
- info->downloadcount = atoi(info_data+10);
- j++;
- }
- else if (!strncmp(info_data, "MYFAV ", 6))
- {
- info->myfav = atoi(info_data+6);
- j++;
- }
- else if (!strncmp(info_data, "PUBLISH ", 8))
- {
- info->publish = atoi(info_data+8);
- j++;
- }
- 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++;
- }
- j++;
- }
- info_data = p;
- }
- if (j>=8) {
- return 1;
- } else {
- return -1;
- }
-}
-
-int search_results(char *str, int votes)
-{
- int i,j;
- char *p,*q,*r,*s,*vu,*vd,*pu,*sd;
-
- for (i=0; i<GRID_X*GRID_Y; i++)
- {
- if (search_ids[i])
- {
- free(search_ids[i]);
- search_ids[i] = NULL;
- }
- if (search_names[i])
- {
- free(search_names[i]);
- search_names[i] = NULL;
- }
- if (search_dates[i])
- {
- free(search_dates[i]);
- search_dates[i] = NULL;
- }
- if (search_owners[i])
- {
- free(search_owners[i]);
- search_owners[i] = NULL;
- }
- if (search_thumbs[i])
- {
- free(search_thumbs[i]);
- search_thumbs[i] = NULL;
- search_thsizes[i] = 0;
- }
- }
- for (j=0; j<TAG_MAX; j++)
- if (tag_names[j])
- {
- free(tag_names[j]);
- tag_names[j] = NULL;
- }
- server_motd[0] = 0;
-
- if (!str || !*str)
- return 0;
-
- i = 0;
- j = 0;
- s = NULL;
- do_open = 0;
- while (1)
- {
- if (!*str)
- break;
- p = strchr(str, '\n');
- if (!p)
- p = str + strlen(str);
- else
- *(p++) = 0;
- if (!strncmp(str, "OPEN ", 5))
- {
- do_open = 1;
- if (i>=GRID_X*GRID_Y)
- break;
- if (votes)
- {
- pu = strchr(str+5, ' ');
- if (!pu)
- return i;
- *(pu++) = 0;
- s = strchr(pu, ' ');
- if (!s)
- return i;
- *(s++) = 0;
- vu = strchr(s, ' ');
- if (!vu)
- return i;
- *(vu++) = 0;
- vd = strchr(vu, ' ');
- if (!vd)
- return i;
- *(vd++) = 0;
- q = strchr(vd, ' ');
- }
- else
- {
- pu = strchr(str+5, ' ');
- if (!pu)
- return i;
- *(pu++) = 0;
- vu = strchr(pu, ' ');
- if (!vu)
- return i;
- *(vu++) = 0;
- vd = strchr(vu, ' ');
- if (!vd)
- return i;
- *(vd++) = 0;
- q = strchr(vd, ' ');
- }
- if (!q)
- return i;
- *(q++) = 0;
- r = strchr(q, ' ');
- if (!r)
- return i;
- *(r++) = 0;
- search_ids[i] = mystrdup(str+5);
-
- search_publish[i] = atoi(pu);
- search_scoreup[i] = atoi(vu);
- search_scoredown[i] = atoi(vd);
-
- search_owners[i] = mystrdup(q);
- search_names[i] = mystrdup(r);
-
- if (s)
- search_votes[i] = atoi(s);
- thumb_cache_find(str+5, search_thumbs+i, search_thsizes+i);
- i++;
- }
- else if (!strncmp(str, "HISTORY ", 8))
- {
- char * id_d_temp = NULL;
- if (i>=GRID_X*GRID_Y)
- break;
- if (votes)
- {
- sd = strchr(str+8, ' ');
- if (!sd)
- return i;
- *(sd++) = 0;
- pu = strchr(sd, ' ');
- if (!pu)
- return i;
- *(pu++) = 0;
- s = strchr(pu, ' ');
- if (!s)
- return i;
- *(s++) = 0;
- vu = strchr(s, ' ');
- if (!vu)
- return i;
- *(vu++) = 0;
- vd = strchr(vu, ' ');
- if (!vd)
- return i;
- *(vd++) = 0;
- q = strchr(vd, ' ');
- }
- else
- {
- sd = strchr(str+8, ' ');
- if (!sd)
- return i;
- *(sd++) = 0;
- pu = strchr(sd, ' ');
- if (!pu)
- return i;
- *(pu++) = 0;
- vu = strchr(pu, ' ');
- if (!vu)
- return i;
- *(vu++) = 0;
- vd = strchr(vu, ' ');
- if (!vd)
- return i;
- *(vd++) = 0;
- q = strchr(vd, ' ');
- }
- if (!q)
- return i;
- *(q++) = 0;
- r = strchr(q, ' ');
- if (!r)
- return i;
- *(r++) = 0;
- search_ids[i] = mystrdup(str+8);
-
- search_dates[i] = mystrdup(sd);
-
- search_publish[i] = atoi(pu);
- search_scoreup[i] = atoi(vu);
- search_scoredown[i] = atoi(vd);
-
- search_owners[i] = mystrdup(q);
- search_names[i] = mystrdup(r);
-
- if (s)
- search_votes[i] = atoi(s);
-
- //Build thumb cache ID and find
- id_d_temp = malloc(strlen(search_ids[i])+strlen(search_dates[i])+2);
- strcpy(id_d_temp, search_ids[i]);
- strappend(id_d_temp, "_");
- strappend(id_d_temp, search_dates[i]);
- thumb_cache_find(id_d_temp, search_thumbs+i, search_thsizes+i);
- free(id_d_temp);
-
- i++;
- }
- else if (!strncmp(str, "MOTD ", 5))
- {
- strncpy(server_motd, str+5, 511);
- }
- else if (!strncmp(str, "TAG ", 4))
- {
- if (j >= TAG_MAX)
- {
- str = p;
- continue;
- }
- q = strchr(str+4, ' ');
- if (!q)
- {
- str = p;
- continue;
- }
- *(q++) = 0;
- tag_names[j] = mystrdup(str+4);
- tag_votes[j] = atoi(q);
- j++;
- }
- else
- {
- if (i>=GRID_X*GRID_Y)
- break;
- if (votes)
- {
- pu = strchr(str, ' ');
- if (!pu)
- return i;
- *(pu++) = 0;
- s = strchr(pu, ' ');
- if (!s)
- return i;
- *(s++) = 0;
- vu = strchr(s, ' ');
- if (!vu)
- return i;
- *(vu++) = 0;
- vd = strchr(vu, ' ');
- if (!vd)
- return i;
- *(vd++) = 0;
- q = strchr(vd, ' ');
- }
- else
- {
- pu = strchr(str, ' ');
- if (!pu)
- return i;
- *(pu++) = 0;
- vu = strchr(pu, ' ');
- if (!vu)
- return i;
- *(vu++) = 0;
- vd = strchr(vu, ' ');
- if (!vd)
- return i;
- *(vd++) = 0;
- q = strchr(vd, ' ');
- }
- if (!q)
- return i;
- *(q++) = 0;
- r = strchr(q, ' ');
- if (!r)
- return i;
- *(r++) = 0;
- search_ids[i] = mystrdup(str);
-
- search_publish[i] = atoi(pu);
- search_scoreup[i] = atoi(vu);
- search_scoredown[i] = atoi(vd);
-
- search_owners[i] = mystrdup(q);
- search_names[i] = mystrdup(r);
-
- if (s)
- search_votes[i] = atoi(s);
- thumb_cache_find(str, search_thumbs+i, search_thsizes+i);
- i++;
- }
- str = p;
- }
- if (*str)
- i++;
- return i;
-}
-
-int execute_tagop(pixel *vid_buf, char *op, char *tag)
-{
- int status;
- char *result;
-
- char *names[] = {"ID", "Tag", NULL};
- char *parts[2];
-
- char *uri = malloc(strlen(SERVER)+strlen(op)+36);
- sprintf(uri, "http://" SERVER "/Tag.api?Op=%s", op);
-
- parts[0] = svf_id;
- parts[1] = tag;
-
- result = http_multipart_post(
- uri,
- names, parts, NULL,
- svf_user_id, /*svf_pass*/NULL, svf_session_id,
- &status, NULL);
-
- free(uri);
-
- if (status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if (result)
- free(result);
- return 1;
- }
- if (result && strncmp(result, "OK", 2))
- {
- error_ui(vid_buf, 0, result);
- free(result);
- return 1;
- }
-
- if (result && result[2])
- {
- strncpy(svf_tags, result+3, 255);
- svf_id[15] = 0;
- }
-
- if (result)
- free(result);
-
- return 0;
-}
-
-void execute_save(pixel *vid_buf)
-{
- int status;
- char *result;
-
- char *names[] = {"Name","Description", "Data:save.bin", "Thumb:thumb.bin", "Publish", "ID", NULL};
- char *uploadparts[6];
- int plens[6];
-
- uploadparts[0] = svf_name;
- plens[0] = strlen(svf_name);
- uploadparts[1] = svf_description;
- plens[1] = strlen(svf_description);
- uploadparts[2] = build_save(plens+2, 0, 0, XRES, YRES, bmap, vx, vy, pv, fvx, fvy, signs, parts);
- if (!uploadparts[2])
- {
- error_ui(vid_buf, 0, "Error creating save");
- return;
- }
- uploadparts[3] = build_thumb(plens+3, 1);
- uploadparts[4] = (svf_publish==1)?"Public":"Private";
- plens[4] = strlen((svf_publish==1)?"Public":"Private");
-
- if (svf_id[0])
- {
- uploadparts[5] = svf_id;
- plens[5] = strlen(svf_id);
- }
- else
- names[5] = NULL;
-
- result = http_multipart_post(
- "http://" SERVER "/Save.api",
- names, uploadparts, plens,
- svf_user_id, /*svf_pass*/NULL, svf_session_id,
- &status, NULL);
-
- if (svf_last)
- free(svf_last);
- svf_last = uploadparts[2];
- svf_lsize = plens[2];
-
- free(uploadparts[3]);
-
- if (status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if (result)
- free(result);
- return;
- }
- if (!result || strncmp(result, "OK", 2))
- {
- if (!result)
- result = mystrdup("Could not save - no reply from server");
- error_ui(vid_buf, 0, result);
- free(result);
- return;
- }
-
- if (result && result[2])
- {
- strncpy(svf_id, result+3, 15);
- svf_id[15] = 0;
- }
-
- if (!svf_id[0])
- {
- error_ui(vid_buf, 0, "No ID supplied by server");
- free(result);
- return;
- }
-
- thumb_cache_inval(svf_id);
-
- svf_own = 1;
- if (result)
- free(result);
-}
-
-int execute_delete(pixel *vid_buf, char *id)
-{
- int status;
- char *result;
-
- char *names[] = {"ID", NULL};
- char *parts[1];
-
- parts[0] = id;
-
- result = http_multipart_post(
- "http://" SERVER "/Delete.api",
- names, parts, NULL,
- svf_user_id, /*svf_pass*/NULL, svf_session_id,
- &status, NULL);
-
- if (status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if (result)
- free(result);
- return 0;
- }
- if (result && strncmp(result, "INFO: ", 6)==0)
- {
- info_ui(vid_buf, "Info", result+6);
- free(result);
- return 0;
- }
- if (result && strncmp(result, "OK", 2))
- {
- error_ui(vid_buf, 0, result);
- free(result);
- return 0;
- }
-
- if (result)
- free(result);
- return 1;
-}
-
-void execute_submit(pixel *vid_buf, char *id, char *message)
-{
- int status;
- char *result;
-
- char *names[] = {"ID", "Message", NULL};
- char *parts[2];
-
- parts[0] = id;
- parts[1] = message;
-
- result = http_multipart_post(
- "http://" SERVER "/Comment.api",
- names, parts, NULL,
- svf_user_id, /*svf_pass*/NULL, svf_session_id,
- &status, NULL);
-
- if (status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if (result)
- free(result);
- return;
- }
- if (result && strncmp(result, "OK", 2))
- {
- error_ui(vid_buf, 0, result);
- free(result);
- return;
- }
-
- if (result)
- free(result);
-}
-
-int execute_report(pixel *vid_buf, char *id, char *reason)
-{
- int status;
- char *result;
-
- char *names[] = {"ID", "Reason", NULL};
- char *parts[2];
-
- parts[0] = id;
- parts[1] = reason;
-
- result = http_multipart_post(
- "http://" SERVER "/Report.api",
- names, parts, NULL,
- svf_user_id, /*svf_pass*/NULL, svf_session_id,
- &status, NULL);
-
- if (status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if (result)
- free(result);
- return 0;
- }
- if (result && strncmp(result, "OK", 2))
- {
- error_ui(vid_buf, 0, result);
- free(result);
- return 0;
- }
-
- if (result)
- free(result);
- return 1;
-}
-
-void execute_fav(pixel *vid_buf, char *id)
-{
- int status;
- char *result;
-
- char *names[] = {"ID", NULL};
- char *parts[1];
-
- parts[0] = id;
-
- result = http_multipart_post(
- "http://" SERVER "/Favourite.api",
- names, parts, NULL,
- svf_user_id, /*svf_pass*/NULL, svf_session_id,
- &status, NULL);
-
- if (status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if (result)
- free(result);
- return;
- }
- if (result && strncmp(result, "OK", 2))
- {
- error_ui(vid_buf, 0, result);
- free(result);
- return;
- }
-
- if (result)
- free(result);
-}
-
-void execute_unfav(pixel *vid_buf, char *id)
-{
- int status;
- char *result;
-
- char *names[] = {"ID", NULL};
- char *parts[1];
-
- parts[0] = id;
-
- result = http_multipart_post(
- "http://" SERVER "/Favourite.api?Action=Remove",
- names, parts, NULL,
- svf_user_id, /*svf_pass*/NULL, svf_session_id,
- &status, NULL);
-
- if (status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if (result)
- free(result);
- return;
- }
- if (result && strncmp(result, "OK", 2))
- {
- error_ui(vid_buf, 0, result);
- free(result);
- return;
- }
-
- if (result)
- free(result);
-}
-
-int execute_vote(pixel *vid_buf, char *id, char *action)
-{
- int status;
- char *result;
-
- char *names[] = {"ID", "Action", NULL};
- char *parts[2];
-
- parts[0] = id;
- parts[1] = action;
-
- result = http_multipart_post(
- "http://" SERVER "/Vote.api",
- names, parts, NULL,
- svf_user_id, /*svf_pass*/NULL, svf_session_id,
- &status, NULL);
-
- if (status!=200)
- {
- error_ui(vid_buf, status, http_ret_text(status));
- if (result)
- free(result);
- return 0;
- }
- if (result && strncmp(result, "OK", 2))
- {
- error_ui(vid_buf, 0, result);
- free(result);
- return 0;
- }
-
- if (result)
- free(result);
- return 1;
-}
-void open_link(char *uri) {
-#ifdef WIN32
- ShellExecute(0, "OPEN", uri, NULL, NULL, 0);
-#elif MACOSX
- char *cmd = malloc(7+strlen(uri));
- strcpy(cmd, "open ");
- strappend(cmd, uri);
- system(cmd);
-#elif LIN32
- char *cmd = malloc(11+strlen(uri));
- strcpy(cmd, "xdg-open ");
- strappend(cmd, uri);
- system(cmd);
-#elif LIN64
- char *cmd = malloc(11+strlen(uri));
- strcpy(cmd, "xdg-open ");
- strappend(cmd, uri);
- system(cmd);
-#else
- printf("Cannot open browser\n");
-#endif
-}
-struct command_history {
- void *prev_command;
- char *command;
-};
-typedef struct command_history command_history;
-command_history *last_command = NULL;
-command_history *last_command2 = NULL;
-char *console_ui(pixel *vid_buf,char error[255],char console_more) {
- int mx,my,b,cc,ci = -1,i;
- pixel *old_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
- command_history *currentcommand;
- command_history *currentcommand2;
- ui_edit ed;
- ed.x = 15;
- ed.y = 207;
- ed.w = XRES;
- ed.nx = 1;
- ed.def = "";
- strcpy(ed.str, "");
- ed.focus = 1;
- ed.hide = 0;
- ed.multiline = 0;
- ed.cursor = 0;
- //fillrect(vid_buf, -1, -1, XRES, 220, 0, 0, 0, 190);
- if (!old_buf)
- return NULL;
- memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE);
-
- fillrect(old_buf, -1, -1, XRES+BARSIZE, 220, 0, 0, 0, 190);
-
- currentcommand2 = malloc(sizeof(command_history));
- memset(currentcommand2, 0, sizeof(command_history));
- currentcommand2->prev_command = last_command2;
- currentcommand2->command = mystrdup(error);
- last_command2 = currentcommand2;
-
- SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);//enable keyrepeat for console (is disabled on console close later)
- cc = 0;
- while (cc < 80) {
- fillrect(old_buf, -1, -1+cc, XRES+BARSIZE, 2, 0, 0, 0, 160-(cc*2));
- cc++;
- }
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- ed.focus = 1;
-
- memcpy(vid_buf,old_buf,(XRES+BARSIZE)*YRES*PIXELSIZE);
- draw_line(vid_buf, 0, 219, XRES+BARSIZE-1, 219, 228, 228, 228, XRES+BARSIZE);
-#ifdef PYCONSOLE
- if (pygood)
- i=255;
- else
- i=0;
- if (pyready)
- drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.3 (by cracker64, Python enabled)", 255, i, i, 255);
- else
- drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.3 (by cracker64, Python disabled)", 255, i, i, 255);
-#elif defined(LUACONSOLE)
- drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.4 (by cracker64, Lua enabled)", 255, 255, 255, 255);
-#else
- drawtext(vid_buf, 15, 15, "Welcome to The Powder Toy console v.3 (by cracker64)", 255, 255, 255, 255);
-#endif
-
- cc = 0;
- currentcommand = last_command;
- while (cc < 10)
- {
- if (currentcommand==NULL)
- break;
- drawtext(vid_buf, 15, 175-(cc*12), currentcommand->command, 255, 255, 255, 255);
- if (currentcommand->prev_command!=NULL)
- {
- if (cc<9) {
- currentcommand = currentcommand->prev_command;
- } else if (currentcommand->prev_command!=NULL) {
- free(currentcommand->prev_command);
- currentcommand->prev_command = NULL;
- }
- cc++;
- }
- else
- {
- break;
- }
- }
- cc = 0;
- currentcommand2 = last_command2;
- while (cc < 10)
- {
- if (currentcommand2==NULL)
- break;
- drawtext(vid_buf, 215, 175-(cc*12), currentcommand2->command, 255, 225, 225, 255);
- if (currentcommand2->prev_command!=NULL)
- {
- if (cc<9) {
- currentcommand2 = currentcommand2->prev_command;
- } else if (currentcommand2->prev_command!=NULL) {
- free(currentcommand2->prev_command);
- currentcommand2->prev_command = NULL;
- }
- cc++;
- }
- else
- {
- break;
- }
- }
-
- //if(error && ed.str[0]=='\0')
- //drawtext(vid_buf, 20, 207, error, 255, 127, 127, 200);
- if (console_more==0)
- drawtext(vid_buf, 5, 207, ">", 255, 255, 255, 240);
- else
- drawtext(vid_buf, 5, 207, "...", 255, 255, 255, 240);
-
- ui_edit_draw(vid_buf, &ed);
- ui_edit_process(mx, my, b, &ed);
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-#ifdef OGLR
- clearScreenNP(1.0f);
- draw_parts_fbo();
-#endif
- if (sdl_key==SDLK_RETURN)
- {
- currentcommand = malloc(sizeof(command_history));
- memset(currentcommand, 0, sizeof(command_history));
- currentcommand->prev_command = last_command;
- currentcommand->command = mystrdup(ed.str);
- last_command = currentcommand;
- free(old_buf);
- SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
- return currentcommand->command;
- }
- if (sdl_key==SDLK_ESCAPE || sdl_key==SDLK_BACKQUOTE)
- {
- console_mode = 0;
- free(old_buf);
- SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
- return NULL;
- }
- if (sdl_key==SDLK_UP || sdl_key==SDLK_DOWN)
- {
- ci += sdl_key==SDLK_UP?1:-1;
- if (ci<-1)
- ci = -1;
- if (ci==-1)
- {
- strcpy(ed.str, "");
- ed.cursor = strlen(ed.str);
- }
- else
- {
- if (last_command!=NULL) {
- currentcommand = last_command;
- for (cc = 0; cc<ci; cc++) {
- if (currentcommand->prev_command==NULL)
- ci = cc;
- else
- currentcommand = currentcommand->prev_command;
- }
- strcpy(ed.str, currentcommand->command);
- ed.cursor = strlen(ed.str);
- }
- else
- {
- ci = -1;
- strcpy(ed.str, "");
- ed.cursor = strlen(ed.str);
- }
- }
- }
- }
- console_mode = 0;
- free(old_buf);
- SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
- return NULL;
-}
-
-unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int savedColor)
-{//TODO: have the text boxes be editable and update the color.
- int i,ss,hh,vv,cr=127,cg=0,cb=0,b = 0,mx,my,bq = 0,j, lb=0,lx=0,ly=0,lm=0,hidden=0;
- int line_x=0, line_y=0;
- int window_offset_x_left = 2;
- int window_offset_x_right = XRES - 279;
- int window_offset_y = 2;
- int grid_offset_x_left = 5;
- int grid_offset_x_right = XRES - 274;
- int grid_offset_y = 5;
- int onleft_button_offset_x_left = 259;
- int onleft_button_offset_x_right = 4;
- int on_left = 1;
- int grid_offset_x;
- int window_offset_x;
- int onleft_button_offset_x;
- int currH = 0, currS = 255, currV = 127;
- int currR = PIXR(savedColor), currG = PIXG(savedColor), currB = PIXB(savedColor);
- int th = currH, ts = currS, tv = currV;
- int tool = DECO_DRAW;
- int active_color_menu= 0;
- pixel *old_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
- ui_edit box_R;
- ui_edit box_G;
- ui_edit box_B;
-
- zoom_en = 0;
-
- box_R.x = 5;
- box_R.y = 5+255+4;
- box_R.w = 30;
- box_R.nx = 1;
- box_R.def = "";
- strcpy(box_R.str, "127");
- box_R.focus = 0;
- box_R.hide = 0;
- box_R.multiline = 0;
- box_R.cursor = 0;
-
- box_G.x = 40;
- box_G.y = 5+255+4;
- box_G.w = 30;
- box_G.nx = 1;
- box_G.def = "";
- strcpy(box_G.str, "");
- box_G.focus = 0;
- box_G.hide = 0;
- box_G.multiline = 0;
- box_G.cursor = 0;
-
- box_B.x = 75;
- box_B.y = 5+255+4;
- box_B.w = 30;
- box_B.nx = 1;
- box_B.def = "";
- strcpy(box_B.str, "");
- box_B.focus = 0;
- box_B.hide = 0;
- box_B.multiline = 0;
- box_B.cursor = 0;
-
-
- if (!old_buf)
- return PIXRGB(currR,currG,currB);
- memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE);
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- memcpy(vid_buf,old_buf,(XRES+BARSIZE)*(YRES+MENUSIZE)*PIXELSIZE);
- render_before(vid_buf);
- render_after(vid_buf, NULL);
- ui_edit_process(mx, my, b, &box_R);
- ui_edit_process(mx, my, b, &box_G);
- ui_edit_process(mx, my, b, &box_B);
-
- if(on_left==1)
- {
- grid_offset_x = grid_offset_x_left;
- window_offset_x = window_offset_x_left;
- onleft_button_offset_x = onleft_button_offset_x_left;
- box_R.x = 5;
- box_G.x = 40;
- box_B.x = 75;
- }
- else
- {
- grid_offset_x = grid_offset_x_right;
- window_offset_x = window_offset_x_right;
- onleft_button_offset_x = onleft_button_offset_x_right;
- box_R.x = XRES - 254 + 5;
- box_G.x = XRES - 254 + 40;
- box_B.x = XRES - 254 + 75;
- }
- mouse_coords_window_to_sim(&mx, &my, mx, my);//change mouse position while it is in a zoom window
-
- drawrect(vid_buf, -1, -1, XRES+1, YRES+1, 220, 220, 220, 255);
- drawrect(vid_buf, -1, -1, XRES+2, YRES+2, 70, 70, 70, 255);
- drawtext(vid_buf, 2, 388, "Welcome to the decoration editor v.3 (by cracker64) \n\nClicking the current color on the window will move it to the other side. Right click is eraser. ", 255, 255, 255, 255);
-
- if(!hidden)
- {
- clearrect(vid_buf, window_offset_x, window_offset_y, 2+255+4+10+5, 2+255+20);
- drawrect(vid_buf, window_offset_x, window_offset_y, 2+255+4+10+5, 2+255+20, 255, 255, 255, 255);//window around whole thing
-
- drawrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, 255, 255, 255, 255);
- drawrect(vid_buf, window_offset_x + 230, window_offset_y +255+6, 26, 12, 255, 255, 255, 255);
- drawtext(vid_buf, window_offset_x + 232, window_offset_y +255+9, "Clear", 255, 255, 255, 255);
- ui_edit_draw(vid_buf, &box_R);
- ui_edit_draw(vid_buf, &box_G);
- ui_edit_draw(vid_buf, &box_B);
-
- //draw color square
- for(ss=0; ss<=255; ss++)
- for(hh=0;hh<=359;hh++)
- {
- cr = 0;
- cg = 0;
- cb = 0;
- HSV_to_RGB(hh,255-ss,255-ss,&cr,&cg,&cb);
- vid_buf[(ss+grid_offset_y)*(XRES+BARSIZE)+(clamp_flt(hh, 0, 359)+grid_offset_x)] = PIXRGB(cr, cg, cb);
- }
- //draw brightness bar
- for(vv=0; vv<=255; vv++)
- for( i=0; i<10; i++)
- {
- cr = 0;
- cg = 0;
- cb = 0;
- HSV_to_RGB(currH,currS,vv,&cr,&cg,&cb);
- vid_buf[(vv+grid_offset_y)*(XRES+BARSIZE)+(i+grid_offset_x+255+4)] = PIXRGB(cr, cg, cb);
- }
- addpixel(vid_buf,grid_offset_x + clamp_flt(currH, 0, 359),grid_offset_y-1,255,255,255,255);
- addpixel(vid_buf,grid_offset_x -1,grid_offset_y+(255-currS),255,255,255,255);
-
- addpixel(vid_buf,grid_offset_x + clamp_flt(th, 0, 359),grid_offset_y-1,100,100,100,255);
- addpixel(vid_buf,grid_offset_x -1,grid_offset_y+(255-ts),100,100,100,255);
-
- addpixel(vid_buf,grid_offset_x + 255 +3,grid_offset_y+tv,100,100,100,255);
- addpixel(vid_buf,grid_offset_x + 255 +3,grid_offset_y +currV,255,255,255,255);
-
- fillrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, currR, currG, currB, 255);
- }
- for (i=0; i<2; i++)//draw all the menu sections
- {
- draw_color_menu(vid_buf, i, active_color_menu);
- }
-
- for (i=0; i<2; i++)//check mouse position to see if it is on a menu section
- {
- if (!b&&mx>=XRES-2 && mx<XRES+BARSIZE-1 &&my>= (i*16)+YRES+MENUSIZE-16-(DECO_SECTIONS*16) && my<(i*16)+YRES+MENUSIZE-16-(DECO_SECTIONS*16)+15)
- {
- active_color_menu = i;
- }
- }
- if( color_menu_ui(vid_buf, active_color_menu, &currR, &currG, &currB, b, bq, mx, my, &tool) )
- RGB_to_HSV(currR,currG,currB,&currH,&currS,&currV);
-
- if(!box_R.focus)//prevent text update if it is being edited
- sprintf(box_R.str,"%d",currR);
- else
- {
- if(sdl_key == SDLK_RETURN)
- {
- cr = atoi(box_R.str);
- if (cr > 255) cr = 255;
- if (cr < 0) cr = 0;
- currR = cr;
- RGB_to_HSV(currR,currG,currB,&currH,&currS,&currV);
- box_R.focus = 0;
- }
- }
- if(!box_G.focus)
- sprintf(box_G.str,"%d",currG);
- else
- {
- if(sdl_key == SDLK_RETURN)
- {
- cg = atoi(box_G.str);
- if (cg > 255) cg = 255;
- if (cg < 0) cg = 0;
- currG = cg;
- RGB_to_HSV(currR,currG,currB,&currH,&currS,&currV);
- box_G.focus = 0;
- }
- }
- if(!box_B.focus)
- sprintf(box_B.str,"%d",currB);
- else
- {
- if(sdl_key == SDLK_RETURN)
- {
- cb = atoi(box_B.str);
- if (cb > 255) cb = 255;
- if (cb < 0) cb = 0;
- currB = cb;
- RGB_to_HSV(currR,currG,currB,&currH,&currS,&currV);
- box_B.focus = 0;
- }
- }
-
- fillrect(vid_buf, 250, YRES+4, 40, 15, currR, currG, currB, 255);
-
- drawrect(vid_buf, 295, YRES+5, 25, 12, 255, 255, 255, 255);
- if(hidden)
- drawtext(vid_buf, 297, YRES+5 +3, "Show", 255, 255, 255, 255);
- else
- drawtext(vid_buf, 297, YRES+5 +3, "Hide", 255, 255, 255, 255);
-
- if(!lb && !hidden && mx >= window_offset_x && my >= window_offset_y && mx <= window_offset_x+255+4+10+5 && my <= window_offset_y+255+20)//in the main window
- {
- //inside brightness bar
- if(mx >= grid_offset_x +255+4 && my >= grid_offset_y && mx <= grid_offset_x+255+4+10 && my <= grid_offset_y+255)
- {
- tv = my - grid_offset_y;
- if(b)
- {
- currV =my - grid_offset_y;
- HSV_to_RGB(currH,currS,tv,&currR,&currG,&currB);
- }
- HSV_to_RGB(currH,currS,tv,&cr,&cg,&cb);
- //clearrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6,12,12);
- fillrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, cr, cg, cb, 255);
- if(!box_R.focus)
- sprintf(box_R.str,"%d",cr);
- if(!box_G.focus)
- sprintf(box_G.str,"%d",cg);
- if(!box_B.focus)
- sprintf(box_B.str,"%d",cb);
- }
- //inside color grid
- if(mx >= grid_offset_x && my >= grid_offset_y && mx <= grid_offset_x+255 && my <= grid_offset_y+255)
- {
- th = mx - grid_offset_x;
- th = (int)( th*359/255 );
- ts = 255 - (my - grid_offset_y);
- if(b)
- {
- currH = th;
- currS = ts;
- HSV_to_RGB(th,ts,currV,&currR,&currG,&currB);
- }
- HSV_to_RGB(th,ts,currV,&cr,&cg,&cb);
- //clearrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6,12,12);
- fillrect(vid_buf, window_offset_x + onleft_button_offset_x +1, window_offset_y +255+6, 12, 12, cr, cg, cb, 255);
- //sprintf(box_R.def,"%d",cr);
- if(!box_R.focus)
- sprintf(box_R.str,"%d",cr);
- if(!box_G.focus)
- sprintf(box_G.str,"%d",cg);
- if(!box_B.focus)
- sprintf(box_B.str,"%d",cb);
- }
- //switch side button
- if(b && !bq && mx >= window_offset_x + onleft_button_offset_x +1 && my >= window_offset_y +255+6 && mx <= window_offset_x + onleft_button_offset_x +13 && my <= window_offset_y +255+5 +13)
- {
- on_left = !on_left;
- lb = 3;//prevent immediate drawing after clicking
- }
- //clear button
- if(b && !bq && mx >= window_offset_x + 230 && my >= window_offset_y +255+6 && mx <= window_offset_x + 230 +26 && my <= window_offset_y +255+5 +13)
- if (confirm_ui(vid_buf, "Reset Decoration Layer", "Do you really want to erase everything?", "Erase") )
- {
- int i;
- for (i=0;i<NPART;i++)
- parts[i].dcolour = 0;
- }
- }
- else if (mx > XRES || my > YRES)//mouse outside normal drawing area
- {
- //hide/show button
- if (!zoom_en && b && !bq && mx >= 295 && mx <= 295+25 && my >= YRES+5 && my<= YRES+5+12)
- hidden = !hidden;
- }
- else if (sdl_zoom_trig && zoom_en<2)
- {
- mx -= ZSIZE/2;
- my -= ZSIZE/2;
- if (mx<0) mx=0;
- if (my<0) my=0;
- if (mx>XRES-ZSIZE) mx=XRES-ZSIZE;
- if (my>YRES-ZSIZE) my=YRES-ZSIZE;
- zoom_x = mx;
- zoom_y = my;
- zoom_wx = (mx<XRES/2) ? XRES-ZSIZE*ZFACTOR : 0;
- zoom_wy = 0;
- zoom_en = 1;
- hidden = 1;
- if (!b && bq)
- zoom_en = 2;
- }
- else if (b)//there is a click, outside color window
- {
- if (lb)//mouse is held down
- {
- if (lm == 1)//line tool preview
- {
- if (sdl_mod & KMOD_ALT)
- {
- float snap_angle = floor(atan2(my-ly, mx-lx)/(M_PI*0.25)+0.5)*M_PI*0.25;
- float line_mag = sqrtf(pow(mx-lx,2)+pow(my-ly,2));
- line_x = (int)(line_mag*cos(snap_angle)+lx+0.5f);
- line_y = (int)(line_mag*sin(snap_angle)+ly+0.5f);
- }
- else
- {
- line_x = mx;
- line_y = my;
- }
- xor_line(lx, ly, line_x, line_y, vid_buf);
- }
- else if (lm == 2)//box tool preview
- {
- xor_line(lx, ly, lx, my, vid_buf);
- xor_line(lx, my, mx, my, vid_buf);
- xor_line(mx, my, mx, ly, vid_buf);
- xor_line(mx, ly, lx, ly, vid_buf);
- }
- else if(lb!=3)//while mouse is held down, it draws lines between previous and current positions
- {
- line_decorations(lx, ly, mx, my, *bsx, *bsy, currR, currG, currB, b, tool);
- lx = mx;
- ly = my;
- }
- }
- else //first click
- {
- if ((sdl_mod & (KMOD_SHIFT)) && !(sdl_mod & (KMOD_CTRL)))
- {
- lx = mx;
- ly = my;
- lb = b;
- lm = 1;//line
- }
- //start box tool
- else if ((sdl_mod & (KMOD_CTRL)) && !(sdl_mod & (KMOD_SHIFT|KMOD_ALT)))
- {
- lx = mx;
- ly = my;
- lb = b;
- lm = 2;//box
- }
- //sample tool
- else if (((sdl_mod & (KMOD_ALT)) && !(sdl_mod & (KMOD_SHIFT|KMOD_CTRL))) || b==SDL_BUTTON_MIDDLE)
- {
- if (my>=0 && my<YRES && mx>=0 && mx<XRES)
- {
- unsigned int tempcolor = vid_buf[(my)*(XRES+BARSIZE)+(mx)];
- cr = PIXR(tempcolor);
- cg = PIXG(tempcolor);
- cb = PIXB(tempcolor);
- if (cr || cg || cb)
- {
- if (cr && cr<255) cr++;
- if (cg && cg<255) cg++;
- if (cb && cb<255) cb++;
- currR = cr;
- currG = cg;
- currB = cb;
- }
- }
- lx = mx;
- ly = my;
- lb = 0;
- lm = 0;
- }
- else //normal click, draw deco
- {
- create_decorations(mx,my,*bsx,*bsy,currR,currG,currB,b, tool);
- lx = mx;
- ly = my;
- lb = b;
- lm = 0;
- }
- }
- }
- else
- {
- if (lb && lm) //lm is box/line tool
- {
- if (lm == 1)//line
- line_decorations(lx, ly, line_x, line_y, *bsx, *bsy, currR, currG, currB, lb, tool);
- else//box
- box_decorations(lx, ly, mx, my, currR, currG, currB, lb, tool);
- lm = 0;
- }
- lb = 0;
-
- }
- if (zoom_en!=1)
- render_cursor(vid_buf, mx, my, PT_DUST, *bsx, *bsy);
-
- if (zoom_en)
- render_zoom(vid_buf);
-
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- if (sdl_wheel)
- {
- if (sdl_zoom_trig)//zoom window change
- {
- ZSIZE += sdl_wheel;
- if (ZSIZE>60)
- ZSIZE = 60;
- if (ZSIZE<2)
- ZSIZE = 2;
- ZFACTOR = 256/ZSIZE;
- sdl_wheel = 0;
- }
- else //change brush size
- {
- if (!(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
- {
- *bsx += sdl_wheel;
- *bsy += sdl_wheel;
- }
- else if (sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL)))
- {
- *bsx += sdl_wheel;
- }
- else if (sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT)))
- {
- *bsy += sdl_wheel;
- }
- if (*bsx>1180)
- *bsx = 1180;
- if (*bsx<0)
- *bsx = 0;
- if (*bsy>1180)
- *bsy = 1180;
- if (*bsy<0)
- *bsy = 0;
- sdl_wheel = 0;
- /*if(su >= PT_NUM) {
- if(sl < PT_NUM)
- su = sl;
- if(sr < PT_NUM)
- su = sr;
- }*/
- }
- }
- if (sdl_key==SDLK_LEFTBRACKET) {
- if (sdl_zoom_trig)
- {
- ZSIZE -= 1;
- if (ZSIZE>60)
- ZSIZE = 60;
- if (ZSIZE<2)
- ZSIZE = 2;
- ZFACTOR = 256/ZSIZE;
- }
- else
- {
- if (sdl_mod & (KMOD_LALT|KMOD_RALT) && !(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
- {
- *bsx -= 1;
- *bsy -= 1;
- }
- else if (sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL)))
- {
- *bsx -= 1;
- }
- else if (sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT)))
- {
- *bsy -= 1;
- }
- else
- {
- *bsx -= ceil((*bsx/5)+0.5f);
- *bsy -= ceil((*bsy/5)+0.5f);
- }
- if (*bsx>1180)
- *bsx = 1180;
- if (*bsy>1180)
- *bsy = 1180;
- if (*bsx<0)
- *bsx = 0;
- if (*bsy<0)
- *bsy = 0;
- }
- }
- if (sdl_key==SDLK_RIGHTBRACKET) {
- if (sdl_zoom_trig)
- {
- ZSIZE += 1;
- if (ZSIZE>60)
- ZSIZE = 60;
- if (ZSIZE<2)
- ZSIZE = 2;
- ZFACTOR = 256/ZSIZE;
- }
- else
- {
- if (sdl_mod & (KMOD_LALT|KMOD_RALT) && !(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
- {
- *bsx += 1;
- *bsy += 1;
- }
- else if (sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL)))
- {
- *bsx += 1;
- }
- else if (sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT)))
- {
- *bsy += 1;
- }
- else
- {
- *bsx += ceil((*bsx/5)+0.5f);
- *bsy += ceil((*bsy/5)+0.5f);
- }
- if (*bsx>1180)
- *bsx = 1180;
- if (*bsy>1180)
- *bsy = 1180;
- if (*bsx<0)
- *bsx = 0;
- if (*bsy<0)
- *bsy = 0;
- }
- }
- if (sdl_key==SDLK_TAB)
- {
- CURRENT_BRUSH =(CURRENT_BRUSH + 1)%BRUSH_NUM ;
- }
-
- if (!sdl_zoom_trig && zoom_en==1)
- {
- zoom_en = 0;
- }
- if (sdl_key=='z')
- {
- if (sdl_mod & KMOD_ALT)//toggle
- sdl_zoom_trig = (!sdl_zoom_trig)*2;
- else
- sdl_zoom_trig = 1;
- }
- if (sdl_rkey == 'z' && sdl_zoom_trig==1)//if ==2 then it was toggled with alt+z, don't turn off on keyup
- sdl_zoom_trig = 0;
-
- if (!sdl_zoom_trig && zoom_en==1)
- zoom_en = 0;
-
- if (sdl_key=='z' && zoom_en==2)
- zoom_en = 1;
-
- if(sdl_key=='b' || sdl_key==SDLK_ESCAPE)
- {
- free(old_buf);
- return PIXRGB(currR,currG,currB);
- }
- }
- free(old_buf);
- return PIXRGB(currR,currG,currB);
-}
-struct savelist_e {
- char *filename;
- char *name;
- pixel *image;
- void *next;
- void *prev;
-};
-typedef struct savelist_e savelist_e;
-savelist_e *get_local_saves(char *folder, char *search, int *results_ret)
-{
- int index = 0, results = 0;
- savelist_e *new_savelist = NULL;
- savelist_e *current_item = NULL, *new_item = NULL;
- char *fname;
-#if defined(WIN32) && !defined(__GNUC__)
- struct _finddata_t current_file;
- intptr_t findfile_handle;
- char *filematch = malloc(strlen(folder)+4);
- sprintf(filematch, "%s%s", folder, "*.*");
- findfile_handle = _findfirst(filematch, &current_file);
- free(filematch);
- if (findfile_handle == -1L)
- {
- *results_ret = 0;
- return NULL;
- }
- do
- {
- fname = current_file.name;
-#else
- struct dirent *derp;
- DIR *directory = opendir(folder);
- if(!directory)
- {
- printf("Unable to open directory\n");
- *results_ret = 0;
- return NULL;
- }
- while(derp = readdir(directory))
- {
- fname = derp->d_name;
-#endif
- if(strlen(fname)>4)
- {
- char *ext = fname+(strlen(fname)-4);
- if((!strncmp(ext, ".cps", 4) || !strncmp(ext, ".stm", 4)) && (search==NULL || strstr(fname, search)))
- {
- new_item = malloc(sizeof(savelist_e));
- new_item->filename = malloc(strlen(folder)+strlen(fname)+1);
- sprintf(new_item->filename, "%s%s", folder, fname);
- new_item->name = mystrdup(fname);
- new_item->image = NULL;
- new_item->next = NULL;
- if(new_savelist==NULL){
- new_savelist = new_item;
- new_item->prev = NULL;
- } else {
- current_item->next = new_item;
- new_item->prev = current_item;
- }
- current_item = new_item;
- results++;
- }
- }
- }
-#if defined(WIN32) && !defined(__GNUC__)
- while (_findnext(findfile_handle, &current_file) == 0);
- _findclose(findfile_handle);
-#else
- closedir(directory);
-#endif
- *results_ret = results;
- return new_savelist;
-}
-
-void free_saveslist(savelist_e *saves)
-{
- if(!saves)
- return;
- if(saves->next!=NULL)
- free_saveslist(saves->next);
- if(saves->filename!=NULL)
- free(saves->filename);
- if(saves->name!=NULL)
- free(saves->name);
- if(saves->image!=NULL)
- free(saves->image);
-}
-
-int save_filename_ui(pixel *vid_buf)
-{
- int xsize = 16+(XRES/3);
- int ysize = 64+(YRES/3);
- float ca = 0;
- int x0=(XRES+BARSIZE-xsize)/2,y0=(YRES+MENUSIZE-ysize)/2,b=1,bq,mx,my;
- int idtxtwidth, nd=0, imgw, imgh, save_size;
- void *save_data;
- char *savefname = NULL;
- char *filename = NULL;
- pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
- pixel *save_tmp;
- pixel *save_data_image;
- pixel *save = NULL;//calloc((XRES/3)*(YRES/3), PIXELSIZE);
- ui_edit ed;
-
- save_data = build_save(&save_size, 0, 0, XRES, YRES, bmap, vx, vy, pv, fvx, fvy, signs, parts);
- save_data_image = prerender_save(save_data, save_size, &imgw, &imgh);
- if(save_data_image!=NULL)
- {
- save = resample_img(save_data_image, imgw, imgh, XRES/3, YRES/3);
- }
-
- ed.x = x0+11;
- ed.y = y0+25;
- ed.w = xsize-4-16;
- ed.nx = 1;
- ed.def = "[filename]";
- ed.focus = 1;
- ed.hide = 0;
- ed.cursor = 0;
- ed.multiline = 0;
- ed.str[0] = 0;
-
- if(svf_fileopen){
- char * dotloc = NULL;
- strncpy(ed.str, svf_filename, 255);
- if(dotloc = strstr(ed.str, "."))
- {
- dotloc[0] = 0;
- }
- ed.cursor = strlen(ed.str);
- }
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- draw_rgba_image(vid_buf, save_to_disk_image, 0, 0, 0.7);
-
- memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
- drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
- drawtext(vid_buf, x0+8, y0+8, "Filename:", 255, 255, 255, 255);
- drawrect(vid_buf, x0+8, y0+20, xsize-16, 16, 255, 255, 255, 180);
- if(save!=NULL)
- {
- draw_image(vid_buf, save, x0+8, y0+40, XRES/3, YRES/3, 255);
- }
- drawrect(vid_buf, x0+8, y0+40, XRES/3, YRES/3, 192, 192, 192, 255);
-
- drawrect(vid_buf, x0, y0+ysize-16, xsize, 16, 192, 192, 192, 255);
- fillrect(vid_buf, x0, y0+ysize-16, xsize, 16, 170, 170, 192, (int)ca);
- drawtext(vid_buf, x0+8, y0+ysize-12, "Save", 255, 255, 255, 255);
-
- ui_edit_draw(vid_buf, &ed);
- if (strlen(ed.str) || ed.focus)
- drawtext(vid_buf, x0+12+textwidth(ed.str), y0+25, ".cps", 240, 240, 255, 180);
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- memcpy(vid_buf, old_vid, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
-
- ui_edit_process(mx, my, b, &ed);
-
- if(mx > x0 && mx < x0+xsize && my > y0+ysize-16 && my < y0+ysize)
- {
- if(b && !bq)
- {
- FILE *f = NULL;
- savefname = malloc(strlen(ed.str)+5);
- filename = malloc(strlen(LOCAL_SAVE_DIR)+strlen(PATH_SEP)+strlen(ed.str)+5);
- sprintf(filename, "%s%s%s.cps", LOCAL_SAVE_DIR, PATH_SEP, ed.str);
- sprintf(savefname, "%s.cps", ed.str);
-
-#ifdef WIN32
- _mkdir(LOCAL_SAVE_DIR);
-#else
- mkdir(LOCAL_SAVE_DIR, 0755);
-#endif
- f = fopen(filename, "r");
- if(!f || confirm_ui(vid_buf, "A save with the name already exists.", filename, "Overwrite"))
- {
- if(f)
- {
- fclose(f);
- f = NULL;
- }
- f = fopen(filename, "wb");
- if (f)
- {
- fwrite(save_data, save_size, 1, f);
- fclose(f);
- if(svf_fileopen)
- {
- strncpy(svf_filename, savefname, 255);
- svf_fileopen = 1;
-
- //Allow reloading
- if(svf_last)
- free(svf_last);
- svf_last = malloc(save_size);
- memcpy(svf_last, save_data, save_size);
- svf_lsize = save_size;
- }
- break;
- } else {
- error_ui(vid_buf, 0, "Unable to write to save file.");
- }
- }
- fclose(f);
- }
- }
-
- if (sdl_key==SDLK_ESCAPE)
- {
- if (!ed.focus)
- break;
- ed.focus = 0;
- }
- }
-
-savefin:
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
- free(save_data_image);
- free(save_data);
- free(old_vid);
- free(save);
- if(filename) free(filename);
- if(savefname) free(savefname);
- return 0;
-}
-
-void catalogue_ui(pixel * vid_buf)
-{
- int xsize = 8+(XRES/CATALOGUE_S+8)*CATALOGUE_X;
- int ysize = 48+(YRES/CATALOGUE_S+20)*CATALOGUE_Y;
- int x0=(XRES+BARSIZE-xsize)/2,y0=(YRES+MENUSIZE-ysize)/2,b=1,bq,mx,my;
- int rescount, imageoncycle = 0, currentstart = 0, currentoffset = 0, thidden = 0, cactive = 0;
- int listy = 0, listxc;
- int listx = 0, listyc;
- pixel * vid_buf2;
- float scrollvel, offsetf = 0.0f;
- char savetext[128] = "";
- char * last = mystrdup("");
- savelist_e *saves, *cssave, *csave;
- ui_edit ed;
-
- vid_buf2 = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
- if (!vid_buf2)
- return;
-
- ed.w = xsize-16-4;
- ed.x = x0+11;
- ed.y = y0+29;
- ed.multiline = 0;
- ed.def = "[search]";
- ed.focus = 0;
- ed.hide = 0;
- ed.cursor = 0;
- ed.nx = 0;
- strcpy(ed.str, "");
-
- saves = get_local_saves(LOCAL_SAVE_DIR PATH_SEP, NULL, &rescount);
- cssave = csave = saves;
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
- sprintf(savetext, "Found %d save%s", rescount, rescount==1?"":"s");
- clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
- clearrect(vid_buf2, x0-2, y0-2, xsize+4, ysize+4);
- drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
- drawtext(vid_buf, x0+8, y0+8, "Saves", 255, 216, 32, 255);
- drawtext(vid_buf, x0+xsize-8-textwidth(savetext), y0+8, savetext, 255, 216, 32, 255);
- drawrect(vid_buf, x0+8, y0+24, xsize-16, 16, 255, 255, 255, 180);
- if(strcmp(ed.str, last)){
- free(last);
- last = mystrdup(ed.str);
- currentstart = 0;
- if(saves!=NULL) free_saveslist(saves);
- saves = get_local_saves(LOCAL_SAVE_DIR PATH_SEP, last, &rescount);
- cssave = saves;
- scrollvel = 0.0f;
- offsetf = 0.0f;
- thidden = 0;
- }
- //Scrolling
- if (sdl_wheel!=0)
- {
- scrollvel -= (float)sdl_wheel;
- if(scrollvel > 5.0f) scrollvel = 5.0f;
- if(scrollvel < -5.0f) scrollvel = -5.0f;
- sdl_wheel = 0;
- }
- offsetf += scrollvel;
- scrollvel*=0.99f;
- if(offsetf >= (YRES/CATALOGUE_S+20) && rescount)
- {
- if(rescount - thidden > CATALOGUE_X*(CATALOGUE_Y+1))
- {
- int i = 0;
- for(i = 0; i < CATALOGUE_X; i++){
- if(cssave->next==NULL)
- break;
- cssave = cssave->next;
- }
- offsetf -= (YRES/CATALOGUE_S+20);
- thidden += CATALOGUE_X;
- } else {
- offsetf = (YRES/CATALOGUE_S+20);
- }
- }
- if(offsetf > 0.0f && rescount <= CATALOGUE_X*CATALOGUE_Y && rescount)
- {
- offsetf = 0.0f;
- }
- if(offsetf < 0.0f && rescount)
- {
- if(thidden >= CATALOGUE_X)
- {
- int i = 0;
- for(i = 0; i < CATALOGUE_X; i++){
- if(cssave->prev==NULL)
- break;
- cssave = cssave->prev;
- }
- offsetf += (YRES/CATALOGUE_S+20);
- thidden -= CATALOGUE_X;
- } else {
- offsetf = 0.0f;
- }
- }
- currentoffset = (int)offsetf;
- csave = cssave;
- //Diplay
- if(csave!=NULL && rescount)
- {
- listx = 0;
- listy = 0;
- while(csave!=NULL)
- {
- listxc = x0+8+listx*(XRES/CATALOGUE_S+8);
- listyc = y0+48-currentoffset+listy*(YRES/CATALOGUE_S+20);
- if(listyc > y0+ysize) //Stop when we get to the bottom of the viewable
- break;
- cactive = 0;
- if(my > listyc && my < listyc+YRES/CATALOGUE_S+2 && mx > listxc && mx < listxc+XRES/CATALOGUE_S && my > y0+48 && my < y0+ysize)
- {
- if(b)
- {
- int status, size;
- void *data;
- data = file_load(csave->filename, &size);
- if(data){
- status = parse_save(data, size, 1, 0, 0, bmap, vx, vy, pv, fvx, fvy, signs, parts, pmap);
- if(!status)
- {
- //svf_filename[0] = 0;
- strncpy(svf_filename, csave->name, 255);
- svf_fileopen = 1;
- svf_open = 0;
- svf_publish = 0;
- svf_own = 0;
- svf_myvote = 0;
- svf_id[0] = 0;
- svf_name[0] = 0;
- svf_description[0] = 0;
- svf_tags[0] = 0;
- svf_last = data;
- data = NULL;
- svf_lsize = size;
- goto openfin;
- } else {
- error_ui(vid_buf, 0, "Save data corrupt");
- free(data);
- }
- } else {
- error_ui(vid_buf, 0, "Unable to read save file");
- }
- }
- cactive = 1;
- }
- //Generate an image
- if(csave->image==NULL && !imageoncycle){ //imageoncycle: Don't read/parse more than one image per cycle, makes it more resposive for slower computers
- int imgwidth, imgheight, size;
- pixel *tmpimage = NULL;
- void *data = NULL;
- data = file_load(csave->filename, &size);
- if(data!=NULL){
- tmpimage = prerender_save(data, size, &imgwidth, &imgheight);
- if(tmpimage!=NULL)
- {
- csave->image = resample_img(tmpimage, imgwidth, imgheight, XRES/CATALOGUE_S, YRES/CATALOGUE_S);
- free(tmpimage);
- } else {
- //Blank image, TODO: this should default to something else
- csave->image = calloc((XRES/CATALOGUE_S)*(YRES/CATALOGUE_S), PIXELSIZE);
- }
- free(data);
- } else {
- //Blank image, TODO: this should default to something else
- csave->image = calloc((XRES/CATALOGUE_S)*(YRES/CATALOGUE_S), PIXELSIZE);
- }
- imageoncycle = 1;
- }
- if(csave->image!=NULL)
- draw_image(vid_buf2, csave->image, listxc, listyc, XRES/CATALOGUE_S, YRES/CATALOGUE_S, 255);
- drawrect(vid_buf2, listxc, listyc, XRES/CATALOGUE_S, YRES/CATALOGUE_S, 255, 255, 255, 190);
- if(cactive)
- drawtext(vid_buf2, listxc+((XRES/CATALOGUE_S)/2-textwidth(csave->name)/2), listyc+YRES/CATALOGUE_S+3, csave->name, 255, 255, 255, 255);
- else
- drawtext(vid_buf2, listxc+((XRES/CATALOGUE_S)/2-textwidth(csave->name)/2), listyc+YRES/CATALOGUE_S+3, csave->name, 240, 240, 255, 180);
- if (mx>=listxc+XRES/GRID_S-4 && mx<=listxc+XRES/GRID_S+6 && my>=listyc-6 && my<=listyc+4)
- {
- if (b && !bq && confirm_ui(vid_buf, "Do you want to delete?", csave->name, "Delete"))
- {
- remove(csave->filename);
- currentstart = 0;
- if(saves!=NULL) free_saveslist(saves);
- saves = get_local_saves(LOCAL_SAVE_DIR PATH_SEP, last, &rescount);
- cssave = saves;
- scrollvel = 0.0f;
- offsetf = 0.0f;
- thidden = 0;
- if (rescount == 0)
- rmdir(LOCAL_SAVE_DIR PATH_SEP);
- break;
- }
- drawtext(vid_buf2, listxc+XRES/GRID_S-4, listyc-6, "\x86", 255, 48, 32, 255);
- }
- else
- drawtext(vid_buf2, listxc+XRES/GRID_S-4, listyc-6, "\x86", 160, 48, 32, 255);
- drawtext(vid_buf2, listxc+XRES/GRID_S-4, listyc-6, "\x85", 255, 255, 255, 255);
- csave = csave->next;
- if(++listx==CATALOGUE_X){
- listx = 0;
- listy++;
- }
- }
- imageoncycle = 0;
- } else {
- drawtext(vid_buf2, x0+(xsize/2)-(textwidth("No saves found")/2), y0+(ysize/2)+20, "No saves found", 255, 255, 255, 180);
- }
- ui_edit_draw(vid_buf, &ed);
- ui_edit_process(mx, my, b, &ed);
- //Draw the scrollable area onto the main buffer
- {
- pixel *srctemp = vid_buf2, *desttemp = vid_buf;
- int j = 0;
- for (j = y0+42; j < y0+ysize; j++)
- {
- memcpy(desttemp+j*(XRES+BARSIZE)+x0+1, srctemp+j*(XRES+BARSIZE)+x0+1, (xsize-1)*PIXELSIZE);
- //desttemp+=(XRES+BARSIZE);//*PIXELSIZE;
- //srctemp+=(XRES+BARSIZE);//*PIXELSIZE;
- }
- }
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
- if (sdl_key==SDLK_RETURN)
- break;
- if (sdl_key==SDLK_ESCAPE)
- break;
- }
-openfin:
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- if(saves)
- free_saveslist(saves);
- return;
-}
-
-void drawIcon(pixel * vid_buf, int x, int y, int cmode)
-{
- switch (cmode)
- {
- case 0x98:
- drawtext(vid_buf, x, y, "\x98", 128, 160, 255, 255);
- break;
- case 0x99:
- drawtext(vid_buf, x, y, "\x99", 255, 212, 32, 255);
- break;
- case 0x9A:
- drawtext(vid_buf, x, y, "\x9A", 212, 212, 212, 255);
- break;
- case 0x9B:
- drawtext(vid_buf, x+1, y, "\x9B", 255, 0, 0, 255);
- drawtext(vid_buf, x+1, y, "\x9C", 255, 255, 64, 255);
- break;
- case 0xBF:
- drawtext(vid_buf, x, y, "\xBF", 55, 255, 55, 255);
- break;
- case 0xBE:
- drawtext(vid_buf, x+2, y, "\xBE", 255, 0, 0, 255);
- drawtext(vid_buf, x+2, y, "\xBD", 255, 255, 255, 255);
- break;
- case 0xC4:
- drawtext(vid_buf, x, y, "\xC4", 100, 150, 255, 255);
- break;
- case 0xD3:
- drawtext(vid_buf, x, y, "\xD3", 255, 50, 255, 255);
- break;
- case 0xE0:
- drawtext(vid_buf, x, y, "\xE0", 255, 255, 255, 255);
- break;
- case 0xE1:
- drawtext(vid_buf, x, y, "\xE1", 255, 255, 160, 255);
- break;
- case 0xDF:
- drawtext(vid_buf, x, y, "\xDF", 200, 255, 255, 255);
- break;
- case 0xDE:
- drawtext(vid_buf, x, y, "\xDE", 255, 255, 255, 255);
- break;
- case 0xDB:
- drawtext(vid_buf, x, y, "\xDB", 255, 255, 200, 255);
- break;
- case 0xD4:
- drawtext(vid_buf, x, y, "\xD4", 255, 55, 55, 255);
- drawtext(vid_buf, x, y, "\xD5", 55, 255, 55, 255);
- break;
- }
-}
-
-void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation)
-{
- pixel * o_vid_buf;
- pixel *part_vbuf; //Extra video buffer
- pixel *part_vbuf_store;
- int i, j, count, changed, temp;
- int xsize;
- int ysize;
- int yoffset;
- int xoffset;
- int xcoffset;
- int b, bq, mx, my;
- ui_checkbox *render_cb;
- ui_checkbox *display_cb;
- ui_checkbox *colour_cb;
-
- int render_optioncount = 6;
- int render_options[] = {RENDER_EFFE, RENDER_GLOW, RENDER_FIRE, RENDER_BLUR, RENDER_BLOB, RENDER_BASC};
- int render_optionicons[] = {0xE1, 0xDF, 0x9B, 0xC4, 0xBF, 0xDB};
- char * render_desc[] = {"Effects", "Glow", "Fire", "Blur", "Blob", "Basic"};
-
- int display_optioncount = 7;
- int display_options[] = {DISPLAY_AIRC, DISPLAY_AIRP, DISPLAY_AIRV, DISPLAY_AIRH, DISPLAY_WARP, DISPLAY_PERS, DISPLAY_EFFE};
- int display_optionicons[] = {0xD4, 0x99, 0x98, 0xBE, 0xDE, 0x9A, 0xE1};
- char * display_desc[] = {"Air: Cracker", "Air: Pressure", "Air: Velocity", "Air: Heat", "Warp effect", "Persistent", "Effects"};
-
- int colour_optioncount = 4;
- int colour_options[] = {COLOUR_BASC, COLOUR_LIFE, COLOUR_HEAT, COLOUR_GRAD};
- int colour_optionicons[] = {0xDB, 0xE0, 0xBE, 0xD3};
- char * colour_desc[] = {"Basic", "Life", "Heat", "Heat Gradient"};
-
- yoffset = 16;
- xoffset = 0;
-
- xcoffset = 35;
-
- xsize = xcoffset*3;
- ysize = display_optioncount * yoffset + 6;
-
- ycoord -= ysize;
- xcoord -= xsize;
-
- colour_cb = calloc(colour_optioncount, sizeof(ui_checkbox));
- for(i = 0; i < colour_optioncount; i++)
- {
- colour_cb[i].x = (xcoffset * 0) + xcoord + (i * xoffset) + 5;
- colour_cb[i].y = ycoord + (i * yoffset) + 5;
- colour_cb[i].focus = 0;
- colour_cb[i].checked = 0;
- j = 0;
- if(colour_mode == colour_options[i])
- {
- colour_cb[i].checked = 1;
- }
- }
-
- render_cb = calloc(render_optioncount, sizeof(ui_checkbox));
- for(i = 0; i < render_optioncount; i++)
- {
- render_cb[i].x = (xcoffset * 1) + xcoord + (i * xoffset) + 5;
- render_cb[i].y = ycoord + (i * yoffset) + 5;
- render_cb[i].focus = 0;
- render_cb[i].checked = 0;
- j = 0;
- while(render_modes[j])
- {
- if(render_modes[j] == render_options[i])
- {
- render_cb[i].checked = 1;
- break;
- }
- j++;
- }
- }
-
- display_cb = calloc(display_optioncount, sizeof(ui_checkbox));
- for(i = 0; i < display_optioncount; i++)
- {
- display_cb[i].x = (xcoffset * 2) + xcoord + (i * xoffset) + 5;
- display_cb[i].y = ycoord + (i * yoffset) + 5;
- display_cb[i].focus = 0;
- display_cb[i].checked = 0;
- j = 0;
- while(display_modes[j])
- {
- if(display_modes[j] == display_options[i])
- {
- display_cb[i].checked = 1;
- break;
- }
- j++;
- }
- }
-
- o_vid_buf = calloc((YRES+MENUSIZE) * (XRES+BARSIZE), PIXELSIZE);
- //memcpy(o_vid_buf, vid_buf, ((YRES+MENUSIZE) * (XRES+BARSIZE)) * PIXELSIZE);
-
- part_vbuf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); //Extra video buffer
- part_vbuf_store = part_vbuf;
-
- if (!o_vid_buf || !part_vbuf || !part_vbuf_store)
- return;
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- memcpy(vid_buf, o_vid_buf, ((YRES+MENUSIZE) * (XRES+BARSIZE)) * PIXELSIZE);
-#ifdef OGLR
- part_vbuf = vid_buf;
-#else
- if(ngrav_enable && (display_mode & DISPLAY_WARP))
- {
- part_vbuf = part_vbuf_store;
- memset(vid_buf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- } else {
- part_vbuf = vid_buf;
- }
-#endif
- render_before(part_vbuf);
- render_after(part_vbuf, vid_buf);
- quickoptions_menu(vid_buf, b, bq, mx, my);
- for (i=0; i<SC_TOTAL; i++)//draw all the menu sections
- {
- draw_menu(vid_buf, i, active_menu);
- }
- draw_svf_ui(vid_buf, sdl_mod & (KMOD_LCTRL|KMOD_RCTRL));
-
- clearrect(vid_buf, xcoord-2, ycoord-2, xsize+4, ysize+4);
- drawrect(vid_buf, xcoord, ycoord, xsize, ysize, 192, 192, 192, 255);
-
- changed = 0;
- for(i = 0; i < render_optioncount; i++)
- {
- temp = render_cb[i].checked;
- drawIcon(vid_buf, render_cb[i].x + 16, render_cb[i].y+2, render_optionicons[i]);
- ui_checkbox_draw(vid_buf, &(render_cb[i]));
- ui_checkbox_process(mx, my, b, bq, &(render_cb[i]));
- if(render_cb[i].focus)
- drawtext(vid_buf, xcoord - textwidth(render_desc[i]) - 10, render_cb[i].y+2, render_desc[i], 255, 255, 255, 255);
- if(temp != render_cb[i].checked)
- changed = 1;
- }
- if(changed)
- {
- //Compile render options
- count = 1;
- for(i = 0; i < render_optioncount; i++)
- {
- if(render_cb[i].checked)
- count++;
- }
- free(render_modes);
- render_mode = 0;
- render_modes = calloc(count, sizeof(unsigned int));
- count = 0;
- for(i = 0; i < render_optioncount; i++)
- {
- if(render_cb[i].checked)
- {
- render_modes[count] = render_options[i];
- render_mode |= render_options[i];
- count++;
- }
- }
- }
-
- changed = 0;
- for(i = 0; i < display_optioncount; i++)
- {
- temp = display_cb[i].checked;
- drawIcon(vid_buf, display_cb[i].x + 16, display_cb[i].y+2, display_optionicons[i]);
-
- if(display_options[i] & DISPLAY_AIR)
- {
- ui_radio_draw(vid_buf, &(display_cb[i]));
- ui_radio_process(mx, my, b, bq, &(display_cb[i]));
- }
- else
- {
- ui_checkbox_draw(vid_buf, &(display_cb[i]));
- ui_checkbox_process(mx, my, b, bq, &(display_cb[i]));
- }
- if(display_cb[i].checked && (display_options[i] & DISPLAY_AIR)) //One air type only
- {
- for(j = 0; j < display_optioncount; j++)
- {
- if((display_options[j] & DISPLAY_AIR) && j!=i)
- {
- display_cb[j].checked = 0;
- }
- }
- }
- if(display_cb[i].focus)
- drawtext(vid_buf, xcoord - textwidth(display_desc[i]) - 10, display_cb[i].y+2, display_desc[i], 255, 255, 255, 255);
- if(temp != display_cb[i].checked)
- changed = 1;
- }
- if(changed)
- {
- //Compile display options
- count = 1;
- for(i = 0; i < display_optioncount; i++)
- {
- if(display_cb[i].checked)
- count++;
- }
- free(display_modes);
- display_mode = 0;
- display_modes = calloc(count, sizeof(unsigned int));
- count = 0;
- for(i = 0; i < display_optioncount; i++)
- {
- if(display_cb[i].checked)
- {
- display_modes[count] = display_options[i];
- display_mode |= display_options[i];
- count++;
- }
- }
- }
-
- changed = 0;
- for(i = 0; i < colour_optioncount; i++)
- {
- temp = colour_cb[i].checked;
- drawIcon(vid_buf, colour_cb[i].x + 16, colour_cb[i].y+2, colour_optionicons[i]);
- ui_radio_draw(vid_buf, &(colour_cb[i]));
- ui_radio_process(mx, my, b, bq, &(colour_cb[i]));
- if(colour_cb[i].checked) //One colour only
- {
- for(j = 0; j < colour_optioncount; j++)
- {
- if(j!=i)
- {
- colour_cb[j].checked = 0;
- }
- }
- }
- if(colour_cb[i].focus)
- drawtext(vid_buf, xcoord - textwidth(colour_desc[i]) - 10, colour_cb[i].y+2, colour_desc[i], 255, 255, 255, 255);
- if(temp != colour_cb[i].checked)
- changed = 1;
- }
- if(changed)
- {
- //Compile colour options
- colour_mode = 0;
- for(i = 0; i < colour_optioncount; i++)
- {
- if(colour_cb[i].checked)
- {
- colour_mode |= colour_options[i];
- }
- }
- }
-
-#ifdef OGLR
- clearScreenNP(1.0f);
- draw_parts_fbo();
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
-
- if (sdl_key==SDLK_RETURN)
- break;
- if (sdl_key==SDLK_ESCAPE)
- break;
- if (b && !bq && (mx < xcoord || mx > xcoord+xsize || my < ycoord || my > ycoord+ysize))
- break;
- }
-
- free(colour_cb);
-
- free(render_cb);
-
- free(display_cb);
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- free(part_vbuf_store);
-
- free(o_vid_buf);
-}
-
-void simulation_ui(pixel * vid_buf)
-{
- int xsize = 300;
- int ysize = 260;
- int x0=(XRES-xsize)/2,y0=(YRES-MENUSIZE-ysize)/2,b=1,bq,mx,my;
- int new_scale, new_kiosk;
- ui_checkbox cb;
- ui_checkbox cb2;
- ui_checkbox cb3;
- ui_checkbox cb4;
- ui_checkbox cb5;
- ui_checkbox cb6;
- ui_checkbox cb7;
- char * airModeList[] = {"On", "Pressure Off", "Velocity Off", "Off", "No Update"};
- int airModeListCount = 5;
- char * gravityModeList[] = {"Vertical", "Off", "Radial"};
- int gravityModeListCount = 3;
- ui_list list;
- ui_list list2;
-
- cb.x = x0+xsize-16; //Heat simulation
- cb.y = y0+23;
- cb.focus = 0;
- cb.checked = !legacy_enable;
-
- cb2.x = x0+xsize-16; //Newt. Gravity
- cb2.y = y0+79;
- cb2.focus = 0;
- cb2.checked = ngrav_enable;
-
- cb3.x = x0+xsize-16; //Large window
- cb3.y = y0+199;
- cb3.focus = 0;
- cb3.checked = (sdl_scale==2)?1:0;
-
- cb4.x = x0+xsize-16; //Fullscreen
- cb4.y = y0+213;
- cb4.focus = 0;
- cb4.checked = (kiosk_enable==1)?1:0;
-
- cb5.x = x0+xsize-16; //Ambient heat
- cb5.y = y0+51;
- cb5.focus = 0;
- cb5.checked = aheat_enable;
-
- cb6.x = x0+xsize-16; //Water equalisation
- cb6.y = y0+107;
- cb6.focus = 0;
- cb6.checked = water_equal_test;
-
- cb7.x = x0+xsize-16; //Block frame
- cb7.y = y0+227;
- cb7.focus = 0;
- cb7.checked = bframe;
-
- list.x = x0+xsize-76; //Air Mode
- list.y = y0+135;
- list.w = 72;
- list.h = 16;
- list.def = "[air mode]";
- list.selected = airMode;
- list.items = airModeList;
- list.count = airModeListCount;
-
- list2.x = x0+xsize-76; //Gravity Mode
- list2.y = y0+163;
- list2.w = 72;
- list2.h = 16;
- list2.def = "[gravity mode]";
- list2.selected = gravityMode;
- list2.items = gravityModeList;
- list2.count = gravityModeListCount;
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-
- while (!sdl_poll())
- {
- bq = b;
- b = mouse_get_state(&mx, &my);
-
- clearrect(vid_buf, x0-2, y0-2, xsize+4, ysize+4);
- drawrect(vid_buf, x0, y0, xsize, ysize, 192, 192, 192, 255);
- drawtext(vid_buf, x0+8, y0+8, "Simulation options", 255, 216, 32, 255);
-
- drawtext(vid_buf, x0+8, y0+26, "Heat simulation", 255, 255, 255, 255);
- drawtext(vid_buf, x0+12+textwidth("Heat simulation"), y0+26, "Introduced in version 34.", 255, 255, 255, 180);
- drawtext(vid_buf, x0+12, y0+40, "Older saves may behave oddly with this enabled.", 255, 255, 255, 120);
-
- drawtext(vid_buf, x0+8, y0+54, "Ambient heat simulation", 255, 255, 255, 255);
- drawtext(vid_buf, x0+12+textwidth("Ambient heat simulation"), y0+54, "Introduced in version 50.", 255, 255, 255, 180);
- drawtext(vid_buf, x0+12, y0+68, "Older saves may behave oddly with this enabled.", 255, 255, 255, 120);
-
- drawtext(vid_buf, x0+8, y0+82, "Newtonian gravity", 255, 255, 255, 255);
- drawtext(vid_buf, x0+12+textwidth("Newtonian gravity"), y0+82, "Introduced in version 48.", 255, 255, 255, 180);
- drawtext(vid_buf, x0+12, y0+96, "May also cause slow performance on older computers", 255, 255, 255, 120);
-
- drawtext(vid_buf, x0+8, y0+110, "Water Equalization Test", 255, 255, 255, 255);
- drawtext(vid_buf, x0+12+textwidth("Water Equalization Test"), y0+110, "Introduced in version 61.", 255, 255, 255, 180);
- drawtext(vid_buf, x0+12, y0+124, "May lag with lots of water.", 255, 255, 255, 120);
-
- drawtext(vid_buf, x0+8, y0+138, "Air Simulation Mode", 255, 255, 255, 255);
- drawtext(vid_buf, x0+12, y0+152, "airMode", 255, 255, 255, 120);
-
- drawtext(vid_buf, x0+8, y0+166, "Gravity Simulation Mode", 255, 255, 255, 255);
- drawtext(vid_buf, x0+12, y0+180, "gravityMode", 255, 255, 255, 120);
-
- draw_line(vid_buf, x0, y0+194, x0+xsize, y0+194, 150, 150, 150, XRES+BARSIZE);
-
- drawtext(vid_buf, x0+8, y0+200, "Large window", 255, 255, 255, 255);
- drawtext(vid_buf, x0+12+textwidth("Large window"), y0+200, "Double window size for small screens", 255, 255, 255, 180);
-
- drawtext(vid_buf, x0+8, y0+214, "Fullscreen", 255, 255, 255, 255);
- drawtext(vid_buf, x0+12+textwidth("Fullscreen"), y0+214, "Fill the entire screen", 255, 255, 255, 180);
-
- drawtext(vid_buf, x0+8, y0+228, "Block frame", 255, 255, 255, 255);
- drawtext(vid_buf, x0+12+textwidth("Block frame"), y0+228, "Draws a wall frame around screen", 255, 255, 255, 180);
-
- //TODO: Options for Air and Normal gravity
- //Maybe save/load defaults too.
-
- drawtext(vid_buf, x0+5, y0+ysize-11, "OK", 255, 255, 255, 255);
- drawrect(vid_buf, x0, y0+ysize-16, xsize, 16, 192, 192, 192, 255);
-
- ui_checkbox_draw(vid_buf, &cb);
- ui_checkbox_draw(vid_buf, &cb2);
- ui_checkbox_draw(vid_buf, &cb3);
- ui_checkbox_draw(vid_buf, &cb4);
- ui_checkbox_draw(vid_buf, &cb5);
- ui_checkbox_draw(vid_buf, &cb6);
- ui_checkbox_draw(vid_buf, &cb7);
- ui_list_draw(vid_buf, &list);
- ui_list_draw(vid_buf, &list2);
-#ifdef OGLR
- clearScreen(1.0f);
-#endif
- sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
- ui_checkbox_process(mx, my, b, bq, &cb);
- ui_checkbox_process(mx, my, b, bq, &cb2);
- ui_checkbox_process(mx, my, b, bq, &cb3);
- ui_checkbox_process(mx, my, b, bq, &cb4);
- ui_checkbox_process(mx, my, b, bq, &cb5);
- ui_checkbox_process(mx, my, b, bq, &cb6);
- ui_checkbox_process(mx, my, b, bq, &cb7);
- ui_list_process(vid_buf, mx, my, b, &list);
- ui_list_process(vid_buf, mx, my, b, &list2);
-
- if (b && !bq && mx>=x0 && mx<x0+xsize && my>=y0+ysize-16 && my<=y0+ysize)
- break;
-
- if (sdl_key==SDLK_RETURN)
- break;
- if (sdl_key==SDLK_ESCAPE)
- break;
- }
-
- water_equal_test = cb6.checked;
- legacy_enable = !cb.checked;
- aheat_enable = cb5.checked;
- new_scale = (cb3.checked)?2:1;
- new_kiosk = (cb4.checked)?1:0;
- if(list.selected>=0 && list.selected<=4)
- airMode = list.selected;
- if(list2.selected>=0 && list2.selected<=2)
- gravityMode = list2.selected;
- if(new_scale!=sdl_scale || new_kiosk!=kiosk_enable)
- {
- if (!set_scale(new_scale, new_kiosk))
- error_ui(vid_buf, 0, "Could not change display options");
- }
- if(ngrav_enable != cb2.checked)
- {
- if(cb2.checked)
- start_grav_async();
- else
- stop_grav_async();
- }
- if(cb7.checked && !bframe)
- draw_bframe();
- if(!cb7.checked && bframe)
- erase_bframe();
- bframe = cb7.checked;
-
- while (!sdl_poll())
- {
- b = mouse_get_state(&mx, &my);
- if (!b)
- break;
- }
-}
-
-Uint8 mouse_get_state(int *x, int *y)
-{
- //Wrapper around SDL_GetMouseState to divide by sdl_scale
- Uint8 sdl_b;
- int sdl_x, sdl_y;
- sdl_b = SDL_GetMouseState(&sdl_x, &sdl_y);
- *x = sdl_x/sdl_scale;
- *y = sdl_y/sdl_scale;
- return sdl_b;
-}
-
-void mouse_coords_window_to_sim(int *sim_x, int *sim_y, int window_x, int window_y)
-{
- //Change mouse coords to take zoom window into account
- if (zoom_en && window_x>=zoom_wx && window_y>=zoom_wy
- && window_x<(zoom_wx+ZFACTOR*ZSIZE)
- && window_y<(zoom_wy+ZFACTOR*ZSIZE))
- {
- *sim_x = (((window_x-zoom_wx)/ZFACTOR)+zoom_x);
- *sim_y = (((window_y-zoom_wy)/ZFACTOR)+zoom_y);
- }
- else
- {
- *sim_x = window_x;
- *sim_y = window_y;
- }
-}
diff --git a/src/luaconsole.c b/src/luaconsole.c
deleted file mode 100644
index ba63127..0000000
--- a/src/luaconsole.c
+++ /dev/null
@@ -1,2119 +0,0 @@
-/**
- * Powder Toy - Lua console
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <defines.h>
-#ifdef LUACONSOLE
-#include <powder.h>
-#include "gravity.h"
-#include <console.h>
-#include <luaconsole.h>
-
-lua_State *l;
-int step_functions[6] = {0, 0, 0, 0, 0, 0};
-int keypress_function_count = 0;
-int *keypress_functions = NULL;
-int mouseclick_function_count = 0;
-int *mouseclick_functions = NULL;
-int tptProperties; //Table for some TPT properties
-int tptPropertiesVersion;
-int tptElements; //Table for TPT element names
-int tptParts, tptPartsMeta, tptElementTransitions, tptPartsCData, tptPartMeta, tptPart, cIndex;
-void luacon_open(){
- int i = 0, j;
- char tmpname[12];
- int currentElementMeta, currentElement;
- const static struct luaL_reg tptluaapi [] = {
- {"test", &luatpt_test},
- {"drawtext", &luatpt_drawtext},
- {"create", &luatpt_create},
- {"set_pause", &luatpt_setpause},
- {"toggle_pause", &luatpt_togglepause},
- {"set_console", &luatpt_setconsole},
- {"log", &luatpt_log},
- {"set_pressure", &luatpt_set_pressure},
- {"set_gravity", &luatpt_set_gravity},
- {"reset_gravity_field", &luatpt_reset_gravity_field},
- {"reset_velocity", &luatpt_reset_velocity},
- {"reset_spark", &luatpt_reset_spark},
- {"set_property", &luatpt_set_property},
- {"get_property", &luatpt_get_property},
- {"set_wallmap", &luatpt_set_wallmap},
- {"get_wallmap", &luatpt_get_wallmap},
- {"set_elecmap", &luatpt_set_elecmap},
- {"get_elecmap", &luatpt_get_elecmap},
- {"drawpixel", &luatpt_drawpixel},
- {"drawrect", &luatpt_drawrect},
- {"fillrect", &luatpt_fillrect},
- {"drawline", &luatpt_drawline},
- {"textwidth", &luatpt_textwidth},
- {"get_name", &luatpt_get_name},
- {"set_shortcuts", &luatpt_set_shortcuts},
- {"delete", &luatpt_delete},
- {"register_step", &luatpt_register_step},
- {"unregister_step", &luatpt_unregister_step},
- {"register_mouseclick", &luatpt_register_mouseclick},
- {"unregister_mouseclick", &luatpt_unregister_mouseclick},
- {"register_keypress", &luatpt_register_keypress},
- {"unregister_keypress", &luatpt_unregister_keypress},
- {"register_mouseevent", &luatpt_register_mouseclick},
- {"unregister_mouseevent", &luatpt_unregister_mouseclick},
- {"register_keyevent", &luatpt_register_keypress},
- {"unregister_keyevent", &luatpt_unregister_keypress},
- {"input", &luatpt_input},
- {"message_box", &luatpt_message_box},
- {"get_numOfParts", &luatpt_get_numOfParts},
- {"start_getPartIndex", &luatpt_start_getPartIndex},
- {"next_getPartIndex", &luatpt_next_getPartIndex},
- {"getPartIndex", &luatpt_getPartIndex},
- {"hud", &luatpt_hud},
- {"newtonian_gravity", &luatpt_gravity},
- {"ambient_heat", &luatpt_airheat},
- {"active_menu", &luatpt_active_menu},
- {"decorations_enable", &luatpt_decorations_enable},
- {"display_mode", &luatpt_cmode_set},
- {"throw_error", &luatpt_error},
- {"heat", &luatpt_heat},
- {"setfire", &luatpt_setfire},
- {"setdebug", &luatpt_setdebug},
- {"setfpscap",&luatpt_setfpscap},
- {"getscript",&luatpt_getscript},
- {"setwindowsize",&luatpt_setwindowsize},
- {"watertest",&luatpt_togglewater},
- {"screenshot",&luatpt_screenshot},
- {"element",&luatpt_getelement},
- {"element_func",&luatpt_element_func},
- {"graphics_func",&luatpt_graphics_func},
- {NULL,NULL}
- };
-
- l = lua_open();
- luaL_openlibs(l);
- luaL_register(l, "tpt", tptluaapi);
-
- tptProperties = lua_gettop(l);
-
- lua_pushinteger(l, 0);
- lua_setfield(l, tptProperties, "mousex");
- lua_pushinteger(l, 0);
- lua_setfield(l, tptProperties, "mousey");
- lua_pushinteger(l, 0);
- lua_setfield(l, tptProperties, "selectedl");
- lua_pushinteger(l, 0);
- lua_setfield(l, tptProperties, "selectedr");
-
- lua_newtable(l);
- tptPropertiesVersion = lua_gettop(l);
- lua_pushinteger(l, SAVE_VERSION);
- lua_setfield(l, tptPropertiesVersion, "major");
- lua_pushinteger(l, MINOR_VERSION);
- lua_setfield(l, tptPropertiesVersion, "minor");
- lua_pushinteger(l, BUILD_NUM);
- lua_setfield(l, tptPropertiesVersion, "build");
- lua_setfield(l, tptProperties, "version");
-
-#ifdef FFI
- //LuaJIT's ffi gives us direct access to parts data, no need for nested metatables. HOWEVER, this is in no way safe, it's entirely possible for someone to try to read parts[-10]
- lua_pushlightuserdata(l, parts);
- lua_setfield(l, tptProperties, "partsdata");
-
- luaL_dostring (l, "ffi = require(\"ffi\")\n\
-ffi.cdef[[\n\
-typedef struct { int type; int life, ctype; float x, y, vx, vy; float temp; float pavg[2]; int flags; int tmp; int tmp2; unsigned int dcolour; } particle;\n\
-]]\n\
-tpt.parts = ffi.cast(\"particle *\", tpt.partsdata)\n\
-ffi = nil\n\
-tpt.partsdata = nil");
- //Since ffi is REALLY REALLY dangrous, we'll remove it from the environment completely (TODO)
- //lua_pushstring(l, "parts");
- //tptPartsCData = lua_gettable(l, tptProperties);
-#else
- lua_newtable(l);
- tptParts = lua_gettop(l);
- lua_newtable(l);
- tptPartsMeta = lua_gettop(l);
- lua_pushcfunction(l, luacon_partswrite);
- lua_setfield(l, tptPartsMeta, "__newindex");
- lua_pushcfunction(l, luacon_partsread);
- lua_setfield(l, tptPartsMeta, "__index");
- lua_setmetatable(l, tptParts);
- lua_setfield(l, tptProperties, "parts");
-
- lua_newtable(l);
- tptPart = lua_gettop(l);
- lua_newtable(l);
- tptPartMeta = lua_gettop(l);
- lua_pushcfunction(l, luacon_partwrite);
- lua_setfield(l, tptPartMeta, "__newindex");
- lua_pushcfunction(l, luacon_partread);
- lua_setfield(l, tptPartMeta, "__index");
- lua_setmetatable(l, tptPart);
-
- tptPart = luaL_ref(l, LUA_REGISTRYINDEX);
-#endif
-
- lua_newtable(l);
- tptElements = lua_gettop(l);
- for(i = 1; i < PT_NUM; i++)
- {
- for(j = 0; j < strlen(ptypes[i].name); j++)
- tmpname[j] = tolower(ptypes[i].name[j]);
- tmpname[strlen(ptypes[i].name)] = 0;
-
- lua_newtable(l);
- currentElement = lua_gettop(l);
- lua_pushinteger(l, i);
- lua_setfield(l, currentElement, "id");
-
- lua_newtable(l);
- currentElementMeta = lua_gettop(l);
- lua_pushcfunction(l, luacon_elementwrite);
- lua_setfield(l, currentElementMeta, "__newindex");
- lua_pushcfunction(l, luacon_elementread);
- lua_setfield(l, currentElementMeta, "__index");
- lua_setmetatable(l, currentElement);
-
- lua_setfield(l, tptElements, tmpname);
- }
- lua_setfield(l, tptProperties, "el");
-
- lua_newtable(l);
- tptElementTransitions = lua_gettop(l);
- for(i = 1; i < PT_NUM; i++)
- {
- for(j = 0; j < strlen(ptypes[i].name); j++)
- tmpname[j] = tolower(ptypes[i].name[j]);
- tmpname[strlen(ptypes[i].name)] = 0;
-
- lua_newtable(l);
- currentElement = lua_gettop(l);
- lua_newtable(l);
- currentElementMeta = lua_gettop(l);
- lua_pushinteger(l, i);
- lua_setfield(l, currentElement, "value");
- lua_pushcfunction(l, luacon_transitionwrite);
- lua_setfield(l, currentElementMeta, "__newindex");
- lua_pushcfunction(l, luacon_transitionread);
- lua_setfield(l, currentElementMeta, "__index");
- lua_setmetatable(l, currentElement);
-
- lua_setfield(l, tptElementTransitions, tmpname);
- }
- lua_setfield(l, tptProperties, "eltransition");
-
- lua_el_func = (int*)calloc(PT_NUM, sizeof(int));
- lua_el_mode = (int*)calloc(PT_NUM, sizeof(int));
- lua_gr_func = (int*)calloc(PT_NUM, sizeof(int));
- for(i = 0; i < PT_NUM; i++)
- {
- lua_el_mode[i] = 0;
- lua_gr_func[i] = 0;
- }
- lua_sethook(l, &lua_hook, LUA_MASKCOUNT, 4000000);
-}
-#ifndef FFI
-int luacon_partread(lua_State* l){
- int format, offset, tempinteger;
- float tempfloat;
- int i;
- char * key = mystrdup(luaL_optstring(l, 2, ""));
- offset = luacon_particle_getproperty(key, &format);
-
- i = cIndex;
-
- if(i < 0 || i >= NPART || offset==-1)
- {
- if(i < 0 || i >= NPART) {
- free(key);
- return luaL_error(l, "Out of range");
- } else if(strcmp(key, "id")==0) {
- free(key);
- lua_pushnumber(l, i);
- return 1;
- } else {
- free(key);
- return luaL_error(l, "Invalid property");
- }
- }
- free(key);
- switch(format)
- {
- case 0:
- tempinteger = *((int*)(((char*)&parts[i])+offset));
- lua_pushnumber(l, tempinteger);
- break;
- case 1:
- tempfloat = *((float*)(((char*)&parts[i])+offset));
- lua_pushnumber(l, tempfloat);
- break;
- }
- return 1;
-}
-int luacon_partwrite(lua_State* l){
- int format, offset;
- int i;
- char * key = mystrdup(luaL_optstring(l, 2, ""));
- offset = luacon_particle_getproperty(key, &format);
-
- i = cIndex;
-
- if(i < 0 || i >= NPART || offset==-1)
- {
- if(i < 0 || i >= NPART) {
- free(key);
- return luaL_error(l, "array index out of bounds");
- } else {
- free(key);
- return luaL_error(l, "Invalid property");
- }
- }
- free(key);
- switch(format)
- {
- case 0:
- *((int*)(((char*)&parts[i])+offset)) = luaL_optinteger(l, 3, 0);
- break;
- case 1:
- *((float*)(((char*)&parts[i])+offset)) = luaL_optnumber(l, 3, 0);
- break;
- }
- return 1;
-}
-int luacon_partsread(lua_State* l){
- int format, offset;
- char * tempstring;
- int tempinteger;
- float tempfloat;
- int i, currentPart, currentPartMeta;
-
- i = luaL_optinteger(l, 2, 0);
-
- if(i<0 || i>=NPART)
- {
- return luaL_error(l, "array index out of bounds");
- }
-
- lua_rawgeti(l, LUA_REGISTRYINDEX, tptPart);
- cIndex = i;
- return 1;
-}
-int luacon_partswrite(lua_State* l){
- return luaL_error(l, "table readonly");
-}
-#endif
-int luacon_particle_getproperty(char * key, int * format)
-{
- int offset;
- if (strcmp(key, "type")==0){
- offset = offsetof(particle, type);
- *format = 0;
- } else if (strcmp(key, "life")==0){
- offset = offsetof(particle, life);
- *format = 0;
- } else if (strcmp(key, "ctype")==0){
- offset = offsetof(particle, ctype);
- *format = 0;
- } else if (strcmp(key, "temp")==0){
- offset = offsetof(particle, temp);
- *format = 1;
- } else if (strcmp(key, "tmp")==0){
- offset = offsetof(particle, tmp);
- *format = 0;
- } else if (strcmp(key, "tmp2")==0){
- offset = offsetof(particle, tmp2);
- *format = 0;
- } else if (strcmp(key, "vy")==0){
- offset = offsetof(particle, vy);
- *format = 1;
- } else if (strcmp(key, "vx")==0){
- offset = offsetof(particle, vx);
- *format = 1;
- } else if (strcmp(key, "x")==0){
- offset = offsetof(particle, x);
- *format = 1;
- } else if (strcmp(key, "y")==0){
- offset = offsetof(particle, y);
- *format = 1;
- } else if (strcmp(key, "dcolour")==0){
- offset = offsetof(particle, dcolour);
- *format = 0;
- } else if (strcmp(key, "dcolor")==0){
- offset = offsetof(particle, dcolour);
- *format = 0;
- } else {
- offset = -1;
- }
- return offset;
-}
-int luacon_transition_getproperty(char * key, int * format)
-{
- int offset;
- if (strcmp(key, "presHighValue")==0){
- offset = offsetof(part_transition, phv);
- *format = 1;
- } else if (strcmp(key, "presHighType")==0){
- offset = offsetof(part_transition, pht);
- *format = 0;
- } else if (strcmp(key, "presLowValue")==0){
- offset = offsetof(part_transition, plv);
- *format = 1;
- } else if (strcmp(key, "presLowType")==0){
- offset = offsetof(part_transition, plt);
- *format = 0;
- } else if (strcmp(key, "tempHighValue")==0){
- offset = offsetof(part_transition, thv);
- *format = 1;
- } else if (strcmp(key, "tempHighType")==0){
- offset = offsetof(part_transition, tht);
- *format = 0;
- } else if (strcmp(key, "tempLowValue")==0){
- offset = offsetof(part_transition, tlv);
- *format = 1;
- } else if (strcmp(key, "tempLowType")==0){
- offset = offsetof(part_transition, tlt);
- *format = 0;
- } else {
- offset = -1;
- }
- return offset;
-}
-int luacon_transitionread(lua_State* l){
- int format, offset;
- int tempinteger;
- float tempfloat;
- int i;
- char * key = mystrdup(luaL_optstring(l, 2, ""));
- offset = luacon_transition_getproperty(key, &format);
- free(key);
-
- //Get Raw Index value for element
- lua_pushstring(l, "value");
- lua_rawget(l, 1);
-
- i = lua_tointeger(l, lua_gettop(l));
-
- lua_pop(l, 1);
-
- if(i < 0 || i >= PT_NUM || offset==-1)
- {
- return luaL_error(l, "Invalid property");
- }
- switch(format)
- {
- case 0:
- tempinteger = *((int*)(((char*)&ptransitions[i])+offset));
- lua_pushnumber(l, tempinteger);
- break;
- case 1:
- tempfloat = *((float*)(((char*)&ptransitions[i])+offset));
- lua_pushnumber(l, tempfloat);
- break;
- }
- return 1;
-}
-int luacon_transitionwrite(lua_State* l){
- int format, offset;
- int tempinteger;
- float tempfloat;
- int i;
- char * key = mystrdup(luaL_optstring(l, 2, ""));
- offset = luacon_transition_getproperty(key, &format);
- free(key);
-
- //Get Raw Index value for element
- lua_pushstring(l, "value");
- lua_rawget(l, 1);
-
- i = lua_tointeger (l, lua_gettop(l));
-
- lua_pop(l, 1);
-
- if(i < 0 || i >= PT_NUM || offset==-1)
- {
- return luaL_error(l, "Invalid property");
- }
- switch(format)
- {
- case 0:
- *((int*)(((char*)&ptransitions[i])+offset)) = luaL_optinteger(l, 3, 0);
- break;
- case 1:
- *((float*)(((char*)&ptransitions[i])+offset)) = luaL_optnumber(l, 3, 0);
- break;
- }
- return 0;
-}
-int luacon_element_getproperty(char * key, int * format, unsigned int * modified_stuff)
-{
- int offset;
- if (strcmp(key, "name")==0){
- offset = offsetof(part_type, name);
- *format = 2;
- }
- else if (strcmp(key, "color")==0){
- offset = offsetof(part_type, pcolors);
- *format = 0;
- if (modified_stuff)
- *modified_stuff |= LUACON_EL_MODIFIED_GRAPHICS;
- }
- else if (strcmp(key, "colour")==0){
- offset = offsetof(part_type, pcolors);
- *format = 0;
- if (modified_stuff)
- *modified_stuff |= LUACON_EL_MODIFIED_GRAPHICS;
- }
- else if (strcmp(key, "advection")==0){
- offset = offsetof(part_type, advection);
- *format = 1;
- }
- else if (strcmp(key, "airdrag")==0){
- offset = offsetof(part_type, airdrag);
- *format = 1;
- }
- else if (strcmp(key, "airloss")==0){
- offset = offsetof(part_type, airloss);
- *format = 1;
- }
- else if (strcmp(key, "loss")==0){
- offset = offsetof(part_type, loss);
- *format = 1;
- }
- else if (strcmp(key, "collision")==0){
- offset = offsetof(part_type, collision);
- *format = 1;
- }
- else if (strcmp(key, "gravity")==0){
- offset = offsetof(part_type, gravity);
- *format = 1;
- }
- else if (strcmp(key, "diffusion")==0){
- offset = offsetof(part_type, diffusion);
- *format = 1;
- }
- else if (strcmp(key, "hotair")==0){
- offset = offsetof(part_type, hotair);
- *format = 1;
- }
- else if (strcmp(key, "falldown")==0){
- offset = offsetof(part_type, falldown);
- *format = 0;
- }
- else if (strcmp(key, "flammable")==0){
- offset = offsetof(part_type, flammable);
- *format = 0;
- }
- else if (strcmp(key, "explosive")==0){
- offset = offsetof(part_type, explosive);
- *format = 0;
- }
- else if (strcmp(key, "meltable")==0){
- offset = offsetof(part_type, meltable);
- *format = 0;
- }
- else if (strcmp(key, "hardness")==0){
- offset = offsetof(part_type, hardness);
- *format = 0;
- }
- else if (strcmp(key, "menu")==0){
- offset = offsetof(part_type, menu);
- *format = 0;
- if (modified_stuff)
- *modified_stuff |= LUACON_EL_MODIFIED_MENUS;
- }
- else if (strcmp(key, "enabled")==0){
- offset = offsetof(part_type, enabled);
- *format = 0;
- }
- else if (strcmp(key, "weight")==0){
- offset = offsetof(part_type, weight);
- *format = 0;
- if (modified_stuff)
- *modified_stuff |= LUACON_EL_MODIFIED_CANMOVE;
- }
- else if (strcmp(key, "menusection")==0){
- offset = offsetof(part_type, menusection);
- *format = 0;
- if (modified_stuff)
- *modified_stuff |= LUACON_EL_MODIFIED_MENUS;
- }
- else if (strcmp(key, "heat")==0){
- offset = offsetof(part_type, heat);
- *format = 1;
- }
- else if (strcmp(key, "hconduct")==0){
- offset = offsetof(part_type, hconduct);
- *format = 3;
- }
- else if (strcmp(key, "state")==0){
- offset = offsetof(part_type, state);
- *format = 3;
- }
- else if (strcmp(key, "properties")==0){
- offset = offsetof(part_type, properties);
- *format = 0;
- if (modified_stuff)
- *modified_stuff |= LUACON_EL_MODIFIED_GRAPHICS | LUACON_EL_MODIFIED_CANMOVE;
- }
- else if (strcmp(key, "description")==0){
- offset = offsetof(part_type, descs);
- *format = 2;
- }
- else {
- return -1;
- }
- return offset;
-}
-int luacon_elementread(lua_State* l){
- int format, offset;
- char * tempstring;
- int tempinteger;
- float tempfloat;
- int i;
- char * key = mystrdup(luaL_optstring(l, 2, ""));
- offset = luacon_element_getproperty(key, &format, NULL);
- free(key);
-
- //Get Raw Index value for element
- lua_pushstring(l, "id");
- lua_rawget(l, 1);
-
- i = lua_tointeger (l, lua_gettop(l));
-
- lua_pop(l, 1);
-
- if(i < 0 || i >= PT_NUM || offset==-1)
- {
- return luaL_error(l, "Invalid property");
- }
- switch(format)
- {
- case 0:
- tempinteger = *((int*)(((char*)&ptypes[i])+offset));
- lua_pushnumber(l, tempinteger);
- break;
- case 1:
- tempfloat = *((float*)(((char*)&ptypes[i])+offset));
- lua_pushnumber(l, tempfloat);
- break;
- case 2:
- tempstring = *((char**)(((char*)&ptypes[i])+offset));
- lua_pushstring(l, tempstring);
- break;
- case 3:
- tempinteger = *((unsigned char*)(((char*)&ptypes[i])+offset));
- lua_pushnumber(l, tempinteger);
- break;
- }
- return 1;
-}
-int luacon_elementwrite(lua_State* l){
- int format, offset;
- char * tempstring;
- int tempinteger;
- float tempfloat;
- int i;
- unsigned int modified_stuff = 0;
- char * key = mystrdup(luaL_optstring(l, 2, ""));
- offset = luacon_element_getproperty(key, &format, &modified_stuff);
-
- //Get Raw Index value for element
- lua_pushstring(l, "id");
- lua_rawget(l, 1);
-
- i = lua_tointeger (l, lua_gettop(l));
-
- lua_pop(l, 1);
-
- if(i < 0 || i >= PT_NUM || offset==-1)
- {
- free(key);
- return luaL_error(l, "Invalid property");
- }
- switch(format)
- {
- case 0:
- *((int*)(((char*)&ptypes[i])+offset)) = luaL_optinteger(l, 3, 0);
- break;
- case 1:
- *((float*)(((char*)&ptypes[i])+offset)) = luaL_optnumber(l, 3, 0);
- break;
- case 2:
- tempstring = mystrdup(luaL_optstring(l, 3, ""));
- if(strcmp(key, "name")==0)
- {
- int j = 0;
- //Convert to upper case
- for(j = 0; j < strlen(tempstring); j++)
- tempstring[j] = toupper(tempstring[j]);
- if(strlen(tempstring)>4)
- {
- free(tempstring);
- free(key);
- return luaL_error(l, "Name too long");
- }
- if(console_parse_type(tempstring, NULL, NULL))
- {
- free(tempstring);
- free(key);
- return luaL_error(l, "Name in use");
- }
- }
- *((char**)(((char*)&ptypes[i])+offset)) = tempstring;
- //Need some way of cleaning up previous values
- break;
- case 3:
- *((unsigned char*)(((char*)&ptypes[i])+offset)) = luaL_optinteger(l, 3, 0);
- break;
- }
- if (modified_stuff)
- {
- if (modified_stuff & LUACON_EL_MODIFIED_MENUS)
- menu_count();
- if (modified_stuff & LUACON_EL_MODIFIED_CANMOVE)
- init_can_move();
- if (modified_stuff & LUACON_EL_MODIFIED_GRAPHICS)
- memset(graphicscache, 0, sizeof(gcache_item)*PT_NUM);
- }
- free(key);
- return 0;
-}
-int luacon_keyevent(int key, int modifier, int event){
- int i = 0, kpcontinue = 1, callret;
- char tempkey[] = {key, 0};
- if(keypress_function_count){
- for(i = 0; i < keypress_function_count && kpcontinue; i++){
- lua_rawgeti(l, LUA_REGISTRYINDEX, keypress_functions[i]);
- lua_pushstring(l, tempkey);
- lua_pushinteger(l, key);
- lua_pushinteger(l, modifier);
- lua_pushinteger(l, event);
- callret = lua_pcall(l, 4, 1, 0);
- if (callret)
- {
- printf("In key event: %s\n",luacon_geterror());
- }
- if(lua_isboolean(l, -1)){
- kpcontinue = lua_toboolean(l, -1);
- }
- lua_pop(l, 1);
- }
- }
- return kpcontinue;
-}
-int luacon_mouseevent(int mx, int my, int mb, int event, int mouse_wheel){
- int i = 0, mpcontinue = 1, callret;
- if(mouseclick_function_count){
- for(i = 0; i < mouseclick_function_count && mpcontinue; i++){
- lua_rawgeti(l, LUA_REGISTRYINDEX, mouseclick_functions[i]);
- lua_pushinteger(l, mx);
- lua_pushinteger(l, my);
- lua_pushinteger(l, mb);
- lua_pushinteger(l, event);
- lua_pushinteger(l, mouse_wheel);
- callret = lua_pcall(l, 5, 1, 0);
- if (callret)
- {
- printf("In mouse event: %s\n",luacon_geterror());
- }
- if(lua_isboolean(l, -1)){
- mpcontinue = lua_toboolean(l, -1);
- }
- lua_pop(l, 1);
- }
- }
- return mpcontinue;
-}
-int luacon_step(int mx, int my, int selectl, int selectr, int bsx, int bsy){
- int tempret = 0, tempb, i, callret;
- lua_pushinteger(l, bsy);
- lua_pushinteger(l, bsx);
- lua_pushinteger(l, SLALT);
- lua_pushinteger(l, selectr);
- lua_pushinteger(l, selectl);
- lua_pushinteger(l, my);
- lua_pushinteger(l, mx);
- lua_setfield(l, tptProperties, "mousex");
- lua_setfield(l, tptProperties, "mousey");
- lua_setfield(l, tptProperties, "selectedl");
- lua_setfield(l, tptProperties, "selectedr");
- lua_setfield(l, tptProperties, "selecteda");
- lua_setfield(l, tptProperties, "brushx");
- lua_setfield(l, tptProperties, "brushy");
- for(i = 0; i<6; i++){
- if(step_functions[i]){
- loop_time = SDL_GetTicks();
- lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]);
- callret = lua_pcall(l, 0, 0, 0);
- if (callret)
- {
- // failed, TODO: better error reporting
- printf("%s\n",luacon_geterror());
- if (!strcmp(luacon_geterror(),"Error: Infinite loop"))
- {
- lua_pushcfunction(l,&luatpt_unregister_step);
- lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]);
- lua_pcall(l, 1, 0, 0);
- }
- }
- }
- }
- return 0;
-}
-int luacon_eval(char *command){
- loop_time = SDL_GetTicks();
- return luaL_dostring (l, command);
-}
-void lua_hook(lua_State *L, lua_Debug *ar)
-{
- if(ar->event == LUA_HOOKCOUNT && SDL_GetTicks()-loop_time > 3000)
- {
- if (confirm_ui(vid_buf,"Infinite Loop","The Lua code might have an infinite loop. Press OK to stop it","OK"))
- luaL_error(l,"Error: Infinite loop");
- loop_time = SDL_GetTicks();
- }
-}
-int luacon_part_update(int t, int i, int x, int y, int surround_space, int nt)
-{
- int retval = 0, callret;
- if(lua_el_func[t]){
- lua_rawgeti(l, LUA_REGISTRYINDEX, lua_el_func[t]);
- lua_pushinteger(l, i);
- lua_pushinteger(l, x);
- lua_pushinteger(l, y);
- lua_pushinteger(l, surround_space);
- lua_pushinteger(l, nt);
- callret = lua_pcall(l, 5, 1, 0);
- if (callret)
- {
- printf("In particle update: %s\n",luacon_geterror());
- }
- if(lua_isboolean(l, -1)){
- retval = lua_toboolean(l, -1);
- }
- lua_pop(l, 1);
- }
- return retval;
-}
-int luacon_graphics_update(int t, int i, int *pixel_mode, int *cola, int *colr, int *colg, int *colb, int *firea, int *firer, int *fireg, int *fireb)
-{
- int cache = 0, callret;
- lua_rawgeti(l, LUA_REGISTRYINDEX, lua_gr_func[t]);
- lua_pushinteger(l, i);
- lua_pushinteger(l, *colr);
- lua_pushinteger(l, *colg);
- lua_pushinteger(l, *colb);
- callret = lua_pcall(l, 4, 10, 0);
- if (callret)
- {
- printf("In graphics function: %s\n",luacon_geterror());
- }
-
- cache = luaL_optint(l, -10, 0);
- *pixel_mode = luaL_optint(l, -9, *pixel_mode);
- *cola = luaL_optint(l, -8, *cola);
- *colr = luaL_optint(l, -7, *colr);
- *colg = luaL_optint(l, -6, *colg);
- *colb = luaL_optint(l, -5, *colb);
- *firea = luaL_optint(l, -4, *firea);
- *firer = luaL_optint(l, -3, *firer);
- *fireg = luaL_optint(l, -2, *fireg);
- *fireb = luaL_optint(l, -1, *fireb);
- lua_pop(l, 10);
- return cache;
-}
-char *luacon_geterror(){
- char *error = lua_tostring(l, -1);
- if(error==NULL || !error[0]){
- error = "failed to execute";
- }
- return error;
-}
-void luacon_close(){
- lua_close(l);
-}
-int process_command_lua(pixel *vid_buf, char *console, char *console_error)
-{
- int commandret;
- char * tmp_error;
- char console2[15];
- char console3[15];
- char console4[15];
- char console5[15];
- //sprintf(console_error, "%s", console);
- if (console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0)
- {
- sscanf(console,"%14s %14s %14s %14s", console2, console3, console4, console5);
- if (strcmp(console2, "quit")==0)
- {
- return -1;
- }
- else if(strncmp(console, "!", 1)==0)
- {
- return process_command_old(vid_buf, console+1, console_error);
- }
- else
- {
- commandret = luacon_eval(console);
- if (commandret){
- tmp_error = luacon_geterror();
- strncpy(console_error, tmp_error, 254);
- printf("%s\n", tmp_error);
- }
- }
- }
- return 1;
-}
-//Being TPT interface methods:
-int luatpt_test(lua_State* l)
-{
- int testint = 0;
- testint = luaL_optint(l, 1, 0);
- printf("Test successful, got %d\n", testint);
- return 0;
-}
-int luatpt_getelement(lua_State *l)
-{
- int t;
- char* name;
- if(lua_isnumber(l, 1)){
- t = luaL_optint(l, 1, 1);
- if (t<0 || t>=PT_NUM)
- return luaL_error(l, "Unrecognised element number '%d'", t);
- name = ptypes[t&0xFF].name;
- lua_pushstring(l, name);
- } else {
- name = (char*)luaL_optstring(l, 1, "dust");
- if (!console_parse_type(name, &t, NULL))
- return luaL_error(l, "Unrecognised element '%s'", name);
- lua_pushinteger(l, t);
- }
- return 1;
-}
-int luatpt_element_func(lua_State *l)
-{
- if(lua_isfunction(l, 1))
- {
- int element = luaL_optint(l, 2, 0);
- int replace = luaL_optint(l, 3, 0);
- int function;
- lua_pushvalue(l, 1);
- function = luaL_ref(l, LUA_REGISTRYINDEX);
- if(element > 0 && element < PT_NUM)
- {
- lua_el_func[element] = function;
- if(replace)
- lua_el_mode[element] = 2;
- else
- lua_el_mode[element] = 1;
- return 0;
- }
- else
- {
- return luaL_error(l, "Invalid element");
- }
- }
- return 0;
-}
-int luatpt_graphics_func(lua_State *l)
-{
- if(lua_isfunction(l, 1))
- {
- int element = luaL_optint(l, 2, 0);
- int function;
- lua_pushvalue(l, 1);
- function = luaL_ref(l, LUA_REGISTRYINDEX);
- if(element > 0 && element < PT_NUM)
- {
- lua_gr_func[element] = function;
- graphicscache[element].isready = 0;
- return 0;
- }
- else
- {
- return luaL_error(l, "Invalid element");
- }
- }
- else
- return luaL_error(l, "Not a function");
- return 0;
-}
-int luatpt_error(lua_State* l)
-{
- char *error = "";
- error = mystrdup(luaL_optstring(l, 1, "Error text"));
- if(vid_buf!=NULL){
- error_ui(vid_buf, 0, error);
- free(error);
- return 0;
- }
- free(error);
- return luaL_error(l, "Screen buffer does not exist");
-}
-int luatpt_drawtext(lua_State* l)
-{
- char *string;
- int textx, texty, textred, textgreen, textblue, textalpha;
- textx = luaL_optint(l, 1, 0);
- texty = luaL_optint(l, 2, 0);
- string = luaL_optstring(l, 3, "");
- textred = luaL_optint(l, 4, 255);
- textgreen = luaL_optint(l, 5, 255);
- textblue = luaL_optint(l, 6, 255);
- textalpha = luaL_optint(l, 7, 255);
- if (textx<0 || texty<0 || textx>=XRES+BARSIZE || texty>=YRES+MENUSIZE)
- return luaL_error(l, "Screen coordinates out of range (%d,%d)", textx, texty);
- if (textred<0) textred = 0;
- if (textred>255) textred = 255;
- if (textgreen<0) textgreen = 0;
- if (textgreen>255) textgreen = 255;
- if (textblue<0) textblue = 0;
- if (textblue>255) textblue = 255;
- if (textalpha<0) textalpha = 0;
- if (textalpha>255) textalpha = 255;
- if(vid_buf!=NULL){
- drawtext(vid_buf, textx, texty, string, textred, textgreen, textblue, textalpha);
- return 0;
- }
- return luaL_error(l, "Screen buffer does not exist");
-}
-
-int luatpt_create(lua_State* l)
-{
- int x, y, retid, t = -1;
- char * name;
- x = abs(luaL_optint(l, 1, 0));
- y = abs(luaL_optint(l, 2, 0));
- if(x < XRES && y < YRES){
- if(lua_isnumber(l, 3)){
- t = luaL_optint(l, 3, 0);
- if (t<0 || t >= PT_NUM || !ptypes[t].enabled)
- return luaL_error(l, "Unrecognised element number '%d'", t);
- } else {
- name = luaL_optstring(l, 3, "dust");
- if (!console_parse_type(name, &t, NULL))
- return luaL_error(l,"Unrecognised element '%s'", name);
- }
- retid = create_part(-1, x, y, t);
- // failing to create a particle often happens (e.g. if space is already occupied) and isn't usually important, so don't raise an error
- lua_pushinteger(l, retid);
- return 1;
- }
- return luaL_error(l, "Coordinates out of range (%d,%d)", x, y);
-}
-
-int luatpt_setpause(lua_State* l)
-{
- int pausestate;
- pausestate = luaL_optint(l, 1, 0);
- sys_pause = (pausestate==0?0:1);
- return 0;
-}
-
-int luatpt_togglepause(lua_State* l)
-{
- sys_pause=!sys_pause;
- return 0;
-}
-
-int luatpt_togglewater(lua_State* l)
-{
- water_equal_test=!water_equal_test;
- return 0;
-}
-
-int luatpt_setconsole(lua_State* l)
-{
- int consolestate;
- consolestate = luaL_optint(l, 1, 0);
- console_mode = (consolestate==0?0:1);
- return 0;
-}
-
-int luatpt_log(lua_State* l)
-{
- char *buffer;
- buffer = luaL_optstring(l, 1, "");
- strncpy(console_error, buffer, 254);
- return 0;
-}
-
-int luatpt_set_pressure(lua_State* l)
-{
- int nx, ny;
- int x1, y1, width, height;
- float value;
- x1 = abs(luaL_optint(l, 1, 0));
- y1 = abs(luaL_optint(l, 2, 0));
- width = abs(luaL_optint(l, 3, XRES/CELL));
- height = abs(luaL_optint(l, 4, YRES/CELL));
- value = (float)luaL_optint(l, 5, 0.0f);
- if(value > 256.0f)
- value = 256.0f;
- else if(value < -256.0f)
- value = -256.0f;
-
- if(x1 > (XRES/CELL)-1)
- x1 = (XRES/CELL)-1;
- if(y1 > (YRES/CELL)-1)
- y1 = (YRES/CELL)-1;
- if(x1+width > (XRES/CELL)-1)
- width = (XRES/CELL)-x1;
- if(y1+height > (YRES/CELL)-1)
- height = (YRES/CELL)-y1;
- for (nx = x1; nx<x1+width; nx++)
- for (ny = y1; ny<y1+height; ny++)
- {
- pv[ny][nx] = value;
- }
- return 0;
-}
-
-int luatpt_set_gravity(lua_State* l)
-{
- int nx, ny;
- int x1, y1, width, height;
- float value;
- x1 = abs(luaL_optint(l, 1, 0));
- y1 = abs(luaL_optint(l, 2, 0));
- width = abs(luaL_optint(l, 3, XRES/CELL));
- height = abs(luaL_optint(l, 4, YRES/CELL));
- value = (float)luaL_optint(l, 5, 0.0f);
- if(value > 256.0f)
- value = 256.0f;
- else if(value < -256.0f)
- value = -256.0f;
-
- if(x1 > (XRES/CELL)-1)
- x1 = (XRES/CELL)-1;
- if(y1 > (YRES/CELL)-1)
- y1 = (YRES/CELL)-1;
- if(x1+width > (XRES/CELL)-1)
- width = (XRES/CELL)-x1;
- if(y1+height > (YRES/CELL)-1)
- height = (YRES/CELL)-y1;
- for (nx = x1; nx<x1+width; nx++)
- for (ny = y1; ny<y1+height; ny++)
- {
- gravmap[ny*(XRES/CELL)+nx] = value;
- }
- return 0;
-}
-
-int luatpt_reset_gravity_field(lua_State* l)
-{
- int nx, ny;
- int x1, y1, width, height;
- x1 = abs(luaL_optint(l, 1, 0));
- y1 = abs(luaL_optint(l, 2, 0));
- width = abs(luaL_optint(l, 3, XRES/CELL));
- height = abs(luaL_optint(l, 4, YRES/CELL));
- if(x1 > (XRES/CELL)-1)
- x1 = (XRES/CELL)-1;
- if(y1 > (YRES/CELL)-1)
- y1 = (YRES/CELL)-1;
- if(x1+width > (XRES/CELL)-1)
- width = (XRES/CELL)-x1;
- if(y1+height > (YRES/CELL)-1)
- height = (YRES/CELL)-y1;
- for (nx = x1; nx<x1+width; nx++)
- for (ny = y1; ny<y1+height; ny++)
- {
- gravx[ny*(XRES/CELL)+nx] = 0;
- gravy[ny*(XRES/CELL)+nx] = 0;
- gravp[ny*(XRES/CELL)+nx] = 0;
- }
- return 0;
-}
-
-int luatpt_reset_velocity(lua_State* l)
-{
- int nx, ny;
- int x1, y1, width, height;
- x1 = abs(luaL_optint(l, 1, 0));
- y1 = abs(luaL_optint(l, 2, 0));
- width = abs(luaL_optint(l, 3, XRES/CELL));
- height = abs(luaL_optint(l, 4, YRES/CELL));
- if(x1 > (XRES/CELL)-1)
- x1 = (XRES/CELL)-1;
- if(y1 > (YRES/CELL)-1)
- y1 = (YRES/CELL)-1;
- if(x1+width > (XRES/CELL)-1)
- width = (XRES/CELL)-x1;
- if(y1+height > (YRES/CELL)-1)
- height = (YRES/CELL)-y1;
- for (nx = x1; nx<x1+width; nx++)
- for (ny = y1; ny<y1+height; ny++)
- {
- vx[ny][nx] = 0;
- vy[ny][nx] = 0;
- }
- return 0;
-}
-
-int luatpt_reset_spark(lua_State* l)
-{
- int i;
- for (i=0; i<NPART; i++)
- {
- if (parts[i].type==PT_SPRK)
- {
- if (parts[i].ctype >= 0 && parts[i].ctype < PT_NUM)
- {
- parts[i].type = parts[i].ctype;
- parts[i].life = 0;
- }
- else
- kill_part(i);
- }
- }
- return 0;
-}
-
-int luatpt_set_wallmap(lua_State* l)
-{
- int nx, ny, acount;
- int x1, y1, width, height;
- float value;
- acount = lua_gettop(l);
-
- x1 = abs(luaL_optint(l, 1, 0));
- y1 = abs(luaL_optint(l, 2, 0));
- width = abs(luaL_optint(l, 3, XRES/CELL));
- height = abs(luaL_optint(l, 4, YRES/CELL));
- value = (float)luaL_optint(l, acount, 0);
-
- if(acount==5) //Draw rect
- {
- if(x1 > (XRES/CELL))
- x1 = (XRES/CELL);
- if(y1 > (YRES/CELL))
- y1 = (YRES/CELL);
- if(x1+width > (XRES/CELL))
- width = (XRES/CELL)-x1;
- if(y1+height > (YRES/CELL))
- height = (YRES/CELL)-y1;
- for (nx = x1; nx<x1+width; nx++)
- for (ny = y1; ny<y1+height; ny++)
- {
- bmap[ny][nx] = value;
- }
- }
- else //Set point
- {
- if(x1 > (XRES/CELL))
- x1 = (XRES/CELL);
- if(y1 > (YRES/CELL))
- y1 = (YRES/CELL);
- bmap[y1][x1] = value;
- }
- return 0;
-}
-
-int luatpt_get_wallmap(lua_State* l)
-{
- int nx, ny, acount;
- int x1, y1, width, height;
- float value;
- acount = lua_gettop(l);
-
- x1 = abs(luaL_optint(l, 1, 0));
- y1 = abs(luaL_optint(l, 2, 0));
-
- if(x1 > (XRES/CELL) || y1 > (YRES/CELL))
- return luaL_error(l, "Out of range");
-
- lua_pushinteger(l, bmap[y1][x1]);
- return 1;
-}
-
-int luatpt_set_elecmap(lua_State* l)
-{
- int nx, ny, acount;
- int x1, y1, width, height;
- float value;
- acount = lua_gettop(l);
-
- x1 = abs(luaL_optint(l, 1, 0));
- y1 = abs(luaL_optint(l, 2, 0));
- width = abs(luaL_optint(l, 3, XRES/CELL));
- height = abs(luaL_optint(l, 4, YRES/CELL));
- value = (float)luaL_optint(l, acount, 0);
-
- if(acount==5) //Draw rect
- {
- if(x1 > (XRES/CELL))
- x1 = (XRES/CELL);
- if(y1 > (YRES/CELL))
- y1 = (YRES/CELL);
- if(x1+width > (XRES/CELL))
- width = (XRES/CELL)-x1;
- if(y1+height > (YRES/CELL))
- height = (YRES/CELL)-y1;
- for (nx = x1; nx<x1+width; nx++)
- for (ny = y1; ny<y1+height; ny++)
- {
- emap[ny][nx] = value;
- }
- }
- else //Set point
- {
- if(x1 > (XRES/CELL))
- x1 = (XRES/CELL);
- if(y1 > (YRES/CELL))
- y1 = (YRES/CELL);
- emap[y1][x1] = value;
- }
- return 0;
-}
-
-int luatpt_get_elecmap(lua_State* l)
-{
- int nx, ny, acount;
- int x1, y1, width, height;
- float value;
- acount = lua_gettop(l);
-
- x1 = abs(luaL_optint(l, 1, 0));
- y1 = abs(luaL_optint(l, 2, 0));
-
- if(x1 > (XRES/CELL) || y1 > (YRES/CELL))
- return luaL_error(l, "Out of range");
-
- lua_pushinteger(l, emap[y1][x1]);
- return 1;
-}
-
-int luatpt_set_property(lua_State* l)
-{
- char *prop, *name;
- int r, i, x, y, w, h, t, format, nx, ny, partsel = 0, acount;
- float f;
- size_t offset;
- acount = lua_gettop(l);
- prop = luaL_optstring(l, 1, "");
- if(lua_isnumber(l, 3))
- i = abs(luaL_optint(l, 3, -1));
- else
- i = -1;
- if(lua_isnumber(l, 4))
- y = abs(luaL_optint(l, 4, -1));
- else
- y = -1;
- if(lua_isnumber(l, 5))
- w = abs(luaL_optint(l, 5, -1));
- else
- w = -1;
- if(lua_isnumber(l, 6))
- h = abs(luaL_optint(l, 6, -1));
- else
- h = -1;
- //TODO: Use particle_getproperty
- if (strcmp(prop,"type")==0){
- offset = offsetof(particle, type);
- format = 3;
- } else if (strcmp(prop,"life")==0){
- offset = offsetof(particle, life);
- format = 1;
- } else if (strcmp(prop,"ctype")==0){
- offset = offsetof(particle, ctype);
- format = 4;
- } else if (strcmp(prop,"temp")==0){
- offset = offsetof(particle, temp);
- format = 2;
- } else if (strcmp(prop,"tmp")==0){
- offset = offsetof(particle, tmp);
- format = 1;
- } else if (strcmp(prop,"tmp2")==0){
- offset = offsetof(particle, tmp2);
- format = 1;
- } else if (strcmp(prop,"vy")==0){
- offset = offsetof(particle, vy);
- format = 2;
- } else if (strcmp(prop,"vx")==0){
- offset = offsetof(particle, vx);
- format = 2;
- } else if (strcmp(prop,"x")==0){
- offset = offsetof(particle, x);
- format = 2;
- } else if (strcmp(prop,"y")==0){
- offset = offsetof(particle, y);
- format = 2;
- } else if (strcmp(prop,"dcolour")==0 || strcmp(prop,"dcolor")==0){
- offset = offsetof(particle, dcolour);
- format = 1;
- } else {
- return luaL_error(l, "Invalid property '%s'", prop);
- }
- if(acount>2){
- if(!lua_isnumber(l, acount) && lua_isstring(l, acount)){
- name = luaL_optstring(l, acount, "none");
- if (!console_parse_type(name, &partsel, NULL))
- return luaL_error(l, "Unrecognised element '%s'", name);
- }
- }
- if(lua_isnumber(l, 2)){
- if(format==2){
- f = luaL_optnumber(l, 2, 0);
- } else {
- t = luaL_optint(l, 2, 0);
- }
- if (format == 3 && (t<0 || t>=PT_NUM || !ptypes[t].enabled))
- return luaL_error(l, "Unrecognised element number '%d'", t);
- } else {
- name = luaL_optstring(l, 2, "dust");
- if (!console_parse_type(name, &t, NULL))
- return luaL_error(l, "Unrecognised element '%s'", name);
- }
- if(i == -1 || (w != -1 && h != -1)){
- // Got a region
- if(i == -1){
- i = 0;
- y = 0;
- w = XRES;
- h = YRES;
- }
- if (i>=XRES || y>=YRES)
- return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);
- x = i;
- if(x+w > XRES)
- w = XRES-x;
- if(y+h > YRES)
- h = YRES-y;
- for (i = 0; i < NPART; i++)
- {
- if (parts[i].type)
- {
- nx = (int)(parts[i].x + .5f);
- ny = (int)(parts[i].y + .5f);
- if (nx >= x && nx < x+w && ny >= y && ny < y+h && (!partsel || partsel == parts[i].type))
- {
- if(format==2){
- *((float*)(((char*)&parts[i])+offset)) = f;
- } else {
- *((int*)(((char*)&parts[i])+offset)) = t;
- }
- }
- }
- }
- } else {
- // Got coords or particle index
- if(i != -1 && y != -1){
- if (i>=XRES || y>=YRES)
- return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);
- r = pmap[y][i];
- if (!r || (partsel && partsel != parts[r>>8].type))
- r = photons[y][i];
- if (!r || (partsel && partsel != parts[r>>8].type))
- return 0;
- i = r>>8;
- }
- if (i < 0 || i >= NPART)
- return luaL_error(l, "Invalid particle ID '%d'", i);
- if (!parts[i].type)
- return 0;
- if (partsel && partsel != parts[i].type)
- return 0;
- if(format==2){
- *((float*)(((char*)&parts[i])+offset)) = f;
- } else {
- *((int*)(((char*)&parts[i])+offset)) = t;
- }
- }
- return 0;
-}
-
-int luatpt_get_property(lua_State* l)
-{
- int i, r, y;
- char *prop;
- prop = luaL_optstring(l, 1, "");
- i = luaL_optint(l, 2, 0);
- y = luaL_optint(l, 3, -1);
- if(y!=-1 && y < YRES && y >= 0 && i < XRES && i >= 0){
- r = pmap[y][i];
- if (!r)
- r = photons[y][i];
- if (!r)
- {
- if (strcmp(prop,"type")==0){
- lua_pushinteger(l, 0);
- return 1;
- }
- return luaL_error(l, "Particle does not exist");
- }
- i = r>>8;
- }
- else if (y!=-1)
- return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);
- if (i < 0 || i >= NPART)
- return luaL_error(l, "Invalid particle ID '%d'", i);
- if (parts[i].type)
- {
- //TODO: Use particle_getproperty
- if (strcmp(prop,"type")==0){
- lua_pushinteger(l, parts[i].type);
- return 1;
- }
- if (strcmp(prop,"life")==0){
- lua_pushinteger(l, parts[i].life);
- return 1;
- }
- if (strcmp(prop,"ctype")==0){
- lua_pushinteger(l, parts[i].ctype);
- return 1;
- }
- if (strcmp(prop,"temp")==0){
- lua_pushnumber(l, parts[i].temp);
- return 1;
- }
- if (strcmp(prop,"tmp")==0){
- lua_pushinteger(l, parts[i].tmp);
- return 1;
- }
- if (strcmp(prop,"tmp2")==0){
- lua_pushinteger(l, parts[i].tmp2);
- return 1;
- }
- if (strcmp(prop,"vy")==0){
- lua_pushnumber(l, (double)parts[i].vy);
- return 1;
- }
- if (strcmp(prop,"vx")==0){
- lua_pushnumber(l, (double)parts[i].vx);
- return 1;
- }
- if (strcmp(prop,"x")==0){
- lua_pushnumber(l, parts[i].x);
- return 1;
- }
- if (strcmp(prop,"y")==0){
- lua_pushnumber(l, parts[i].y);
- return 1;
- }
- if (strcmp(prop,"dcolour")==0 || strcmp(prop,"dcolor")==0){
- lua_pushinteger(l, parts[i].dcolour);
- return 1;
- }
- if (strcmp(prop,"id")==0){
- lua_pushnumber(l, i);
- return 1;
- }
- }
- else if (strcmp(prop,"type")==0){
- lua_pushinteger(l, 0);
- return 1;
- }
- return luaL_error(l, "Particle does not exist");
-}
-
-int luatpt_drawpixel(lua_State* l)
-{
- int x, y, r, g, b, a;
- x = luaL_optint(l, 1, 0);
- y = luaL_optint(l, 2, 0);
- r = luaL_optint(l, 3, 255);
- g = luaL_optint(l, 4, 255);
- b = luaL_optint(l, 5, 255);
- a = luaL_optint(l, 6, 255);
-
- if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
- return luaL_error(l, "Screen coordinates out of range (%d,%d)", x, y);
- if (r<0) r = 0;
- if (r>255) r = 255;
- if (g<0) g = 0;
- if (g>255) g = 255;
- if (b<0) b = 0;
- if (b>255) b = 255;
- if (a<0) a = 0;
- if (a>255) a = 255;
- if (vid_buf!=NULL)
- {
- drawpixel(vid_buf, x, y, r, g, b, a);
- return 0;
- }
- return luaL_error(l, "Screen buffer does not exist");
-}
-
-int luatpt_drawrect(lua_State* l)
-{
- int x, y, w, h, r, g, b, a;
- x = luaL_optint(l, 1, 0);
- y = luaL_optint(l, 2, 0);
- w = luaL_optint(l, 3, 10);
- h = luaL_optint(l, 4, 10);
- r = luaL_optint(l, 5, 255);
- g = luaL_optint(l, 6, 255);
- b = luaL_optint(l, 7, 255);
- a = luaL_optint(l, 8, 255);
-
- if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
- return luaL_error(l, "Screen coordinates out of range (%d,%d)", x, y);
- if(x+w > XRES+BARSIZE)
- w = XRES+BARSIZE-x;
- if(y+h > YRES+MENUSIZE)
- h = YRES+MENUSIZE-y;
- if (r<0) r = 0;
- if (r>255) r = 255;
- if (g<0) g = 0;
- if (g>255) g = 255;
- if (b<0) b = 0;
- if (b>255) b = 255;
- if (a<0) a = 0;
- if (a>255) a = 255;
- if (vid_buf!=NULL)
- {
- drawrect(vid_buf, x, y, w, h, r, g, b, a);
- return 0;
- }
- return luaL_error(l, "Screen buffer does not exist");
-}
-
-int luatpt_fillrect(lua_State* l)
-{
- int x,y,w,h,r,g,b,a;
- x = luaL_optint(l, 1, 0);
- y = luaL_optint(l, 2, 0);
- w = luaL_optint(l, 3, 10);
- h = luaL_optint(l, 4, 10);
- r = luaL_optint(l, 5, 255);
- g = luaL_optint(l, 6, 255);
- b = luaL_optint(l, 7, 255);
- a = luaL_optint(l, 8, 255);
-
- if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE)
- return luaL_error(l, "Screen coordinates out of range (%d,%d)", x, y);
- if(x+w > XRES+BARSIZE)
- w = XRES+BARSIZE-x;
- if(y+h > YRES+MENUSIZE)
- h = YRES+MENUSIZE-y;
- if (r<0) r = 0;
- if (r>255) r = 255;
- if (g<0) g = 0;
- if (g>255) g = 255;
- if (b<0) b = 0;
- if (b>255) b = 255;
- if (a<0) a = 0;
- if (a>255) a = 255;
- if (vid_buf!=NULL)
- {
- fillrect(vid_buf, x, y, w, h, r, g, b, a);
- return 0;
- }
- return luaL_error(l, "Screen buffer does not exist");
-}
-
-int luatpt_drawline(lua_State* l)
-{
- int x1,y1,x2,y2,r,g,b,a;
- x1 = luaL_optint(l, 1, 0);
- y1 = luaL_optint(l, 2, 0);
- x2 = luaL_optint(l, 3, 10);
- y2 = luaL_optint(l, 4, 10);
- r = luaL_optint(l, 5, 255);
- g = luaL_optint(l, 6, 255);
- b = luaL_optint(l, 7, 255);
- a = luaL_optint(l, 8, 255);
-
- //Don't need to check coordinates, as they are checked in blendpixel
- if (r<0) r = 0;
- if (r>255) r = 255;
- if (g<0) g = 0;
- if (g>255) g = 255;
- if (b<0) b = 0;
- if (b>255) b = 255;
- if (a<0) a = 0;
- if (a>255) a = 255;
- if (vid_buf!=NULL)
- {
- blend_line(vid_buf, x1, y1, x2, y2, r, g, b, a);
- return 0;
- }
- return luaL_error(l, "Screen buffer does not exist");
-}
-
-int luatpt_textwidth(lua_State* l)
-{
- char * string;
- int strwidth = 0;
- string = luaL_optstring(l, 1, "");
- strwidth = textwidth(string);
- lua_pushinteger(l, strwidth);
- return 1;
-}
-
-int luatpt_get_name(lua_State* l)
-{
- if (svf_login){
- lua_pushstring(l, svf_user);
- return 1;
- }
- lua_pushstring(l, "");
- return 1;
-}
-
-int luatpt_set_shortcuts(lua_State* l)
-{
- int state;
- state = luaL_optint(l, 1, 0);
- sys_shortcuts = (state==0?0:1);
- return 0;
-}
-
-int luatpt_delete(lua_State* l)
-{
- int arg1, arg2;
- arg1 = abs(luaL_optint(l, 1, 0));
- arg2 = luaL_optint(l, 2, -1);
- if(arg2 == -1 && arg1 < NPART){
- kill_part(arg1);
- return 0;
- }
- arg2 = abs(arg2);
- if(arg2 < YRES && arg1 < XRES){
- delete_part(arg1, arg2, 0);
- return 0;
- }
- return luaL_error(l,"Invalid coordinates or particle ID");
-}
-
-int luatpt_register_step(lua_State* l)
-{
- int ref, i, ifree = -1;
- if(lua_isfunction(l, 1)){
- for(i = 0; i<6; i++){
- if(!step_functions[i]){
- if (ifree<0) ifree = i;
- } else {
- lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]);
- if(lua_equal(l, 1, lua_gettop(l))){
- lua_pop(l, 1);
- return luaL_error(l, "Function already registered");
- }
- lua_pop(l, 1);
- }
- }
- if (ifree>=0)
- {
- ref = luaL_ref(l, LUA_REGISTRYINDEX);
- step_functions[ifree] = ref;
- return 0;
- }
- else return luaL_error(l, "Step function limit reached");
- }
- return 0;
-}
-int luatpt_unregister_step(lua_State* l)
-{
- int i;
- if(lua_isfunction(l, 1)){
- for(i = 0; i<6; i++){
- if (step_functions[i]){
- lua_rawgeti(l, LUA_REGISTRYINDEX, step_functions[i]);
- if(lua_equal(l, 1, lua_gettop(l))){
- lua_pop(l, 1);
- luaL_unref(l, LUA_REGISTRYINDEX, step_functions[i]);
- step_functions[i] = 0;
- }
- else lua_pop(l, 1);
- }
- }
- }
- return 0;
-}
-int luatpt_register_keypress(lua_State* l)
-{
- int *newfunctions, i;
- if(lua_isfunction(l, 1)){
- for(i = 0; i<keypress_function_count; i++){
- lua_rawgeti(l, LUA_REGISTRYINDEX, keypress_functions[i]);
- if(lua_equal(l, 1, lua_gettop(l))){
- lua_pop(l, 1);
- return luaL_error(l, "Function already registered");
- }
- lua_pop(l, 1);
- }
- newfunctions = calloc(keypress_function_count+1, sizeof(int));
- if(keypress_functions){
- memcpy(newfunctions, keypress_functions, keypress_function_count*sizeof(int));
- free(keypress_functions);
- }
- newfunctions[keypress_function_count] = luaL_ref(l, LUA_REGISTRYINDEX);
- keypress_function_count++;
- keypress_functions = newfunctions;
- }
- return 0;
-}
-int luatpt_unregister_keypress(lua_State* l)
-{
- int *newfunctions, i, functionindex = -1;
- if(lua_isfunction(l, 1)){
- for(i = 0; i<keypress_function_count; i++){
- lua_rawgeti(l, LUA_REGISTRYINDEX, keypress_functions[i]);
- if(lua_equal(l, 1, lua_gettop(l))){
- functionindex = i;
- }
- lua_pop(l, 1);
- }
- }
- if(functionindex != -1){
- luaL_unref(l, LUA_REGISTRYINDEX, keypress_functions[functionindex]);
- if(functionindex != keypress_function_count-1){
- memmove(keypress_functions+functionindex+1, keypress_functions+functionindex+1, (keypress_function_count-functionindex-1)*sizeof(int));
- }
- if(keypress_function_count-1 > 0){
- newfunctions = calloc(keypress_function_count-1, sizeof(int));
- memcpy(newfunctions, keypress_functions, (keypress_function_count-1)*sizeof(int));
- free(keypress_functions);
- keypress_functions = newfunctions;
- } else {
- free(keypress_functions);
- keypress_functions = NULL;
- }
- keypress_function_count--;
- } else {
- return luaL_error(l, "Function not registered");
- }
- return 0;
-}
-int luatpt_register_mouseclick(lua_State* l)
-{
- int *newfunctions, i;
- if(lua_isfunction(l, 1)){
- for(i = 0; i<mouseclick_function_count; i++){
- lua_rawgeti(l, LUA_REGISTRYINDEX, mouseclick_functions[i]);
- if(lua_equal(l, 1, lua_gettop(l))){
- lua_pop(l, 1);
- return luaL_error(l, "Function already registered");
- }
- lua_pop(l, 1);
- }
- newfunctions = calloc(mouseclick_function_count+1, sizeof(int));
- if(mouseclick_functions){
- memcpy(newfunctions, mouseclick_functions, mouseclick_function_count*sizeof(int));
- free(mouseclick_functions);
- }
- newfunctions[mouseclick_function_count] = luaL_ref(l, LUA_REGISTRYINDEX);
- mouseclick_function_count++;
- mouseclick_functions = newfunctions;
- }
- return 0;
-}
-int luatpt_unregister_mouseclick(lua_State* l)
-{
- int *newfunctions, i, functionindex = -1;
- if(lua_isfunction(l, 1)){
- for(i = 0; i<mouseclick_function_count; i++){
- lua_rawgeti(l, LUA_REGISTRYINDEX, mouseclick_functions[i]);
- if(lua_equal(l, 1, lua_gettop(l))){
- functionindex = i;
- }
- lua_pop(l, 1);
- }
- }
- if(functionindex != -1){
- luaL_unref(l, LUA_REGISTRYINDEX, mouseclick_functions[functionindex]);
- if(functionindex != mouseclick_function_count-1){
- memmove(mouseclick_functions+functionindex+1, mouseclick_functions+functionindex+1, (mouseclick_function_count-functionindex-1)*sizeof(int));
- }
- if(mouseclick_function_count-1 > 0){
- newfunctions = calloc(mouseclick_function_count-1, sizeof(int));
- memcpy(newfunctions, mouseclick_functions, (mouseclick_function_count-1)*sizeof(int));
- free(mouseclick_functions);
- mouseclick_functions = newfunctions;
- } else {
- free(mouseclick_functions);
- mouseclick_functions = NULL;
- }
- mouseclick_function_count--;
- } else {
- return luaL_error(l, "Function not registered");
- }
- return 0;
-}
-int luatpt_input(lua_State* l)
-{
- char *prompt, *title, *result, *shadow, *text;
- title = mystrdup(luaL_optstring(l, 1, "Title"));
- prompt = mystrdup(luaL_optstring(l, 2, "Enter some text:"));
- text = mystrdup(luaL_optstring(l, 3, ""));
- shadow = mystrdup(luaL_optstring(l, 4, ""));
-
- if (vid_buf!=NULL)
- {
- result = input_ui(vid_buf, title, prompt, text, shadow);
- lua_pushstring(l, result);
- free(result);
- free(title);
- free(prompt);
- free(text);
- free(shadow);
- return 1;
- }
- free(title);
- free(prompt);
- free(text);
- free(shadow);
- return luaL_error(l, "Screen buffer does not exist");
-}
-int luatpt_message_box(lua_State* l)
-{
- char *title, *text;
- title = mystrdup(luaL_optstring(l, 1, "Title"));
- text = mystrdup(luaL_optstring(l, 2, "Message"));
- if (vid_buf!=NULL)
- {
- info_ui(vid_buf, title, text);
- free(title);
- free(text);
- return 0;
- }
- free(title);
- free(text);
- return luaL_error(l, "Screen buffer does not exist");;
-}
-int luatpt_get_numOfParts(lua_State* l)
-{
- lua_pushinteger(l, NUM_PARTS);
- return 1;
-}
-int luatpt_start_getPartIndex(lua_State* l)
-{
- getPartIndex_curIdx = -1;
- return 1;
-}
-int luatpt_next_getPartIndex(lua_State* l)
-{
- while(1)
- {
- getPartIndex_curIdx++;
- if(getPartIndex_curIdx >= NPART)
- {
- getPartIndex_curIdx = 0;
- lua_pushboolean(l, 0);
- return 1;
- }
- if(parts[getPartIndex_curIdx].type)
- break;
-
- }
-
- lua_pushboolean(l, 1);
- return 1;
-}
-int luatpt_getPartIndex(lua_State* l)
-{
- if(getPartIndex_curIdx < 0)
- {
- lua_pushinteger(l, 0);
- return 1;
- }
- lua_pushinteger(l, getPartIndex_curIdx);
- return 1;
-}
-int luatpt_hud(lua_State* l)
-{
- int hudstate;
- hudstate = luaL_optint(l, 1, 0);
- hud_enable = (hudstate==0?0:1);
- return 0;
-}
-int luatpt_gravity(lua_State* l)
-{
- int gravstate;
- gravstate = luaL_optint(l, 1, 0);
- if(gravstate)
- start_grav_async();
- else
- stop_grav_async();
- ngrav_enable = (gravstate==0?0:1);
- return 0;
-}
-int luatpt_airheat(lua_State* l)
-{
- int aheatstate;
- aheatstate = luaL_optint(l, 1, 0);
- aheat_enable = (aheatstate==0?0:1);
- return 0;
-}
-int luatpt_active_menu(lua_State* l)
-{
- int menuid;
- menuid = luaL_optint(l, 1, -1);
- if (menuid < SC_TOTAL && menuid >= 0)
- active_menu = menuid;
- else
- return luaL_error(l, "Invalid menu");
- return 0;
-}
-int luatpt_decorations_enable(lua_State* l)
-{
- int aheatstate;
- aheatstate = luaL_optint(l, 1, 0);
- decorations_enable = (aheatstate==0?0:1);
- return 0;
-}
-
-int luatpt_heat(lua_State* l)
-{
- int heatstate;
- heatstate = luaL_optint(l, 1, 0);
- legacy_enable = (heatstate==1?0:1);
- return 0;
-}
-int luatpt_cmode_set(lua_State* l)
-{
- int cmode = luaL_optint(l, 1, CM_FIRE);
- set_cmode(cmode);
- return 0;
-}
-int luatpt_setfire(lua_State* l)
-{
- int firesize = luaL_optint(l, 2, 4);
- float fireintensity = (float)luaL_optnumber(l, 1, 1.0f);
- prepare_alpha(firesize, fireintensity);
- return 0;
-}
-int luatpt_setdebug(lua_State* l)
-{
- int debug = luaL_optint(l, 1, 0);
- debug_flags = debug;
- return 0;
-}
-int luatpt_setfpscap(lua_State* l)
-{
- int fpscap = luaL_optint(l, 1, 0);
- if (fpscap < 2)
- return luaL_error(l, "fps cap too small");
- limitFPS = fpscap;
- return 0;
-}
-int luatpt_getscript(lua_State* l)
-{
- char *fileid = NULL, *filedata = NULL, *fileuri = NULL, *fileauthor = NULL, *filename = NULL, *lastError = NULL, *luacommand = NULL;
- int len, ret,run_script;
- FILE * outputfile;
-
- fileauthor = mystrdup(luaL_optstring(l, 1, ""));
- fileid = mystrdup(luaL_optstring(l, 2, ""));
- run_script = luaL_optint(l, 3, 0);
- if(!fileauthor || !fileid || strlen(fileauthor)<1 || strlen(fileid)<1)
- goto fin;
- if(!confirm_ui(vid_buf, "Do you want to install script?", fileid, "Install"))
- goto fin;
-
- fileuri = malloc(strlen(SCRIPTSERVER)+strlen(fileauthor)+strlen(fileid)+44);
- sprintf(fileuri, "http://" SCRIPTSERVER "/GetScript.api?Author=%s&Filename=%s", fileauthor, fileid);
-
- filedata = http_auth_get(fileuri, svf_user_id, NULL, svf_session_id, &ret, &len);
-
- if(len <= 0 || !filedata)
- {
- lastError = "Server did not return data.";
- goto fin;
- }
- if(ret != 200)
- {
- lastError = http_ret_text(ret);
- goto fin;
- }
-
- filename = malloc(strlen(fileauthor)+strlen(fileid)+strlen(PATH_SEP)+strlen(LOCAL_LUA_DIR)+6);
- sprintf(filename, LOCAL_LUA_DIR PATH_SEP "%s_%s.lua", fileauthor, fileid);
-
-#ifdef WIN32
- _mkdir(LOCAL_LUA_DIR);
-#else
- mkdir(LOCAL_LUA_DIR, 0755);
-#endif
-
- outputfile = fopen(filename, "r");
- if(outputfile)
- {
- fclose(outputfile);
- outputfile = NULL;
- if(confirm_ui(vid_buf, "File already exists, overwrite?", filename, "Overwrite"))
- {
- outputfile = fopen(filename, "w");
- }
- else
- {
- goto fin;
- }
- }
- else
- {
- outputfile = fopen(filename, "w");
- }
-
- if(!outputfile)
- {
- lastError = "Unable to write to file";
- goto fin;
- }
-
-
- fputs(filedata, outputfile);
- fclose(outputfile);
- outputfile = NULL;
- if(run_script)
- {
- luacommand = malloc(strlen(filename)+20);
- sprintf(luacommand,"dofile(\"%s\")",filename);
- luacon_eval(luacommand);
- }
-
-fin:
- if(fileid) free(fileid);
- if(filedata) free(filedata);
- if(fileuri) free(fileuri);
- if(fileauthor) free(fileauthor);
- if(filename) free(filename);
- if(luacommand) free(luacommand);
- luacommand = NULL;
-
- if(lastError) return luaL_error(l, lastError);
- return 0;
-}
-
-int luatpt_setwindowsize(lua_State* l)
-{
- int result, scale = luaL_optint(l,1,1), kiosk = luaL_optint(l,2,0);
- if (scale!=2) scale = 1;
- if (kiosk!=1) kiosk = 0;
- result = set_scale(scale, kiosk);
- lua_pushnumber(l, result);
- return 1;
-}
-
-int luatpt_screenshot(lua_State* l)
-{
- int captureUI = luaL_optint(l, 1, 0);
- if(vid_buf)
- {
- if(captureUI)
- {
- dump_frame(vid_buf, XRES+BARSIZE, YRES+MENUSIZE, XRES+BARSIZE);
- }
- else
- {
- dump_frame(vid_buf, XRES, YRES, XRES+BARSIZE);
- }
- return 0;
- }
- return luaL_error(l, "Screen buffer does not exist");
-}
-
-#endif
diff --git a/src/main.c b/src/main.c
deleted file mode 100644
index d61e015..0000000
--- a/src/main.c
+++ /dev/null
@@ -1,2881 +0,0 @@
-/**
- * Powder Toy - Main source
- *
- * Copyright (c) 2008 - 2011 Stanislaw Skowronek.
- * Copyright (c) 2010 - 2011 Simon Robertshaw
- * Copyright (c) 2010 - 2011 Skresanov Savely
- * Copyright (c) 2010 - 2011 Bryan Hoyle
- * Copyright (c) 2010 - 2011 Nathan Cousins
- * Copyright (c) 2010 - 2011 cracker64
- * Copyright (c) 2011 jacksonmj
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <defines.h>
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <SDL/SDL.h>
-#include <SDL/SDL_audio.h>
-#include <bzlib.h>
-#include <time.h>
-#include <pthread.h>
-
-#ifdef WIN32
-#include <direct.h>
-#else
-#include <sys/stat.h>
-#include <unistd.h>
-#endif
-
-#include <misc.h>
-#include <font.h>
-#include <powder.h>
-#include "gravity.h"
-#include <graphics.h>
-#include <powdergraphics.h>
-#include <http.h>
-#include <md5.h>
-#include <update.h>
-#include <hmap.h>
-#include <air.h>
-#include <icon.h>
-#include <console.h>
-#ifdef LUACONSOLE
-#include "luaconsole.h"
-#endif
-#include "save.h"
-
-pixel *vid_buf;
-
-#define NUM_SOUNDS 2
-struct sample {
- Uint8 *data;
- Uint32 dpos;
- Uint32 dlen;
-} sounds[NUM_SOUNDS];
-
-void mixaudio(void *unused, Uint8 *stream, int len)
-{
- int i;
- Uint32 amount;
-
- for ( i=0; i<NUM_SOUNDS; ++i ) {
- amount = (sounds[i].dlen-sounds[i].dpos);
- if ( amount > len ) {
- amount = len;
- }
- SDL_MixAudio(stream, &sounds[i].data[sounds[i].dpos], amount, SDL_MIX_MAXVOLUME);
- sounds[i].dpos += amount;
- }
-}
-
-//plays a .wav file (sounds must be enabled)
-void play_sound(char *file)
-{
- int index;
- SDL_AudioSpec wave;
- Uint8 *data;
- Uint32 dlen;
- SDL_AudioCVT cvt;
-
- if (!sound_enable) return;
-
- /* Look for an empty (or finished) sound slot */
- for ( index=0; index<NUM_SOUNDS; ++index ) {
- if ( sounds[index].dpos == sounds[index].dlen ) {
- break;
- }
- }
- if ( index == NUM_SOUNDS )
- return;
-
- /* Load the sound file and convert it to 16-bit stereo at 22kHz */
- if ( SDL_LoadWAV(file, &wave, &data, &dlen) == NULL ) {
- fprintf(stderr, "Couldn't load %s: %s\n", file, SDL_GetError());
- return;
- }
- SDL_BuildAudioCVT(&cvt, wave.format, wave.channels, wave.freq,
- AUDIO_S16, 2, 22050);
- cvt.buf = malloc(dlen*cvt.len_mult);
- memcpy(cvt.buf, data, dlen);
- cvt.len = dlen;
- SDL_ConvertAudio(&cvt);
- SDL_FreeWAV(data);
-
- /* Put the sound data in the slot (it starts playing immediately) */
- if ( sounds[index].data ) {
- free(sounds[index].data);
- }
- SDL_LockAudio();
- sounds[index].data = cvt.buf;
- sounds[index].dlen = cvt.len_cvt;
- sounds[index].dpos = 0;
- SDL_UnlockAudio();
-}
-
-static const char *it_msg =
- "\blThe Powder Toy - Version " MTOS(SAVE_VERSION) "." MTOS(MINOR_VERSION) " - http://powdertoy.co.uk, irc.freenode.net #powder\n"
- "\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\x7F\n"
- "\n"
- "\bgControl+C/V/X are Copy, Paste and cut respectively.\n"
- "\bgTo choose a material, hover over one of the icons on the right, it will show a selection of elements in that group.\n"
- "\bgPick your material from the menu using mouse left/right buttons.\n"
- "Draw freeform lines by dragging your mouse left/right button across the drawing area.\n"
- "Shift+drag will create straight lines of particles.\n"
- "Ctrl+drag will result in filled rectangles.\n"
- "Ctrl+Shift+click will flood-fill a closed area.\n"
- "Ctrl+Z will act as Undo.\n"
- "Middle click or Alt+Click to \"sample\" the particles.\n"
- "\n\boUse 'Z' for a zoom tool. Click to make the drawable zoom window stay around. Use the wheel to change the zoom strength\n"
- "Use 'S' to save parts of the window as 'stamps'.\n"
- "'L' will load the most recent stamp, 'K' shows a library of stamps you saved.\n"
- "'C' will cycle the display mode (Fire, Blob, Velocity, etc.). The numbers on the keyboard do the same\n"
- "Use the mouse scroll wheel to change the tool size for particles.\n"
- "The spacebar can be used to pause physics.\n"
- "'P' will take a screenshot and save it into the current directory.\n"
- "\n"
- "Contributors: \bgStanislaw K Skowronek (\brhttp://powder.unaligned.org\bg, \bbirc.unaligned.org #wtf\bg),\n"
- "\bgSimon Robertshaw, Skresanov Savely, cracker64, Catelite, Bryan Hoyle, Nathan Cousins, jacksonmj,\n"
- "\bgLieuwe Mosch, Anthony Boot, Matthew \"me4502\", MaksProg, jacob1\n"
- "\n"
- "\bgTo use online features such as saving, you need to register at: \brhttp://powdertoy.co.uk/Register.html\n"
- "\n"
- "\bt" MTOS(SAVE_VERSION) "." MTOS(MINOR_VERSION) "." MTOS(BUILD_NUM) " "
-#ifdef X86
- "X86 "
-#endif
-#ifdef X86_SSE
- "X86_SSE "
-#endif
-#ifdef X86_SSE2
- "X86_SSE2 "
-#endif
-#ifdef X86_SSE3
- "X86_SSE3 "
-#endif
-#ifdef LIN32
- "LIN32 "
-#endif
-#ifdef LIN64
- "LIN64 "
-#endif
-#ifdef WIN32
- "WIN32 "
-#endif
-#ifdef MACOSX
- "MACOSX "
-#endif
-#ifdef LUACONSOLE
- "LUACONSOLE "
-#endif
-#ifdef GRAVFFT
- "GRAVFFT "
-#endif
-#ifdef REALISTIC
- "REALISTIC"
-#endif
- ;
-
-typedef struct
-{
- int start, inc;
- pixel *vid;
-} upstruc;
-
-static const char *old_ver_msg_beta = "A new beta is available - click here!";
-static const char *old_ver_msg = "A new version is available - click here!";
-char new_message_msg[255];
-float mheat = 0.0f;
-
-int saveURIOpen = 0;
-char * saveDataOpen = NULL;
-int saveDataOpenSize = 0;
-
-int do_open = 0;
-int sys_pause = 0;
-int sys_shortcuts = 1;
-int legacy_enable = 0; //Used to disable new features such as heat, will be set by save.
-int aheat_enable; //Ambient heat
-int decorations_enable = 1;
-int hud_enable = 1;
-int active_menu = 0;
-int framerender = 0;
-int pretty_powder = 0;
-int amd = 1;
-int FPSB = 0;
-int MSIGN =-1;
-int frameidx = 0;
-//int CGOL = 0;
-//int GSPEED = 1;//causes my .exe to crash..
-int sound_enable = 0;
-int loop_time = 0;
-
-int debug_flags = 0;
-int debug_perf_istart = 1;
-int debug_perf_iend = 0;
-long debug_perf_frametime[DEBUG_PERF_FRAMECOUNT];
-long debug_perf_partitime[DEBUG_PERF_FRAMECOUNT];
-long debug_perf_time = 0;
-
-sign signs[MAXSIGNS];
-
-int numCores = 4;
-
-int core_count()
-{
- int numCPU = 1;
-#ifdef MT
-#ifdef WIN32
- SYSTEM_INFO sysinfo;
- GetSystemInfo( &sysinfo );
- numCPU = sysinfo.dwNumberOfProcessors;
-#else
-#ifdef MACOSX
- numCPU = 4;
-#else
- numCPU = sysconf( _SC_NPROCESSORS_ONLN );
-#endif
-#endif
-
- printf("Cpus: %d\n", numCPU);
- if (numCPU>1)
- printf("Multithreading enabled\n");
- else
- printf("Multithreading disabled\n");
-#endif
- return numCPU;
-}
-
-int mousex = 0, mousey = 0; //They contain mouse position
-int kiosk_enable = 0;
-
-void sdl_seticon(void)
-{
-#ifdef WIN32
- //SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon_w32, 32, 32, 32, 128, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
- //SDL_WM_SetIcon(icon, NULL/*app_icon_mask*/);
-#else
-#ifdef MACOSX
- //SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon_w32, 32, 32, 32, 128, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
- //SDL_WM_SetIcon(icon, NULL/*app_icon_mask*/);
-#else
- SDL_Surface *icon = SDL_CreateRGBSurfaceFrom(app_icon, 16, 16, 32, 64, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000);
- SDL_WM_SetIcon(icon, NULL/*app_icon_mask*/);
-#endif
-#endif
-}
-
-int frame_idx=0;
-void dump_frame(pixel *src, int w, int h, int pitch)
-{
- char frame_name[32];
- int j,i;
- unsigned char c[3];
- FILE *f;
- sprintf(frame_name,"frame%04d.ppm",frame_idx);
- f=fopen(frame_name,"wb");
- fprintf(f,"P6\n%d %d\n255\n",w,h);
- for (j=0; j<h; j++)
- {
- for (i=0; i<w; i++)
- {
- c[0] = PIXR(src[i]);
- c[1] = PIXG(src[i]);
- c[2] = PIXB(src[i]);
- fwrite(c,3,1,f);
- }
- src+=pitch;
- }
- fclose(f);
- frame_idx++;
-}
-
-/***********************************************************
- * STATE MANAGEMENT *
- ***********************************************************/
-
-char bframe = 0;
-
-void clear_sim(void)
-{
- int i, x, y;
- memset(bmap, 0, sizeof(bmap));
- memset(emap, 0, sizeof(emap));
- memset(signs, 0, sizeof(signs));
- MSIGN = -1;
- memset(parts, 0, sizeof(particle)*NPART);
- for (i=0; i<NPART-1; i++)
- parts[i].life = i+1;
- parts[NPART-1].life = -1;
- pfree = 0;
- parts_lastActiveIndex = 0;
- memset(pmap, 0, sizeof(pmap));
- memset(pv, 0, sizeof(pv));
- memset(vx, 0, sizeof(vx));
- memset(vy, 0, sizeof(vy));
- memset(fvx, 0, sizeof(fvx));
- memset(fvy, 0, sizeof(fvy));
- memset(photons, 0, sizeof(photons));
- memset(wireless, 0, sizeof(wireless));
- memset(gol2, 0, sizeof(gol2));
- memset(portalp, 0, sizeof(portalp));
- memset(fighters, 0, sizeof(fighters));
- fighcount = 0;
- ISSPAWN1 = ISSPAWN2 = 0;
- player.spwn = 0;
- player2.spwn = 0;
- emp_decor = 0;
- memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- memset(fire_r, 0, sizeof(fire_r));
- memset(fire_g, 0, sizeof(fire_g));
- memset(fire_b, 0, sizeof(fire_b));
- if(gravmask)
- memset(gravmask, 0xFFFFFFFF, (XRES/CELL)*(YRES/CELL)*sizeof(unsigned));
- if(gravy)
- memset(gravy, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- if(gravx)
- memset(gravx, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- if(gravp)
- memset(gravp, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float));
- for(x = 0; x < XRES/CELL; x++){
- for(y = 0; y < YRES/CELL; y++){
- hv[y][x] = 273.15f+22.0f; //Set to room temperature
- }
- }
- if(bframe)
- draw_bframe();
-}
-
-// stamps library
-
-stamp stamps[STAMP_MAX];//[STAMP_X*STAMP_Y];
-
-int stamp_count = 0;
-
-unsigned last_time=0, last_name=0;
-void stamp_gen_name(char *fn)
-{
- unsigned t=(unsigned)time(NULL);
-
- if (last_time!=t)
- {
- last_time=t;
- last_name=0;
- }
- else
- last_name++;
-
- sprintf(fn, "%08x%02x", last_time, last_name);
-}
-
-void stamp_update(void)
-{
- FILE *f;
- int i;
- f=fopen("stamps" PATH_SEP "stamps.def", "wb");
- if (!f)
- return;
- for (i=0; i<STAMP_MAX; i++)
- {
- if (!stamps[i].name[0])
- break;
- if (stamps[i].dodelete!=1)
- {
- fwrite(stamps[i].name, 1, 10, f);
- }
- else
- {
- char name[30] = {0};
- sprintf(name,"stamps%s%s.stm",PATH_SEP,stamps[i].name);
- remove(name);
- }
- }
- fclose(f);
-}
-
-void stamp_gen_thumb(int i)
-{
- char fn[64];
- void *data;
- int size, factor_x, factor_y;
- pixel *tmp;
-
- if (stamps[i].thumb)
- {
- free(stamps[i].thumb);
- stamps[i].thumb = NULL;
- }
-
- sprintf(fn, "stamps" PATH_SEP "%s.stm", stamps[i].name);
- data = file_load(fn, &size);
-
- if (data)
- {
- stamps[i].thumb = prerender_save(data, size, &(stamps[i].thumb_w), &(stamps[i].thumb_h));
- if (stamps[i].thumb && (stamps[i].thumb_w>XRES/GRID_S || stamps[i].thumb_h>YRES/GRID_S))
- {
- factor_x = ceil((float)stamps[i].thumb_w/(float)(XRES/GRID_S));
- factor_y = ceil((float)stamps[i].thumb_h/(float)(YRES/GRID_S));
- if (factor_y > factor_x)
- factor_x = factor_y;
- tmp = rescale_img(stamps[i].thumb, stamps[i].thumb_w, stamps[i].thumb_h, &(stamps[i].thumb_w), &(stamps[i].thumb_h), factor_x);
- free(stamps[i].thumb);
- stamps[i].thumb = tmp;
- }
- }
-
- free(data);
-}
-
-int clipboard_ready = 0;
-void *clipboard_data = 0;
-int clipboard_length = 0;
-
-void stamp_save(int x, int y, int w, int h)
-{
- FILE *f;
- int n;
- char fn[64], sn[16];
- void *s=build_save(&n, x, y, w, h, bmap, vx, vy, pv, fvx, fvy, signs, parts);
- if (!s)
- return;
-
-#ifdef WIN32
- _mkdir("stamps");
-#else
- mkdir("stamps", 0755);
-#endif
-
- stamp_gen_name(sn);
- sprintf(fn, "stamps" PATH_SEP "%s.stm", sn);
-
- f = fopen(fn, "wb");
- if (!f)
- return;
- fwrite(s, n, 1, f);
- fclose(f);
-
- free(s);
-
- if (stamps[STAMP_MAX-1].thumb)
- free(stamps[STAMP_MAX-1].thumb);
- memmove(stamps+1, stamps, sizeof(struct stamp)*(STAMP_MAX-1));
- memset(stamps, 0, sizeof(struct stamp));
- if (stamp_count<STAMP_MAX)
- stamp_count++;
-
- strcpy(stamps[0].name, sn);
- stamp_gen_thumb(0);
-
- stamp_update();
-}
-
-void *stamp_load(int i, int *size)
-{
- void *data;
- char fn[64];
- struct stamp tmp;
-
- if (!stamps[i].thumb || !stamps[i].name[0])
- return NULL;
-
- sprintf(fn, "stamps" PATH_SEP "%s.stm", stamps[i].name);
- data = file_load(fn, size);
- if (!data)
- return NULL;
-
- if (i>0)
- {
- memcpy(&tmp, stamps+i, sizeof(struct stamp));
- memmove(stamps+1, stamps, sizeof(struct stamp)*i);
- memcpy(stamps, &tmp, sizeof(struct stamp));
-
- stamp_update();
- }
-
- return data;
-}
-
-void stamp_init(void)
-{
- int i;
- FILE *f;
-
- memset(stamps, 0, sizeof(stamps));
-
- f=fopen("stamps" PATH_SEP "stamps.def", "rb");
- if (!f)
- return;
- for (i=0; i<STAMP_MAX; i++)
- {
- fread(stamps[i].name, 1, 10, f);
- if (!stamps[i].name[0])
- break;
- stamp_count++;
- stamp_gen_thumb(i);
- }
- fclose(f);
-}
-
-void del_stamp(int d)
-{
- stamps[d].dodelete = 1;
- stamp_update();
- stamp_count = 0;
- stamp_init();
-}
-
-void thumb_cache_inval(char *id);
-
-char *thumb_cache_id[THUMB_CACHE_SIZE];
-void *thumb_cache_data[THUMB_CACHE_SIZE];
-int thumb_cache_size[THUMB_CACHE_SIZE];
-int thumb_cache_lru[THUMB_CACHE_SIZE];
-
-void thumb_cache_inval(char *id)
-{
- int i,j;
- for (i=0; i<THUMB_CACHE_SIZE; i++)
- if (thumb_cache_id[i] && !strcmp(id, thumb_cache_id[i]))
- break;
- if (i >= THUMB_CACHE_SIZE)
- return;
- free(thumb_cache_id[i]);
- free(thumb_cache_data[i]);
- thumb_cache_id[i] = NULL;
- for (j=0; j<THUMB_CACHE_SIZE; j++)
- if (thumb_cache_lru[j] > thumb_cache_lru[i])
- thumb_cache_lru[j]--;
-}
-void thumb_cache_add(char *id, void *thumb, int size)
-{
- int i,m=-1,j=-1;
- thumb_cache_inval(id);
- for (i=0; i<THUMB_CACHE_SIZE; i++)
- {
- if (!thumb_cache_id[i])
- break;
- if (thumb_cache_lru[i] > m)
- {
- m = thumb_cache_lru[i];
- j = i;
- }
- }
- if (i >= THUMB_CACHE_SIZE)
- {
- thumb_cache_inval(thumb_cache_id[j]);
- i = j;
- }
- for (j=0; j<THUMB_CACHE_SIZE; j++)
- thumb_cache_lru[j] ++;
- thumb_cache_id[i] = mystrdup(id);
- thumb_cache_data[i] = malloc(size);
- memcpy(thumb_cache_data[i], thumb, size);
- thumb_cache_size[i] = size;
- thumb_cache_lru[i] = 0;
-}
-int thumb_cache_find(char *id, void **thumb, int *size)
-{
- int i,j;
- for (i=0; i<THUMB_CACHE_SIZE; i++)
- if (thumb_cache_id[i] && !strcmp(id, thumb_cache_id[i]))
- break;
- if (i >= THUMB_CACHE_SIZE)
- return 0;
- for (j=0; j<THUMB_CACHE_SIZE; j++)
- if (thumb_cache_lru[j] < thumb_cache_lru[i])
- thumb_cache_lru[j]++;
- thumb_cache_lru[i] = 0;
- *thumb = malloc(thumb_cache_size[i]);
- *size = thumb_cache_size[i];
- memcpy(*thumb, thumb_cache_data[i], *size);
- return 1;
-}
-
-char http_proxy_string[256] = "";
-
-unsigned char last_major=0, last_minor=0, last_build=0, update_flag=0;
-
-char *tag = "(c) 2008-9 Stanislaw Skowronek";
-int itc = 0;
-char itc_msg[64] = "[?]";
-
-char my_uri[] = "http://" SERVER "/Update.api?Action=Download&Architecture="
-#if defined WIN32
- "Windows32"
-#elif defined LIN32
- "Linux32"
-#elif defined LIN64
- "Linux64"
-#elif defined MACOSX
- "MacOSX"
-#else
- "Unknown"
-#endif
- "&InstructionSet="
-#if defined X86_SSE3
- "SSE3"
-#elif defined X86_SSE2
- "SSE2"
-#elif defined X86_SSE
- "SSE"
-#else
- "SSE"
-#endif
- ;
-
-int set_scale(int scale, int kiosk){
- int old_scale = sdl_scale, old_kiosk = kiosk_enable;
- sdl_scale = scale;
- kiosk_enable = kiosk;
- if (!sdl_open())
- {
- sdl_scale = old_scale;
- kiosk_enable = old_kiosk;
- sdl_open();
- return 0;
- }
- return 1;
-}
-
-#ifdef RENDERER
-int main(int argc, char *argv[])
-{
- pixel *vid_buf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
- int load_size, i=0, j=0;
- void *load_data = file_load(argv[1], &load_size);
- unsigned char c[3];
- char ppmfilename[256], ptifilename[256], ptismallfilename[256];
- FILE *f;
-
- colour_mode = COLOUR_DEFAULT;
- init_display_modes();
- TRON_init_graphics();
-
- sys_pause = 1;
- parts = calloc(sizeof(particle), NPART);
- for (i=0; i<NPART-1; i++)
- parts[i].life = i+1;
- parts[NPART-1].life = -1;
- pfree = 0;
-
- pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
-
- prepare_alpha(CELL, 1.0f);
- prepare_graphicscache();
- flm_data = generate_gradient(flm_data_colours, flm_data_pos, flm_data_points, 200);
- plasma_data = generate_gradient(plasma_data_colours, plasma_data_pos, plasma_data_points, 200);
-
- player.elem = player2.elem = PT_DUST;
- player.frames = player2.frames = 0;
-
- sprintf(ppmfilename, "%s.ppm", argv[2]);
- sprintf(ptifilename, "%s.pti", argv[2]);
- sprintf(ptismallfilename, "%s-small.pti", argv[2]);
-
- if(load_data && load_size){
- int parsestate = 0;
- //parsestate = parse_save(load_data, load_size, 1, 0, 0);
- parsestate = parse_save(load_data, load_size, 1, 0, 0, bmap, vx, vy, pv, fvx, fvy, signs, parts, pmap);
-
- decorations_enable = 0;
- for(i=0; i<30; i++){
- memset(vid_buf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- draw_walls(vid_buf);
- update_particles(vid_buf);
- render_parts(vid_buf);
- render_fire(vid_buf);
- }
-
- render_signs(vid_buf);
-
- if(parsestate>0){
- //return 0;
- info_box(vid_buf, "Save file invalid or from newer version");
- }
-
- //Save PTi images
- char * datares = NULL, *scaled_buf;
- int res = 0, sw, sh;
- datares = ptif_pack(vid_buf, XRES, YRES, &res);
- if(datares!=NULL){
- f=fopen(ptifilename, "wb");
- fwrite(datares, res, 1, f);
- fclose(f);
- free(datares);
- datares = NULL;
- }
- scaled_buf = resample_img(vid_buf, XRES, YRES, XRES/GRID_Z, YRES/GRID_Z);
- datares = ptif_pack(scaled_buf, XRES/GRID_Z, YRES/GRID_Z, &res);
- if(datares!=NULL){
- f=fopen(ptismallfilename, "wb");
- fwrite(datares, res, 1, f);
- fclose(f);
- free(datares);
- datares = NULL;
- }
- free(scaled_buf);
- //Save PPM image
- f=fopen(ppmfilename, "wb");
- fprintf(f,"P6\n%d %d\n255\n",XRES,YRES);
- for (j=0; j<YRES; j++)
- {
- for (i=0; i<XRES; i++)
- {
- c[0] = PIXR(vid_buf[i]);
- c[1] = PIXG(vid_buf[i]);
- c[2] = PIXB(vid_buf[i]);
- fwrite(c,3,1,f);
- }
- vid_buf+=XRES+BARSIZE;
- }
- fclose(f);
-
- return 1;
- }
-
- return 0;
-}
-#else
-int main(int argc, char *argv[])
-{
- pixel *part_vbuf; //Extra video buffer
- pixel *part_vbuf_store;
- char uitext[512] = "";
- char heattext[256] = "";
- char coordtext[128] = "";
- int currentTime = 0;
- int FPS = 0, pastFPS = 0, elapsedTime = 0;
- void *http_ver_check, *http_session_check = NULL;
- char *ver_data=NULL, *check_data=NULL, *tmp;
- //char console_error[255] = "";
- int result, i, j, bq, bc = 0, do_check=0, do_s_check=0, old_version=0, http_ret=0,http_s_ret=0, major, minor, buildnum, is_beta = 0, old_ver_len, new_message_len=0;
-#ifdef INTERNAL
- int vs = 0;
-#endif
- int wavelength_gfx = 0;
- int x, y, line_x, line_y, b = 0, sl=1, sr=0, su=0, c, lb = 0, lx = 0, ly = 0, lm = 0;//, tx, ty;
- int da = 0, dae = 0, db = 0, it = 2047, mx, my, bsx = 2, bsy = 2, quickoptions_tooltip_fade_invert, it_invert = 0;
- float nfvx, nfvy;
- int load_mode=0, load_w=0, load_h=0, load_x=0, load_y=0, load_size=0;
- void *load_data=NULL;
- pixel *load_img=NULL;//, *fbi_img=NULL;
- int save_mode=0, save_x=0, save_y=0, save_w=0, save_h=0, copy_mode=0;
- unsigned int rgbSave = PIXRGB(127,0,0);
- SDL_AudioSpec fmt;
- int username_flash = 0, username_flash_t = 1;
- int saveOpenError = 0;
-#ifdef PTW32_STATIC_LIB
- pthread_win32_process_attach_np();
- pthread_win32_thread_attach_np();
-#endif
- limitFPS = 60;
- vid_buf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
- part_vbuf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); //Extra video buffer
- part_vbuf_store = part_vbuf;
- pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE);
-
- gravity_init();
- GSPEED = 1;
-
- /* Set 16-bit stereo audio at 22Khz */
- fmt.freq = 22050;
- fmt.format = AUDIO_S16;
- fmt.channels = 2;
- fmt.samples = 512;
- fmt.callback = mixaudio;
- fmt.userdata = NULL;
-
-#ifdef MT
- numCores = core_count();
-#endif
-//TODO: Move out version stuff
- menu_count();
- parts = calloc(sizeof(particle), NPART);
- cb_parts = calloc(sizeof(particle), NPART);
- init_can_move();
-
-#ifdef LUACONSOLE
- luacon_open();
-#endif
-
- colour_mode = COLOUR_DEFAULT;
- init_display_modes();
- TRON_init_graphics();
-
- //fbi_img = render_packed_rgb(fbi, FBI_W, FBI_H, FBI_CMP);
-
- for (i=1; i<argc; i++)
- {
- if (!strncmp(argv[i], "ddir", 5) && i+1<argc)
- {
- chdir(argv[i+1]);
- i++;
- }
- else if (!strncmp(argv[i], "ptsave", 7) && i+1<argc)
- {
- //Prevent reading of any arguments after ptsave for security
- i++;
- argc = i+2;
- break;
- }
- else if (!strncmp(argv[i], "open", 5) && i+1<argc)
- {
- saveDataOpen = file_load(argv[i+1], &saveDataOpenSize);
- i++;
- }
- }
-
- load_presets();
- clear_sim();
-
- for (i=1; i<argc; i++)
- {
- if (!strncmp(argv[i], "scale:", 6))
- {
- sdl_scale = (argv[i][6]=='2') ? 2 : 1;
- }
- else if (!strncmp(argv[i], "proxy:", 6))
- {
- memset(http_proxy_string, 0, sizeof(http_proxy_string));
- strncpy(http_proxy_string, argv[i]+6, 255);
- }
- else if (!strncmp(argv[i], "nohud", 5))
- {
- hud_enable = 0;
- }
- else if (!strncmp(argv[i], "kiosk", 5))
- {
- kiosk_enable = 1;
- //sdl_scale = 2; //Removed because some displays cannot handle the resolution
- hud_enable = 0;
- }
- else if (!strncmp(argv[i], "sound", 5))
- {
- /* Open the audio device and start playing sound! */
- if ( SDL_OpenAudio(&fmt, NULL) < 0 )
- {
- fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
- }
- else
- {
- sound_enable = 1;
- SDL_PauseAudio(0);
- }
- }
- else if (!strncmp(argv[i], "scripts", 8))
- {
- file_script = 1;
- }
- else if (!strncmp(argv[i], "open", 5) && i+1<argc)
- {
- i++;
- }
- else if (!strncmp(argv[i], "ddir", 5) && i+1<argc)
- {
- i++;
- }
- else if (!strncmp(argv[i], "ptsave", 7) && i+1<argc)
- {
- int ci = 0, ns = 0, okay = 0;
- char * tempString = argv[i+1];
- int tempStringLength = strlen(argv[i+1])-7;
- int tempSaveID = 0;
- char tempNumberString[32];
- puts("Got ptsave");
- i++;
- tempNumberString[31] = 0;
- tempNumberString[0] = 0;
- if(!strncmp(tempString, "ptsave:", 7) && tempStringLength)
- {
- puts("ptsave:// protocol");
- tempString+=7;
- while(tempString[ci] && ns<30 && ci<tempStringLength)
- {
- if(tempString[ci]>=48 && tempString[ci]<=57)
- {
- tempNumberString[ns++] = tempString[ci];
- tempNumberString[ns] = 0;
- }
- else if(tempString[ci]=='#')
- {
- okay = 1;
- break;
- }
- else
- {
- puts("ptsave: invalid save ID");
- break;
- }
- ci++;
- }
- if(!tempString[ci])
- {
- okay = 1;
- }
- if(okay)
- {
- tempSaveID = atoi(tempNumberString);
- }
- }
- if(tempSaveID > 0)
- {
- puts("Got ptsave:id");
- saveURIOpen = tempSaveID;
- it = 0;
- }
- break;
- }
- }
-
- make_kernel();
-
- stamp_init();
-
- if (!sdl_open())
- {
- sdl_scale = 1;
- kiosk_enable = 0;
- if (!sdl_open()) exit(1);
- }
- save_presets(0);
- http_init(http_proxy_string[0] ? http_proxy_string : NULL);
-
- prepare_alpha(CELL, 1.0f);
- prepare_graphicscache();
- flm_data = generate_gradient(flm_data_colours, flm_data_pos, flm_data_points, 200);
- plasma_data = generate_gradient(plasma_data_colours, plasma_data_pos, plasma_data_points, 200);
-
- if (cpu_check())
- {
- error_ui(vid_buf, 0, "Unsupported CPU. Try another version.");
- return 1;
- }
-
- if(saveOpenError)
- {
- saveOpenError = 0;
- error_ui(vid_buf, 0, "Unable to open save file.");
- }
-
- http_ver_check = http_async_req_start(NULL, "http://" SERVER "/Update.api?Action=CheckVersion", NULL, 0, 0);
- if (svf_login) {
- http_auth_headers(http_ver_check, svf_user_id, NULL, svf_session_id); //Add authentication so beta checking can be done from user basis
- http_session_check = http_async_req_start(NULL, "http://" SERVER "/Login.api?Action=CheckSession", NULL, 0, 0);
- http_auth_headers(http_session_check, svf_user_id, NULL, svf_session_id);
- }
-#ifdef LUACONSOLE
- luacon_eval("dofile(\"autorun.lua\")"); //Autorun lua script
-#endif
- while (!sdl_poll()) //the main loop
- {
- frameidx++;
- frameidx %= 30;
- if (!sys_pause||framerender) //only update air if not paused
- {
- update_air();
- if(aheat_enable)
- update_airh();
- }
-
- if(gravwl_timeout)
- {
- if(gravwl_timeout==1)
- gravity_mask();
- gravwl_timeout--;
- }
-
- //Can't be too sure (Limit the cursor size)
- if (bsx>1180)
- bsx = 1180;
- if (bsx<0)
- bsx = 0;
- if (bsy>1180)
- bsy = 1180;
- if (bsy<0)
- bsy = 0;
-
- //Pretty powders, colour cycle
- //sandcolour_r = 0;
- //sandcolour_g = 0;
- sandcolour_b = sandcolour_r = sandcolour_g = (int)(20.0f*sin((float)sandcolour_frame*(M_PI/180.0f)));
- sandcolour_frame++;
- sandcolour_frame%=360;
-
-#ifdef OGLR
- part_vbuf = vid_buf;
-#else
- if(ngrav_enable && (display_mode & DISPLAY_WARP))
- {
- part_vbuf = part_vbuf_store;
- memset(vid_buf, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- } else {
- part_vbuf = vid_buf;
- }
-#endif
- render_before(part_vbuf);
-
- if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME))
- {
- #ifdef WIN32
- #elif defined(MACOSX)
- #else
- struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
- debug_perf_time = ts.tv_nsec;
- #endif
- }
-
- update_particles(part_vbuf); //update everything
-
- if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME))
- {
- #ifdef WIN32
- #elif defined(MACOSX)
- #else
- struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
-
- debug_perf_partitime[debug_perf_iend] = ts.tv_nsec - debug_perf_time;
-
- debug_perf_time = ts.tv_nsec;
- #endif
- }
-
- render_after(part_vbuf, vid_buf);
- if(su == WL_GRAV+100)
- draw_grav_zones(part_vbuf);
-
- if(debug_flags & (DEBUG_PERFORMANCE_CALC|DEBUG_PERFORMANCE_FRAME))
- {
- #ifdef WIN32
- #elif defined(MACOSX)
- #else
- struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
-
- debug_perf_frametime[debug_perf_iend] = ts.tv_nsec - debug_perf_time;
- #endif
- debug_perf_iend++;
- debug_perf_iend %= DEBUG_PERF_FRAMECOUNT;
- debug_perf_istart++;
- debug_perf_istart %= DEBUG_PERF_FRAMECOUNT;
- }
-
- gravity_update_async(); //Check for updated velocity maps from gravity thread
- if (!sys_pause||framerender) //Only update if not paused
- memset(gravmap, 0, (XRES/CELL)*(YRES/CELL)*sizeof(float)); //Clear the old gravmap
-
- if (framerender) {
- framerender = 0;
- sys_pause = 1;
- }
-
- memset(vid_buf+((XRES+BARSIZE)*YRES), 0, (PIXELSIZE*(XRES+BARSIZE))*MENUSIZE);//clear menu areas
- clearrect(vid_buf, XRES-1, 0, BARSIZE+1, YRES);
-
- draw_svf_ui(vid_buf, sdl_mod & (KMOD_LCTRL|KMOD_RCTRL));
-
- if(debug_flags)
- {
- draw_debug_info(vid_buf, lm, lx, ly, x, y, line_x, line_y);
- }
-
- if (http_ver_check)
- {
- if (!do_check && http_async_req_status(http_ver_check))
- {
- ver_data = http_async_req_stop(http_ver_check, &http_ret, NULL);
- if (http_ret==200 && ver_data)
- {
- if (sscanf(ver_data, "%d.%d.%d.%d", &major, &minor, &is_beta, &buildnum)==4)
- if (buildnum>BUILD_NUM)
- old_version = 1;
- if (is_beta)
- {
- old_ver_len = textwidth((char*)old_ver_msg_beta);
- }
- else
- {
- old_ver_len = textwidth((char*)old_ver_msg);
- }
- free(ver_data);
- }
- http_ver_check = NULL;
- }
- do_check = (do_check+1) & 15;
- }
- if (saveDataOpen)
- {
- //Clear all settings and simulation data
- clear_sim();
- it=0;
- legacy_enable = 0;
- svf_filename[0] = 0;
- svf_fileopen = 0;
- svf_myvote = 0;
- svf_open = 0;
- svf_publish = 0;
- svf_own = 0;
- svf_id[0] = 0;
- svf_name[0] = 0;
- svf_tags[0] = 0;
- svf_description[0] = 0;
- gravityMode = 0;
- airMode = 0;
-
- svf_last = saveDataOpen;
- svf_lsize = saveDataOpenSize;
- if(parse_save(saveDataOpen, saveDataOpenSize, 1, 0, 0, bmap, fvx, fvy, vx, vy, pv, signs, parts, pmap))
- {
- saveOpenError = 1;
- svf_last = NULL;
- svf_lsize = 0;
- free(saveDataOpen);
- }
- saveDataOpenSize = 0;
- saveDataOpen = NULL;
- }
- if (http_session_check)
- {
- if (!do_s_check && http_async_req_status(http_session_check))
- {
- char saveURIOpenString[512];
- check_data = http_async_req_stop(http_session_check, &http_s_ret, NULL);
- if (http_s_ret==200 && check_data)
- {
- if (!strncmp(check_data, "EXPIRED", 7))
- {
- //Session expired
- printf("EXPIRED");
- strcpy(svf_user, "");
- strcpy(svf_pass, "");
- strcpy(svf_user_id, "");
- strcpy(svf_session_id, "");
- svf_login = 0;
- svf_own = 0;
- svf_admin = 0;
- svf_mod = 0;
- svf_messages = 0;
- }
- else if (!strncmp(check_data, "BANNED", 6))
- {
- //User banned
- printf("BANNED");
- strcpy(svf_user, "");
- strcpy(svf_pass, "");
- strcpy(svf_user_id, "");
- strcpy(svf_session_id, "");
- svf_login = 0;
- svf_own = 0;
- svf_admin = 0;
- svf_mod = 0;
- svf_messages = 0;
- error_ui(vid_buf, 0, "Unable to log in\nYour account has been suspended, consider reading the rules.");
- }
- else if (!strncmp(check_data, "OK", 2))
- {
- //Session valid
- if (strlen(check_data)>2) {
- //User is elevated
- if (!strncmp(check_data+3, "ADMIN", 5))
- {
- //Check for messages
- svf_messages = atoi(check_data+9);
- svf_admin = 1;
- svf_mod = 0;
- }
- else if (!strncmp(check_data+3, "MOD", 3))
- {
- //Check for messages
- svf_messages = atoi(check_data+7);
- svf_admin = 0;
- svf_mod = 1;
- } else {
- //Check for messages
- svf_messages = atoi(check_data+3);
- }
- }
- }
- else
- {
- //No idea, but log the user out anyway
- strcpy(svf_user, "");
- strcpy(svf_pass, "");
- strcpy(svf_user_id, "");
- strcpy(svf_session_id, "");
- svf_login = 0;
- svf_own = 0;
- svf_admin = 0;
- svf_mod = 0;
- svf_messages = 0;
- }
- save_presets(0);
- free(check_data);
- } else {
- //Unable to check session, YOU WILL BE TERMINATED
- strcpy(svf_user, "");
- strcpy(svf_pass, "");
- strcpy(svf_user_id, "");
- strcpy(svf_session_id, "");
- svf_login = 0;
- svf_own = 0;
- svf_admin = 0;
- svf_mod = 0;
- svf_messages = 0;
- }
- http_session_check = NULL;
- if(saveURIOpen)
- {
- sprintf(saveURIOpenString, "%d", saveURIOpen);
- open_ui(vid_buf, saveURIOpenString, NULL);
- saveURIOpen = 0;
- }
- } else {
- if(saveURIOpen)
- info_box_overlay(vid_buf, "Waiting for login...");
- clearrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14);
- drawrect(vid_buf, XRES-125+BARSIZE/*385*/, YRES+(MENUSIZE-16), 91, 14, 255, 255, 255, 255);
- drawtext(vid_buf, XRES-122+BARSIZE/*388*/, YRES+(MENUSIZE-13), "\x84", 255, 255, 255, 255);
- if (username_flash>30) {
- username_flash_t = -1;
- username_flash = 30;
- } else if (username_flash<0) {
- username_flash_t = 1;
- username_flash = 0;
- }
- username_flash += username_flash_t;
- if (svf_login)
- drawtext(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), svf_user, 255, 255, 255, 175-(username_flash*5));
- else
- drawtext(vid_buf, XRES-104+BARSIZE/*406*/, YRES+(MENUSIZE-12), "[checking]", 255, 255, 255, 255);
- }
- do_s_check = (do_s_check+1) & 15;
- }
- else
- {
- char saveURIOpenString[512];
- if(saveURIOpen)
- {
- sprintf(saveURIOpenString, "%d", saveURIOpen);
- open_ui(vid_buf, saveURIOpenString, NULL);
- saveURIOpen = 0;
- }
- }
-#ifdef LUACONSOLE
- if(sdl_key){
- if(!luacon_keyevent(sdl_key, sdl_mod, LUACON_KDOWN))
- sdl_key = 0;
- }
- if(sdl_rkey){
- if(!luacon_keyevent(sdl_rkey, sdl_mod, LUACON_KUP))
- sdl_rkey = 0;
- }
-#endif
- if (sys_shortcuts==1)//all shortcuts can be disabled by python scripts
- {
- stickmen_keys();
- if (sdl_key=='q' || sdl_key==SDLK_ESCAPE)
- {
- if (confirm_ui(vid_buf, "You are about to quit", "Are you sure you want to quit?", "Quit"))
- {
- break;
- }
- }
- if (sdl_key=='i' && (sdl_mod & KMOD_CTRL))
- {
- if(confirm_ui(vid_buf, "Install Powder Toy", "You are about to install The Powder Toy", "Install"))
- {
- if(register_extension())
- {
- info_ui(vid_buf, "Install success", "Powder Toy has been installed!");
- }
- else
- {
- error_ui(vid_buf, 0, "Install failed - You may not have permission or you may be on a platform that does not support installation");
- }
- }
- }
- if (sdl_key=='f')
- {
- framerender = 1;
- }
- if ((sdl_key=='l' || sdl_key=='k') && stamps[0].name[0])
- {
- if (load_mode)
- {
- free(load_img);
- free(load_data);
- load_mode = 0;
- load_data = NULL;
- load_img = NULL;
- }
- if (it > 50)
- it = 50;
- if (sdl_key=='k' && stamps[1].name[0])
- {
- j = stamp_ui(vid_buf);
- if (j>=0)
- load_data = stamp_load(j, &load_size);
- else
- load_data = NULL;
- }
- else
- load_data = stamp_load(0, &load_size);
- if (load_data)
- {
- load_img = prerender_save(load_data, load_size, &load_w, &load_h);
- if (load_img)
- load_mode = 1;
- else
- free(load_data);
- }
- }
- if (sdl_key=='s' && ((sdl_mod & (KMOD_CTRL)) || !player2.spwn))
- {
- if (it > 50)
- it = 50;
- save_mode = 1;
- }
- if(sdl_key=='e')
- {
- element_search_ui(vid_buf, &sl, &sr);
- }
- //TODO: Superseded by new display mode switching, need some keyboard shortcuts
- if (sdl_key=='1')
- {
- set_cmode(CM_VEL);
- }
- if (sdl_key=='2')
- {
- set_cmode(CM_PRESS);
- }
- if (sdl_key=='3')
- {
- set_cmode(CM_PERS);
- }
- if (sdl_key=='4')
- {
- set_cmode(CM_FIRE);
- }
- if (sdl_key=='5')
- {
- set_cmode(CM_BLOB);
- }
- if (sdl_key=='6')
- {
- set_cmode(CM_HEAT);
- }
- if (sdl_key=='7')
- {
- set_cmode(CM_FANCY);
- }
- if (sdl_key=='8')
- {
- set_cmode(CM_NOTHING);
- }
- if (sdl_key=='9')
- {
- set_cmode(CM_GRAD);
- }
- if (sdl_key=='0')
- {
- set_cmode(CM_CRACK);
- }
- if (sdl_key=='1'&& (sdl_mod & (KMOD_SHIFT)) && DEBUG_MODE)
- {
- set_cmode(CM_LIFE);
- }
- if (sdl_key==SDLK_TAB)
- {
- CURRENT_BRUSH =(CURRENT_BRUSH + 1)%BRUSH_NUM ;
- }
- if (sdl_key==SDLK_LEFTBRACKET) {
- if (sdl_zoom_trig)
- {
- ZSIZE -= 1;
- if (ZSIZE>60)
- ZSIZE = 60;
- if (ZSIZE<2)
- ZSIZE = 2;
- ZFACTOR = 256/ZSIZE;
- }
- else
- {
- if (sdl_mod & (KMOD_LALT|KMOD_RALT) && !(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
- {
- bsx -= 1;
- bsy -= 1;
- }
- else if (sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL)))
- {
- bsx -= 1;
- }
- else if (sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT)))
- {
- bsy -= 1;
- }
- else
- {
- bsx -= ceil((bsx/5)+0.5f);
- bsy -= ceil((bsy/5)+0.5f);
- }
- if (bsx>1180)
- bsx = 1180;
- if (bsy>1180)
- bsy = 1180;
- if (bsx<0)
- bsx = 0;
- if (bsy<0)
- bsy = 0;
- }
- }
- if (sdl_key==SDLK_RIGHTBRACKET) {
- if (sdl_zoom_trig)
- {
- ZSIZE += 1;
- if (ZSIZE>60)
- ZSIZE = 60;
- if (ZSIZE<2)
- ZSIZE = 2;
- ZFACTOR = 256/ZSIZE;
- }
- else
- {
- if (sdl_mod & (KMOD_LALT|KMOD_RALT) && !(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
- {
- bsx += 1;
- bsy += 1;
- }
- else if (sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL)))
- {
- bsx += 1;
- }
- else if (sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT)))
- {
- bsy += 1;
- }
- else
- {
- bsx += ceil((bsx/5)+0.5f);
- bsy += ceil((bsy/5)+0.5f);
- }
- if (bsx>1180)
- bsx = 1180;
- if (bsy>1180)
- bsy = 1180;
- if (bsx<0)
- bsx = 0;
- if (bsy<0)
- bsy = 0;
- }
- }
- if (sdl_key=='d' && ((sdl_mod & (KMOD_CTRL)) || !player2.spwn))
- DEBUG_MODE = !DEBUG_MODE;
- if (sdl_key=='i')
- {
- int nx, ny;
- for (nx = 0; nx<XRES/CELL; nx++)
- for (ny = 0; ny<YRES/CELL; ny++)
- {
- pv[ny][nx] = -pv[ny][nx];
- vx[ny][nx] = -vx[ny][nx];
- vy[ny][nx] = -vy[ny][nx];
- }
- }
- if (sdl_key==SDLK_INSERT || sdl_key == SDLK_SEMICOLON)// || sdl_key==SDLK_BACKQUOTE)
- REPLACE_MODE = !REPLACE_MODE;
- if (sdl_key==SDLK_BACKQUOTE)
- {
- console_mode = !console_mode;
- //hud_enable = !console_mode;
- }
- if (sdl_key=='b')
- {
- if (sdl_mod & KMOD_CTRL)
- {
- decorations_enable = !decorations_enable;
- itc = 51;
- if (decorations_enable) strcpy(itc_msg, "Decorations layer: On");
- else strcpy(itc_msg, "Decorations layer: Off");
- }
- else
- {
- decorations_enable = 1;
- rgbSave = decorations_ui(vid_buf,&bsx,&bsy,rgbSave);//decoration_mode = !decoration_mode;
- }
- }
- if (sdl_key=='g')
- {
- if(sdl_mod & (KMOD_CTRL))
- {
- drawgrav_enable =! drawgrav_enable;
- }
- else
- {
- if (sdl_mod & (KMOD_SHIFT))
- GRID_MODE = (GRID_MODE+9)%10;
- else
- GRID_MODE = (GRID_MODE+1)%10;
- }
- }
- if (sdl_key=='m')
- {
- if(sl!=sr)
- {
- sl ^= sr;
- sr ^= sl;
- sl ^= sr;
- }
- dae = 51;
- }
- if (sdl_key=='=')
- {
- int nx, ny;
- if (sdl_mod & (KMOD_CTRL))
- {
- for (i=0; i<NPART; i++)
- if (parts[i].type==PT_SPRK)
- {
- if (parts[i].ctype >= 0 && parts[i].ctype < PT_NUM && ptypes[parts[i].ctype].enabled)
- {
- parts[i].type = parts[i].ctype;
- parts[i].life = 0;
- }
- else
- kill_part(i);
- }
- }
- else
- {
- for (nx = 0; nx<XRES/CELL; nx++)
- for (ny = 0; ny<YRES/CELL; ny++)
- {
- pv[ny][nx] = 0;
- vx[ny][nx] = 0;
- vy[ny][nx] = 0;
- }
- }
- }
-
- if (sdl_key=='w' && (!player2.spwn || (sdl_mod & (KMOD_CTRL)))) //Gravity, by Moach
- {
- ++gravityMode; // cycle gravity mode
- itc = 51;
-
- switch (gravityMode)
- {
- default:
- gravityMode = 0;
- case 0:
- strcpy(itc_msg, "Gravity: Vertical");
- break;
- case 1:
- strcpy(itc_msg, "Gravity: Off");
- break;
- case 2:
- strcpy(itc_msg, "Gravity: Radial");
- break;
-
- }
- }
- if (sdl_key=='y')
- {
- ++airMode;
- itc = 52;
-
- switch (airMode)
- {
- default:
- airMode = 0;
- case 0:
- strcpy(itc_msg, "Air: On");
- break;
- case 1:
- strcpy(itc_msg, "Air: Pressure Off");
- break;
- case 2:
- strcpy(itc_msg, "Air: Velocity Off");
- break;
- case 3:
- strcpy(itc_msg, "Air: Off");
- break;
- case 4:
- strcpy(itc_msg, "Air: No Update");
- break;
- }
- }
-
- if (sdl_key=='t')
- VINE_MODE = !VINE_MODE;
- if (sdl_key==SDLK_SPACE)
- sys_pause = !sys_pause;
- if (sdl_key=='u')
- aheat_enable = !aheat_enable;
- if (sdl_key=='h' && !(sdl_mod & KMOD_LCTRL))
- {
- hud_enable = !hud_enable;
- }
- if (sdl_key==SDLK_F1 || (sdl_key=='h' && (sdl_mod & KMOD_LCTRL)))
- {
- if(!it)
- {
- it = 8047;
- }
- else
- {
- it = 0;
- }
- }
- if (sdl_key=='n')
- pretty_powder = !pretty_powder;
- if (sdl_key=='p')
- dump_frame(vid_buf, XRES, YRES, XRES+BARSIZE);
- if (sdl_key=='v'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))
- {
- if (clipboard_ready==1 && clipboard_data)
- {
- load_data = malloc(clipboard_length);
- memcpy(load_data, clipboard_data, clipboard_length);
- load_size = clipboard_length;
- if (load_data)
- {
- load_img = prerender_save(load_data, load_size, &load_w, &load_h);
- if (load_img)
- load_mode = 1;
- else
- free(load_data);
- }
- }
- }
- if (load_mode==1)
- {
- matrix2d transform = m2d_identity;
- vector2d translate = v2d_zero;
- void *ndata;
- int doTransform = 0;
- if (sdl_key=='r'&&(sdl_mod & (KMOD_CTRL))&&(sdl_mod & (KMOD_SHIFT)))
- {
- transform = m2d_new(-1,0,0,1); //horizontal invert
- doTransform = 1;
- }
- else if (sdl_key=='r'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))
- {
- transform = m2d_new(0,1,-1,0); //rotate anticlockwise 90 degrees
- doTransform = 1;
- }
- else if (sdl_mod & (KMOD_CTRL))
- {
- doTransform = 1;
- if (sdl_key==SDLK_LEFT) translate = v2d_new(-1,0);
- else if (sdl_key==SDLK_RIGHT) translate = v2d_new(1,0);
- else if (sdl_key==SDLK_UP) translate = v2d_new(0,-1);
- else if (sdl_key==SDLK_DOWN) translate = v2d_new(0,1);
- else doTransform = 0;
- }
- if (doTransform)
- {
- ndata = transform_save(load_data, &load_size, transform, translate);
- if (ndata!=load_data) free(load_data);
- free(load_img);
- load_data = ndata;
- load_img = prerender_save(load_data, load_size, &load_w, &load_h);
- }
- }
- if (sdl_key=='r'&&!(sdl_mod & (KMOD_CTRL|KMOD_SHIFT)))
- GENERATION = 0;
- if (sdl_key=='x'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))
- {
- save_mode = 1;
- copy_mode = 2;
- }
- if (sdl_key=='c'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))
- {
- save_mode = 1;
- copy_mode = 1;
- }
- //TODO: Superseded by new display mode switching, need some keyboard shortcuts
- /*else if (sdl_key=='c')
- {
- set_cmode((cmode+1) % CM_COUNT);
- if (it > 50)
- it = 50;
- }*/
- if (sdl_key=='z') // Undo
- {
- if (sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))
- {
- int cbx, cby, cbi;
-
- for (cbi=0; cbi<NPART; cbi++)
- parts[cbi] = cb_parts[cbi];
- parts_lastActiveIndex = NPART-1;
-
- for (cby = 0; cby<YRES; cby++)
- for (cbx = 0; cbx<XRES; cbx++)
- pmap[cby][cbx] = cb_pmap[cby][cbx];
-
- for (cby = 0; cby<(YRES/CELL); cby++)
- for (cbx = 0; cbx<(XRES/CELL); cbx++)
- {
- vx[cby][cbx] = cb_vx[cby][cbx];
- vy[cby][cbx] = cb_vy[cby][cbx];
- pv[cby][cbx] = cb_pv[cby][cbx];
- hv[cby][cbx] = cb_hv[cby][cbx];
- bmap[cby][cbx] = cb_bmap[cby][cbx];
- emap[cby][cbx] = cb_emap[cby][cbx];
- }
-
- force_stacking_check = 1;//check for excessive stacking of particles next time update_particles is run
- }
- else
- {
- if (sdl_mod & KMOD_ALT)//toggle
- sdl_zoom_trig = (!sdl_zoom_trig)*2;
- else
- sdl_zoom_trig = 1;
- }
- }
- if (sdl_rkey == 'z' && sdl_zoom_trig==1)//if ==2 then it was toggled with alt+z, don't turn off on keyup
- sdl_zoom_trig = 0;
- }
-#ifdef INTERNAL
- int counterthing;
- if (sdl_key=='v'&&!(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)))//frame capture
- {
- if (sdl_mod & (KMOD_SHIFT)) {
- if (vs>=1)
- vs = 0;
- else
- vs = 3;//every other frame
- }
- else
- {
- if (vs>=1)
- vs = 0;
- else
- vs = 1;
- }
- counterthing = 0;
- }
- if (vs)
- {
- if (counterthing+1>=vs)
- {
- dump_frame(vid_buf, XRES, YRES, XRES+BARSIZE);
- counterthing = 0;
- }
- counterthing = (counterthing+1)%3;
- }
-#endif
-
- if (sdl_wheel)
- {
- if (sdl_zoom_trig)//zoom window change
- {
- ZSIZE += sdl_wheel;
- if (ZSIZE>60)
- ZSIZE = 60;
- if (ZSIZE<2)
- ZSIZE = 2;
- ZFACTOR = 256/ZSIZE;
- //sdl_wheel = 0;
- }
- else //change brush size
- {
- if (!(sdl_mod & (KMOD_SHIFT|KMOD_CTRL)))
- {
- bsx += sdl_wheel;
- bsy += sdl_wheel;
- }
- else if (sdl_mod & (KMOD_SHIFT) && !(sdl_mod & (KMOD_CTRL)))
- {
- bsx += sdl_wheel;
- }
- else if (sdl_mod & (KMOD_CTRL) && !(sdl_mod & (KMOD_SHIFT)))
- {
- bsy += sdl_wheel;
- }
- if (bsx>1180)
- bsx = 1180;
- if (bsx<0)
- bsx = 0;
- if (bsy>1180)
- bsy = 1180;
- if (bsy<0)
- bsy = 0;
- //sdl_wheel = 0;
- /*if(su >= PT_NUM) {
- if(sl < PT_NUM)
- su = sl;
- if(sr < PT_NUM)
- su = sr;
- }*/
- }
- }
-
- bq = bc; // bq is previous mouse state
- bc = b = mouse_get_state(&x, &y); // b is current mouse state
-
-#ifdef LUACONSOLE
- if(bc && bq){
- if(!luacon_mouseevent(x, y, bc, LUACON_MPRESS, sdl_wheel)){
- b = 0;
- }
- }
- else if(bc && !bq){
- if(!luacon_mouseevent(x, y, bc, LUACON_MDOWN, sdl_wheel)){
- b = 0;
- }
- }
- else if(!bc && bq){
- if(!luacon_mouseevent(x, y, bq, LUACON_MUP, sdl_wheel)){
- b = 0;
- }
- }
- else if (sdl_wheel){
- luacon_mouseevent(x, y, bq, 0, sdl_wheel);
- }
-
- luacon_step(x, y,sl,sr,bsx,bsy);
-#endif
- sdl_wheel = 0;
- quickoptions_menu(vid_buf, b, bq, x, y);
-
- for (i=0; i<SC_TOTAL; i++)//draw all the menu sections
- {
- draw_menu(vid_buf, i, active_menu);
- }
-
- for (i=0; i<SC_TOTAL; i++)//check mouse position to see if it is on a menu section
- {
- if (!b&&x>=(XRES-2) && x<(XRES+BARSIZE-1) &&y>= ((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)) && y<((i*16)+YRES+MENUSIZE-16-(SC_TOTAL*16)+15))
- {
- active_menu = i;
- }
- }
- menu_ui_v3(vid_buf, active_menu, &sl, &sr, &su, &dae, b, bq, x, y); //draw the elements in the current menu
- mouse_coords_window_to_sim(&x, &y, x, y);//change mouse position while it is in a zoom window
- if (y>=0 && y<YRES && x>=0 && x<XRES)
- {
- int cr; //cr is particle under mouse, for drawing HUD information
- char nametext[50];
- if (photons[y][x]) {
- cr = photons[y][x];
- } else {
- cr = pmap[y][x];
- }
- if (cr)
- {
- if ((cr&0xFF)==PT_LIFE && parts[cr>>8].ctype>=0 && parts[cr>>8].ctype<NGOLALT)
- {
- sprintf(nametext, "%s (%s)", ptypes[cr&0xFF].name, gmenu[parts[cr>>8].ctype].name);
- }
- else if ((cr&0xFF)==PT_LAVA && parts[cr>>8].ctype > 0 && parts[cr>>8].ctype < PT_NUM )
- {
- char lowername[6];
- int ix;
- strcpy(lowername, ptypes[parts[cr>>8].ctype].name);
- for (ix = 0; lowername[ix]; ix++)
- lowername[ix] = tolower(lowername[ix]);
-
- sprintf(nametext, "Molten %s", lowername);
- }
- else if (((cr&0xFF)==PT_PIPE || (cr&0xFF) == PT_PPIP) && (parts[cr>>8].tmp&0xFF) > 0 && (parts[cr>>8].tmp&0xFF) < PT_NUM )
- {
- char lowername[6];
- int ix;
- strcpy(lowername, ptypes[parts[cr>>8].tmp&0xFF].name);
- for (ix = 0; lowername[ix]; ix++)
- lowername[ix] = tolower(lowername[ix]);
-
- sprintf(nametext, "Pipe with %s", lowername);
- }
- else if (DEBUG_MODE)
- {
- int tctype = parts[cr>>8].ctype;
- if ((cr&0xFF)==PT_PIPE || (cr&0xFF) == PT_PPIP)
- {
- tctype = parts[cr>>8].tmp&0xFF;
- }
- if (tctype>=PT_NUM || tctype<0 || (cr&0xFF)==PT_PHOT)
- tctype = 0;
- sprintf(nametext, "%s (%s)", ptypes[cr&0xFF].name, ptypes[tctype].name);
- }
- else
- {
- strcpy(nametext, ptypes[cr&0xFF].name);
- }
- if (DEBUG_MODE)
- {
- sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C, Life: %d, Tmp:%d", nametext, pv[y/CELL][x/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life, parts[cr>>8].tmp);
- sprintf(coordtext, "#%d, X:%d Y:%d", cr>>8, x, y);
- }
- else
- {
-#ifdef BETA
- sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C, Life: %d, Tmp:%d", nametext, pv[y/CELL][x/CELL], parts[cr>>8].temp-273.15f, parts[cr>>8].life, parts[cr>>8].tmp);
-#else
- sprintf(heattext, "%s, Pressure: %3.2f, Temp: %4.2f C", nametext, pv[y/CELL][x/CELL], parts[cr>>8].temp-273.15f);
-#endif
- }
- if ((cr&0xFF)==PT_PHOT) wavelength_gfx = parts[cr>>8].ctype;
- }
- else
- {
- sprintf(heattext, "Empty, Pressure: %3.2f", pv[y/CELL][x/CELL]);
- if (DEBUG_MODE)
- {
- if (ngrav_enable)
- sprintf(coordtext, "X:%d Y:%d. GX: %.2f GY: %.2f", x, y, gravx[((y/CELL)*(XRES/CELL))+(x/CELL)], gravy[((y/CELL)*(XRES/CELL))+(x/CELL)]);
- else
- sprintf(coordtext, "X:%d Y:%d", x, y);
- }
- }
- }
-
-
- mx = x;
- my = y;
- if (b && !bq && x>=(XRES-19-new_message_len) &&
- x<=(XRES-14) && y>=(YRES-37) && y<=(YRES-24) && svf_messages)
- {
- open_link("http://" SERVER "/Conversations.html");
- }
- if (update_flag)
- {
- info_box(vid_buf, "Finalizing update...");
- if (last_build>BUILD_NUM)
- {
- update_cleanup();
- error_ui(vid_buf, 0, "Update failed - try downloading a new version.");
- }
- else
- {
- if (update_finish())
- error_ui(vid_buf, 0, "Update failed - try downloading a new version.");
- else
- info_ui(vid_buf, "Update success", "You have successfully updated the Powder Toy!");
- }
- update_flag = 0;
- }
-
- if (b && !bq && x>=(XRES-19-old_ver_len) &&
- x<=(XRES-14) && y>=(YRES-22) && y<=(YRES-9) && old_version)
- {
- tmp = malloc(128);
-#ifdef BETA
- if (is_beta)
- {
- sprintf(tmp, "Your version: %d.%d Beta (%d)\nNew version: %d.%d Beta (%d)", SAVE_VERSION, MINOR_VERSION, BUILD_NUM, major, minor, buildnum);
- }
- else
- {
- sprintf(tmp, "Your version: %d.%d Beta (%d)\nNew version: %d.%d (%d)", SAVE_VERSION, MINOR_VERSION, BUILD_NUM, major, minor, buildnum);
- }
-#else
- if (is_beta)
- {
- sprintf(tmp, "Your version: %d.%d (%d)\nNew version: %d.%d Beta (%d)", SAVE_VERSION, MINOR_VERSION, BUILD_NUM, major, minor, buildnum);
- }
- else
- {
- sprintf(tmp, "Your version: %d.%d (%d)\nNew version: %d.%d (%d)", SAVE_VERSION, MINOR_VERSION, BUILD_NUM, major, minor, buildnum);
- }
-#endif
- if (confirm_ui(vid_buf, "Do you want to update The Powder Toy?", tmp, "Update"))
- {
- free(tmp);
- tmp = download_ui(vid_buf, my_uri, &i);
- if (tmp)
- {
- save_presets(1);
- if (update_start(tmp, i))
- {
- update_cleanup();
- save_presets(0);
- error_ui(vid_buf, 0, "Update failed - try downloading a new version.");
- }
- else
- return 0;
- }
- }
- else
- {
- free(tmp);
- old_version = 0;
- }
- }
- if (y>=(YRES+(MENUSIZE-20))) //mouse checks for buttons at the bottom, to draw mouseover texts
- {
- if (x>=189 && x<=202 && svf_login && svf_open && svf_myvote==0)
- {
- db = svf_own ? 275 : 272;
- if (da < 51)
- da ++;
- }
- else if (x>=204 && x<=217 && svf_login && svf_open && svf_myvote==0)
- {
- db = svf_own ? 275 : 272;
- if (da < 51)
- da ++;
- }
- else if (x>=189 && x<=217 && svf_login && svf_open && svf_myvote!=0)
- {
- db = (svf_myvote==1) ? 273 : 274;
- if (da < 51)
- da ++;
- }
- else if (x>=219 && x<=((XRES+BARSIZE-(510-349))) && svf_login && svf_open)
- {
- db = svf_own ? 257 : 256;
- if (da < 51)
- da ++;
- }
- else if (x>=((XRES+BARSIZE-(510-351))) && x<((XRES+BARSIZE-(510-366))))
- {
- db = 270;
- if (da < 51)
- da ++;
- }
- else if (x>=((XRES+BARSIZE-(510-367))) && x<((XRES+BARSIZE-(510-383))))
- {
- db = 266;
- if (da < 51)
- da ++;
- }
- else if (x>=37 && x<=187)
- {
- if(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))
- {
- db = 277;
- if (da < 51)
- da ++;
- }
- else if(svf_login)
- {
- db = 259;
- if (svf_open && svf_own && x<=55)
- db = 258;
- if (da < 51)
- da ++;
- }
- }
- else if (x>=((XRES+BARSIZE-(510-385))) && x<=((XRES+BARSIZE-(510-476))))
- {
- db = svf_login ? 261 : 260;
- if (svf_admin)
- {
- db = 268;
- }
- else if (svf_mod)
- {
- db = 271;
- }
- if (da < 51)
- da ++;
- }
- else if (x>=1 && x<=17)
- {
- if(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))
- db = 276;
- else
- db = 262;
- if (da < 51)
- da ++;
- }
- else if (x>=((XRES+BARSIZE-(510-494))) && x<=((XRES+BARSIZE-(510-509))))
- {
- db = sys_pause ? 264 : 263;
- if (da < 51)
- da ++;
- }
- else if (x>=((XRES+BARSIZE-(510-476))) && x<=((XRES+BARSIZE-(510-491))))
- {
- db = 267;
- if (da < 51)
- da ++;
- }
- else if (x>=19 && x<=35 && svf_open)
- {
- db = 265;
- if (da < 51)
- da ++;
- }
- else if (da > 0)
- da --;
- }
- else if (da > 0)//fade away mouseover text
- da --;
-
- if (dae > 0) //Fade away selected elements
- dae --;
-
- if (!sdl_zoom_trig && zoom_en==1)
- zoom_en = 0;
-
- if (sdl_key=='z' && !(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) && zoom_en==2 && sys_shortcuts==1)
- zoom_en = 1;
-
- if (load_mode)
- {
- load_x = CELL*((mx-load_w/2+CELL/2)/CELL);
- load_y = CELL*((my-load_h/2+CELL/2)/CELL);
- if (load_x+load_w>XRES) load_x=XRES-load_w;
- if (load_y+load_h>YRES) load_y=YRES-load_h;
- if (load_x<0) load_x=0;
- if (load_y<0) load_y=0;
- if (bq==1 && !b)
- {
- parse_save(load_data, load_size, 0, load_x, load_y, bmap, vx, vy, pv, fvx, fvy, signs, parts, pmap);
- free(load_data);
- free(load_img);
- load_mode = 0;
- }
- else if (bq==4 && !b)
- {
- free(load_data);
- free(load_img);
- load_mode = 0;
- }
- }
- else if (save_mode==1)//getting the area you are selecting
- {
- save_x = mx;
- save_y = my;
- if (save_x >= XRES) save_x = XRES-1;
- if (save_y >= YRES) save_y = YRES-1;
- save_w = 1;
- save_h = 1;
- if (b==1)
- {
- save_mode = 2;
- }
- else if (b==4)
- {
- save_mode = 0;
- copy_mode = 0;
- }
- }
- else if (save_mode==2)
- {
- save_w = mx + 1 - save_x;
- save_h = my + 1 - save_y;
- if (save_w+save_x>XRES) save_w = XRES-save_x;
- if (save_h+save_y>YRES) save_h = YRES-save_y;
- if (save_w+save_x<0) save_w = 0;
- if (save_h+save_y<0) save_h = 0;
- //if (save_w<1) save_w = 1;
- //if (save_h<1) save_h = 1;
- if (!b)
- {
- if (save_w < 0)
- {
- save_x = save_x + save_w - 1;
- save_w = abs(save_w) + 2;
- }
- if (save_h < 0)
- {
- save_y = save_y + save_h - 1;
- save_h = abs(save_h) + 2;
- }
- if (save_h > 0 && save_w > 0)
- {
- if (copy_mode==1)//CTRL-C, copy
- {
- clipboard_data=build_save(&clipboard_length, save_x, save_y, save_w, save_h, bmap, vx, vy, pv, fvx, fvy, signs, parts);
- if (clipboard_data)
- clipboard_ready = 1;
- }
- else if (copy_mode==2)//CTRL-X, cut
- {
- clipboard_data=build_save(&clipboard_length, save_x, save_y, save_w, save_h, bmap, vx, vy, pv, fvx, fvy, signs, parts);
- if (clipboard_data)
- {
- clipboard_ready = 1;
- clear_area(save_x, save_y, save_w, save_h);
- }
- }
- else//normal save
- {
- stamp_save(save_x, save_y, save_w, save_h);
- }
- }
- copy_mode = 0;
- save_mode = 0;
- }
- }
- else if (sdl_zoom_trig && zoom_en<2)
- {
- x -= ZSIZE/2;
- y -= ZSIZE/2;
- if (x<0) x=0;
- if (y<0) y=0;
- if (x>XRES-ZSIZE) x=XRES-ZSIZE;
- if (y>YRES-ZSIZE) y=YRES-ZSIZE;
- zoom_x = x;
- zoom_y = y;
- zoom_wx = (x<XRES/2) ? XRES-ZSIZE*ZFACTOR : 0;
- zoom_wy = 0;
- zoom_en = 1;
- if (!b && bq)
- {
- zoom_en = 2;
- sdl_zoom_trig = 0;
- }
- }
- else if (b)//there is a click
- {
- if (it > 50)
- it = 50;
- if (y>=YRES+(MENUSIZE-20))//check if mouse is on menu buttons
- {
- if (!lb)//mouse is NOT held down, so it is a first click
- {
- if (x>=189 && x<=202 && svf_login && svf_open && svf_myvote==0 && svf_own==0)
- {
- if (execute_vote(vid_buf, svf_id, "Up"))
- {
- svf_myvote = 1;
- }
- }
- if (x>=204 && x<=217 && svf_login && svf_open && svf_myvote==0 && svf_own==0)
- {
- if (execute_vote(vid_buf, svf_id, "Down"))
- {
- svf_myvote = -1;
- }
- }
- if (x>=219 && x<=(XRES+BARSIZE-(510-349)) && svf_login && svf_open)
- tag_list_ui(vid_buf);
- if (x>=(XRES+BARSIZE-(510-351)) && x<(XRES+BARSIZE-(510-366)) && !bq)
- {
- //legacy_enable = !legacy_enable;
- simulation_ui(vid_buf);
- }
- if (x>=(XRES+BARSIZE-(510-367)) && x<=(XRES+BARSIZE-(510-383)) && !bq)
- {
- clear_sim();
- for (i=0; i<NPART-1; i++)
- parts[i].life = i+1;
- parts[NPART-1].life = -1;
- pfree = 0;
-
- legacy_enable = 0;
- svf_filename[0] = 0;
- svf_fileopen = 0;
- svf_myvote = 0;
- svf_open = 0;
- svf_publish = 0;
- svf_own = 0;
- svf_id[0] = 0;
- svf_name[0] = 0;
- svf_tags[0] = 0;
- svf_description[0] = 0;
- gravityMode = 0;
- airMode = 0;
- svf_last = NULL;
- svf_lsize = 0;
- }
- if (x>=(XRES+BARSIZE-(510-385)) && x<=(XRES+BARSIZE-(510-476)))
- {
- login_ui(vid_buf);
- if (svf_login) {
- save_presets(0);
- http_session_check = NULL;
- }
- }
- if(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))
- {
- if (x>=37 && x<=187)
- {
- save_filename_ui(vid_buf);
-
- }
- if (x>=1 && x<=17)
- {
- catalogue_ui(vid_buf);
- }
- } else {
- if (x>=37 && x<=187 && svf_login)
- {
- if (!svf_open || !svf_own || x>51)
- {
- if (save_name_ui(vid_buf)) {
- execute_save(vid_buf);
- if (svf_id[0]) {
- copytext_ui(vid_buf, "Save ID", "Saved successfully!", svf_id);
- }
- }
- }
- else
- execute_save(vid_buf);
- while (!sdl_poll())
- if (!mouse_get_state(&x, &y))
- break;
- b = bq = 0;
- }
- if (x>=1 && x<=17)
- {
- search_ui(vid_buf);
- memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE);
- memset(fire_r, 0, sizeof(fire_r));
- memset(fire_g, 0, sizeof(fire_g));
- memset(fire_b, 0, sizeof(fire_b));
- }
- }
- if (x>=19 && x<=35 && svf_last && !bq) {
- //int tpval = sys_pause;
- if (b == 1 || !strncmp(svf_id,"",8))
- parse_save(svf_last, svf_lsize, 1, 0, 0, bmap, vx, vy, pv, fvx, fvy, signs, parts, pmap);
- else
- open_ui(vid_buf, svf_id, NULL);
- //sys_pause = tpval;
- }
- if (x>=(XRES+BARSIZE-(510-476)) && x<=(XRES+BARSIZE-(510-491)) && !bq)
- {
- render_ui(vid_buf, XRES+BARSIZE-(510-491)+1, YRES+22, 3);
- }
- if (x>=(XRES+BARSIZE-(510-494)) && x<=(XRES+BARSIZE-(510-509)) && !bq)
- sys_pause = !sys_pause;
- lb = 0;
- }
- }
- else if (y<YRES && x<XRES)// mouse is in playing field
- {
- int signi;
-
- c = (b&1) ? sl : sr; //c is element to be spawned
- su = c;
-
- if (c!=WL_SIGN+100 && c!=PT_FIGH)
- {
- if (!bq)
- for (signi=0; signi<MAXSIGNS; signi++)
- if (sregexp(signs[signi].text, "^{c:[0-9]*|.*}$")==0)
- {
- int signx, signy, signw, signh;
- get_sign_pos(signi, &signx, &signy, &signw, &signh);
- if (x>=signx && x<=signx+signw && y>=signy && y<=signy+signh)
- {
- char buff[256];
- int sldr;
-
- memset(buff, 0, sizeof(buff));
-
- for (sldr=3; signs[signi].text[sldr] != '|'; sldr++)
- buff[sldr-3] = signs[signi].text[sldr];
-
- buff[sldr-3] = '\0';
- open_ui(vid_buf, buff, 0);
- break;
- }
- }
- }
-
- if (c==WL_SIGN+100 || MSIGN!=-1) // if sign tool is selected or a sign is being moved
- {
- if (!bq)
- add_sign_ui(vid_buf, x, y);
- }
- else if (c==PT_FIGH)
- {
- if (!bq)
- create_part(-1, x, y, PT_FIGH);
- }
- //for the click functions, lx and ly, are the positions of where the FIRST click happened. x,y are current mouse position.
- else if (lb)//lb means you are holding mouse down
- {
- if (lm == 1)//line tool
- {
- if (sdl_mod & KMOD_ALT)
- {
- float snap_angle = floor(atan2(y-ly, x-lx)/(M_PI*0.25)+0.5)*M_PI*0.25;
- float line_mag = sqrtf(pow(x-lx,2)+pow(y-ly,2));
- line_x = (int)(line_mag*cos(snap_angle)+lx+0.5f);
- line_y = (int)(line_mag*sin(snap_angle)+ly+0.5f);
- }
- else
- {
- line_x = x;
- line_y = y;
- }
- xor_line(lx, ly, line_x, line_y, vid_buf);
- if (c==WL_FAN+100 && lx>=0 && ly>=0 && lx<XRES && ly<YRES && bmap[ly/CELL][lx/CELL]==WL_FAN)
- {
- nfvx = (line_x-lx)*0.005f;
- nfvy = (line_y-ly)*0.005f;
- flood_parts(lx, ly, WL_FANHELPER, -1, WL_FAN, 0);
- for (j=0; j<YRES/CELL; j++)
- for (i=0; i<XRES/CELL; i++)
- if (bmap[j][i] == WL_FANHELPER)
- {
- fvx[j][i] = nfvx;
- fvy[j][i] = nfvy;
- bmap[j][i] = WL_FAN;
- }
- }
- if (c == SPC_WIND)
- {
- for (j=-bsy; j<=bsy; j++)
- for (i=-bsx; i<=bsx; i++)
- if (lx+i>0 && ly+j>0 && lx+i<XRES && ly+j<YRES && InCurrentBrush(i,j,bsx,bsy))
- {
- vx[(ly+j)/CELL][(lx+i)/CELL] += (line_x-lx)*0.002f;
- vy[(ly+j)/CELL][(lx+i)/CELL] += (line_y-ly)*0.002f;
- }
- }
- }
- else if (lm == 2)//box tool
- {
- xor_line(lx, ly, lx, y, vid_buf);
- xor_line(lx, y, x, y, vid_buf);
- xor_line(x, y, x, ly, vid_buf);
- xor_line(x, ly, lx, ly, vid_buf);
- }
- else//while mouse is held down, it draws lines between previous and current positions
- {
- if (c == SPC_WIND)
- {
- for (j=-bsy; j<=bsy; j++)
- for (i=-bsx; i<=bsx; i++)
- if (x+i>0 && y+j>0 && x+i<XRES && y+j<YRES && InCurrentBrush(i,j,bsx,bsy))
- {
- vx[(y+j)/CELL][(x+i)/CELL] += (x-lx)*0.01f;
- vy[(y+j)/CELL][(x+i)/CELL] += (y-ly)*0.01f;
- }
- }
- else
- {
- create_line(lx, ly, x, y, bsx, bsy, c, get_brush_flags());
- }
- lx = x;
- ly = y;
- }
- }
- else //it is the first click
- {
- //start line tool
- if ((sdl_mod & (KMOD_SHIFT)) && !(sdl_mod & (KMOD_CTRL)))
- {
- lx = x;
- ly = y;
- lb = b;
- lm = 1;//line
- }
- //start box tool
- else if ((sdl_mod & (KMOD_CTRL)) && !(sdl_mod & (KMOD_SHIFT|KMOD_ALT)))
- {
- lx = x;
- ly = y;
- lb = b;
- lm = 2;//box
- }
- //flood fill
- else if ((sdl_mod & (KMOD_CTRL)) && (sdl_mod & (KMOD_SHIFT)) && !(sdl_mod & (KMOD_ALT)))
- {
- if (sdl_mod & (KMOD_CAPS))
- c = 0;
- if (c!=WL_STREAM+100&&c!=SPC_AIR&&c!=SPC_HEAT&&c!=SPC_COOL&&c!=SPC_VACUUM&&!REPLACE_MODE&&c!=SPC_WIND&&c!=SPC_PGRV&&c!=SPC_NGRV)
- flood_parts(x, y, c, -1, -1, get_brush_flags());
- if (c==SPC_HEAT || c==SPC_COOL)
- create_parts(x, y, bsx, bsy, c, get_brush_flags(), 1);
- lx = x;
- ly = y;
- lb = 0;
- lm = 0;
- }
- //sample
- else if (((sdl_mod & (KMOD_ALT)) && !(sdl_mod & (KMOD_SHIFT|KMOD_CTRL))) || b==SDL_BUTTON_MIDDLE)
- {
- if (y>=0 && y<YRES && x>=0 && x<XRES)
- {
- int cr;
- cr = pmap[y][x];
- if (!cr)
- cr = photons[y][x];
- if (cr)
- {
- c = sl = cr&0xFF;
- if (c==PT_LIFE)
- c = sl = (parts[cr>>8].ctype << 8) | c;
- }
- else
- {
- //Something
- }
- }
- lx = x;
- ly = y;
- lb = 0;
- lm = 0;
- }
- else //normal click, spawn element
- {
- //Copy state before drawing any particles (for undo)7
- int cbx, cby, cbi;
-
- for (cbi=0; cbi<NPART; cbi++)
- cb_parts[cbi] = parts[cbi];
-
- for (cby = 0; cby<YRES; cby++)
- for (cbx = 0; cbx<XRES; cbx++)
- cb_pmap[cby][cbx] = pmap[cby][cbx];
-
- for (cby = 0; cby<(YRES/CELL); cby++)
- for (cbx = 0; cbx<(XRES/CELL); cbx++)
- {
- cb_vx[cby][cbx] = vx[cby][cbx];
- cb_vy[cby][cbx] = vy[cby][cbx];
- cb_pv[cby][cbx] = pv[cby][cbx];
- cb_hv[cby][cbx] = hv[cby][cbx];
- cb_bmap[cby][cbx] = bmap[cby][cbx];
- cb_emap[cby][cbx] = emap[cby][cbx];
- }
- create_parts(x, y, bsx, bsy, c, get_brush_flags(), 1);
- lx = x;
- ly = y;
- lb = b;
- lm = 0;
- }
- }
- }
- }
- else
- {
- if (lb && lm) //lm is box/line tool
- {
- c = (lb&1) ? sl : sr;
- su = c;
- if (lm == 1)//line
- {
- if (c!=WL_FAN+100 || lx<0 || ly<0 || lx>=XRES || ly>=YRES || bmap[ly/CELL][lx/CELL]!=WL_FAN)
- create_line(lx, ly, line_x, line_y, bsx, bsy, c, get_brush_flags());
- }
- else//box
- create_box(lx, ly, x, y, c, get_brush_flags());
- lm = 0;
- }
- lb = 0;
- }
-
- if (load_mode)//draw preview of stamp
- {
- draw_image(vid_buf, load_img, load_x, load_y, load_w, load_h, 128);
- xor_rect(vid_buf, load_x, load_y, load_w, load_h);
- }
-
- if (save_mode)//draw dotted lines for selection
- {
- int savex = save_x, savey = save_y, savew = save_w, saveh = save_h;
- if (savew < 0)
- {
- savex = savex + savew - 1;
- savew = abs(savew) + 2;
- }
- if (saveh < 0)
- {
- savey = savey + saveh - 1;
- saveh = abs(saveh) + 2;
- }
- xor_rect(vid_buf, savex, savey, savew, saveh);
- da = 51;//draws mouseover text for the message
- if (copy_mode != 2)
- db = 269;//the save message
- else
- db = 278;
- }
-
- if (zoom_en!=1 && !load_mode && !save_mode)//draw normal cursor
- {
- render_cursor(vid_buf, mx, my, su, bsx, bsy);
- mousex = mx;
- mousey = my;
- }
-#ifdef OGLR
- draw_parts_fbo();
-#endif
- if (zoom_en)
- render_zoom(vid_buf);
-
- if (da)
- switch (db)//various mouseover messages, da is the alpha
- {
- case 256:
- drawtext(vid_buf, 16, YRES-24, "Add simulation tags.", 255, 255, 255, da*5);
- break;
- case 257:
- drawtext(vid_buf, 16, YRES-24, "Add and remove simulation tags.", 255, 255, 255, da*5);
- break;
- case 258:
- drawtext(vid_buf, 16, YRES-24, "Save the simulation under the current name.", 255, 255, 255, da*5);
- break;
- case 259:
- drawtext(vid_buf, 16, YRES-24, "Save the simulation under a new name.", 255, 255, 255, da*5);
- break;
- case 260:
- drawtext(vid_buf, 16, YRES-24, "Sign into the Simulation Server.", 255, 255, 255, da*5);
- break;
- case 261:
- drawtext(vid_buf, 16, YRES-24, "Sign into the Simulation Server under a new name.", 255, 255, 255, da*5);
- break;
- case 262:
- drawtext(vid_buf, 16, YRES-24, "Find & open a simulation", 255, 255, 255, da*5);
- break;
- case 263:
- drawtext(vid_buf, 16, YRES-24, "Pause the simulation", 255, 255, 255, da*5);
- break;
- case 264:
- drawtext(vid_buf, 16, YRES-24, "Resume the simulation", 255, 255, 255, da*5);
- break;
- case 265:
- drawtext(vid_buf, 16, YRES-24, "Reload the simulation", 255, 255, 255, da*5);
- break;
- case 266:
- drawtext(vid_buf, 16, YRES-24, "Erase all particles and walls", 255, 255, 255, da*5);
- break;
- case 267:
- drawtext(vid_buf, 16, YRES-24, "Change display mode", 255, 255, 255, da*5);
- break;
- case 268:
- drawtext(vid_buf, 16, YRES-24, "Annuit C\245ptis", 255, 255, 255, da*5);
- break;
- case 269:
- drawtext(vid_buf, 16, YRES-24, "Click-and-drag to specify a rectangle to copy (right click = cancel).", 255, 216, 32, da*5);
- break;
- case 270:
- drawtext(vid_buf, 16, YRES-24, "Simulation options", 255, 255, 255, da*5);
- break;
- case 271:
- drawtext(vid_buf, 16, YRES-24, "You're a moderator", 255, 255, 255, da*5);
- break;
- case 272:
- drawtext(vid_buf, 16, YRES-24, "Like/Dislike this save.", 255, 255, 255, da*5);
- break;
- case 273:
- drawtext(vid_buf, 16, YRES-24, "You like this.", 255, 255, 255, da*5);
- break;
- case 274:
- drawtext(vid_buf, 16, YRES-24, "You dislike this.", 255, 255, 255, da*5);
- break;
- case 275:
- drawtext(vid_buf, 16, YRES-24, "You cannot vote on your own save.", 255, 255, 255, da*5);
- break;
- case 276:
- drawtext(vid_buf, 16, YRES-24, "Open a simulation from your hard drive.", 255, 255, 255, da*5);
- break;
- case 277:
- drawtext(vid_buf, 16, YRES-24, "Save the simulation to your hard drive.", 255, 255, 255, da*5);
- break;
- case 278: //Fix for Ctrl + X showing copy message
- drawtext(vid_buf, 16, YRES-24, "Click-and-drag to specify a rectangle to copy and then cut (right click = cancel).", 255, 216, 32, da*5);
- break;
- default:
- drawtext(vid_buf, 16, YRES-24, (char *)ptypes[db].descs, 255, 255, 255, da*5);
- }
- if (itc)//message in the middle of the screen, such as view mode changes
- {
- itc--;
- drawtext_outline(vid_buf, (XRES-textwidth(itc_msg))/2, ((YRES/2)-10), itc_msg, 255, 255, 255, itc>51?255:itc*5, 0, 0, 0, itc>51?255:itc*5);
- }
- if (it)//intro message
- {
- it--;
- drawtext(vid_buf, 16, 20, it_msg, 255, 255, 255, it>51?255:it*5);
- }
-
- if (old_version)
- {
- clearrect(vid_buf, XRES-21-old_ver_len, YRES-24, old_ver_len+9, 17);
- if (is_beta)
- {
- drawtext(vid_buf, XRES-16-old_ver_len, YRES-19, old_ver_msg_beta, 255, 216, 32, 255);
- }
- else
- {
- drawtext(vid_buf, XRES-16-old_ver_len, YRES-19, old_ver_msg, 255, 216, 32, 255);
- }
- drawrect(vid_buf, XRES-19-old_ver_len, YRES-22, old_ver_len+5, 13, 255, 216, 32, 255);
- }
-
- if (svf_messages)
- {
- sprintf(new_message_msg, "You have %d new message%s, Click to view", svf_messages, (svf_messages>1)?"s":"");
- new_message_len = textwidth(new_message_msg);
-
- clearrect(vid_buf, XRES-21-new_message_len, YRES-39, new_message_len+9, 17);
- drawtext(vid_buf, XRES-16-new_message_len, YRES-34, new_message_msg, 255, 186, 32, 255);
- drawrect(vid_buf, XRES-19-new_message_len, YRES-37, new_message_len+5, 13, 255, 186, 32, 255);
- }
-
- FPS++;
- currentTime = SDL_GetTicks();
- elapsedTime = currentTime-pastFPS;
- if ((FPS>2 || elapsedTime>1000*2/limitFPS) && elapsedTime && FPS*1000/elapsedTime>limitFPS)
- {
- while (FPS*1000/elapsedTime>limitFPS)
- {
- SDL_Delay(1);
- currentTime = SDL_GetTicks();
- elapsedTime = currentTime-pastFPS;
- }
- }
- if (elapsedTime>=1000)
- {
- FPSB = FPS;
- FPS = 0;
- pastFPS = currentTime;
- }
-
- if (hud_enable)
- {
-#ifdef BETA
- sprintf(uitext, "Beta Build %d FPS:%d Parts:%d Gravity:%d Air:%d", BUILD_NUM, FPSB, NUM_PARTS, gravityMode, airMode);
-#else
- if (DEBUG_MODE)
- sprintf(uitext, "Build %d FPS:%d Parts:%d Gravity:%d Air:%d", BUILD_NUM, FPSB, NUM_PARTS, gravityMode, airMode);
- else
- sprintf(uitext, "FPS:%d", FPSB);
-#endif
- if (REPLACE_MODE)
- strappend(uitext, " [REPLACE MODE]");
- if (sdl_mod&(KMOD_CAPS))
- strappend(uitext, " [CAPS LOCK]");
- if (GRID_MODE)
- {
- char gridtext[15];
- sprintf(gridtext, " [GRID: %d]", GRID_MODE);
- strappend(uitext, gridtext);
- }
-#ifdef INTERNAL
- if (vs)
- strappend(uitext, " [FRAME CAPTURE]");
-#endif
- quickoptions_tooltip_fade_invert = 255 - (quickoptions_tooltip_fade*20);
- it_invert = 50 - it;
- if(it_invert < 0)
- it_invert = 0;
- if(it_invert > 50)
- it_invert = 50;
- if (sdl_zoom_trig||zoom_en)
- {
- if (zoom_x<XRES/2)
- {
- fillrect(vid_buf, XRES-20-textwidth(heattext), 266, textwidth(heattext)+8, 15, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
- drawtext(vid_buf, XRES-16-textwidth(heattext), 270, heattext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
- if (DEBUG_MODE)
- {
- fillrect(vid_buf, XRES-20-textwidth(coordtext), 280, textwidth(coordtext)+8, 13, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
- drawtext(vid_buf, XRES-16-textwidth(coordtext), 282, coordtext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
- }
- if (wavelength_gfx)
- draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),265,2,wavelength_gfx);
- }
- else
- {
- fillrect(vid_buf, 12, 266, textwidth(heattext)+8, 15, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
- drawtext(vid_buf, 16, 270, heattext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
- if (DEBUG_MODE)
- {
- fillrect(vid_buf, 12, 280, textwidth(coordtext)+8, 13, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
- drawtext(vid_buf, 16, 282, coordtext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
- }
- if (wavelength_gfx)
- draw_wavelengths(vid_buf,12,265,2,wavelength_gfx);
- }
- }
- else
- {
- fillrect(vid_buf, XRES-20-textwidth(heattext), 12, textwidth(heattext)+8, 15, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
- drawtext(vid_buf, XRES-16-textwidth(heattext), 16, heattext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
- if (DEBUG_MODE)
- {
- fillrect(vid_buf, XRES-20-textwidth(coordtext), 26, textwidth(coordtext)+8, 11, 0, 0, 0, quickoptions_tooltip_fade_invert*0.5);
- drawtext(vid_buf, XRES-16-textwidth(coordtext), 27, coordtext, 255, 255, 255, quickoptions_tooltip_fade_invert*0.75);
- }
- if (wavelength_gfx)
- draw_wavelengths(vid_buf,XRES-20-textwidth(heattext),11,2,wavelength_gfx);
- }
- wavelength_gfx = 0;
- fillrect(vid_buf, 12, 12, textwidth(uitext)+8, 15, 0, 0, 0, it_invert*2.5);
- drawtext(vid_buf, 16, 16, uitext, 32, 216, 255, it_invert * 4);
-
- }
-
- if (console_mode)
- {
-#ifdef LUACONSOLE
- char *console;
- sys_pause = 1;
- console = console_ui(vid_buf, console_error, console_more);
- console = mystrdup(console);
- strcpy(console_error,"");
- if (process_command_lua(vid_buf, console, console_error)==-1)
- {
- free(console);
- break;
- }
- free(console);
-#else
- char *console;
- sys_pause = 1;
- console = console_ui(vid_buf, console_error, console_more);
- console = mystrdup(console);
- strcpy(console_error,"");
- if (process_command_old(vid_buf, console, console_error)==-1)
- {
- free(console);
- break;
- }
- free(console);
-#endif
- }
-
- sdl_blit(0, 0, XRES+BARSIZE, YRES+MENUSIZE, vid_buf, XRES+BARSIZE);
-
- //Setting an element for the stick man
- if (player.spwn==0)
- {
- if ((sr>0 && sr<PT_NUM && ptypes[sr].enabled && ptypes[sr].falldown>0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH)
- player.elem = sr;
- else
- player.elem = PT_DUST;
- }
- if (player2.spwn==0)
- {
- if ((sr>0 && sr<PT_NUM && ptypes[sr].enabled && ptypes[sr].falldown>0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH)
- player2.elem = sr;
- else
- player2.elem = PT_DUST;
- }
- }
- save_presets(0);
-
- SDL_CloseAudio();
- http_done();
- gravity_cleanup();
-#ifdef LUACONSOLE
- luacon_close();
-#endif
-#ifdef PTW32_STATIC_LIB
- pthread_win32_thread_detach_np();
- pthread_win32_process_detach_np();
-#endif
- return 0;
-}
-#endif
diff --git a/src/md5.c b/src/md5.c
deleted file mode 100644
index 1bad12b..0000000
--- a/src/md5.c
+++ /dev/null
@@ -1,231 +0,0 @@
-// based on public-domain code from Colin Plumb (1993)
-#include <string.h>
-#include <md5.h>
-
-static unsigned getu32(const unsigned char *addr)
-{
- return (((((unsigned long)addr[3] << 8) | addr[2]) << 8) | addr[1]) << 8 | addr[0];
-}
-
-static void putu32(unsigned data, unsigned char *addr)
-{
- addr[0] = (unsigned char)data;
- addr[1] = (unsigned char)(data >> 8);
- addr[2] = (unsigned char)(data >> 16);
- addr[3] = (unsigned char)(data >> 24);
-}
-
-void md5_init(struct md5_context *ctx)
-{
- ctx->buf[0] = 0x67452301;
- ctx->buf[1] = 0xefcdab89;
- ctx->buf[2] = 0x98badcfe;
- ctx->buf[3] = 0x10325476;
-
- ctx->bits[0] = 0;
- ctx->bits[1] = 0;
-}
-
-void md5_update(struct md5_context *ctx, unsigned char const *buf, unsigned len)
-{
- unsigned t;
-
- // update bit count
- t = ctx->bits[0];
- if ((ctx->bits[0] = (t + ((unsigned)len << 3)) & 0xffffffff) < t)
- ctx->bits[1]++; // carry
- ctx->bits[1] += len >> 29;
-
- t = (t >> 3) & 0x3f;
-
- // use leading data to top up the buffer
-
- if (t)
- {
- unsigned char *p = ctx->in + t;
-
- t = 64-t;
- if (len < t)
- {
- memcpy(p, buf, len);
- return;
- }
- memcpy(p, buf, t);
- md5_transform(ctx->buf, ctx->in);
- buf += t;
- len -= t;
- }
-
- // following 64-byte chunks
-
- while (len >= 64)
- {
- memcpy(ctx->in, buf, 64);
- md5_transform(ctx->buf, ctx->in);
- buf += 64;
- len -= 64;
- }
-
- // save rest of bytes for later
-
- memcpy(ctx->in, buf, len);
-}
-
-void md5_final(unsigned char digest[16], struct md5_context *ctx)
-{
- unsigned count;
- unsigned char *p;
-
- // #bytes mod64
- count = (ctx->bits[0] >> 3) & 0x3F;
-
- // first char of padding = 0x80
- p = ctx->in + count;
- *p++ = 0x80;
-
- // calculate # of bytes to pad
- count = 64 - 1 - count;
-
- // Pad out to 56 mod 64
- if (count < 8)
- {
- // we need to finish a whole block before padding
- memset(p, 0, count);
- md5_transform(ctx->buf, ctx->in);
- memset(ctx->in, 0, 56);
- }
- else
- {
- // just pad to 56 bytes
- memset(p, 0, count-8);
- }
-
- // append length & final transform
- putu32(ctx->bits[0], ctx->in + 56);
- putu32(ctx->bits[1], ctx->in + 60);
-
- md5_transform(ctx->buf, ctx->in);
- putu32(ctx->buf[0], digest);
- putu32(ctx->buf[1], digest + 4);
- putu32(ctx->buf[2], digest + 8);
- putu32(ctx->buf[3], digest + 12);
- memset(ctx, 0, sizeof(ctx));
-}
-
-#define F1(x, y, z) (z ^ (x & (y ^ z)))
-#define F2(x, y, z) F1(z, x, y)
-#define F3(x, y, z) (x ^ y ^ z)
-#define F4(x, y, z) (y ^ (x | ~z))
-
-#define MD5STEP(f, w, x, y, z, data, s) \
- ( w += f(x, y, z) + data, w &= 0xffffffff, w = w<<s | w>>(32-s), w += x )
-
-void md5_transform(unsigned buf[4], const unsigned char inraw[64])
-{
- unsigned a, b, c, d;
- unsigned in[16];
- int i;
-
- for (i = 0; i < 16; ++i)
- in[i] = getu32 (inraw + 4 * i);
-
- a = buf[0];
- b = buf[1];
- c = buf[2];
- d = buf[3];
-
- MD5STEP(F1, a, b, c, d, in[ 0]+0xd76aa478, 7);
- MD5STEP(F1, d, a, b, c, in[ 1]+0xe8c7b756, 12);
- MD5STEP(F1, c, d, a, b, in[ 2]+0x242070db, 17);
- MD5STEP(F1, b, c, d, a, in[ 3]+0xc1bdceee, 22);
- MD5STEP(F1, a, b, c, d, in[ 4]+0xf57c0faf, 7);
- MD5STEP(F1, d, a, b, c, in[ 5]+0x4787c62a, 12);
- MD5STEP(F1, c, d, a, b, in[ 6]+0xa8304613, 17);
- MD5STEP(F1, b, c, d, a, in[ 7]+0xfd469501, 22);
- MD5STEP(F1, a, b, c, d, in[ 8]+0x698098d8, 7);
- MD5STEP(F1, d, a, b, c, in[ 9]+0x8b44f7af, 12);
- MD5STEP(F1, c, d, a, b, in[10]+0xffff5bb1, 17);
- MD5STEP(F1, b, c, d, a, in[11]+0x895cd7be, 22);
- MD5STEP(F1, a, b, c, d, in[12]+0x6b901122, 7);
- MD5STEP(F1, d, a, b, c, in[13]+0xfd987193, 12);
- MD5STEP(F1, c, d, a, b, in[14]+0xa679438e, 17);
- MD5STEP(F1, b, c, d, a, in[15]+0x49b40821, 22);
-
- MD5STEP(F2, a, b, c, d, in[ 1]+0xf61e2562, 5);
- MD5STEP(F2, d, a, b, c, in[ 6]+0xc040b340, 9);
- MD5STEP(F2, c, d, a, b, in[11]+0x265e5a51, 14);
- MD5STEP(F2, b, c, d, a, in[ 0]+0xe9b6c7aa, 20);
- MD5STEP(F2, a, b, c, d, in[ 5]+0xd62f105d, 5);
- MD5STEP(F2, d, a, b, c, in[10]+0x02441453, 9);
- MD5STEP(F2, c, d, a, b, in[15]+0xd8a1e681, 14);
- MD5STEP(F2, b, c, d, a, in[ 4]+0xe7d3fbc8, 20);
- MD5STEP(F2, a, b, c, d, in[ 9]+0x21e1cde6, 5);
- MD5STEP(F2, d, a, b, c, in[14]+0xc33707d6, 9);
- MD5STEP(F2, c, d, a, b, in[ 3]+0xf4d50d87, 14);
- MD5STEP(F2, b, c, d, a, in[ 8]+0x455a14ed, 20);
- MD5STEP(F2, a, b, c, d, in[13]+0xa9e3e905, 5);
- MD5STEP(F2, d, a, b, c, in[ 2]+0xfcefa3f8, 9);
- MD5STEP(F2, c, d, a, b, in[ 7]+0x676f02d9, 14);
- MD5STEP(F2, b, c, d, a, in[12]+0x8d2a4c8a, 20);
-
- MD5STEP(F3, a, b, c, d, in[ 5]+0xfffa3942, 4);
- MD5STEP(F3, d, a, b, c, in[ 8]+0x8771f681, 11);
- MD5STEP(F3, c, d, a, b, in[11]+0x6d9d6122, 16);
- MD5STEP(F3, b, c, d, a, in[14]+0xfde5380c, 23);
- MD5STEP(F3, a, b, c, d, in[ 1]+0xa4beea44, 4);
- MD5STEP(F3, d, a, b, c, in[ 4]+0x4bdecfa9, 11);
- MD5STEP(F3, c, d, a, b, in[ 7]+0xf6bb4b60, 16);
- MD5STEP(F3, b, c, d, a, in[10]+0xbebfbc70, 23);
- MD5STEP(F3, a, b, c, d, in[13]+0x289b7ec6, 4);
- MD5STEP(F3, d, a, b, c, in[ 0]+0xeaa127fa, 11);
- MD5STEP(F3, c, d, a, b, in[ 3]+0xd4ef3085, 16);
- MD5STEP(F3, b, c, d, a, in[ 6]+0x04881d05, 23);
- MD5STEP(F3, a, b, c, d, in[ 9]+0xd9d4d039, 4);
- MD5STEP(F3, d, a, b, c, in[12]+0xe6db99e5, 11);
- MD5STEP(F3, c, d, a, b, in[15]+0x1fa27cf8, 16);
- MD5STEP(F3, b, c, d, a, in[ 2]+0xc4ac5665, 23);
-
- MD5STEP(F4, a, b, c, d, in[ 0]+0xf4292244, 6);
- MD5STEP(F4, d, a, b, c, in[ 7]+0x432aff97, 10);
- MD5STEP(F4, c, d, a, b, in[14]+0xab9423a7, 15);
- MD5STEP(F4, b, c, d, a, in[ 5]+0xfc93a039, 21);
- MD5STEP(F4, a, b, c, d, in[12]+0x655b59c3, 6);
- MD5STEP(F4, d, a, b, c, in[ 3]+0x8f0ccc92, 10);
- MD5STEP(F4, c, d, a, b, in[10]+0xffeff47d, 15);
- MD5STEP(F4, b, c, d, a, in[ 1]+0x85845dd1, 21);
- MD5STEP(F4, a, b, c, d, in[ 8]+0x6fa87e4f, 6);
- MD5STEP(F4, d, a, b, c, in[15]+0xfe2ce6e0, 10);
- MD5STEP(F4, c, d, a, b, in[ 6]+0xa3014314, 15);
- MD5STEP(F4, b, c, d, a, in[13]+0x4e0811a1, 21);
- MD5STEP(F4, a, b, c, d, in[ 4]+0xf7537e82, 6);
- MD5STEP(F4, d, a, b, c, in[11]+0xbd3af235, 10);
- MD5STEP(F4, c, d, a, b, in[ 2]+0x2ad7d2bb, 15);
- MD5STEP(F4, b, c, d, a, in[ 9]+0xeb86d391, 21);
-
- buf[0] += a;
- buf[1] += b;
- buf[2] += c;
- buf[3] += d;
-}
-
-static char hex[] = "0123456789abcdef";
-void md5_ascii(char *result, unsigned char const *buf, unsigned len)
-{
- struct md5_context md5;
- unsigned char hash[16];
- int i;
-
- if (len==0)
- len = strlen((char *)buf);
-
- md5_init(&md5);
- md5_update(&md5, buf, len);
- md5_final(hash, &md5);
-
- for (i=0; i<16; i++)
- {
- result[i*2] = hex[(hash[i]>>4)&0xF];
- result[i*2+1] = hex[hash[i]&0x0F];
- }
- result[32] = 0;
-}
diff --git a/src/misc.c b/src/misc.c
deleted file mode 100644
index 322a56a..0000000
--- a/src/misc.c
+++ /dev/null
@@ -1,1005 +0,0 @@
-/**
- * Powder Toy - miscellaneous functions
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <regex.h>
-#include <sys/types.h>
-#include <math.h>
-#include "misc.h"
-#include "defines.h"
-#include "interface.h"
-#include "graphics.h"
-#include "powder.h"
-#include "gravity.h"
-#include <icondoc.h>
-#include <update.h>
-#if defined WIN32
-#include <shlobj.h>
-#include <shlwapi.h>
-#include <windows.h>
-#else
-#include <unistd.h>
-#endif
-#ifdef MACOSX
-#include <ApplicationServices/ApplicationServices.h>
-#endif
-#include "cJSON.h"
-
-char *clipboard_text = NULL;
-
-//Signum function
-#if defined(WIN32) && !defined(__GNUC__)
-int isign(float i)
-#else
-inline int isign(float i)
-#endif
-{
- if (i<0)
- return -1;
- if (i>0)
- return 1;
- return 0;
-}
-
-#if defined(WIN32) && !defined(__GNUC__)
-unsigned clamp_flt(float f, float min, float max)
-#else
-inline unsigned clamp_flt(float f, float min, float max)
-#endif
-{
- if (f<min)
- return 0;
- if (f>max)
- return 255;
- return (int)(255.0f*(f-min)/(max-min));
-}
-
-#if defined(WIN32) && !defined(__GNUC__)
-float restrict_flt(float f, float min, float max)
-#else
-inline float restrict_flt(float f, float min, float max)
-#endif
-{
- if (f<min)
- return min;
- if (f>max)
- return max;
- return f;
-}
-
-char *mystrdup(char *s)
-{
- char *x;
- if (s)
- {
- x = (char*)malloc(strlen(s)+1);
- strcpy(x, s);
- return x;
- }
- return s;
-}
-
-void strlist_add(struct strlist **list, char *str)
-{
- struct strlist *item = malloc(sizeof(struct strlist));
- item->str = mystrdup(str);
- item->next = *list;
- *list = item;
-}
-
-int strlist_find(struct strlist **list, char *str)
-{
- struct strlist *item;
- for (item=*list; item; item=item->next)
- if (!strcmp(item->str, str))
- return 1;
- return 0;
-}
-
-void strlist_free(struct strlist **list)
-{
- struct strlist *item;
- while (*list)
- {
- item = *list;
- *list = (*list)->next;
- free(item);
- }
-}
-
-void clean_text(char *text, int vwidth)
-{
- int i = 0;
- if(textwidth(text) > vwidth){
- text[textwidthx(text, vwidth)] = 0;
- }
- for(i = 0; i < strlen(text); i++){
- if(! (text[i]>=' ' && text[i]<127)){
- text[i] = ' ';
- }
- }
-}
-
-void draw_bframe()
-{
- int i;
- for(i=0; i<(XRES/CELL); i++)
- {
- bmap[0][i]=WL_WALL;
- bmap[YRES/CELL-1][i]=WL_WALL;
- }
- for(i=1; i<((YRES/CELL)-1); i++)
- {
- bmap[i][0]=WL_WALL;
- bmap[i][XRES/CELL-1]=WL_WALL;
- }
-}
-
-void erase_bframe()
-{
- int i;
- for(i=0; i<(XRES/CELL); i++)
- {
- bmap[0][i]=0;
- bmap[YRES/CELL-1][i]=0;
- }
- for(i=1; i<((YRES/CELL)-1); i++)
- {
- bmap[i][0]=0;
- bmap[i][XRES/CELL-1]=0;
- }
-}
-
-void save_presets(int do_update)
-{
- char * outputdata;
- int count, i;
- cJSON *root, *userobj, *versionobj, *graphicsobj;
- FILE* f;
-
- root = cJSON_CreateObject();
-
- cJSON_AddStringToObject(root, "Powder Toy Preferences", "Don't modify this file unless you know what you're doing. P.S: editing the admin/mod fields in your user info doesn't give you magical powers");
-
- //User Info
- if(svf_login){
- cJSON_AddItemToObject(root, "user", userobj=cJSON_CreateObject());
- cJSON_AddStringToObject(userobj, "name", svf_user);
- cJSON_AddStringToObject(userobj, "id", svf_user_id);
- cJSON_AddStringToObject(userobj, "session_id", svf_session_id);
- if(svf_admin){
- cJSON_AddTrueToObject(userobj, "admin");
- cJSON_AddFalseToObject(userobj, "mod");
- } else if(svf_mod){
- cJSON_AddFalseToObject(userobj, "admin");
- cJSON_AddTrueToObject(userobj, "mod");
- } else {
- cJSON_AddFalseToObject(userobj, "admin");
- cJSON_AddFalseToObject(userobj, "mod");
- }
- }
-
- //Version Info
- cJSON_AddItemToObject(root, "version", versionobj=cJSON_CreateObject());
- cJSON_AddNumberToObject(versionobj, "major", SAVE_VERSION);
- cJSON_AddNumberToObject(versionobj, "minor", MINOR_VERSION);
- cJSON_AddNumberToObject(versionobj, "build", BUILD_NUM);
- if(do_update){
- cJSON_AddTrueToObject(versionobj, "update");
- } else {
- cJSON_AddFalseToObject(versionobj, "update");
- }
-
- //Display settings
- cJSON_AddItemToObject(root, "graphics", graphicsobj=cJSON_CreateObject());
- cJSON_AddNumberToObject(graphicsobj, "colour", colour_mode);
- count = 0; i = 0; while(display_modes[i++]){ count++; }
- cJSON_AddItemToObject(graphicsobj, "display", cJSON_CreateIntArray(display_modes, count));
- count = 0; i = 0; while(render_modes[i++]){ count++; }
- cJSON_AddItemToObject(graphicsobj, "render", cJSON_CreateIntArray(render_modes, count));
-
- //General settings
- cJSON_AddStringToObject(root, "proxy", http_proxy_string);
- cJSON_AddNumberToObject(root, "scale", sdl_scale);
- cJSON_AddNumberToObject(root, "bframe", bframe);
- cJSON_AddNumberToObject(root, "Debug mode", DEBUG_MODE);
- cJSON_AddNumberToObject(root, "decorations_enable", decorations_enable);
- cJSON_AddNumberToObject(root, "ngrav_enable", ngrav_enable);
- cJSON_AddNumberToObject(root, "kiosk_enable", kiosk_enable);
- cJSON_AddNumberToObject(root, "drawgrav_enable", drawgrav_enable);
-
- outputdata = cJSON_Print(root);
- cJSON_Delete(root);
-
- f = fopen("powder.pref", "wb");
- if(!f)
- return;
- fwrite(outputdata, 1, strlen(outputdata), f);
- fclose(f);
- free(outputdata);
- //Old format, here for reference only
- /*FILE *f=fopen("powder.def", "wb");
- unsigned char sig[4] = {0x50, 0x44, 0x65, 0x68};
- unsigned char tmp = sdl_scale;
- if (!f)
- return;
- fwrite(sig, 1, 4, f);
- save_string(f, svf_user);
- //save_string(f, svf_pass);
- save_string(f, svf_user_id);
- save_string(f, svf_session_id);
- fwrite(&tmp, 1, 1, f);
- tmp = cmode;
- fwrite(&tmp, 1, 1, f);
- tmp = svf_admin;
- fwrite(&tmp, 1, 1, f);
- tmp = svf_mod;
- fwrite(&tmp, 1, 1, f);
- save_string(f, http_proxy_string);
- tmp = SAVE_VERSION;
- fwrite(&tmp, 1, 1, f);
- tmp = MINOR_VERSION;
- fwrite(&tmp, 1, 1, f);
- tmp = BUILD_NUM;
- fwrite(&tmp, 1, 1, f);
- tmp = do_update;
- fwrite(&tmp, 1, 1, f);
- fclose(f);*/
-}
-
-int sregexp(const char *str, char *pattern)
-{
- int result;
- regex_t patternc;
- if (regcomp(&patternc, pattern, 0)!=0)
- return 1;
- result = regexec(&patternc, str, 0, NULL, 0);
- regfree(&patternc);
- return result;
-}
-
-void load_presets(void)
-{
- int prefdatasize = 0, i, count;
- char * prefdata = file_load("powder.pref", &prefdatasize);
- cJSON *root;
- if(prefdata && (root = cJSON_Parse(prefdata)))
- {
- cJSON *userobj, *versionobj, *tmpobj, *graphicsobj, *tmparray;
-
- //Read user data
- userobj = cJSON_GetObjectItem(root, "user");
- if(userobj){
- svf_login = 1;
- if((tmpobj = cJSON_GetObjectItem(userobj, "name")) && tmpobj->type == cJSON_String) strncpy(svf_user, tmpobj->valuestring, 63); else svf_user[0] = 0;
- if((tmpobj = cJSON_GetObjectItem(userobj, "id")) && tmpobj->type == cJSON_String) strncpy(svf_user_id, tmpobj->valuestring, 63); else svf_user_id[0] = 0;
- if((tmpobj = cJSON_GetObjectItem(userobj, "session_id")) && tmpobj->type == cJSON_String) strncpy(svf_session_id, tmpobj->valuestring, 63); else svf_session_id[0] = 0;
- if((tmpobj = cJSON_GetObjectItem(userobj, "admin")) && tmpobj->type == cJSON_True) {
- svf_admin = 1;
- svf_mod = 0;
- } else if((tmpobj = cJSON_GetObjectItem(userobj, "mod")) && tmpobj->type == cJSON_True) {
- svf_mod = 1;
- svf_admin = 0;
- } else {
- svf_admin = 0;
- svf_mod = 0;
- }
- } else {
- svf_login = 0;
- svf_user[0] = 0;
- svf_user_id[0] = 0;
- svf_session_id[0] = 0;
- svf_admin = 0;
- svf_mod = 0;
- }
-
- //Read version data
- versionobj = cJSON_GetObjectItem(root, "version");
- if(versionobj){
- if(tmpobj = cJSON_GetObjectItem(versionobj, "major")) last_major = tmpobj->valueint;
- if(tmpobj = cJSON_GetObjectItem(versionobj, "minor")) last_minor = tmpobj->valueint;
- if(tmpobj = cJSON_GetObjectItem(versionobj, "build")) last_build = tmpobj->valueint;
- if((tmpobj = cJSON_GetObjectItem(versionobj, "update")) && tmpobj->type == cJSON_True)
- update_flag = 1;
- else
- update_flag = 0;
- } else {
- last_major = 0;
- last_minor = 0;
- last_build = 0;
- update_flag = 0;
- }
-
- //Read display settings
- graphicsobj = cJSON_GetObjectItem(root, "graphics");
- if(graphicsobj)
- {
- if(tmpobj = cJSON_GetObjectItem(graphicsobj, "colour")) colour_mode = tmpobj->valueint;
- if(tmpobj = cJSON_GetObjectItem(graphicsobj, "display"))
- {
- count = cJSON_GetArraySize(tmpobj);
- free(display_modes);
- display_mode = 0;
- display_modes = calloc(count+1, sizeof(unsigned int));
- for(i = 0; i < count; i++)
- {
- display_mode |= cJSON_GetArrayItem(tmpobj, i)->valueint;
- display_modes[i] = cJSON_GetArrayItem(tmpobj, i)->valueint;
- }
- }
- if(tmpobj = cJSON_GetObjectItem(graphicsobj, "render"))
- {
- count = cJSON_GetArraySize(tmpobj);
- free(render_modes);
- render_mode = 0;
- render_modes = calloc(count+1, sizeof(unsigned int));
- for(i = 0; i < count; i++)
- {
- render_mode |= cJSON_GetArrayItem(tmpobj, i)->valueint;
- render_modes[i] = cJSON_GetArrayItem(tmpobj, i)->valueint;
- }
- }
- }
-
- //Read general settings
- if((tmpobj = cJSON_GetObjectItem(root, "proxy")) && tmpobj->type == cJSON_String) strncpy(http_proxy_string, tmpobj->valuestring, 255); else http_proxy_string[0] = 0;
- //TODO: Translate old cmode value into new *_mode values
- if(tmpobj = cJSON_GetObjectItem(root, "scale")) sdl_scale = tmpobj->valueint;
- if(tmpobj = cJSON_GetObjectItem(root, "bframe")) bframe = tmpobj->valueint;
- if(tmpobj = cJSON_GetObjectItem(root, "Debug mode")) DEBUG_MODE = tmpobj->valueint;
- if(tmpobj = cJSON_GetObjectItem(root, "decorations_enable")) decorations_enable = tmpobj->valueint;
- if(tmpobj = cJSON_GetObjectItem(root, "ngrav_enable")) { if (tmpobj->valueint) start_grav_async(); };
- if(tmpobj = cJSON_GetObjectItem(root, "kiosk_enable")) { kiosk_enable = tmpobj->valueint; if (kiosk_enable) set_scale(sdl_scale, kiosk_enable); }
- if(tmpobj = cJSON_GetObjectItem(root, "drawgrav_enable")) drawgrav_enable = tmpobj->valueint;
-
- cJSON_Delete(root);
- free(prefdata);
- } else { //Fallback and read from old def file
- FILE *f=fopen("powder.def", "rb");
- unsigned char sig[4], tmp;
- if (!f)
- return;
- fread(sig, 1, 4, f);
- if (sig[0]!=0x50 || sig[1]!=0x44 || sig[2]!=0x65)
- {
- if (sig[0]==0x4D && sig[1]==0x6F && sig[2]==0x46 && sig[3]==0x6F)
- {
- if (fseek(f, -3, SEEK_END))
- {
- remove("powder.def");
- return;
- }
- if (fread(sig, 1, 3, f) != 3)
- {
- remove("powder.def");
- goto fail;
- }
- //last_major = sig[0];
- //last_minor = sig[1];
- last_build = 0;
- update_flag = sig[2];
- }
- fclose(f);
- remove("powder.def");
- return;
- }
- if (sig[3]==0x66) {
- if (load_string(f, svf_user, 63))
- goto fail;
- if (load_string(f, svf_pass, 63))
- goto fail;
- } else {
- if (load_string(f, svf_user, 63))
- goto fail;
- if (load_string(f, svf_user_id, 63))
- goto fail;
- if (load_string(f, svf_session_id, 63))
- goto fail;
- }
- svf_login = !!svf_session_id[0];
- if (fread(&tmp, 1, 1, f) != 1)
- goto fail;
- sdl_scale = (tmp == 2) ? 2 : 1;
- if (fread(&tmp, 1, 1, f) != 1)
- goto fail;
- //TODO: Translate old cmode value into new *_mode values
- //cmode = tmp%CM_COUNT;
- if (fread(&tmp, 1, 1, f) != 1)
- goto fail;
- svf_admin = tmp;
- if (fread(&tmp, 1, 1, f) != 1)
- goto fail;
- svf_mod = tmp;
- if (load_string(f, http_proxy_string, 255))
- goto fail;
-
- if (sig[3]!=0x68) { //Pre v64 format
- if (fread(sig, 1, 3, f) != 3)
- goto fail;
- last_build = 0;
- } else {
- if (fread(sig, 1, 4, f) != 4)
- goto fail;
- last_build = sig[3];
- }
- last_major = sig[0];
- last_minor = sig[1];
- update_flag = sig[2];
- fail:
- fclose(f);
- }
-}
-
-void save_string(FILE *f, char *str)
-{
- int li = strlen(str);
- unsigned char lb[2];
- lb[0] = li;
- lb[1] = li >> 8;
- fwrite(lb, 2, 1, f);
- fwrite(str, li, 1, f);
-}
-
-int load_string(FILE *f, char *str, int max)
-{
- int li;
- unsigned char lb[2];
- fread(lb, 2, 1, f);
- li = lb[0] | (lb[1] << 8);
- if (li > max)
- {
- str[0] = 0;
- return 1;
- }
- fread(str, li, 1, f);
- str[li] = 0;
- return 0;
-}
-
-void strcaturl(char *dst, char *src)
-{
- char *d;
- unsigned char *s;
-
- for (d=dst; *d; d++) ;
-
- for (s=(unsigned char *)src; *s; s++)
- {
- if ((*s>='0' && *s<='9') ||
- (*s>='a' && *s<='z') ||
- (*s>='A' && *s<='Z'))
- *(d++) = *s;
- else
- {
- *(d++) = '%';
- *(d++) = hex[*s>>4];
- *(d++) = hex[*s&15];
- }
- }
- *d = 0;
-}
-
-void strappend(char *dst, char *src)
-{
- char *d;
- unsigned char *s;
-
- for (d=dst; *d; d++) ;
-
- for (s=(unsigned char *)src; *s; s++)
- {
- *(d++) = *s;
- }
- *d = 0;
-}
-
-void *file_load(char *fn, int *size)
-{
- FILE *f = fopen(fn, "rb");
- void *s;
-
- if (!f)
- return NULL;
- fseek(f, 0, SEEK_END);
- *size = ftell(f);
- fseek(f, 0, SEEK_SET);
- s = malloc(*size);
- if (!s)
- {
- fclose(f);
- return NULL;
- }
- fread(s, *size, 1, f);
- fclose(f);
- return s;
-}
-
-int cpu_check(void)
-{
-#ifdef MACOSX
- return 0;
-#else
-#ifdef X86
- unsigned af,bf,cf,df;
- x86_cpuid(0, af, bf, cf, df);
- if (bf==0x68747541 && cf==0x444D4163 && df==0x69746E65)
- amd = 1;
- x86_cpuid(1, af, bf, cf, df);
-#ifdef X86_SSE
- if (!(df&(1<<25)))
- return 1;
-#endif
-#ifdef X86_SSE2
- if (!(df&(1<<26)))
- return 1;
-#endif
-#ifdef X86_SSE3
- if (!(cf&1))
- return 1;
-#endif
-#endif
-#endif
- return 0;
-}
-
-matrix2d m2d_multiply_m2d(matrix2d m1, matrix2d m2)
-{
- matrix2d result = {
- m1.a*m2.a+m1.b*m2.c, m1.a*m2.b+m1.b*m2.d,
- m1.c*m2.a+m1.d*m2.c, m1.c*m2.b+m1.d*m2.d
- };
- return result;
-}
-vector2d m2d_multiply_v2d(matrix2d m, vector2d v)
-{
- vector2d result = {
- m.a*v.x+m.b*v.y,
- m.c*v.x+m.d*v.y
- };
- return result;
-}
-matrix2d m2d_multiply_float(matrix2d m, float s)
-{
- matrix2d result = {
- m.a*s, m.b*s,
- m.c*s, m.d*s,
- };
- return result;
-}
-
-vector2d v2d_multiply_float(vector2d v, float s)
-{
- vector2d result = {
- v.x*s,
- v.y*s
- };
- return result;
-}
-
-vector2d v2d_add(vector2d v1, vector2d v2)
-{
- vector2d result = {
- v1.x+v2.x,
- v1.y+v2.y
- };
- return result;
-}
-vector2d v2d_sub(vector2d v1, vector2d v2)
-{
- vector2d result = {
- v1.x-v2.x,
- v1.y-v2.y
- };
- return result;
-}
-
-matrix2d m2d_new(float me0, float me1, float me2, float me3)
-{
- matrix2d result = {me0,me1,me2,me3};
- return result;
-}
-vector2d v2d_new(float x, float y)
-{
- vector2d result = {x, y};
- return result;
-}
-
-void clipboard_push_text(char * text)
-{
-#ifdef MACOSX
- PasteboardRef newclipboard;
-
- if (PasteboardCreate(kPasteboardClipboard, &newclipboard)!=noErr) return;
- if (PasteboardClear(newclipboard)!=noErr) return;
- PasteboardSynchronize(newclipboard);
-
- CFDataRef data = CFDataCreate(kCFAllocatorDefault, text, strlen(text));
- PasteboardPutItemFlavor(newclipboard, (PasteboardItemID)1, CFSTR("com.apple.traditional-mac-plain-text"), data, 0);
-#elif defined WIN32
- if (OpenClipboard(NULL))
- {
- HGLOBAL cbuffer;
- char * glbuffer;
-
- EmptyClipboard();
-
- cbuffer = GlobalAlloc(GMEM_DDESHARE, strlen(text)+1);
- glbuffer = (char*)GlobalLock(cbuffer);
-
- strcpy(glbuffer, text);
-
- GlobalUnlock(cbuffer);
- SetClipboardData(CF_TEXT, cbuffer);
- CloseClipboard();
- }
-#elif (defined(LIN32) || defined(LIN64)) && defined(SDL_VIDEO_DRIVER_X11)
- if (clipboard_text!=NULL) {
- free(clipboard_text);
- clipboard_text = NULL;
- }
- clipboard_text = mystrdup(text);
- sdl_wminfo.info.x11.lock_func();
- XSetSelectionOwner(sdl_wminfo.info.x11.display, XA_CLIPBOARD, sdl_wminfo.info.x11.window, CurrentTime);
- XFlush(sdl_wminfo.info.x11.display);
- sdl_wminfo.info.x11.unlock_func();
-#else
- printf("Not implemented: put text on clipboard \"%s\"\n", text);
-#endif
-}
-
-char * clipboard_pull_text()
-{
-#ifdef MACOSX
- printf("Not implemented: get text from clipboard\n");
-#elif defined WIN32
- if (OpenClipboard(NULL))
- {
- HANDLE cbuffer;
- char * glbuffer;
-
- cbuffer = GetClipboardData(CF_TEXT);
- glbuffer = (char*)GlobalLock(cbuffer);
- GlobalUnlock(cbuffer);
- CloseClipboard();
- if(glbuffer!=NULL){
- return mystrdup(glbuffer);
- } else {
- return "";
- }
- }
-#elif (defined(LIN32) || defined(LIN64)) && defined(SDL_VIDEO_DRIVER_X11)
- printf("Not implemented: get text from clipboard\n");
-#else
- printf("Not implemented: get text from clipboard\n");
-#endif
- return "";
-}
-
-int register_extension()
-{
-#if defined WIN32
- int returnval;
- LONG rresult;
- HKEY newkey;
- char *currentfilename = exe_name();
- char *iconname = NULL;
- char *opencommand = NULL;
- char *protocolcommand = NULL;
- //char AppDataPath[MAX_PATH];
- char *AppDataPath = NULL;
- iconname = malloc(strlen(currentfilename)+6);
- sprintf(iconname, "%s,-102", currentfilename);
-
- //Create Roaming application data folder
- /*if(!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE, NULL, 0, AppDataPath)))
- {
- returnval = 0;
- goto finalise;
- }*/
-
- AppDataPath = _getcwd(NULL, 0);
-
- //Move Game executable into application data folder
- //TODO: Implement
-
- opencommand = malloc(strlen(currentfilename)+53+strlen(AppDataPath));
- protocolcommand = malloc(strlen(currentfilename)+55+strlen(AppDataPath));
- /*if((strlen(AppDataPath)+strlen(APPDATA_SUBDIR "\\Powder Toy"))<MAX_PATH)
- {
- strappend(AppDataPath, APPDATA_SUBDIR);
- _mkdir(AppDataPath);
- strappend(AppDataPath, "\\Powder Toy");
- _mkdir(AppDataPath);
- } else {
- returnval = 0;
- goto finalise;
- }*/
- sprintf(opencommand, "\"%s\" open \"%%1\" ddir \"%s\"", currentfilename, AppDataPath);
- sprintf(protocolcommand, "\"%s\" ddir \"%s\" ptsave \"%%1\"", currentfilename, AppDataPath);
-
- //Create protocol entry
- rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\ptsave", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
- if (rresult != ERROR_SUCCESS) {
- returnval = 0;
- goto finalise;
- }
- rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"Powder Toy Save", strlen("Powder Toy Save")+1);
- if (rresult != ERROR_SUCCESS) {
- RegCloseKey(newkey);
- returnval = 0;
- goto finalise;
- }
- rresult = RegSetValueEx(newkey, (LPBYTE)"URL Protocol", 0, REG_SZ, (LPBYTE)"", strlen("")+1);
- if (rresult != ERROR_SUCCESS) {
- RegCloseKey(newkey);
- returnval = 0;
- goto finalise;
- }
- RegCloseKey(newkey);
-
-
- //Set Protocol DefaultIcon
- rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\ptsave\\DefaultIcon", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
- if (rresult != ERROR_SUCCESS) {
- returnval = 0;
- goto finalise;
- }
- rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)iconname, strlen(iconname)+1);
- if (rresult != ERROR_SUCCESS) {
- RegCloseKey(newkey);
- returnval = 0;
- goto finalise;
- }
- RegCloseKey(newkey);
-
- //Set Protocol Launch command
- rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\ptsave\\shell\\open\\command", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
- if (rresult != ERROR_SUCCESS) {
- returnval = 0;
- goto finalise;
- }
- rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)protocolcommand, strlen(protocolcommand)+1);
- if (rresult != ERROR_SUCCESS) {
- RegCloseKey(newkey);
- returnval = 0;
- goto finalise;
- }
- RegCloseKey(newkey);
-
- //Create extension entry
- rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\.cps", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
- if (rresult != ERROR_SUCCESS) {
- returnval = 0;
- goto finalise;
- }
- rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"PowderToySave", strlen("PowderToySave")+1);
- if (rresult != ERROR_SUCCESS) {
- RegCloseKey(newkey);
- returnval = 0;
- goto finalise;
- }
- RegCloseKey(newkey);
-
- rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\.stm", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
- if (rresult != ERROR_SUCCESS) {
- returnval = 0;
- goto finalise;
- }
- rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"PowderToySave", strlen("PowderToySave")+1);
- if (rresult != ERROR_SUCCESS) {
- RegCloseKey(newkey);
- returnval = 0;
- goto finalise;
- }
- RegCloseKey(newkey);
-
- //Create program entry
- rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
- if (rresult != ERROR_SUCCESS) {
- returnval = 0;
- goto finalise;
- }
- rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)"Powder Toy Save", strlen("Powder Toy Save")+1);
- if (rresult != ERROR_SUCCESS) {
- RegCloseKey(newkey);
- returnval = 0;
- goto finalise;
- }
- RegCloseKey(newkey);
-
- //Set DefaultIcon
- rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave\\DefaultIcon", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
- if (rresult != ERROR_SUCCESS) {
- returnval = 0;
- goto finalise;
- }
- rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)iconname, strlen(iconname)+1);
- if (rresult != ERROR_SUCCESS) {
- RegCloseKey(newkey);
- returnval = 0;
- goto finalise;
- }
- RegCloseKey(newkey);
-
- //Set Launch command
- rresult = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Classes\\PowderToySave\\shell\\open\\command", 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &newkey, NULL);
- if (rresult != ERROR_SUCCESS) {
- returnval = 0;
- goto finalise;
- }
- rresult = RegSetValueEx(newkey, 0, 0, REG_SZ, (LPBYTE)opencommand, strlen(opencommand)+1);
- if (rresult != ERROR_SUCCESS) {
- RegCloseKey(newkey);
- returnval = 0;
- goto finalise;
- }
- RegCloseKey(newkey);
-
- returnval = 1;
- finalise:
-
- if(iconname) free(iconname);
- if(opencommand) free(opencommand);
- if(currentfilename) free(currentfilename);
- if(protocolcommand) free(protocolcommand);
-
- return returnval;
-#elif defined(LIN32) || defined(LIN64)
- char *currentfilename = exe_name();
- FILE *f;
- char *mimedata =
-"<?xml version=\"1.0\"?>\n"
-" <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>\n"
-" <mime-type type=\"application/vnd.powdertoy.save\">\n"
-" <comment>Powder Toy save</comment>\n"
-" <glob pattern=\"*.cps\"/>\n"
-" <glob pattern=\"*.stm\"/>\n"
-" </mime-type>\n"
-"</mime-info>\n";
- f = fopen("powdertoy-save.xml", "wb");
- if (!f)
- return 0;
- fwrite(mimedata, 1, strlen(mimedata), f);
- fclose(f);
-
- char *desktopfiledata_tmp =
-"[Desktop Entry]\n"
-"Type=Application\n"
-"Name=Powder Toy\n"
-"Comment=Physics sandbox game\n"
-"MimeType=application/vnd.powdertoy.save;\n"
-"NoDisplay=true\n";
- char *desktopfiledata = malloc(strlen(desktopfiledata_tmp)+strlen(currentfilename)+100);
- strcpy(desktopfiledata, desktopfiledata_tmp);
- strappend(desktopfiledata, "Exec=");
- strappend(desktopfiledata, currentfilename);
- strappend(desktopfiledata, " open %f\n");
- f = fopen("powdertoy-tpt.desktop", "wb");
- if (!f)
- return 0;
- fwrite(desktopfiledata, 1, strlen(desktopfiledata), f);
- fclose(f);
- system("xdg-mime install powdertoy-save.xml");
- system("xdg-desktop-menu install powdertoy-tpt.desktop");
- f = fopen("powdertoy-save-32.png", "wb");
- if (!f)
- return 0;
- fwrite(icon_doc_32_png, 1, sizeof(icon_doc_32_png), f);
- fclose(f);
- f = fopen("powdertoy-save-16.png", "wb");
- if (!f)
- return 0;
- fwrite(icon_doc_16_png, 1, sizeof(icon_doc_16_png), f);
- fclose(f);
- system("xdg-icon-resource install --noupdate --context mimetypes --size 32 powdertoy-save-32.png application-vnd.powdertoy.save");
- system("xdg-icon-resource install --noupdate --context mimetypes --size 16 powdertoy-save-16.png application-vnd.powdertoy.save");
- system("xdg-icon-resource forceupdate");
- system("xdg-mime default powdertoy-tpt.desktop application/vnd.powdertoy.save");
- unlink("powdertoy-save-32.png");
- unlink("powdertoy-save-16.png");
- unlink("powdertoy-save.xml");
- unlink("powdertoy-tpt.desktop");
- return 1;
-#elif defined MACOSX
- return 0;
-#endif
-}
-
-void HSV_to_RGB(int h,int s,int v,int *r,int *g,int *b)//convert 0-255(0-360 for H) HSV values to 0-255 RGB
-{
- float hh, ss, vv, c, x;
- int m;
- hh = h/60.0f;//normalize values
- ss = s/255.0f;
- vv = v/255.0f;
- c = vv * ss;
- x = c * ( 1 - fabs(fmod(hh,2.0) -1) );
- if(hh<1){
- *r = (int)(c*255.0);
- *g = (int)(x*255.0);
- *b = 0;
- }
- else if(hh<2){
- *r = (int)(x*255.0);
- *g = (int)(c*255.0);
- *b = 0;
- }
- else if(hh<3){
- *r = 0;
- *g = (int)(c*255.0);
- *b = (int)(x*255.0);
- }
- else if(hh<4){
- *r = 0;
- *g = (int)(x*255.0);
- *b = (int)(c*255.0);
- }
- else if(hh<5){
- *r = (int)(x*255.0);
- *g = 0;
- *b = (int)(c*255.0);
- }
- else if(hh<6){
- *r = (int)(c*255.0);
- *g = 0;
- *b = (int)(x*255.0);
- }
- m = (int)((vv-c)*255.0);
- *r += m;
- *g += m;
- *b += m;
-}
-
-void RGB_to_HSV(int r,int g,int b,int *h,int *s,int *v)//convert 0-255 RGB values to 0-255(0-360 for H) HSV
-{
- float rr, gg, bb, a,x,c,d;
- rr = r/255.0f;//normalize values
- gg = g/255.0f;
- bb = b/255.0f;
- a = fmin(rr,gg);
- a = fmin(a,bb);
- x = fmax(rr,gg);
- x = fmax(x,bb);
- if (a==x)//greyscale
- {
- *h = 0;
- *s = 0;
- *v = (int)(a*255.0);
- }
- else
- {
- c = (rr==a) ? gg-bb : ((bb==a) ? rr-gg : bb-rr);
- d = (rr==a) ? 3 : ((bb==a) ? 1 : 5);
- *h = (int)(60.0*(d - c/(x - a)));
- *s = (int)(255.0*((x - a)/x));
- *v = (int)(255.0*x);
- }
-}
-
-void membwand(void * destv, void * srcv, size_t destsize, size_t srcsize)
-{
- size_t i;
- unsigned char * dest = destv;
- unsigned char * src = srcv;
- for(i = 0; i < destsize; i++){
- dest[i] = dest[i] & src[i%srcsize];
- }
-}
-vector2d v2d_zero = {0,0};
-matrix2d m2d_identity = {1,0,0,1};
diff --git a/src/powder.c b/src/powder.c
deleted file mode 100644
index 9f1970e..0000000
--- a/src/powder.c
+++ /dev/null
@@ -1,3751 +0,0 @@
-/**
- * Powder Toy - particle simulation
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdint.h>
-#include <math.h>
-#include <defines.h>
-#include <powder.h>
-#include <air.h>
-#include <misc.h>
-#include "gravity.h"
-#ifdef LUACONSOLE
-#include <luaconsole.h>
-#endif
-
-int wire_placed = 0;
-
-int lighting_recreate = 0;
-int force_stacking_check = 0;//whether to force a check for excessively stacked particles
-
-playerst player;
-playerst player2;
-
-playerst fighters[256]; //255 is the maximum number of fighters
-unsigned char fighcount = 0; //Contains the number of fighters
-
-particle *parts;
-particle *cb_parts;
-
-int airMode = 0;
-
-
-unsigned char bmap[YRES/CELL][XRES/CELL];
-unsigned char emap[YRES/CELL][XRES/CELL];
-
-unsigned char cb_bmap[YRES/CELL][XRES/CELL];
-unsigned char cb_emap[YRES/CELL][XRES/CELL];
-
-int pfree;
-
-unsigned pmap[YRES][XRES];
-int pmap_count[YRES][XRES];
-unsigned cb_pmap[YRES][XRES];
-unsigned photons[YRES][XRES];
-
-void get_gravity_field(int x, int y, float particleGrav, float newtonGrav, float *pGravX, float *pGravY)
-{
- *pGravX = newtonGrav*gravx[(y/CELL)*(XRES/CELL)+(x/CELL)];
- *pGravY = newtonGrav*gravy[(y/CELL)*(XRES/CELL)+(x/CELL)];
- switch (gravityMode)
- {
- default:
- case 0: //normal, vertical gravity
- *pGravY += particleGrav;
- break;
- case 1: //no gravity
- break;
- case 2: //radial gravity
- if (x-XCNTR != 0 || y-YCNTR != 0)
- {
- float pGravMult = particleGrav/sqrtf((x-XCNTR)*(x-XCNTR) + (y-YCNTR)*(y-YCNTR));
- *pGravX -= pGravMult * (float)(x - XCNTR);
- *pGravY -= pGravMult * (float)(y - YCNTR);
- }
- }
-}
-
-static int pn_junction_sprk(int x, int y, int pt)
-{
- unsigned r = pmap[y][x];
- if ((r & 0xFF) != pt)
- return 0;
- r >>= 8;
- if (parts[r].type != pt)
- return 0;
- if (parts[r].life != 0)
- return 0;
-
- parts[r].ctype = pt;
- part_change_type(r,x,y,PT_SPRK);
- parts[r].life = 4;
- return 1;
-}
-
-static void photoelectric_effect(int nx, int ny)//create sparks from PHOT when hitting PSCN and NSCN
-{
- 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);
- }
-}
-
-unsigned char can_move[PT_NUM][PT_NUM];
-
-void init_can_move()
-{
- // can_move[moving type][type at destination]
- // 0 = No move/Bounce
- // 1 = Swap
- // 2 = Both particles occupy the same space.
- // 3 = Varies, go run some extra checks
- int t, rt, stkm_move;
- for (rt=0;rt<PT_NUM;rt++)
- can_move[0][rt] = 0; // particles that don't exist shouldn't move...
- for (t=1;t<PT_NUM;t++)
- for (rt=0;rt<PT_NUM;rt++)
- can_move[t][rt] = 1;
- for (rt=1;rt<PT_NUM;rt++)
- {
- can_move[PT_PHOT][rt] = 2;
- }
- for (t=1;t<PT_NUM;t++)
- {
- for (rt=1;rt<PT_NUM;rt++)
- {
- // weight check, also prevents particles of same type displacing each other
- if (ptypes[t].weight <= ptypes[rt].weight || rt==PT_GEL) can_move[t][rt] = 0;
- if (t==PT_NEUT && ptypes[rt].properties&PROP_NEUTPASS)
- can_move[t][rt] = 2;
- if (t==PT_NEUT && ptypes[rt].properties&PROP_NEUTABSORB)
- can_move[t][rt] = 1;
- if (t==PT_NEUT && ptypes[rt].properties&PROP_NEUTPENETRATE)
- can_move[t][rt] = 1;
- if (ptypes[t].properties&PROP_NEUTPENETRATE && rt==PT_NEUT)
- can_move[t][rt] = 0;
- if (ptypes[t].properties&TYPE_ENERGY && ptypes[rt].properties&TYPE_ENERGY)
- can_move[t][rt] = 2;
- }
- }
- can_move[PT_DEST][PT_DMND] = 0;
- can_move[PT_DEST][PT_CLNE] = 0;
- can_move[PT_DEST][PT_PCLN] = 0;
- can_move[PT_DEST][PT_BCLN] = 0;
- can_move[PT_DEST][PT_PBCN] = 0;
- can_move[PT_BIZR][PT_FILT] = 2;
- can_move[PT_BIZRG][PT_FILT] = 2;
- for (t=0;t<PT_NUM;t++)
- {
- //spark shouldn't move
- can_move[PT_SPRK][t] = 0;
- stkm_move = 0;
- if (ptypes[t].properties & (TYPE_LIQUID | TYPE_GAS))
- stkm_move = 2;
- if (!t || t==PT_PRTO || t==PT_SPAWN || t==PT_SPAWN2)
- stkm_move = 2;
- can_move[PT_STKM][t] = stkm_move;
- can_move[PT_STKM2][t] = stkm_move;
- can_move[PT_FIGH][t] = stkm_move;
- }
- for (t=0;t<PT_NUM;t++)
- {
- // make them eat things
- can_move[t][PT_BHOL] = 1;
- can_move[t][PT_NBHL] = 1;
- can_move[t][PT_STKM] = 0;
- can_move[t][PT_STKM2] = 0;
- can_move[t][PT_FIGH] = 0;
- //INVIS behaviour varies with pressure
- can_move[t][PT_INVIS] = 3;
- //stop CNCT being displaced by other particles
- can_move[t][PT_CNCT] = 0;
- //void behaviour varies with powered state and ctype
- can_move[t][PT_PVOD] = 3;
- can_move[t][PT_VOID] = 3;
- }
- for (t=0;t<PT_NUM;t++)
- {
- if (t==PT_GLAS || t==PT_PHOT || t==PT_CLNE || t==PT_PCLN
- || t==PT_GLOW || t==PT_WATR || t==PT_DSTW || t==PT_SLTW
- || t==PT_ISOZ || t==PT_ISZS || t==PT_FILT || t==PT_INVIS
- || t==PT_QRTZ || t==PT_PQRT)
- can_move[PT_PHOT][t] = 2;
- }
- can_move[PT_ELEC][PT_LCRY] = 2;
- can_move[PT_ELEC][PT_EXOT] = 2;
- can_move[PT_NEUT][PT_EXOT] = 2;
- can_move[PT_PHOT][PT_LCRY] = 3;//varies according to LCRY life
-
- can_move[PT_PHOT][PT_BIZR] = 2;
- can_move[PT_ELEC][PT_BIZR] = 2;
- can_move[PT_PHOT][PT_BIZRG] = 2;
- can_move[PT_ELEC][PT_BIZRG] = 2;
- can_move[PT_PHOT][PT_BIZRS] = 2;
- can_move[PT_ELEC][PT_BIZRS] = 2;
-
- can_move[PT_NEUT][PT_INVIS] = 2;
- //whol eats anar
- can_move[PT_ANAR][PT_WHOL] = 1;
- can_move[PT_ANAR][PT_NWHL] = 1;
- can_move[PT_THDR][PT_THDR] = 2;
- can_move[PT_EMBR][PT_EMBR] = 2;
-}
-
-/*
- RETURN-value explenation
-1 = Swap
-0 = No move/Bounce
-2 = Both particles occupy the same space.
- */
-int eval_move(int pt, int nx, int ny, unsigned *rr)
-{
- unsigned r;
- int result;
-
- if (nx<0 || ny<0 || nx>=XRES || ny>=YRES)
- return 0;
-
- r = pmap[ny][nx];
- if (r)
- r = (r&~0xFF) | parts[r>>8].type;
- if (rr)
- *rr = r;
- if (pt>=PT_NUM || (r&0xFF)>=PT_NUM)
- return 0;
- result = can_move[pt][r&0xFF];
- if (result==3)
- {
- if ((pt==PT_PHOT || pt==PT_ELEC) && (r&0xFF)==PT_LCRY)
- result = (parts[r>>8].life > 5)? 2 : 0;
- if ((r&0xFF)==PT_INVIS)
- {
- if (pv[ny/CELL][nx/CELL]>4.0f || pv[ny/CELL][nx/CELL]<-4.0f) result = 2;
- else result = 0;
- }
- if ((r&0xFF)==PT_PVOD)
- {
- if (parts[r>>8].life == 10)
- {
- if(!parts[r>>8].ctype || (parts[r>>8].ctype==pt)!=(parts[r>>8].tmp&1))
- result = 1;
- else
- result = 0;
- }
- else result = 0;
- }
- if ((r&0xFF)==PT_VOID)
- {
- if(!parts[r>>8].ctype || (parts[r>>8].ctype==pt)!=(parts[r>>8].tmp&1))
- result = 1;
- else
- result = 0;
- }
- }
- if (bmap[ny/CELL][nx/CELL])
- {
- if (bmap[ny/CELL][nx/CELL]==WL_ALLOWGAS && !(ptypes[pt].properties&TYPE_GAS))// && ptypes[pt].falldown!=0 && pt!=PT_FIRE && pt!=PT_SMKE)
- return 0;
- if (bmap[ny/CELL][nx/CELL]==WL_ALLOWENERGY && !(ptypes[pt].properties&TYPE_ENERGY))// && ptypes[pt].falldown!=0 && pt!=PT_FIRE && pt!=PT_SMKE)
- return 0;
- if (bmap[ny/CELL][nx/CELL]==WL_ALLOWLIQUID && ptypes[pt].falldown!=2)
- return 0;
- if (bmap[ny/CELL][nx/CELL]==WL_ALLOWSOLID && ptypes[pt].falldown!=1)
- return 0;
- if (bmap[ny/CELL][nx/CELL]==WL_ALLOWAIR || bmap[ny/CELL][nx/CELL]==WL_WALL || bmap[ny/CELL][nx/CELL]==WL_WALLELEC)
- return 0;
- if (bmap[ny/CELL][nx/CELL]==WL_EWALL && !emap[ny/CELL][nx/CELL])
- return 0;
- if (bmap[ny/CELL][nx/CELL]==WL_EHOLE && !emap[ny/CELL][nx/CELL] && !(ptypes[pt].properties&TYPE_SOLID) && !(ptypes[r&0xFF].properties&TYPE_SOLID))
- return 2;
- }
- return result;
-}
-
-int try_move(int i, int x, int y, int nx, int ny)
-{
- unsigned r, e;
-
- if (x==nx && y==ny)
- return 1;
- if (nx<0 || ny<0 || nx>=XRES || ny>=YRES)
- return 1;
-
- e = eval_move(parts[i].type, nx, ny, &r);
-
- /* 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;
-
- if (!e) //if no movement
- {
- if (!(ptypes[parts[i].type].properties & TYPE_ENERGY))
- return 0;
- if (!legacy_enable && parts[i].type==PT_PHOT && r)//PHOT heat conduction
- {
- if ((r & 0xFF) == PT_COAL || (r & 0xFF) == PT_BCOL)
- parts[r>>8].temp = parts[i].temp;
-
- if ((r & 0xFF) < PT_NUM && ptypes[r&0xFF].hconduct && ((r&0xFF)!=PT_HSWC||parts[r>>8].life==10) && (r&0xFF)!=PT_FILT)
- parts[i].temp = parts[r>>8].temp = restrict_flt((parts[r>>8].temp+parts[i].temp)/2, MIN_TEMP, MAX_TEMP);
- }
- if ((parts[i].type==PT_NEUT || parts[i].type==PT_ELEC) && ((r&0xFF)==PT_CLNE || (r&0xFF)==PT_PCLN || (r&0xFF)==PT_BCLN || (r&0xFF)==PT_PBCN)) {
- if (!parts[r>>8].ctype)
- parts[r>>8].ctype = parts[i].type;
- }
- if ((r&0xFF)==PT_PRTI && (ptypes[parts[i].type].properties & TYPE_ENERGY))
- {
- int nnx, count;
- for (count=0; count<8; count++)
- {
- if (isign(x-nx)==isign(portal_rx[count]) && isign(y-ny)==isign(portal_ry[count]))
- break;
- }
- count = count%8;
- parts[r>>8].tmp = (int)((parts[r>>8].temp-73.15f)/100+1);
- if (parts[r>>8].tmp>=CHANNELS) parts[r>>8].tmp = CHANNELS-1;
- else if (parts[r>>8].tmp<0) parts[r>>8].tmp = 0;
- for ( nnx=0; nnx<80; nnx++)
- if (!portalp[parts[r>>8].tmp][count][nnx].type)
- {
- portalp[parts[r>>8].tmp][count][nnx] = parts[i];
- parts[i].type=PT_NONE;
- break;
- }
- }
- return 0;
- }
-
- if (e == 2) //if occupy same space
- {
- 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_PHOT && (r&0xFF)==PT_FILT)
- {
- int temp_bin = (int)((parts[r>>8].temp-273.0f)*0.025f);
- if (temp_bin < 0) temp_bin = 0;
- if (temp_bin > 25) temp_bin = 25;
- if(!parts[r>>8].tmp){
- parts[i].ctype = 0x1F << temp_bin; //Assign Colour
- } else if(parts[r>>8].tmp==1){
- parts[i].ctype &= 0x1F << temp_bin; //Filter Colour
- } else if(parts[r>>8].tmp==2){
- parts[i].ctype |= 0x1F << temp_bin; //Add Colour
- } else if(parts[r>>8].tmp==3){
- parts[i].ctype &= ~(0x1F << temp_bin); //Subtract Colour
- }
- }
- if (parts[i].type == PT_NEUT && (r&0xFF)==PT_GLAS) {
- if (rand() < RAND_MAX/10)
- create_cherenkov_photon(i);
- }
- if (parts[i].type == PT_PHOT && (r&0xFF)==PT_INVIS && pv[ny/CELL][nx/CELL]<=4.0f && pv[ny/CELL][nx/CELL]>=-4.0f) {
- part_change_type(i,x,y,PT_NEUT);
- parts[i].ctype = 0;
- }
- if ((parts[i].type==PT_BIZR||parts[i].type==PT_BIZRG) && (r&0xFF)==PT_FILT)
- {
- int temp_bin = (int)((parts[r>>8].temp-273.0f)*0.025f);
- if (temp_bin < 0) temp_bin = 0;
- if (temp_bin > 25) temp_bin = 25;
- parts[i].ctype = 0x1F << temp_bin;
- }
- return 1;
- }
- //else e=1 , we are trying to swap the particles, return 0 no swap/move, 1 is still overlap/move, because the swap takes place later
-
- if (parts[i].type==PT_NEUT && (ptypes[r&0xFF].properties&PROP_NEUTABSORB))
- {
- kill_part(i);
- return 0;
- }
- if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_PVOD) //this is where void eats particles
- {
- //void ctype already checked in eval_move
- kill_part(i);
- return 0;
- }
- if ((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) //this is where blackhole eats particles
- {
- kill_part(i);
- if (!legacy_enable)
- {
- parts[r>>8].temp = restrict_flt(parts[r>>8].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);//3.0f;
- }
-
- return 0;
- }
- if (((r&0xFF)==PT_WHOL||(r&0xFF)==PT_NWHL) && parts[i].type==PT_ANAR) //whitehole eats anar
- {
- kill_part(i);
- if (!legacy_enable)
- {
- parts[r>>8].temp = restrict_flt(parts[r>>8].temp- (MAX_TEMP-parts[i].temp)/2, MIN_TEMP, MAX_TEMP);
- }
-
- return 0;
- }
-
- if (parts[i].type==PT_CNCT && y<ny && (pmap[y+1][x]&0xFF)==PT_CNCT)//check below CNCT for another CNCT
- return 0;
-
- if ((bmap[y/CELL][x/CELL]==WL_EHOLE && !emap[y/CELL][x/CELL]) && !(bmap[ny/CELL][nx/CELL]==WL_EHOLE && !emap[ny/CELL][nx/CELL]))
- return 0;
-
- if(parts[i].type==PT_GBMB&&parts[i].life>0)
- return 0;
-
- e = r >> 8; //e is now the particle number at r (pmap[ny][nx])
- if (r)//the swap part, if we make it this far, swap
- {
- if (parts[i].type==PT_NEUT) {
- // target material is NEUTPENETRATE, meaning it gets moved around when neutron passes
- unsigned s = pmap[y][x];
- if (s && !(ptypes[s&0xFF].properties&PROP_NEUTPENETRATE))
- return 1; // if the element currently underneath neutron isn't NEUTPENETRATE, don't move anything except the neutron
- // if nothing is currently underneath neutron, only move target particle
- if (s)
- {
- pmap[ny][nx] = (s&~(0xFF))|parts[s>>8].type;
- parts[s>>8].x = nx;
- parts[s>>8].y = ny;
- }
- else pmap[ny][nx] = 0;
- parts[e].x = x;
- parts[e].y = y;
- pmap[y][x] = (e<<8)|parts[e].type;
- return 1;
- }
-
- if ((pmap[ny][nx]>>8)==e) pmap[ny][nx] = 0;
- parts[e].x += x-nx;
- parts[e].y += y-ny;
- pmap[(int)(parts[e].y+0.5f)][(int)(parts[e].x+0.5f)] = (e<<8)|parts[e].type;
- }
- return 1;
-}
-
-// try to move particle, and if successful update pmap and parts[i].x,y
-int do_move(int i, int x, int y, float nxf, float nyf)
-{
- int nx = (int)(nxf+0.5f), ny = (int)(nyf+0.5f), result;
- if (parts[i].type == PT_NONE)
- return 0;
- result = try_move(i, x, y, nx, ny);
- if (result)
- {
- int t = parts[i].type;
- parts[i].x = nxf;
- parts[i].y = nyf;
- if (ny!=y || nx!=x)
- {
- if ((pmap[y][x]>>8)==i) pmap[y][x] = 0;
- else if ((photons[y][x]>>8)==i) photons[y][x] = 0;
- if (nx<CELL || nx>=XRES-CELL || ny<CELL || ny>=YRES-CELL)//kill_part if particle is out of bounds
- {
- kill_part(i);
- return -1;
- }
- if (ptypes[t].properties & TYPE_ENERGY)
- photons[ny][nx] = t|(i<<8);
- else if (t)
- pmap[ny][nx] = t|(i<<8);
- }
- }
- return result;
-}
-
-
-static unsigned direction_to_map(float dx, float dy, int t)
-{
- // TODO:
- // Adding extra directions causes some inaccuracies.
- // Not adding them causes problems with some diagonal surfaces (photons absorbed instead of reflected).
- // For now, don't add them.
- // Solution may involve more intelligent setting of initial i0 value in find_next_boundary?
- // or rewriting normal/boundary finding code
-
- return (dx >= 0) |
- (((dx + dy) >= 0) << 1) | /* 567 */
- ((dy >= 0) << 2) | /* 4+0 */
- (((dy - dx) >= 0) << 3) | /* 321 */
- ((dx <= 0) << 4) |
- (((dx + dy) <= 0) << 5) |
- ((dy <= 0) << 6) |
- (((dy - dx) <= 0) << 7);
- /*
- return (dx >= -0.001) |
- (((dx + dy) >= -0.001) << 1) | // 567
- ((dy >= -0.001) << 2) | // 4+0
- (((dy - dx) >= -0.001) << 3) | // 321
- ((dx <= 0.001) << 4) |
- (((dx + dy) <= 0.001) << 5) |
- ((dy <= 0.001) << 6) |
- (((dy - dx) <= 0.001) << 7);
- }*/
-}
-
-static int is_blocking(int t, int x, int y)
-{
- if (t & REFRACT) {
- if (x<0 || y<0 || x>=XRES || y>=YRES)
- return 0;
- if ((pmap[y][x] & 0xFF) == PT_GLAS)
- return 1;
- return 0;
- }
-
- return !eval_move(t, x, y, NULL);
-}
-
-static int is_boundary(int pt, int x, int y)
-{
- if (!is_blocking(pt,x,y))
- return 0;
- if (is_blocking(pt,x,y-1) && is_blocking(pt,x,y+1) && is_blocking(pt,x-1,y) && is_blocking(pt,x+1,y))
- return 0;
- return 1;
-}
-
-static int find_next_boundary(int pt, int *x, int *y, int dm, int *em)
-{
- static int dx[8] = {1,1,0,-1,-1,-1,0,1};
- static int dy[8] = {0,1,1,1,0,-1,-1,-1};
- static int de[8] = {0x83,0x07,0x0E,0x1C,0x38,0x70,0xE0,0xC1};
- int i, ii, i0;
-
- if (*x <= 0 || *x >= XRES-1 || *y <= 0 || *y >= YRES-1)
- return 0;
-
- if (*em != -1) {
- i0 = *em;
- dm &= de[i0];
- } else
- i0 = 0;
-
- for (ii=0; ii<8; ii++) {
- i = (ii + i0) & 7;
- if ((dm & (1 << i)) && is_boundary(pt, *x+dx[i], *y+dy[i])) {
- *x += dx[i];
- *y += dy[i];
- *em = i;
- return 1;
- }
- }
-
- return 0;
-}
-
-int get_normal(int pt, int x, int y, float dx, float dy, float *nx, float *ny)
-{
- int ldm, rdm, lm, rm;
- int lx, ly, lv, rx, ry, rv;
- int i, j;
- float r, ex, ey;
-
- if (!dx && !dy)
- return 0;
-
- if (!is_boundary(pt, x, y))
- return 0;
-
- ldm = direction_to_map(-dy, dx, pt);
- rdm = direction_to_map(dy, -dx, pt);
- lx = rx = x;
- ly = ry = y;
- lv = rv = 1;
- lm = rm = -1;
-
- j = 0;
- for (i=0; i<SURF_RANGE; i++) {
- if (lv)
- lv = find_next_boundary(pt, &lx, &ly, ldm, &lm);
- if (rv)
- rv = find_next_boundary(pt, &rx, &ry, rdm, &rm);
- j += lv + rv;
- if (!lv && !rv)
- break;
- }
-
- if (j < NORMAL_MIN_EST)
- return 0;
-
- if ((lx == rx) && (ly == ry))
- return 0;
-
- ex = rx - lx;
- ey = ry - ly;
- r = 1.0f/hypot(ex, ey);
- *nx = ey * r;
- *ny = -ex * r;
-
- return 1;
-}
-
-int get_normal_interp(int pt, float x0, float y0, float dx, float dy, float *nx, float *ny)
-{
- int x, y, i;
-
- dx /= NORMAL_FRAC;
- dy /= NORMAL_FRAC;
-
- for (i=0; i<NORMAL_INTERP; i++) {
- x = (int)(x0 + 0.5f);
- y = (int)(y0 + 0.5f);
- if (is_boundary(pt, x, y))
- break;
- x0 += dx;
- y0 += dy;
- }
- if (i >= NORMAL_INTERP)
- return 0;
-
- if (pt == PT_PHOT)
- photoelectric_effect(x, y);
-
- return get_normal(pt, x, y, dx, dy, nx, ny);
-}
-
-//For soap only
-void detach(int i)
-{
- if ((parts[i].ctype&2) == 2)
- {
- if ((parts[parts[i].tmp].ctype&4) == 4)
- parts[parts[i].tmp].ctype ^= 4;
- }
-
- if ((parts[i].ctype&4) == 4)
- {
- if ((parts[parts[i].tmp2].ctype&2) == 2)
- parts[parts[i].tmp2].ctype ^= 2;
- }
-
- parts[i].ctype = 0;
-}
-
-void kill_part(int i)//kills particle number i
-{
- int x, y;
-
- // Remove from pmap even if type==0, otherwise infinite recursion occurs when flood fill deleting
- // a particle which sets type to 0 without calling kill_part (such as LIFE)
- x = (int)(parts[i].x+0.5f);
- y = (int)(parts[i].y+0.5f);
- if (x>=0 && y>=0 && x<XRES && y<YRES) {
- if ((pmap[y][x]>>8)==i)
- pmap[y][x] = 0;
- else if ((photons[y][x]>>8)==i)
- photons[y][x] = 0;
- }
-
- if (parts[i].type == PT_NONE) //This shouldn't happen anymore, but it's here just in case
- return;
-
- if (parts[i].type == PT_STKM)
- {
- player.spwn = 0;
- }
- if (parts[i].type == PT_STKM2)
- {
- player2.spwn = 0;
- }
- if (parts[i].type == PT_FIGH)
- {
- fighters[(unsigned char)parts[i].tmp].spwn = 0;
- fighcount--;
- }
- if (parts[i].type == PT_SPAWN)
- {
- ISSPAWN1 = 0;
- }
- if (parts[i].type == PT_SPAWN2)
- {
- ISSPAWN2 = 0;
- }
- if (parts[i].type == PT_SOAP)
- {
- detach(i);
- }
-
- parts[i].type = PT_NONE;
- parts[i].life = pfree;
- pfree = i;
-}
-
-#if defined(WIN32) && !defined(__GNUC__)
-_inline void part_change_type(int i, int x, int y, int t)
-#else
-inline void part_change_type(int i, int x, int y, int t)//changes the type of particle number i, to t. This also changes pmap at the same time.
-#endif
-{
- if (x<0 || y<0 || x>=XRES || y>=YRES || i>=NPART || t<0 || t>=PT_NUM)
- return;
- if (!ptypes[t].enabled)
- t = PT_NONE;
-
- if (parts[i].type == PT_STKM)
- player.spwn = 0;
-
- if (parts[i].type == PT_STKM2)
- player2.spwn = 0;
-
- if (parts[i].type == PT_FIGH)
- {
- fighters[(unsigned char)parts[i].tmp].spwn = 0;
- fighcount--;
- }
-
- parts[i].type = t;
- if (ptypes[t].properties & TYPE_ENERGY)
- {
- photons[y][x] = t|(i<<8);
- if ((pmap[y][x]>>8)==i)
- pmap[y][x] = 0;
- }
- else
- {
- pmap[y][x] = t|(i<<8);
- if ((photons[y][x]>>8)==i)
- photons[y][x] = 0;
- }
-}
-
-#if defined(WIN32) && !defined(__GNUC__)
-_inline int create_part(int p, int x, int y, int tv)
-#else
-inline int create_part(int p, int x, int y, int tv)//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.
-#endif
-{
- int i;
-
- int t = tv & 0xFF;
- int v = (tv >> 8) & 0xFF;
-
- if (x<0 || y<0 || x>=XRES || y>=YRES || ((t<=0 || t>=PT_NUM)&&t!=SPC_HEAT&&t!=SPC_COOL&&t!=SPC_AIR&&t!=SPC_VACUUM&&t!=SPC_PGRV&&t!=SPC_NGRV))
- return -1;
- if (t>=0 && t<PT_NUM && !ptypes[t].enabled)
- return -1;
- if(t==SPC_PROP) {
- return -1; //Prop tool works on a mouse click basic, make sure it doesn't do anything here
- }
-
- if (t==SPC_HEAT||t==SPC_COOL)
- {
- int r = pmap[y][x];
- if (!(r&0xFF))
- r = photons[y][x];
- if ((r&0xFF)!=PT_NONE&&(r&0xFF)<PT_NUM)
- {
- if (t==SPC_HEAT&&parts[r>>8].temp<MAX_TEMP)
- {
- float heatchange;
- int 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[r>>8].temp>MIN_TEMP)
- {
- float heatchange;
- int 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 r>>8;
- }
- else
- {
- return -1;
- }
- }
- if (t==SPC_AIR)
- {
- pv[y/CELL][x/CELL] += 0.10f;
- return -1;
- }
- if (t==SPC_VACUUM)
- {
- pv[y/CELL][x/CELL] -= 0.10f;
- return -1;
- }
- if (t==SPC_PGRV)
- {
- gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = 5;
- return -1;
- }
- if (t==SPC_NGRV)
- {
- gravmap[(y/CELL)*(XRES/CELL)+(x/CELL)] = -5;
- return -1;
- }
-
-
- if (t==PT_SPRK)
- {
- if((pmap[y][x]&0xFF)==PT_WIRE){
- parts[pmap[y][x]>>8].ctype=PT_DUST;
- }
- if (!((pmap[y][x]&0xFF)==PT_INST||(ptypes[pmap[y][x]&0xFF].properties&PROP_CONDUCTS)))
- return -1;
- if (parts[pmap[y][x]>>8].life!=0)
- return -1;
- if (p==-2 && (pmap[y][x]&0xFF)==PT_INST)
- {
- flood_INST(x, y, PT_SPRK, PT_INST);
- return pmap[y][x]>>8;
- }
- parts[pmap[y][x]>>8].type = PT_SPRK;
- parts[pmap[y][x]>>8].life = 4;
- parts[pmap[y][x]>>8].ctype = pmap[y][x]&0xFF;
- pmap[y][x] = (pmap[y][x]&~0xFF) | PT_SPRK;
- return pmap[y][x]>>8;
- }
- if (t==PT_SPAWN&&ISSPAWN1)
- return -1;
- if (t==PT_SPAWN2&&ISSPAWN2)
- 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
- // If there isn't a particle but there is a wall, check whether the new particle is allowed to be in it
- // (not "!=2" for wall check because eval_move returns 1 for moving into empty space)
- // If there's no particle and no wall, assume creation is allowed
- if (pmap[y][x] ? (eval_move(t, x, y, NULL)!=2) : (bmap[y/CELL][x/CELL] && eval_move(t, x, y, NULL)==0))
- {
- if ((pmap[y][x]&0xFF)!=PT_SPAWN&&(pmap[y][x]&0xFF)!=PT_SPAWN2)
- {
- if (t!=PT_STKM&&t!=PT_STKM2&&t!=PT_FIGH)
- {
- return -1;
- }
- }
- }
- if (pfree == -1)
- return -1;
- i = pfree;
- pfree = parts[i].life;
- }
- else if (p==-2)//creating from brush
- {
- if (pmap[y][x])
- {
- int pmaptype = (pmap[y][x]&0xFF);
- if ((
- (pmaptype==PT_STOR&&!(ptypes[t].properties&TYPE_SOLID))||
- pmaptype==PT_CLNE||
- pmaptype==PT_BCLN||
- pmaptype==PT_CONV||
- (pmaptype==PT_PCLN&&t!=PT_PSCN&&t!=PT_NSCN)||
- (pmaptype==PT_PBCN&&t!=PT_PSCN&&t!=PT_NSCN)
- )&&(
- t!=PT_CLNE&&t!=PT_PCLN&&
- t!=PT_BCLN&&t!=PT_STKM&&
- t!=PT_STKM2&&t!=PT_PBCN&&
- t!=PT_STOR&&t!=PT_FIGH)
- )
- {
- parts[pmap[y][x]>>8].ctype = t;
- if (t==PT_LIFE && v<NGOLALT && (pmap[y][x]&0xFF)!=PT_STOR) parts[pmap[y][x]>>8].tmp = v;
- }
- else if (pmaptype == PT_DTEC && pmaptype != t)
- {
- parts[pmap[y][x]>>8].ctype = t;
- if (t==PT_LIFE && v<NGOLALT) parts[pmap[y][x]>>8].tmp = v;
- }
- return -1;
- }
- if (photons[y][x] && (ptypes[t].properties & TYPE_ENERGY))
- return -1;
- if (pfree == -1)
- return -1;
- i = pfree;
- pfree = parts[i].life;
- }
- else if (p==-3)//skip pmap checks, e.g. for sing explosion
- {
- if (pfree == -1)
- return -1;
- i = pfree;
- pfree = parts[i].life;
- }
- else
- {
- int oldX = (int)(parts[p].x+0.5f);
- int oldY = (int)(parts[p].y+0.5f);
- if ((pmap[oldY][oldX]>>8)==p)
- pmap[oldY][oldX] = 0;
- if ((photons[oldY][oldX]>>8)==p)
- photons[oldY][oldX] = 0;
- i = p;
- }
-
- if (i>parts_lastActiveIndex) parts_lastActiveIndex = i;
-
- parts[i].dcolour = 0;
- parts[i].flags = 0;
- if (t==PT_GLAS)
- {
- parts[i].pavg[1] = pv[y/CELL][x/CELL];
- }
- else if (t==PT_QRTZ)
- {
- parts[i].pavg[1] = pv[y/CELL][x/CELL];
- }
- else
- {
- parts[i].pavg[0] = 0.0f;
- parts[i].pavg[1] = 0.0f;
- }
- if (t!=PT_STKM&&t!=PT_STKM2&&t!=PT_FIGH)//set everything to default values first, except for stickman.
- {
- parts[i].x = (float)x;
- parts[i].y = (float)y;
-#ifdef OGLR
- parts[i].lastX = (float)x;
- parts[i].lastY = (float)y;
-#endif
- parts[i].type = t;
- parts[i].vx = 0;
- parts[i].vy = 0;
- parts[i].life = 0;
- parts[i].ctype = 0;
- parts[i].temp = ptypes[t].heat;
- parts[i].tmp = 0;
- parts[i].tmp2 = 0;
- }
- //now set various properties that we want at spawn.
- /*if (ptypes[t].properties&PROP_LIFE) {
- int r;
- for (r = 0; r<NGOL; r++)
- if (t==goltype[r])
- parts[i].tmp = grule[r+1][9] - 1;
- }*/
- switch (t)
- {
- case PT_SOAP:
- parts[i].tmp = -1;
- parts[i].tmp2 = -1;
- break;
- case PT_ACID: case PT_CAUS:
- parts[i].life = 75;
- break;
- /*Testing
- case PT_WOOD:
- parts[i].life = 150;
- break;
- End Testing*/
- case PT_WARP:
- parts[i].life = rand()%95+70;
- break;
- case PT_FUSE:
- parts[i].life = 50;
- parts[i].tmp = 50;
- break;
- case PT_LIFE:
- if (v<NGOLALT)
- {
- parts[i].tmp = grule[v+1][9] - 1;
- parts[i].ctype = v;
- }
- break;
- case PT_DEUT:
- parts[i].life = 10;
- break;
- case PT_MERC:
- parts[i].tmp = 10;
- break;
- case PT_BRAY:
- parts[i].life = 30;
- break;
- case PT_GPMP: case PT_PUMP:
- parts[i].life = 10;
- break;
- case PT_SING:
- parts[i].life = rand()%50+60;
- break;
- case PT_QRTZ:
- parts[i].tmp = (rand()%11);
- break;
- case PT_PQRT:
- parts[i].tmp = (rand()%11);
- break;
- case PT_CLST:
- parts[i].tmp = (rand()%7);
- break;
- case PT_FSEP:
- parts[i].life = 50;
- break;
- case PT_COAL:
- parts[i].life = 110;
- parts[i].tmp = 50;
- break;
- case PT_IGNT:
- parts[i].life = 3;
- break;
- case PT_FRZW:
- parts[i].life = 100;
- break;
- case PT_PIPE:
- case PT_PPIP:
- parts[i].life = 60;
- break;
- case PT_BCOL:
- parts[i].life = 110;
- break;
- case PT_FIRE:
- parts[i].life = rand()%50+120;
- break;
- case PT_PLSM:
- parts[i].life = rand()%150+50;
- break;
- case PT_HFLM:
- parts[i].life = rand()%150+50;
- break;
- case PT_LAVA:
- parts[i].life = rand()%120+240;
- break;
- case PT_NBLE:
- parts[i].life = 0;
- break;
- case PT_ICEI:
- parts[i].ctype = PT_WATR;
- break;
- case PT_MORT:
- parts[i].vx = 2;
- break;
- case PT_EXOT:
- parts[i].life = 1000;
- parts[i].tmp = 244;
- break;
- case PT_EMBR:
- parts[i].life = 50;
- break;
- case PT_STKM:
- if (player.spwn==0)
- {
- parts[i].x = (float)x;
- parts[i].y = (float)y;
-#ifdef OGLR
- parts[i].lastX = (float)x;
- parts[i].lastY = (float)y;
-#endif
- parts[i].type = PT_STKM;
- parts[i].vx = 0;
- parts[i].vy = 0;
- parts[i].life = 100;
- parts[i].ctype = 0;
- parts[i].temp = ptypes[t].heat;
- STKM_init_legs(&player, i);
- player.spwn = 1;
- }
- else
- {
- return -1;
- }
- create_part(-3,x,y,PT_SPAWN);
- ISSPAWN1 = 1;
- break;
- case PT_STKM2:
- if (player2.spwn==0)
- {
- parts[i].x = (float)x;
- parts[i].y = (float)y;
-#ifdef OGLR
- parts[i].lastX = (float)x;
- parts[i].lastY = (float)y;
-#endif
- parts[i].type = PT_STKM2;
- parts[i].vx = 0;
- parts[i].vy = 0;
- parts[i].life = 100;
- parts[i].ctype = 0;
- parts[i].temp = ptypes[t].heat;
- STKM_init_legs(&player2, i);
- player2.spwn = 1;
- }
- else
- {
- return -1;
- }
- create_part(-3,x,y,PT_SPAWN2);
- ISSPAWN2 = 1;
- break;
- case PT_BIZR: case PT_BIZRG: case PT_BIZRS:
- parts[i].ctype = 0x47FFFF;
- break;
- case PT_DTEC:
- parts[i].tmp2 = 2;
- break;
- default:
- if (t==PT_FIGH)
- {
- unsigned char fcount = 0;
- while (fcount < 100 && fcount < (fighcount+1) && fighters[fcount].spwn==1) fcount++;
- if (fcount < 100 && fighters[fcount].spwn==0)
- {
- parts[i].x = (float)x;
- parts[i].y = (float)y;
-#ifdef OGLR
- parts[i].lastX = (float)x;
- parts[i].lastY = (float)y;
-#endif
- parts[i].type = PT_FIGH;
- parts[i].vx = 0;
- parts[i].vy = 0;
- parts[i].life = 100;
- parts[i].ctype = 0;
- parts[i].tmp = fcount;
- parts[i].temp = ptypes[t].heat;
- STKM_init_legs(&fighters[fcount], i);
- fighters[fcount].spwn = 1;
- fighters[fcount].elem = PT_DUST;
- fighcount++;
-
- return i;
- }
- return -1;
- }
- if (t==PT_PHOT)
- {
- float a = (rand()%8) * 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 (t==PT_ELEC)
- {
- float a = (rand()%360)*3.14159f/180.0f;
- parts[i].life = 680;
- parts[i].vx = 2.0f*cosf(a);
- parts[i].vy = 2.0f*sinf(a);
- }
- if (t==PT_NEUT)
- {
- float r = (rand()%128+128)/127.0f;
- float a = (rand()%360)*3.14159f/180.0f;
- parts[i].life = rand()%480+480;
- parts[i].vx = r*cosf(a);
- parts[i].vy = r*sinf(a);
- }
- if (t==PT_TRON)
- {
- int randhue = rand()%360;
- int randomdir = rand()%4;
- parts[i].tmp = 1|(randomdir<<5)|(randhue<<7);//set as a head and a direction
- parts[i].tmp2 = 4;//tail
- parts[i].life = 5;
- }
- if (t==PT_LIGH)
- {
- float gx, gy, gsize;
- if (p!=-2)
- {
- parts[i].life=30;
- parts[i].temp=parts[i].life*150.0f; // temperature of the lighting shows the power of the lighting
- }
- get_gravity_field(x, y, 1.0f, 1.0f, &gx, &gy);
- gsize = gx*gx+gy*gy;
- if (gsize<0.0016f)
- {
- float angle = (rand()%6284)*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)))+rand()%40-20+360)%360;
- parts[i].tmp2 = 4;
- }
- }
- //and finally set the pmap/photon maps to the newly created particle
- 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);
-
- //Fancy dust effects for powder types
- if((ptypes[t].properties & TYPE_PART) && pretty_powder)
- {
- int colr, colg, colb, randa;
- randa = (rand()%30)-15;
- colr = (PIXR(ptypes[t].pcolors)+sandcolour_r+(rand()%20)-10+randa);
- colg = (PIXG(ptypes[t].pcolors)+sandcolour_g+(rand()%20)-10+randa);
- colb = (PIXB(ptypes[t].pcolors)+sandcolour_b+(rand()%20)-10+randa);
- colr = colr>255 ? 255 : (colr<0 ? 0 : colr);
- colg = colg>255 ? 255 : (colg<0 ? 0 : colg);
- colb = colb>255 ? 255 : (colb<0 ? 0 : colb);
- parts[i].dcolour = 0xFF000000 | (colr<<16) | (colg<<8) | colb;
- }
-
- return i;
-}
-
-static void create_gain_photon(int pp)//photons from PHOT going through GLOW
-{
- float xx, yy;
- int i, lr, temp_bin, nx, ny;
-
- if (pfree == -1)
- return;
- i = pfree;
-
- lr = rand() % 2;
-
- if (lr) {
- 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;
- yy = parts[pp].y - 0.3*parts[pp].vx;
- }
-
- nx = (int)(xx + 0.5f);
- ny = (int)(yy + 0.5f);
-
- if (nx<0 || ny<0 || nx>=XRES || ny>=YRES)
- return;
-
- if ((pmap[ny][nx] & 0xFF) != PT_GLOW)
- return;
-
- pfree = parts[i].life;
- if (i>parts_lastActiveIndex) parts_lastActiveIndex = i;
-
- parts[i].type = PT_PHOT;
- parts[i].life = 680;
- parts[i].x = xx;
- parts[i].y = yy;
- parts[i].vx = parts[pp].vx;
- parts[i].vy = parts[pp].vy;
- parts[i].temp = parts[pmap[ny][nx] >> 8].temp;
- parts[i].tmp = 0;
- parts[i].pavg[0] = parts[i].pavg[1] = 0.0f;
- photons[ny][nx] = PT_PHOT|(i<<8);
-
- temp_bin = (int)((parts[i].temp-273.0f)*0.25f);
- if (temp_bin < 0) temp_bin = 0;
- if (temp_bin > 25) temp_bin = 25;
- parts[i].ctype = 0x1F << temp_bin;
-}
-
-static void create_cherenkov_photon(int pp)//photons from NEUT going through GLAS
-{
- int i, lr, nx, ny;
- float r, eff_ior;
-
- if (pfree == -1)
- return;
- i = pfree;
-
- nx = (int)(parts[pp].x + 0.5f);
- ny = (int)(parts[pp].y + 0.5f);
- if ((pmap[ny][nx] & 0xFF) != PT_GLAS)
- return;
-
- if (hypotf(parts[pp].vx, parts[pp].vy) < 1.44f)
- return;
-
- pfree = parts[i].life;
- if (i>parts_lastActiveIndex) parts_lastActiveIndex = i;
-
- lr = rand() % 2;
-
- parts[i].type = PT_PHOT;
- parts[i].ctype = 0x00000F80;
- parts[i].life = 680;
- parts[i].x = parts[pp].x;
- parts[i].y = parts[pp].y;
- parts[i].temp = parts[pmap[ny][nx] >> 8].temp;
- parts[i].tmp = 0;
- parts[i].pavg[0] = parts[i].pavg[1] = 0.0f;
- photons[ny][nx] = PT_PHOT|(i<<8);
-
- if (lr) {
- 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;
- }
-
- /* photons have speed of light. no discussion. */
- r = 1.269 / hypotf(parts[i].vx, parts[i].vy);
- parts[i].vx *= r;
- parts[i].vy *= r;
-}
-
-#if defined(WIN32) && !defined(__GNUC__)
-_inline void delete_part(int x, int y, int flags)//calls kill_part with the particle located at x,y
-#else
-inline void delete_part(int x, int y, int flags)//calls kill_part with the particle located at x,y
-#endif
-{
- unsigned i;
-
- if (x<0 || y<0 || x>=XRES || y>=YRES)
- return;
- if (photons[y][x]) {
- i = photons[y][x];
- } else {
- i = pmap[y][x];
- }
-
- if (!i)
- return;
- if (!(flags&BRUSH_SPECIFIC_DELETE) || parts[i>>8].type==SLALT || SLALT==0)//specific deletiom
- {
- kill_part(i>>8);
- }
- else if (ptypes[parts[i>>8].type].menusection==SEC)//specific menu deletion
- {
- kill_part(i>>8);
- }
- else
- return;
-}
-
-#if defined(WIN32) && !defined(__GNUC__)
-_inline int is_wire(int x, int y)
-#else
-inline int is_wire(int x, int y)
-#endif
-{
- return bmap[y][x]==WL_DETECT || bmap[y][x]==WL_EWALL || bmap[y][x]==WL_ALLOWLIQUID || bmap[y][x]==WL_WALLELEC || bmap[y][x]==WL_ALLOWALLELEC || bmap[y][x]==WL_EHOLE;
-}
-
-#if defined(WIN32) && !defined(__GNUC__)
-_inline int is_wire_off(int x, int y)
-#else
-inline int is_wire_off(int x, int y)
-#endif
-{
- return (bmap[y][x]==WL_DETECT || bmap[y][x]==WL_EWALL || bmap[y][x]==WL_ALLOWLIQUID || bmap[y][x]==WL_WALLELEC || bmap[y][x]==WL_ALLOWALLELEC || bmap[y][x]==WL_EHOLE) && emap[y][x]<8;
-}
-
-int get_wavelength_bin(int *wm)
-{
- int i, w0=30, wM=0;
-
- if (!*wm)
- return -1;
-
- for (i=0; i<30; i++)
- if (*wm & (1<<i)) {
- if (i < w0)
- w0 = i;
- if (i > wM)
- wM = i;
- }
-
- if (wM-w0 < 5)
- return (wM+w0)/2;
-
- i = rand() % (wM-w0-3);
- i += w0;
-
- *wm &= 0x1F << i;
- return i + 2;
-}
-
-void set_emap(int x, int y)
-{
- int x1, x2;
-
- if (!is_wire_off(x, y))
- return;
-
- // go left as far as possible
- x1 = x2 = x;
- while (x1>0)
- {
- if (!is_wire_off(x1-1, y))
- break;
- x1--;
- }
- while (x2<XRES/CELL-1)
- {
- if (!is_wire_off(x2+1, y))
- break;
- x2++;
- }
-
- // fill span
- for (x=x1; x<=x2; x++)
- emap[y][x] = 16;
-
- // fill children
-
- if (y>1 && x1==x2 &&
- is_wire(x1-1, y-1) && is_wire(x1, y-1) && is_wire(x1+1, y-1) &&
- !is_wire(x1-1, y-2) && is_wire(x1, y-2) && !is_wire(x1+1, y-2))
- set_emap(x1, y-2);
- else if (y>0)
- for (x=x1; x<=x2; x++)
- if (is_wire_off(x, y-1))
- {
- if (x==x1 || x==x2 || y>=YRES/CELL-1 ||
- is_wire(x-1, y-1) || is_wire(x+1, y-1) ||
- is_wire(x-1, y+1) || !is_wire(x, y+1) || is_wire(x+1, y+1))
- set_emap(x, y-1);
- }
-
- if (y<YRES/CELL-2 && x1==x2 &&
- is_wire(x1-1, y+1) && is_wire(x1, y+1) && is_wire(x1+1, y+1) &&
- !is_wire(x1-1, y+2) && is_wire(x1, y+2) && !is_wire(x1+1, y+2))
- set_emap(x1, y+2);
- else if (y<YRES/CELL-1)
- for (x=x1; x<=x2; x++)
- if (is_wire_off(x, y+1))
- {
- if (x==x1 || x==x2 || y<0 ||
- is_wire(x-1, y+1) || is_wire(x+1, y+1) ||
- is_wire(x-1, y-1) || !is_wire(x, y-1) || is_wire(x+1, y-1))
- set_emap(x, y+1);
- }
-}
-
-#if defined(WIN32) && !defined(__GNUC__)
-int parts_avg(int ci, int ni,int t)//t is the particle you are looking for, returns the particle between two particles
-#else
-inline int parts_avg(int ci, int ni,int t)
-#endif
-{
- if (t==PT_INSL)//to keep electronics working
- {
- int pmr = pmap[((int)(parts[ci].y+0.5f) + (int)(parts[ni].y+0.5f))/2][((int)(parts[ci].x+0.5f) + (int)(parts[ni].x+0.5f))/2];
- if (pmr)
- return parts[pmr>>8].type;
- else
- return PT_NONE;
- }
- else
- {
- int pmr2 = pmap[(int)((parts[ci].y + parts[ni].y)/2+0.5f)][(int)((parts[ci].x + parts[ni].x)/2+0.5f)];//seems to be more accurate.
- if (pmr2)
- {
- if (parts[pmr2>>8].type==t)
- return t;
- }
- else
- return PT_NONE;
- }
- return PT_NONE;
-}
-
-
-int nearest_part(int ci, int t, int max_d)
-{
- int distance = (max_d!=-1)?max_d:MAX_DISTANCE;
- int ndistance = 0;
- int id = -1;
- int i = 0;
- int cx = (int)parts[ci].x;
- int cy = (int)parts[ci].y;
- for (i=0; i<=parts_lastActiveIndex; i++)
- {
- if ((parts[i].type==t||(t==-1&&parts[i].type))&&!parts[i].life&&i!=ci)
- {
- ndistance = abs(cx-parts[i].x)+abs(cy-parts[i].y);// Faster but less accurate Older: sqrt(pow(cx-parts[i].x, 2)+pow(cy-parts[i].y, 2));
- if (ndistance<distance)
- {
- distance = ndistance;
- id = i;
- }
- }
- }
- return id;
-}
-
-void create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int type, int flags)
-{
- int i;
- float xint, yint;
- int *xmid, *ymid;
- int voffset = variance/2;
- xmid = calloc(midpoints + 2, sizeof(int));
- ymid = calloc(midpoints + 2, sizeof(int));
- xint = (float)(dx-sx)/(float)(midpoints+1.0f);
- yint = (float)(dy-sy)/(float)(midpoints+1.0f);
- xmid[0] = sx;
- xmid[midpoints+1] = dx;
- ymid[0] = sy;
- ymid[midpoints+1] = dy;
-
- for(i = 1; i <= midpoints; i++)
- {
- ymid[i] = ymid[i-1]+yint;
- xmid[i] = xmid[i-1]+xint;
- }
-
- for(i = 0; i <= midpoints; i++)
- {
- if(i!=midpoints)
- {
- xmid[i+1] += (rand()%variance)-voffset;
- ymid[i+1] += (rand()%variance)-voffset;
- }
- create_line(xmid[i], ymid[i], xmid[i+1], ymid[i+1], 0, 0, type, flags);
- }
- free(xmid);
- free(ymid);
-}
-
-//the main function for updating particles
-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, 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;
- float pt = R_TEMP;
- float c_heat = 0.0f;
- int h_count = 0;
- int starti = (start*-1);
- int surround[8];
- int surround_hconduct[8];
- int lighting_ok=1;
- unsigned int elem_properties;
- float pGravX, pGravY, pGravD;
- int excessive_stacking_found = 0;
-
- if (sys_pause&&lighting_recreate>0)
- {
- for (i=0; i<=parts_lastActiveIndex; i++)
- {
- if (parts[i].type==PT_LIGH && parts[i].tmp2>0)
- {
- lighting_ok=0;
- break;
- }
- }
- }
-
- if (lighting_ok)
- lighting_recreate--;
-
- if (lighting_recreate<0)
- lighting_recreate=1;
-
- if (lighting_recreate>21)
- lighting_recreate=21;
-
- if (sys_pause&&!framerender)//do nothing if paused
- return;
-
- if (force_stacking_check || (rand()%10)==0)
- {
- force_stacking_check = 0;
- excessive_stacking_found = 0;
- for (y=0; y<YRES; y++)
- {
- for (x=0; x<XRES; x++)
- {
- // Use a threshold, since some particle stacking can be normal (e.g. BIZR + FILT)
- // Setting pmap_count[y][x] > NPART means BHOL will form in that spot
- if (pmap_count[y][x]>5)
- {
- if (bmap[y/CELL][x/CELL]==WL_EHOLE)
- {
- // Allow more stacking in E-hole
- if (pmap_count[y][x]>1500)
- {
- pmap_count[y][x] = pmap_count[y][x] + NPART;
- excessive_stacking_found = 1;
- }
- }
- // Random chance to turn into BHOL that increases with the amount of stacking, up to a threshold where it is certain to turn into BHOL
- else if (pmap_count[y][x]>1500 || (rand()%1600)<=(pmap_count[y][x]+100))
- {
- pmap_count[y][x] = pmap_count[y][x] + NPART;
- excessive_stacking_found = 1;
- }
- }
- }
- }
- if (excessive_stacking_found)
- {
- for (i=0; i<=parts_lastActiveIndex; i++)
- {
- if (parts[i].type)
- {
- t = parts[i].type;
- x = (int)(parts[i].x+0.5f);
- y = (int)(parts[i].y+0.5f);
- if (x>=0 && y>=0 && x<XRES && y<YRES && !(ptypes[t].properties&TYPE_ENERGY))
- {
- if (pmap_count[y][x]>=NPART)
- {
- if (pmap_count[y][x]>NPART)
- {
- create_part(i, x, y, PT_NBHL);
- parts[i].temp = MAX_TEMP;
- parts[i].tmp = pmap_count[y][x]-NPART;//strength of grav field
- if (parts[i].tmp>51200) parts[i].tmp = 51200;
- pmap_count[y][x] = NPART;
- }
- else
- {
- kill_part(i);
- }
- }
- }
- }
- }
- }
- }
-
- if (ISGRAV==1)//crappy grav color handling, i will change this someday
- {
- ISGRAV = 0;
- GRAV ++;
- GRAV_R = 60;
- GRAV_G = 0;
- GRAV_B = 0;
- GRAV_R2 = 30;
- GRAV_G2 = 30;
- GRAV_B2 = 0;
- for ( q = 0; q <= GRAV; q++)
- {
- if (GRAV_R >0 && GRAV_G==0)
- {
- GRAV_R--;
- GRAV_B++;
- }
- if (GRAV_B >0 && GRAV_R==0)
- {
- GRAV_B--;
- GRAV_G++;
- }
- if (GRAV_G >0 && GRAV_B==0)
- {
- GRAV_G--;
- GRAV_R++;
- }
- if (GRAV_R2 >0 && GRAV_G2==0)
- {
- GRAV_R2--;
- GRAV_B2++;
- }
- if (GRAV_B2 >0 && GRAV_R2==0)
- {
- GRAV_B2--;
- GRAV_G2++;
- }
- if (GRAV_G2 >0 && GRAV_B2==0)
- {
- GRAV_G2--;
- GRAV_R2++;
- }
- }
- if (GRAV>180) GRAV = 0;
-
- }
- if (ISLOVE==1)//LOVE element handling
- {
- ISLOVE = 0;
- for (ny=0; ny<YRES-4; ny++)
- {
- for (nx=0; nx<XRES-4; nx++)
- {
- r=pmap[ny][nx];
- if (!r)
- {
- continue;
- }
- else if ((ny<9||nx<9||ny>YRES-7||nx>XRES-10)&&parts[r>>8].type==PT_LOVE)
- kill_part(r>>8);
- else if (parts[r>>8].type==PT_LOVE)
- {
- love[nx/9][ny/9] = 1;
- }
-
- }
- }
- for (nx=9; nx<=XRES-18; nx++)
- {
- for (ny=9; ny<=YRES-7; ny++)
- {
- if (love[nx/9][ny/9]==1)
- {
- for ( nnx=0; nnx<9; nnx++)
- for ( nny=0; nny<9; nny++)
- {
- if (ny+nny>0&&ny+nny<YRES&&nx+nnx>=0&&nx+nnx<XRES)
- {
- rt=pmap[ny+nny][nx+nnx];
- if (!rt&&loverule[nnx][nny]==1)
- create_part(-1,nx+nnx,ny+nny,PT_LOVE);
- else if (!rt)
- continue;
- else if (parts[rt>>8].type==PT_LOVE&&loverule[nnx][nny]==0)
- kill_part(rt>>8);
- }
- }
- }
- love[nx/9][ny/9]=0;
- }
- }
- }
- if (ISLOLZ==1)//LOLZ element handling
- {
- ISLOLZ = 0;
- for (ny=0; ny<YRES-4; ny++)
- {
- for (nx=0; nx<XRES-4; nx++)
- {
- r=pmap[ny][nx];
- if (!r)
- {
- continue;
- }
- else if ((ny<9||nx<9||ny>YRES-7||nx>XRES-10)&&parts[r>>8].type==PT_LOLZ)
- kill_part(r>>8);
- else if (parts[r>>8].type==PT_LOLZ)
- {
- lolz[nx/9][ny/9] = 1;
- }
-
- }
- }
- for (nx=9; nx<=XRES-18; nx++)
- {
- for (ny=9; ny<=YRES-7; ny++)
- {
- if (lolz[nx/9][ny/9]==1)
- {
- for ( nnx=0; nnx<9; nnx++)
- for ( nny=0; nny<9; nny++)
- {
- if (ny+nny>0&&ny+nny<YRES&&nx+nnx>=0&&nx+nnx<XRES)
- {
- rt=pmap[ny+nny][nx+nnx];
- if (!rt&&lolzrule[nny][nnx]==1)
- create_part(-1,nx+nnx,ny+nny,PT_LOLZ);
- else if (!rt)
- continue;
- else if (parts[rt>>8].type==PT_LOLZ&&lolzrule[nny][nnx]==0)
- kill_part(rt>>8);
-
- }
- }
- }
- lolz[nx/9][ny/9]=0;
- }
- }
- }
- //wire!
- if(wire_placed == 1)
- {
- wire_placed = 0;
- for (nx=0; nx<XRES; nx++)
- {
- for (ny=0; ny<YRES; ny++)
- {
- r = pmap[ny][nx];
- if (!r)
- continue;
- if(parts[r>>8].type==PT_WIRE)
- parts[r>>8].tmp=parts[r>>8].ctype;
- }
- }
- }
-
- if (ppip_changed)
- {
- for (i=0; i<=parts_lastActiveIndex; i++)
- {
- if (parts[i].type==PT_PPIP)
- {
- parts[i].tmp |= (parts[i].tmp&0xE0000000)>>3;
- parts[i].tmp &= ~0xE0000000;
- }
- }
- ppip_changed = 0;
- }
-
- //game of life!
- if (ISGOL==1&&++CGOL>=GSPEED)//GSPEED is frames per generation
- {
- int createdsomething = 0;
- CGOL=0;
- ISGOL=0;
- for (ny=CELL; ny<YRES-CELL; ny++)
- {//go through every particle and set neighbor map
- for (nx=CELL; nx<XRES-CELL; nx++)
- {
- r = pmap[ny][nx];
- if (!r)
- {
- gol[ny][nx] = 0;
- continue;
- }
- else
- {
- //for ( golnum=1; golnum<=NGOL; golnum++) //This shouldn't be necessary any more.
- //{
- if (parts[r>>8].type==PT_LIFE/* && parts[r>>8].ctype==golnum-1*/)
- {
- golnum = parts[r>>8].ctype+1;
- if (golnum<=0 || golnum>NGOLALT) {
- parts[r>>8].type = PT_NONE;
- continue;
- }
- if (parts[r>>8].tmp == grule[golnum][9]-1) {
- gol[ny][nx] = golnum;
- for ( nnx=-1; nnx<2; nnx++)
- {
- for ( nny=-1; nny<2; nny++)//it will count itself as its own neighbor, which is needed, but will have 1 extra for delete check
- {
- rt = pmap[((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL];
- if (!rt || (rt&0xFF)==PT_LIFE)
- {
- gol2[((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][golnum] ++;
- gol2[((ny+nny+YRES-3*CELL)%(YRES-2*CELL))+CELL][((nx+nnx+XRES-3*CELL)%(XRES-2*CELL))+CELL][0] ++;
- }
- }
- }
- } else {
- parts[r>>8].tmp --;
- if (parts[r>>8].tmp<=0)
- parts[r>>8].type = PT_NONE;//using kill_part makes it not work
- }
- }
- //}
- }
- }
- }
- for (ny=CELL; ny<YRES-CELL; ny++)
- { //go through every particle again, but check neighbor map, then update particles
- for (nx=CELL; nx<XRES-CELL; nx++)
- {
- r = pmap[ny][nx];
- neighbors = gol2[ny][nx][0];
- if (neighbors==0 || !((r&0xFF)==PT_LIFE || !(r&0xFF)))
- continue;
- for ( golnum = 1; golnum<=NGOL; golnum++)
- {
- goldelete = neighbors;
- if (gol[ny][nx]==0&&grule[golnum][goldelete]>=2&&gol2[ny][nx][golnum]>=(goldelete%2)+goldelete/2)
- {
- if (create_part(-1, nx, ny, PT_LIFE|((golnum-1)<<8)))
- createdsomething = 1;
- }
- else if (gol[ny][nx]==golnum&&(grule[golnum][goldelete-1]==0||grule[golnum][goldelete-1]==2))//subtract 1 because it counted itself
- {
- if (parts[r>>8].tmp==grule[golnum][9]-1)
- parts[r>>8].tmp --;
- }
- if (r && parts[r>>8].tmp<=0)
- parts[r>>8].type = PT_NONE;//using kill_part makes it not work
- }
- for ( z = 0; z<=NGOL; z++)
- gol2[ny][nx][z] = 0;//this improves performance A LOT compared to the memset, i was getting ~23 more fps with this.
- }
- }
- if (createdsomething)
- GENERATION ++;
- //memset(gol2, 0, sizeof(gol2));
- }
- if (ISWIRE>0)//wifi channel reseting
- {
- for ( q = 0; q<(int)(MAX_TEMP-73.15f)/100+2; q++)
- {
- wireless[q][0] = wireless[q][1];
- wireless[q][1] = 0;
- }
- ISWIRE--;
- }
- for (i=0; i<=parts_lastActiveIndex; i++)
- if (parts[i].type)
- {
- t = parts[i].type;
-#ifdef OGLR
- parts[i].lastX = parts[i].x;
- parts[i].lastY = parts[i].y;
-#endif
- if (t<0 || t>=PT_NUM)
- {
- kill_part(i);
- continue;
- }
- elem_properties = ptypes[t].properties;
- if (parts[i].life>0 && (elem_properties&PROP_LIFE_DEC))
- {
- // automatically decrease life
- parts[i].life--;
- if (parts[i].life<=0 && (elem_properties&(PROP_LIFE_KILL_DEC|PROP_LIFE_KILL)))
- {
- // kill on change to no life
- kill_part(i);
- continue;
- }
- }
- else if (parts[i].life<=0 && (elem_properties&PROP_LIFE_KILL))
- {
- // kill if no life
- kill_part(i);
- continue;
- }
- }
- //the main particle loop function, goes over all particles.
- for (i=0; i<=parts_lastActiveIndex; i++)
- if (parts[i].type)
- {
- t = parts[i].type;
- x = (int)(parts[i].x+0.5f);
- y = (int)(parts[i].y+0.5f);
-
- //this kills any particle out of the screen, or in a wall where it isn't supposed to go
- if (x<CELL || y<CELL || x>=XRES-CELL || y>=YRES-CELL ||
- (bmap[y/CELL][x/CELL] &&
- (bmap[y/CELL][x/CELL]==WL_WALL ||
- bmap[y/CELL][x/CELL]==WL_WALLELEC ||
- bmap[y/CELL][x/CELL]==WL_ALLOWAIR ||
- (bmap[y/CELL][x/CELL]==WL_DESTROYALL) ||
- (bmap[y/CELL][x/CELL]==WL_ALLOWLIQUID && ptypes[t].falldown!=2) ||
- (bmap[y/CELL][x/CELL]==WL_ALLOWSOLID && ptypes[t].falldown!=1) ||
- (bmap[y/CELL][x/CELL]==WL_ALLOWGAS && !(ptypes[t].properties&TYPE_GAS)) || //&& ptypes[t].falldown!=0 && parts[i].type!=PT_FIRE && parts[i].type!=PT_SMKE && parts[i].type!=PT_HFLM) ||
- (bmap[y/CELL][x/CELL]==WL_ALLOWENERGY && !(ptypes[t].properties&TYPE_ENERGY)) ||
- (bmap[y/CELL][x/CELL]==WL_DETECT && (t==PT_METL || t==PT_SPRK)) ||
- (bmap[y/CELL][x/CELL]==WL_EWALL && !emap[y/CELL][x/CELL])) && (t!=PT_STKM) && (t!=PT_STKM2) && (t!=PT_FIGH)))
- {
- kill_part(i);
- continue;
- }
- if (bmap[y/CELL][x/CELL]==WL_DETECT && emap[y/CELL][x/CELL]<8)
- set_emap(x/CELL, y/CELL);
-
- //adding to velocity from the particle's velocity
- vx[y/CELL][x/CELL] = vx[y/CELL][x/CELL]*ptypes[t].airloss + ptypes[t].airdrag*parts[i].vx;
- vy[y/CELL][x/CELL] = vy[y/CELL][x/CELL]*ptypes[t].airloss + ptypes[t].airdrag*parts[i].vy;
-
- if (t==PT_GAS||t==PT_NBLE)
- {
- if (pv[y/CELL][x/CELL]<3.5f)
- pv[y/CELL][x/CELL] += ptypes[t].hotair*(3.5f-pv[y/CELL][x/CELL]);
- if (y+CELL<YRES && pv[y/CELL+1][x/CELL]<3.5f)
- pv[y/CELL+1][x/CELL] += ptypes[t].hotair*(3.5f-pv[y/CELL+1][x/CELL]);
- if (x+CELL<XRES)
- {
- if (pv[y/CELL][x/CELL+1]<3.5f)
- pv[y/CELL][x/CELL+1] += ptypes[t].hotair*(3.5f-pv[y/CELL][x/CELL+1]);
- if (y+CELL<YRES && pv[y/CELL+1][x/CELL+1]<3.5f)
- pv[y/CELL+1][x/CELL+1] += ptypes[t].hotair*(3.5f-pv[y/CELL+1][x/CELL+1]);
- }
- }
- else//add the hotair variable to the pressure map, like black hole, or white hole.
- {
- pv[y/CELL][x/CELL] += ptypes[t].hotair;
- if (y+CELL<YRES)
- pv[y/CELL+1][x/CELL] += ptypes[t].hotair;
- if (x+CELL<XRES)
- {
- pv[y/CELL][x/CELL+1] += ptypes[t].hotair;
- if (y+CELL<YRES)
- pv[y/CELL+1][x/CELL+1] += ptypes[t].hotair;
- }
- }
-
- //Gravity mode by Moach
- switch (gravityMode)
- {
- default:
- case 0:
- pGravX = 0.0f;
- pGravY = ptypes[t].gravity;
- break;
- case 1:
- pGravX = pGravY = 0.0f;
- break;
- case 2:
- pGravD = 0.01f - hypotf((x - XCNTR), (y - YCNTR));
- pGravX = ptypes[t].gravity * ((float)(x - XCNTR) / pGravD);
- pGravY = ptypes[t].gravity * ((float)(y - YCNTR) / pGravD);
- }
- //Get some gravity from the gravity map
- if (t==PT_ANAR)
- {
- // perhaps we should have a ptypes variable for this
- pGravX -= gravx[(y/CELL)*(XRES/CELL)+(x/CELL)];
- pGravY -= gravy[(y/CELL)*(XRES/CELL)+(x/CELL)];
- }
- else if(t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH && !(ptypes[t].properties & TYPE_SOLID))
- {
- pGravX += gravx[(y/CELL)*(XRES/CELL)+(x/CELL)];
- pGravY += gravy[(y/CELL)*(XRES/CELL)+(x/CELL)];
- }
- //velocity updates for the particle
- if (!(parts[i].flags&FLAG_MOVABLE))
- {
- parts[i].vx *= ptypes[t].loss;
- parts[i].vy *= ptypes[t].loss;
- }
- //particle gets velocity from the vx and vy maps
- parts[i].vx += ptypes[t].advection*vx[y/CELL][x/CELL] + pGravX;
- parts[i].vy += ptypes[t].advection*vy[y/CELL][x/CELL] + pGravY;
-
-
- if (ptypes[t].diffusion)//the random diffusion that gases have
- {
-#ifdef REALISTIC
- //The magic number controlls diffusion speed
- parts[i].vx += 0.05f*sqrtf(parts[i].temp)*ptypes[t].diffusion*(rand()/(0.5f*RAND_MAX)-1.0f);
- parts[i].vy += 0.05f*sqrtf(parts[i].temp)*ptypes[t].diffusion*(rand()/(0.5f*RAND_MAX)-1.0f);
-#else
- parts[i].vx += ptypes[t].diffusion*(rand()/(0.5f*RAND_MAX)-1.0f);
- parts[i].vy += ptypes[t].diffusion*(rand()/(0.5f*RAND_MAX)-1.0f);
-#endif
- }
-
- j = surround_space = nt = 0;//if nt is greater than 1 after this, then there is a particle around the current particle, that is NOT the current particle's type, for water movement.
- for (nx=-1; nx<2; nx++)
- for (ny=-1; ny<2; ny++) {
- if (nx||ny) {
- surround[j] = r = pmap[y+ny][x+nx];
- j++;
- if (!(r&0xFF))
- surround_space++;//there is empty space
- if ((r&0xFF)!=t)
- nt++;//there is nothing or a different particle
- }
- }
-
- gel_scale = 1.0f;
- if (t==PT_GEL)
- gel_scale = parts[i].tmp*2.55f;
-
- if (!legacy_enable)
- {
- if (y-2 >= 0 && y-2 < YRES && (ptypes[t].properties&TYPE_LIQUID) && (t!=PT_GEL || gel_scale>(1+rand()%255))) {//some heat convection for liquids
- r = pmap[y-2][x];
- if (!(!r || parts[i].type != (r&0xFF))) {
- if (parts[i].temp>parts[r>>8].temp) {
- swappage = parts[i].temp;
- parts[i].temp = parts[r>>8].temp;
- parts[r>>8].temp = swappage;
- }
- }
- }
-
- //heat transfer code
- h_count = 0;
-#ifdef REALISTIC
- if (t&&(t!=PT_HSWC||parts[i].life==10)&&(ptypes[t].hconduct*gel_scale))
- {
- float c_Cm = 0.0f;
-#else
- if (t&&(t!=PT_HSWC||parts[i].life==10)&&(ptypes[t].hconduct*gel_scale)>(rand()%250))
- {
- float c_Cm = 0.0f;
-#endif
- if (aheat_enable && !(ptypes[t].properties&PROP_NOAMBHEAT))
- {
-#ifdef REALISTIC
- c_heat = parts[i].temp*96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight)
- + hv[y/CELL][x/CELL]*100*(pv[y/CELL][x/CELL]+273.15f)/256;
- c_Cm = 96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight)
- + 100*(pv[y/CELL][x/CELL]+273.15f)/256;
- pt = c_heat/c_Cm;
- pt = restrict_flt(pt, -MAX_TEMP+MIN_TEMP, MAX_TEMP-MIN_TEMP);
- parts[i].temp = pt;
- //Pressure increase from heat (temporary)
- pv[y/CELL][x/CELL] += (pt-hv[y/CELL][x/CELL])*0.004;
- hv[y/CELL][x/CELL] = pt;
-#else
- c_heat = (hv[y/CELL][x/CELL]-parts[i].temp)*0.04;
- c_heat = restrict_flt(c_heat, -MAX_TEMP+MIN_TEMP, MAX_TEMP-MIN_TEMP);
- parts[i].temp += c_heat;
- hv[y/CELL][x/CELL] -= c_heat;
-#endif
- }
- c_heat = 0.0f; c_Cm = 0.0f;
- for (j=0; j<8; j++)
- {
- surround_hconduct[j] = i;
- r = surround[j];
- if (!r)
- continue;
- rt = r&0xFF;
-
- if (rt&&ptypes[rt].hconduct&&(rt!=PT_HSWC||parts[r>>8].life==10)
- &&(t!=PT_FILT||(rt!=PT_BRAY&&rt!=PT_BIZR&&rt!=PT_BIZRG))
- &&(rt!=PT_FILT||(t!=PT_BRAY&&t!=PT_PHOT&&t!=PT_BIZR&&t!=PT_BIZRG)))
- {
- surround_hconduct[j] = r>>8;
-#ifdef REALISTIC
- if (rt==PT_GEL)
- gel_scale = parts[r>>8].tmp*2.55f;
- else gel_scale = 1.0f;
-
- c_heat += parts[r>>8].temp*96.645/ptypes[rt].hconduct*gel_scale*fabs(ptypes[rt].weight);
- c_Cm += 96.645/ptypes[rt].hconduct*gel_scale*fabs(ptypes[rt].weight);
-#else
- c_heat += parts[r>>8].temp;
-#endif
- h_count++;
- }
- }
-#ifdef REALISTIC
- if (t==PT_GEL)
- gel_scale = parts[i].tmp*2.55f;
- else gel_scale = 1.0f;
-
- if (t == PT_PHOT)
- pt = (c_heat+parts[i].temp*96.645)/(c_Cm+96.645);
- else
- pt = (c_heat+parts[i].temp*96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight))/(c_Cm+96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight));
-
- c_heat += parts[i].temp*96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight);
- c_Cm += 96.645/ptypes[t].hconduct*gel_scale*fabs(ptypes[t].weight);
- parts[i].temp = restrict_flt(pt, MIN_TEMP, MAX_TEMP);
-#else
- pt = (c_heat+parts[i].temp)/(h_count+1);
- pt = parts[i].temp = restrict_flt(pt, MIN_TEMP, MAX_TEMP);
- for (j=0; j<8; j++)
- {
- parts[surround_hconduct[j]].temp = pt;
- }
-#endif
-
- ctemph = ctempl = pt;
- // change boiling point with pressure
- if ((ptypes[t].state==ST_LIQUID && ptransitions[t].tht>-1 && ptransitions[t].tht<PT_NUM && ptypes[ptransitions[t].tht].state==ST_GAS)
- || t==PT_LNTG || t==PT_SLTW)
- ctemph -= 2.0f*pv[y/CELL][x/CELL];
- else if ((ptypes[t].state==ST_GAS && ptransitions[t].tlt>-1 && ptransitions[t].tlt<PT_NUM && ptypes[ptransitions[t].tlt].state==ST_LIQUID)
- || t==PT_WTRV)
- ctempl -= 2.0f*pv[y/CELL][x/CELL];
- s = 1;
-
- //A fix for ice with ctype = 0
- if ((t==PT_ICEI || t==PT_SNOW) && (parts[i].ctype==0 || parts[i].ctype>=PT_NUM || parts[i].ctype==PT_ICEI || parts[i].ctype==PT_SNOW))
- parts[i].ctype = PT_WATR;
-
- if (ctemph>ptransitions[t].thv&&ptransitions[t].tht>-1) {
- // particle type change due to high temperature
-#ifdef REALISTIC
- float dbt = ctempl - pt;
- if (ptransitions[t].tht!=PT_NUM)
- {
- if (platent[t] <= (c_heat - (ptransitions[t].thv - dbt)*c_Cm))
- {
- pt = (c_heat - platent[t])/c_Cm;
- t = ptransitions[t].tht;
- }
- else
- {
- parts[i].temp = restrict_flt(ptransitions[t].thv - dbt, MIN_TEMP, MAX_TEMP);
- s = 0;
- }
- }
-#else
- if (ptransitions[t].tht!=PT_NUM)
- t = ptransitions[t].tht;
-#endif
- else if (t==PT_ICEI || t==PT_SNOW) {
- if (parts[i].ctype<PT_NUM&&parts[i].ctype!=t) {
- if (ptransitions[parts[i].ctype].tlt==t&&pt<=ptransitions[parts[i].ctype].tlv) s = 0;
- else {
-#ifdef REALISTIC
- //One ice table value for all it's kinds
- if (platent[t] <= (c_heat - (ptransitions[parts[i].ctype].tlv - dbt)*c_Cm))
- {
- pt = (c_heat - platent[t])/c_Cm;
- t = parts[i].ctype;
- parts[i].ctype = PT_NONE;
- parts[i].life = 0;
- }
- else
- {
- parts[i].temp = restrict_flt(ptransitions[parts[i].ctype].tlv - dbt, MIN_TEMP, MAX_TEMP);
- s = 0;
- }
-#else
- t = parts[i].ctype;
- parts[i].ctype = PT_NONE;
- parts[i].life = 0;
-#endif
- }
- }
- else s = 0;
- }
- else if (t==PT_SLTW) {
-#ifdef REALISTIC
- if (platent[t] <= (c_heat - (ptransitions[t].thv - dbt)*c_Cm))
- {
- pt = (c_heat - platent[t])/c_Cm;
-
- if (rand()%4==0) t = PT_SALT;
- else t = PT_WTRV;
- }
- else
- {
- parts[i].temp = restrict_flt(ptransitions[t].thv - dbt, MIN_TEMP, MAX_TEMP);
- s = 0;
- }
-#else
- if (rand()%4==0) t = PT_SALT;
- else t = PT_WTRV;
-#endif
- }
- else s = 0;
- } else if (ctempl<ptransitions[t].tlv&&ptransitions[t].tlt>-1) {
- // particle type change due to low temperature
-#ifdef REALISTIC
- float dbt = ctempl - pt;
- if (ptransitions[t].tlt!=PT_NUM)
- {
- if (platent[ptransitions[t].tlt] >= (c_heat - (ptransitions[t].tlv - dbt)*c_Cm))
- {
- pt = (c_heat + platent[ptransitions[t].tlt])/c_Cm;
- t = ptransitions[t].tlt;
- }
- else
- {
- parts[i].temp = restrict_flt(ptransitions[t].tlv - dbt, MIN_TEMP, MAX_TEMP);
- s = 0;
- }
- }
-#else
- if (ptransitions[t].tlt!=PT_NUM)
- t = ptransitions[t].tlt;
-#endif
- else if (t==PT_WTRV) {
- if (pt<273.0f) t = PT_RIME;
- else t = PT_DSTW;
- }
- else if (t==PT_LAVA) {
- if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && parts[i].ctype!=PT_LAVA) {
- if (parts[i].ctype==PT_THRM&&pt>=ptransitions[PT_BMTL].thv) s = 0;
- else if (ptransitions[parts[i].ctype].tht==PT_LAVA) {
- if (pt>=ptransitions[parts[i].ctype].thv) s = 0;
- }
- else if (pt>=973.0f) s = 0; // freezing point for lava with any other (not listed in ptransitions as turning into lava) ctype
- if (s) {
- t = parts[i].ctype;
- parts[i].ctype = PT_NONE;
- if (t==PT_THRM) {
- parts[i].tmp = 0;
- t = PT_BMTL;
- }
- if (t==PT_PLUT)
- {
- parts[i].tmp = 0;
- t = PT_LAVA;
- }
- }
- }
- else if (pt<973.0f) t = PT_STNE;
- else s = 0;
- }
- else s = 0;
- }
- else s = 0;
-#ifdef REALISTIC
- pt = restrict_flt(pt, MIN_TEMP, MAX_TEMP);
- for (j=0; j<8; j++)
- {
- parts[surround_hconduct[j]].temp = pt;
- }
-#endif
- if (s) { // particle type change occurred
- if (t==PT_ICEI||t==PT_LAVA||t==PT_SNOW)
- parts[i].ctype = parts[i].type;
- if (!(t==PT_ICEI&&parts[i].ctype==PT_FRZW)) parts[i].life = 0;
- if (ptypes[t].state==ST_GAS&&ptypes[parts[i].type].state!=ST_GAS)
- pv[y/CELL][x/CELL] += 0.50f;
- part_change_type(i,x,y,t);
- if (t==PT_FIRE||t==PT_PLSM||t==PT_HFLM)
- parts[i].life = rand()%50+120;
- if (t==PT_LAVA) {
- if (parts[i].ctype==PT_BRMT) parts[i].ctype = PT_BMTL;
- else if (parts[i].ctype==PT_SAND) parts[i].ctype = PT_GLAS;
- else if (parts[i].ctype==PT_BGLA) parts[i].ctype = PT_GLAS;
- else if (parts[i].ctype==PT_PQRT) parts[i].ctype = PT_QRTZ;
- parts[i].life = rand()%120+240;
- }
- if (t==PT_NONE) {
- kill_part(i);
- goto killed;
- }
- }
-
- pt = parts[i].temp = restrict_flt(parts[i].temp, MIN_TEMP, MAX_TEMP);
- if (t==PT_LAVA) {
- parts[i].life = restrict_flt((parts[i].temp-700)/7, 0.0f, 400.0f);
- if (parts[i].ctype==PT_THRM&&parts[i].tmp>0)
- {
- parts[i].tmp--;
- parts[i].temp = 3500;
- }
- if (parts[i].ctype==PT_PLUT&&parts[i].tmp>0)
- {
- parts[i].tmp--;
- parts[i].temp = MAX_TEMP;
- }
- }
- }
- else parts[i].temp = restrict_flt(parts[i].temp, MIN_TEMP, MAX_TEMP);
- }
-
- if (t==PT_LIFE)
- {
- parts[i].temp = restrict_flt(parts[i].temp-50.0f, MIN_TEMP, MAX_TEMP);
- ISGOL=1;//means there is a life particle on screen
- }
- if (t==PT_WIRE)
- {
- wire_placed = 1;
- }
- //spark updates from walls
- if ((ptypes[t].properties&PROP_CONDUCTS) || t==PT_SPRK)
- {
- nx = x % CELL;
- if (nx == 0)
- nx = x/CELL - 1;
- else if (nx == CELL-1)
- nx = x/CELL + 1;
- else
- nx = x/CELL;
- ny = y % CELL;
- if (ny == 0)
- ny = y/CELL - 1;
- else if (ny == CELL-1)
- ny = y/CELL + 1;
- else
- ny = y/CELL;
- if (nx>=0 && ny>=0 && nx<XRES/CELL && ny<YRES/CELL)
- {
- if (t!=PT_SPRK)
- {
- if (emap[ny][nx]==12 && !parts[i].life)
- {
- part_change_type(i,x,y,PT_SPRK);
- parts[i].life = 4;
- parts[i].ctype = t;
- t = PT_SPRK;
- }
- }
- else if (bmap[ny][nx]==WL_DETECT || bmap[ny][nx]==WL_EWALL || bmap[ny][nx]==WL_ALLOWLIQUID || bmap[ny][nx]==WL_WALLELEC || bmap[ny][nx]==WL_ALLOWALLELEC || bmap[ny][nx]==WL_EHOLE)
- set_emap(nx, ny);
- }
- }
-
- //the basic explosion, from the .explosive variable
- if ((ptypes[t].explosive&2) && pv[y/CELL][x/CELL]>2.5f)
- {
- parts[i].life = rand()%80+180;
- parts[i].temp = restrict_flt(ptypes[PT_FIRE].heat + (ptypes[t].flammable/2), MIN_TEMP, MAX_TEMP);
- t = PT_FIRE;
- part_change_type(i,x,y,t);
- pv[y/CELL][x/CELL] += 0.25f * CFDS;
- }
-
-
- s = 1;
- gravtot = fabs(gravy[(y/CELL)*(XRES/CELL)+(x/CELL)])+fabs(gravx[(y/CELL)*(XRES/CELL)+(x/CELL)]);
- if (pv[y/CELL][x/CELL]>ptransitions[t].phv&&ptransitions[t].pht>-1) {
- // particle type change due to high pressure
- if (ptransitions[t].pht!=PT_NUM)
- t = ptransitions[t].pht;
- else if (t==PT_BMTL) {
- if (pv[y/CELL][x/CELL]>2.5f)
- t = PT_BRMT;
- else if (pv[y/CELL][x/CELL]>1.0f && parts[i].tmp==1)
- t = PT_BRMT;
- else s = 0;
- }
- else s = 0;
- } else if (pv[y/CELL][x/CELL]<ptransitions[t].plv&&ptransitions[t].plt>-1) {
- // particle type change due to low pressure
- if (ptransitions[t].plt!=PT_NUM)
- t = ptransitions[t].plt;
- else s = 0;
- } else if (gravtot>(ptransitions[t].phv/4.0f)&&ptransitions[t].pht>-1) {
- // particle type change due to high gravity
- if (ptransitions[t].pht!=PT_NUM)
- t = ptransitions[t].pht;
- else if (t==PT_BMTL) {
- if (gravtot>0.625f)
- t = PT_BRMT;
- else if (gravtot>0.25f && parts[i].tmp==1)
- t = PT_BRMT;
- else s = 0;
- }
- else s = 0;
- } else s = 0;
- if (s) { // particle type change occurred
- parts[i].life = 0;
- part_change_type(i,x,y,t);
- if (t==PT_FIRE)
- parts[i].life = rand()%50+120;
- if (t==PT_NONE) {
- kill_part(i);
- goto killed;
- }
- }
-
- //call the particle update function, if there is one
-#ifdef LUACONSOLE
- if (ptypes[t].update_func && lua_el_mode[t] != 2)
-#else
- if (ptypes[t].update_func)
-#endif
- {
- if ((*(ptypes[t].update_func))(i,x,y,surround_space,nt))
- continue;
- else if (t==PT_WARP)
- {
- // Warp does some movement in its update func, update variables to avoid incorrect data in pmap
- x = (int)(parts[i].x+0.5f);
- y = (int)(parts[i].y+0.5f);
- }
- }
-#ifdef LUACONSOLE
- if(lua_el_mode[t])
- {
- if(luacon_part_update(t,i,x,y,surround_space,nt))
- continue;
- // Need to update variables, in case they've been changed by Lua
- x = (int)(parts[i].x+0.5f);
- y = (int)(parts[i].y+0.5f);
- }
-#endif
- if (legacy_enable)//if heat sim is off
- update_legacy_all(i,x,y,surround_space,nt);
-
-killed:
- if (parts[i].type == PT_NONE)//if its dead, skip to next particle
- continue;
-
- if (!parts[i].vx&&!parts[i].vy)//if its not moving, skip to next particle, movement code it next
- continue;
-
-#if defined(WIN32) && !defined(__GNUC__)
- mv = max(fabsf(parts[i].vx), fabsf(parts[i].vy));
-#else
- mv = fmaxf(fabsf(parts[i].vx), fabsf(parts[i].vy));
-#endif
- if (mv < ISTP)
- {
- clear_x = x;
- clear_y = y;
- clear_xf = parts[i].x;
- clear_yf = parts[i].y;
- fin_xf = clear_xf + parts[i].vx;
- fin_yf = clear_yf + parts[i].vy;
- fin_x = (int)(fin_xf+0.5f);
- fin_y = (int)(fin_yf+0.5f);
- }
- else
- {
- // interpolate to see if there is anything in the way
- dx = parts[i].vx*ISTP/mv;
- dy = parts[i].vy*ISTP/mv;
- fin_xf = parts[i].x;
- fin_yf = parts[i].y;
- while (1)
- {
- mv -= ISTP;
- fin_xf += dx;
- fin_yf += dy;
- fin_x = (int)(fin_xf+0.5f);
- fin_y = (int)(fin_yf+0.5f);
- if (mv <= 0.0f)
- {
- // nothing found
- fin_xf = parts[i].x + parts[i].vx;
- fin_yf = parts[i].y + parts[i].vy;
- fin_x = (int)(fin_xf+0.5f);
- fin_y = (int)(fin_yf+0.5f);
- clear_xf = fin_xf-dx;
- clear_yf = fin_yf-dy;
- clear_x = (int)(clear_xf+0.5f);
- clear_y = (int)(clear_yf+0.5f);
- break;
- }
- if (fin_x<CELL || fin_y<CELL || fin_x>=XRES-CELL || fin_y>=YRES-CELL || pmap[fin_y][fin_x] || (bmap[fin_y/CELL][fin_x/CELL] && (bmap[fin_y/CELL][fin_x/CELL]==WL_DESTROYALL || !eval_move(t,fin_x,fin_y,NULL))))
- {
- // found an obstacle
- clear_xf = fin_xf-dx;
- clear_yf = fin_yf-dy;
- clear_x = (int)(clear_xf+0.5f);
- clear_y = (int)(clear_yf+0.5f);
- break;
- }
- if (bmap[fin_y/CELL][fin_x/CELL]==WL_DETECT && emap[fin_y/CELL][fin_x/CELL]<8)
- set_emap(fin_x/CELL, fin_y/CELL);
- }
- }
-
- stagnant = parts[i].flags & FLAG_STAGNANT;
- parts[i].flags &= ~FLAG_STAGNANT;
-
- if (t==PT_STKM || t==PT_STKM2 || t==PT_FIGH)
- {
- int nx, ny;
- //head movement, let head pass through anything
- parts[i].x += parts[i].vx;
- parts[i].y += parts[i].vy;
- nx = (int)((float)parts[i].x+0.5f);
- ny = (int)((float)parts[i].y+0.5f);
- if (ny!=y || nx!=x)
- {
- if ((pmap[y][x]>>8)==i) pmap[y][x] = 0;
- else if ((photons[y][x]>>8)==i) photons[y][x] = 0;
- if (nx<CELL || nx>=XRES-CELL || ny<CELL || ny>=YRES-CELL)
- {
- kill_part(i);
- continue;
- }
- if (ptypes[t].properties & TYPE_ENERGY)
- photons[ny][nx] = t|(i<<8);
- else if (t)
- pmap[ny][nx] = t|(i<<8);
- }
- }
- else if (ptypes[t].properties & TYPE_ENERGY)
- {
- if (t == PT_PHOT) {
- if (parts[i].flags&FLAG_SKIPMOVE)
- {
- parts[i].flags &= ~FLAG_SKIPMOVE;
- continue;
- }
-
- rt = pmap[fin_y][fin_x] & 0xFF;
- lt = pmap[y][x] & 0xFF;
-
- r = eval_move(PT_PHOT, fin_x, fin_y, NULL);
- if (((rt==PT_GLAS && lt!=PT_GLAS) || (rt!=PT_GLAS && lt==PT_GLAS)) && r) {
- if (!get_normal_interp(REFRACT|t, parts[i].x, parts[i].y, parts[i].vx, parts[i].vy, &nrx, &nry)) {
- kill_part(i);
- 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;
- nrx = -nrx;
- nry = -nry;
- if (rt==PT_GLAS && lt!=PT_GLAS)
- nn = 1.0f/nn;
- ct1 = parts[i].vx*nrx + parts[i].vy*nry;
- ct2 = 1.0f - (nn*nn)*(1.0f-(ct1*ct1));
- if (ct2 < 0.0f) {
- // total internal reflection
- parts[i].vx -= 2.0f*ct1*nrx;
- parts[i].vy -= 2.0f*ct1*nry;
- fin_xf = parts[i].x;
- fin_yf = parts[i].y;
- fin_x = x;
- fin_y = y;
- } else {
- // refraction
- ct2 = sqrtf(ct2);
- ct2 = ct2 - nn*ct1;
- parts[i].vx = nn*parts[i].vx + ct2*nrx;
- parts[i].vy = nn*parts[i].vy + ct2*nry;
- }
- }
- }
- if (stagnant)//FLAG_STAGNANT set, was reflected on previous frame
- {
- // cast coords as int then back to float for compatibility with existing saves
- if (!do_move(i, x, y, (float)fin_x, (float)fin_y) && parts[i].type) {
- kill_part(i);
- continue;
- }
- }
- else if (!do_move(i, x, y, fin_xf, fin_yf))
- {
- if (parts[i].type == PT_NONE)
- continue;
- // reflection
- parts[i].flags |= FLAG_STAGNANT;
- if (t==PT_NEUT && 100>(rand()%1000))
- {
- kill_part(i);
- continue;
- }
- r = pmap[fin_y][fin_x];
-
- if (((r&0xFF)==PT_PIPE || (r&0xFF) == PT_PPIP) && !(parts[r>>8].tmp&0xFF))
- {
- parts[r>>8].tmp = (parts[r>>8].tmp&~0xFF) | parts[i].type;
- parts[r>>8].temp = parts[i].temp;
- parts[r>>8].tmp2 = parts[i].life;
- parts[r>>8].pavg[0] = parts[i].tmp;
- parts[r>>8].pavg[1] = parts[i].ctype;
- kill_part(i);
- continue;
- }
-
- // 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, parts[i].x, parts[i].y, parts[i].vx, parts[i].vy, &nrx, &nry)) {
- dp = nrx*parts[i].vx + nry*parts[i].vy;
- parts[i].vx -= 2.0f*dp*nrx;
- parts[i].vy -= 2.0f*dp*nry;
- // leave the actual movement until next frame so that reflection of fast particles and refraction happen correctly
- } else {
- if (t!=PT_NEUT)
- kill_part(i);
- continue;
- }
- if (!(parts[i].ctype&0x3FFFFFFF)&&t!=PT_NEUT&&t!=PT_ELEC) {
- kill_part(i);
- continue;
- }
- }
- }
- else if (ptypes[t].falldown==0)
- {
- // gases and solids (but not powders)
- if (!do_move(i, x, y, fin_xf, fin_yf))
- {
- if (parts[i].type == PT_NONE)
- continue;
- // can't move there, so bounce off
- // TODO
- if (fin_x>x+ISTP) fin_x=x+ISTP;
- if (fin_x<x-ISTP) fin_x=x-ISTP;
- if (fin_y>y+ISTP) fin_y=y+ISTP;
- if (fin_y<y-ISTP) fin_y=y-ISTP;
- if (do_move(i, x, y, 0.25f+(float)(2*x-fin_x), 0.25f+fin_y))
- {
- parts[i].vx *= ptypes[t].collision;
- }
- else if (do_move(i, x, y, 0.25f+fin_x, 0.25f+(float)(2*y-fin_y)))
- {
- parts[i].vy *= ptypes[t].collision;
- }
- else
- {
- parts[i].vx *= ptypes[t].collision;
- parts[i].vy *= ptypes[t].collision;
- }
- }
- }
- else
- {
- if (water_equal_test && ptypes[t].falldown == 2 && 1>= rand()%400)//checking stagnant is cool, but then it doesn't update when you change it later.
- {
- if (!flood_water(x,y,i,y, parts[i].tmp2))
- goto movedone;
- }
- // liquids and powders
- if (!do_move(i, x, y, fin_xf, fin_yf))
- {
- if (parts[i].type == PT_NONE)
- continue;
- if (fin_x!=x && do_move(i, x, y, fin_xf, clear_yf))
- {
- parts[i].vx *= ptypes[t].collision;
- parts[i].vy *= ptypes[t].collision;
- }
- else if (fin_y!=y && do_move(i, x, y, clear_xf, fin_yf))
- {
- parts[i].vx *= ptypes[t].collision;
- parts[i].vy *= ptypes[t].collision;
- }
- else
- {
- s = 1;
- r = (rand()%2)*2-1;
- if ((clear_x!=x || clear_y!=y || nt || surround_space) &&
- (fabsf(parts[i].vx)>0.01f || fabsf(parts[i].vy)>0.01f))
- {
- // allow diagonal movement if target position is blocked
- // but no point trying this if particle is stuck in a block of identical particles
- dx = parts[i].vx - parts[i].vy*r;
- dy = parts[i].vy + parts[i].vx*r;
- if (fabsf(dy)>fabsf(dx))
- mv = fabsf(dy);
- else
- mv = fabsf(dx);
- dx /= mv;
- dy /= mv;
- if (do_move(i, x, y, clear_xf+dx, clear_yf+dy))
- {
- parts[i].vx *= ptypes[t].collision;
- parts[i].vy *= ptypes[t].collision;
- goto movedone;
- }
- swappage = dx;
- dx = dy*r;
- dy = -swappage*r;
- if (do_move(i, x, y, clear_xf+dx, clear_yf+dy))
- {
- parts[i].vx *= ptypes[t].collision;
- parts[i].vy *= ptypes[t].collision;
- goto movedone;
- }
- }
- if (ptypes[t].falldown>1 && !ngrav_enable && gravityMode==0 && parts[i].vy>fabsf(parts[i].vx))
- {
- s = 0;
- // stagnant is true if FLAG_STAGNANT was set for this particle in previous frame
- if (!stagnant || nt) //nt is if there is an something else besides the current particle type, around the particle
- rt = 30;//slight less water lag, although it changes how it moves a lot
- else
- rt = 10;
-
- if (t==PT_GEL)
- rt = parts[i].tmp*0.20f+5.0f;
-
- for (j=clear_x+r; j>=0 && j>=clear_x-rt && j<clear_x+rt && j<XRES; j+=r)
- {
- if (((pmap[fin_y][j]&0xFF)!=t || bmap[fin_y/CELL][j/CELL])
- && (s=do_move(i, x, y, (float)j, fin_yf)))
- {
- nx = (int)(parts[i].x+0.5f);
- ny = (int)(parts[i].y+0.5f);
- break;
- }
- if (fin_y!=clear_y && ((pmap[clear_y][j]&0xFF)!=t || bmap[clear_y/CELL][j/CELL])
- && (s=do_move(i, x, y, (float)j, clear_yf)))
- {
- nx = (int)(parts[i].x+0.5f);
- ny = (int)(parts[i].y+0.5f);
- break;
- }
- if ((pmap[clear_y][j]&0xFF)!=t || (bmap[clear_y/CELL][j/CELL] && bmap[clear_y/CELL][j/CELL]!=WL_STREAM))
- break;
- }
- if (parts[i].vy>0)
- r = 1;
- else
- r = -1;
- if (s==1)
- for (j=ny+r; j>=0 && j<YRES && j>=ny-rt && j<ny+rt; j+=r)
- {
- if (((pmap[j][nx]&0xFF)!=t || bmap[j/CELL][nx/CELL]) && do_move(i, nx, ny, (float)nx, (float)j))
- break;
- if ((pmap[j][nx]&255)!=t || (bmap[j/CELL][nx/CELL] && bmap[j/CELL][nx/CELL]!=WL_STREAM))
- break;
- }
- else if (s==-1) {} // particle is out of bounds
- else if ((clear_x!=x||clear_y!=y) && do_move(i, x, y, clear_xf, clear_yf)) {}
- else parts[i].flags |= FLAG_STAGNANT;
- parts[i].vx *= ptypes[t].collision;
- parts[i].vy *= ptypes[t].collision;
- }
- else if (ptypes[t].falldown>1 && fabsf(pGravX*parts[i].vx+pGravY*parts[i].vy)>fabsf(pGravY*parts[i].vx-pGravX*parts[i].vy))
- {
- float nxf, nyf, prev_pGravX, prev_pGravY, ptGrav = ptypes[t].gravity;
- s = 0;
- // stagnant is true if FLAG_STAGNANT was set for this particle in previous frame
- if (!stagnant || nt) //nt is if there is an something else besides the current particle type, around the particle
- rt = 30;//slight less water lag, although it changes how it moves a lot
- else
- rt = 10;
- nxf = clear_xf;
- nyf = clear_yf;
- for (j=0;j<rt;j++)
- {
- switch (gravityMode)
- {
- default:
- case 0:
- pGravX = 0.0f;
- pGravY = ptGrav;
- break;
- case 1:
- pGravX = pGravY = 0.0f;
- break;
- case 2:
- pGravD = 0.01f - hypotf((nx - XCNTR), (ny - YCNTR));
- pGravX = ptGrav * ((float)(nx - XCNTR) / pGravD);
- pGravY = ptGrav * ((float)(ny - YCNTR) / pGravD);
- }
- pGravX += gravx[(ny/CELL)*(XRES/CELL)+(nx/CELL)];
- pGravY += gravy[(ny/CELL)*(XRES/CELL)+(nx/CELL)];
- if (fabsf(pGravY)>fabsf(pGravX))
- mv = fabsf(pGravY);
- else
- mv = fabsf(pGravX);
- if (mv<0.0001f) break;
- pGravX /= mv;
- pGravY /= mv;
- if (j)
- {
- nxf += r*(pGravY*2.0f-prev_pGravY);
- nyf += -r*(pGravX*2.0f-prev_pGravX);
- }
- else
- {
- nxf += r*pGravY;
- nyf += -r*pGravX;
- }
- prev_pGravX = pGravX;
- prev_pGravY = pGravY;
- nx = (int)(nxf+0.5f);
- ny = (int)(nyf+0.5f);
- if (nx<0 || ny<0 || nx>=XRES || ny >=YRES)
- break;
- if ((pmap[ny][nx]&0xFF)!=t || bmap[ny/CELL][nx/CELL])
- {
- s = do_move(i, x, y, nxf, nyf);
- if (s)
- {
- nx = (int)(parts[i].x+0.5f);
- ny = (int)(parts[i].y+0.5f);
- break;
- }
- if (bmap[ny/CELL][nx/CELL]!=WL_STREAM)
- break;
- }
- }
- if (s==1)
- {
- clear_x = nx;
- clear_y = ny;
- for (j=0;j<rt;j++)
- {
- switch (gravityMode)
- {
- default:
- case 0:
- pGravX = 0.0f;
- pGravY = ptGrav;
- break;
- case 1:
- pGravX = pGravY = 0.0f;
- break;
- case 2:
- pGravD = 0.01f - hypotf((nx - XCNTR), (ny - YCNTR));
- pGravX = ptGrav * ((float)(nx - XCNTR) / pGravD);
- pGravY = ptGrav * ((float)(ny - YCNTR) / pGravD);
- }
- pGravX += gravx[(ny/CELL)*(XRES/CELL)+(nx/CELL)];
- pGravY += gravy[(ny/CELL)*(XRES/CELL)+(nx/CELL)];
- if (fabsf(pGravY)>fabsf(pGravX))
- mv = fabsf(pGravY);
- else
- mv = fabsf(pGravX);
- if (mv<0.0001f) break;
- pGravX /= mv;
- pGravY /= mv;
- nxf += pGravX;
- nyf += pGravY;
- nx = (int)(nxf+0.5f);
- ny = (int)(nyf+0.5f);
- if (nx<0 || ny<0 || nx>=XRES || ny>=YRES)
- break;
- if ((pmap[ny][nx]&0xFF)!=t || bmap[ny/CELL][nx/CELL])
- {
- s = do_move(i, clear_x, clear_y, nxf, nyf);
- if (s || bmap[ny/CELL][nx/CELL]!=WL_STREAM)
- break;
- }
- }
- }
- else if (s==-1) {} // particle is out of bounds
- else if ((clear_x!=x||clear_y!=y) && do_move(i, x, y, clear_xf, clear_yf)) {}
- else parts[i].flags |= FLAG_STAGNANT;
- parts[i].vx *= ptypes[t].collision;
- parts[i].vy *= ptypes[t].collision;
- }
- else
- {
- // if interpolation was done, try moving to last clear position
- if ((clear_x!=x||clear_y!=y) && do_move(i, x, y, clear_xf, clear_yf)) {}
- else parts[i].flags |= FLAG_STAGNANT;
- parts[i].vx *= ptypes[t].collision;
- parts[i].vy *= ptypes[t].collision;
- }
- }
- }
- }
-movedone:
- continue;
- }
-}
-
-int parts_lastActiveIndex = NPART-1;
-void update_particles(pixel *vid)//doesn't update the particles themselves, but some other things
-{
- int i, x, y, t;
- int lastPartUsed = 0;
- int lastPartUnused = -1;
-#ifdef MT
- int pt = 0, pc = 0;
- pthread_t *InterThreads;
-#endif
-
- memset(pmap, 0, sizeof(pmap));
- memset(pmap_count, 0, sizeof(pmap_count));
- memset(photons, 0, sizeof(photons));
- NUM_PARTS = 0;
- for (i=0; i<=parts_lastActiveIndex; i++)//the particle loop that resets the pmap/photon maps every frame, to update them.
- {
- if (parts[i].type)
- {
- t = parts[i].type;
- x = (int)(parts[i].x+0.5f);
- y = (int)(parts[i].y+0.5f);
- if (x>=0 && y>=0 && x<XRES && y<YRES)
- {
- if (ptypes[t].properties & TYPE_ENERGY)
- photons[y][x] = t|(i<<8);
- else
- {
- // Particles are sometimes allowed to go inside INVS and FILT
- // To make particles collide correctly when inside these elements, these elements must not overwrite an existing pmap entry from particles inside them
- if (!pmap[y][x] || (t!=PT_INVIS && t!= PT_FILT))
- pmap[y][x] = t|(i<<8);
- // Count number of particles at each location, for excess stacking check
- // (there are a few exceptions, including energy particles - currently no limit on stacking those)
- if (t!=PT_THDR && t!=PT_EMBR && t!=PT_FIGH && t!=PT_PLSM)
- pmap_count[y][x]++;
- }
- }
- lastPartUsed = i;
- NUM_PARTS ++;
- }
- else
- {
- if (lastPartUnused<0) pfree = i;
- else parts[lastPartUnused].life = i;
- lastPartUnused = i;
- }
- }
- if (lastPartUnused==-1)
- {
- if (parts_lastActiveIndex>=NPART-1) pfree = -1;
- else pfree = parts_lastActiveIndex+1;
- }
- else
- {
- if (parts_lastActiveIndex>=NPART-1) parts[lastPartUnused].life = -1;
- else parts[lastPartUnused].life = parts_lastActiveIndex+1;
- }
- parts_lastActiveIndex = lastPartUsed;
- if (!sys_pause||framerender)
- {
- for (y=0; y<YRES/CELL; y++)
- {
- for (x=0; x<XRES/CELL; x++)
- {
- if (emap[y][x])
- emap[y][x] --;
- bmap_blockair[y][x] = (bmap[y][x]==WL_WALL || bmap[y][x]==WL_WALLELEC || (bmap[y][x]==WL_EWALL && !emap[y][x]));
- bmap_blockairh[y][x] = (bmap[y][x]==WL_WALL || bmap[y][x]==WL_WALLELEC || bmap[y][x]==WL_GRAV || (bmap[y][x]==WL_EWALL && !emap[y][x]));
- }
- }
- }
-
- update_particles_i(vid, 0, 1);
-}
-
-void clear_area(int area_x, int area_y, int area_w, int area_h)
-{
- int cx = 0;
- int cy = 0;
- int i;
- for (cy=0; cy<area_h; cy++)
- {
- for (cx=0; cx<area_w; cx++)
- {
- bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0;
- delete_part(cx+area_x, cy+area_y, 0);
- }
- }
- for (i=0; i<MAXSIGNS; i++)
- {
- if (signs[i].x>=area_x && signs[i].x<area_x+area_w && signs[i].y>=area_y && signs[i].y<area_y+area_h)
- {
- signs[i].text[0] = 0;
- }
- }
-}
-
-void create_box(int x1, int y1, int x2, int y2, int c, int flags)
-{
- int i, j;
- if (c==SPC_PROP)
- return;
- if (x1>x2)
- {
- i = x2;
- x2 = x1;
- x1 = i;
- }
- if (y1>y2)
- {
- j = y2;
- y2 = y1;
- y1 = j;
- }
- for (j=y1; j<=y2; j++)
- for (i=x1; i<=x2; i++)
- create_parts(i, j, 0, 0, c, flags, 1);
-}
-
-int flood_prop_2(int x, int y, size_t propoffset, void * propvalue, int proptype, int parttype, char * bitmap)
-{
- int x1, x2, i, dy = 1;
- x1 = x2 = x;
- while (x1>=CELL)
- {
- if ((pmap[y][x1-1]&0xFF)!=parttype || bitmap[(y*XRES)+x1-1])
- {
- break;
- }
- x1--;
- }
- while (x2<XRES-CELL)
- {
- if ((pmap[y][x2+1]&0xFF)!=parttype || bitmap[(y*XRES)+x2+1])
- {
- break;
- }
- x2++;
- }
- for (x=x1; x<=x2; x++)
- {
- i = pmap[y][x]>>8;
- if(proptype==2){
- *((float*)(((char*)&parts[i])+propoffset)) = *((float*)propvalue);
- } else if(proptype==0) {
- *((int*)(((char*)&parts[i])+propoffset)) = *((int*)propvalue);
- } else if(proptype==1) {
- *((char*)(((char*)&parts[i])+propoffset)) = *((char*)propvalue);
- }
- bitmap[(y*XRES)+x] = 1;
- }
- if (y>=CELL+dy)
- for (x=x1; x<=x2; x++)
- if ((pmap[y-dy][x]&0xFF)==parttype && !bitmap[((y-dy)*XRES)+x])
- if (!flood_prop_2(x, y-dy, propoffset, propvalue, proptype, parttype, bitmap))
- return 0;
- if (y<YRES-CELL-dy)
- for (x=x1; x<=x2; x++)
- if ((pmap[y+dy][x]&0xFF)==parttype && !bitmap[((y+dy)*XRES)+x])
- if (!flood_prop_2(x, y+dy, propoffset, propvalue, proptype, parttype, bitmap))
- return 0;
- return 1;
-}
-
-int flood_prop(int x, int y, size_t propoffset, void * propvalue, int proptype)
-{
- int r = 0;
- char * bitmap = malloc(XRES*YRES); //Bitmap for checking
- memset(bitmap, 0, XRES*YRES);
- r = pmap[y][x];
- flood_prop_2(x, y, propoffset, propvalue, proptype, r&0xFF, bitmap);
- free(bitmap);
-}
-
-#define PMAP_CMP_CONDUCTIVE(pmap, t) (((pmap)&0xFF)==(t) || (((pmap)&0xFF)==PT_SPRK && parts[(pmap)>>8].ctype==(t)))
-
-int flood_INST(int x, int y, int fullc, int cm)
-{
- int c = fullc&0xFF;
- int x1, x2, dy = (c<PT_NUM)?1:CELL;
- int co = c;
- int coord_stack_limit = XRES*YRES;
- unsigned short (*coord_stack)[2];
- int coord_stack_size = 0;
- int created_something = 0;
-
- if (c>=PT_NUM)
- return 0;
-
- if (cm==-1)
- {
- if (c==0)
- {
- cm = pmap[y][x]&0xFF;
- if (!cm)
- return 0;
- }
- else
- cm = 0;
- }
-
- if ((pmap[y][x]&0xFF)!=cm || parts[pmap[y][x]>>8].life!=0)
- return 1;
-
- coord_stack = malloc(sizeof(unsigned short)*2*coord_stack_limit);
- coord_stack[coord_stack_size][0] = x;
- coord_stack[coord_stack_size][1] = y;
- coord_stack_size++;
-
- do
- {
- coord_stack_size--;
- x = coord_stack[coord_stack_size][0];
- y = coord_stack[coord_stack_size][1];
- x1 = x2 = x;
- // go left as far as possible
- while (x1>=CELL)
- {
- if ((pmap[y][x1-1]&0xFF)!=cm || parts[pmap[y][x1-1]>>8].life!=0)
- {
- break;
- }
- x1--;
- }
- // go right as far as possible
- while (x2<XRES-CELL)
- {
- if ((pmap[y][x2+1]&0xFF)!=cm || parts[pmap[y][x2+1]>>8].life!=0)
- {
- break;
- }
- x2++;
- }
- // fill span
- for (x=x1; x<=x2; x++)
- {
- if (create_part(-1, x, y, fullc)>=0)
- created_something = 1;
- }
-
- // add vertically adjacent pixels to stack
- // (wire crossing for INST)
- if (y>=CELL+1 && x1==x2 &&
- PMAP_CMP_CONDUCTIVE(pmap[y-1][x1-1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y-1][x1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y-1][x1+1], cm) &&
- !PMAP_CMP_CONDUCTIVE(pmap[y-2][x1-1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y-2][x1], cm) && !PMAP_CMP_CONDUCTIVE(pmap[y-2][x1+1], cm))
- {
- // travelling vertically up, skipping a horizontal line
- if ((pmap[y-2][x1]&0xFF)==cm && !parts[pmap[y-2][x1]>>8].life)
- {
- coord_stack[coord_stack_size][0] = x1;
- coord_stack[coord_stack_size][1] = y-2;
- coord_stack_size++;
- if (coord_stack_size>=coord_stack_limit)
- {
- free(coord_stack);
- return -1;
- }
- }
- }
- else if (y>=CELL+1)
- {
- for (x=x1; x<=x2; x++)
- {
- if ((pmap[y-1][x]&0xFF)==cm && !parts[pmap[y-1][x]>>8].life)
- {
- if (x==x1 || x==x2 || y>=YRES-CELL-1 || !PMAP_CMP_CONDUCTIVE(pmap[y+1][x], cm))
- {
- // if at the end of a horizontal section, or if it's a T junction
- coord_stack[coord_stack_size][0] = x;
- coord_stack[coord_stack_size][1] = y-1;
- coord_stack_size++;
- if (coord_stack_size>=coord_stack_limit)
- {
- free(coord_stack);
- return -1;
- }
- }
- }
- }
- }
-
- if (y<YRES-CELL-1 && x1==x2 &&
- PMAP_CMP_CONDUCTIVE(pmap[y+1][x1-1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y+1][x1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y+1][x1+1], cm) &&
- !PMAP_CMP_CONDUCTIVE(pmap[y+2][x1-1], cm) && PMAP_CMP_CONDUCTIVE(pmap[y+2][x1], cm) && !PMAP_CMP_CONDUCTIVE(pmap[y+2][x1+1], cm))
- {
- // travelling vertically down, skipping a horizontal line
- if ((pmap[y+2][x1]&0xFF)==cm && !parts[pmap[y+2][x1]>>8].life)
- {
- coord_stack[coord_stack_size][0] = x1;
- coord_stack[coord_stack_size][1] = y+2;
- coord_stack_size++;
- if (coord_stack_size>=coord_stack_limit)
- {
- free(coord_stack);
- return -1;
- }
- }
- }
- else if (y<YRES-CELL-1)
- {
- for (x=x1; x<=x2; x++)
- {
- if ((pmap[y+1][x]&0xFF)==cm && !parts[pmap[y+1][x]>>8].life)
- {
- if (x==x1 || x==x2 || y<0 || !PMAP_CMP_CONDUCTIVE(pmap[y-1][x], cm))
- {
- // if at the end of a horizontal section, or if it's a T junction
- coord_stack[coord_stack_size][0] = x;
- coord_stack[coord_stack_size][1] = y+1;
- coord_stack_size++;
- if (coord_stack_size>=coord_stack_limit)
- {
- free(coord_stack);
- return -1;
- }
- }
-
- }
- }
- }
- } while (coord_stack_size>0);
- free(coord_stack);
- return created_something;
-}
-
-
-int flood_parts(int x, int y, int fullc, int cm, int bm, int flags)
-{
- int c = fullc&0xFF;
- int x1, x2, dy = (c<PT_NUM)?1:CELL;
- int co = c;
- int coord_stack_limit = XRES*YRES;
- unsigned short (*coord_stack)[2];
- int coord_stack_size = 0;
- int created_something = 0;
-
- if (c==SPC_PROP)
- return 0;
- if (cm==-1)
- {
- if (c==0)
- {
- cm = pmap[y][x]&0xFF;
- if (!cm)
- return 0;
- if ((flags&BRUSH_REPLACEMODE) && cm!=SLALT)
- return 0;
- }
- else
- cm = 0;
- }
- if (bm==-1)
- {
- if (c-UI_WALLSTART+UI_ACTUALSTART==WL_ERASE)
- {
- bm = bmap[y/CELL][x/CELL];
- if (!bm)
- return 0;
- if (bm==WL_WALL)
- cm = 0xFF;
- }
- else
- bm = 0;
- }
-
- if (((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm )||( (flags&BRUSH_SPECIFIC_DELETE) && cm!=SLALT))
- return 1;
-
- coord_stack = malloc(sizeof(unsigned short)*2*coord_stack_limit);
- coord_stack[coord_stack_size][0] = x;
- coord_stack[coord_stack_size][1] = y;
- coord_stack_size++;
-
- do
- {
- coord_stack_size--;
- x = coord_stack[coord_stack_size][0];
- y = coord_stack[coord_stack_size][1];
- x1 = x2 = x;
- // go left as far as possible
- while (x1>=CELL)
- {
- if ((pmap[y][x1-1]&0xFF)!=cm || bmap[y/CELL][(x1-1)/CELL]!=bm)
- {
- break;
- }
- x1--;
- }
- // go right as far as possible
- while (x2<XRES-CELL)
- {
- if ((pmap[y][x2+1]&0xFF)!=cm || bmap[y/CELL][(x2+1)/CELL]!=bm)
- {
- break;
- }
- x2++;
- }
- // fill span
- for (x=x1; x<=x2; x++)
- {
- if (create_parts(x, y, 0, 0, fullc, flags, 1))
- created_something = 1;
- }
-
- // add vertically adjacent pixels to stack
- if (y>=CELL+dy)
- for (x=x1; x<=x2; x++)
- if ((pmap[y-dy][x]&0xFF)==cm && bmap[(y-dy)/CELL][x/CELL]==bm)
- {
- coord_stack[coord_stack_size][0] = x;
- coord_stack[coord_stack_size][1] = y-dy;
- coord_stack_size++;
- if (coord_stack_size>=coord_stack_limit)
- {
- free(coord_stack);
- return -1;
- }
- }
- if (y<YRES-CELL-dy)
- for (x=x1; x<=x2; x++)
- if ((pmap[y+dy][x]&0xFF)==cm && bmap[(y+dy)/CELL][x/CELL]==bm)
- {
- coord_stack[coord_stack_size][0] = x;
- coord_stack[coord_stack_size][1] = y+dy;
- coord_stack_size++;
- if (coord_stack_size>=coord_stack_limit)
- {
- free(coord_stack);
- return -1;
- }
- }
- } while (coord_stack_size>0);
- free(coord_stack);
- return created_something;
-}
-
-int flood_water(int x, int y, int i, int originaly, int check)
-{
- int x1 = 0,x2 = 0;
- // go left as far as possible
- x1 = x2 = x;
- if (!pmap[y][x])
- return 1;
-
- while (x1>=CELL)
- {
- if ((ptypes[(pmap[y][x1-1]&0xFF)].falldown)!=2)
- {
- break;
- }
- x1--;
- }
- while (x2<XRES-CELL)
- {
- if ((ptypes[(pmap[y][x2+1]&0xFF)].falldown)!=2)
- {
- break;
- }
- x2++;
- }
-
- // fill span
- for (x=x1; x<=x2; x++)
- {
- parts[pmap[y][x]>>8].tmp2 = !check;//flag it as checked, maybe shouldn't use .tmp2
- //check above, maybe around other sides too?
- if ( ((y-1) > originaly) && !pmap[y-1][x] && eval_move(parts[i].type, x, y-1, NULL))
- {
- int oldx = (int)(parts[i].x + 0.5f);
- int oldy = (int)(parts[i].y + 0.5f);
- pmap[y-1][x] = pmap[oldy][oldx];
- pmap[oldy][oldx] = 0;
- parts[i].x = x;
- parts[i].y = y-1;
- return 0;
- }
- }
- // fill children
-
- if (y>=CELL+1)
- for (x=x1; x<=x2; x++)
- if ((ptypes[(pmap[y-1][x]&0xFF)].falldown)==2 && parts[pmap[y-1][x]>>8].tmp2 == check)
- if (!flood_water(x, y-1, i, originaly, check))
- return 0;
- if (y<YRES-CELL-1)
- for (x=x1; x<=x2; x++)
- if ((ptypes[(pmap[y+1][x]&0xFF)].falldown)==2 && parts[pmap[y+1][x]>>8].tmp2 == check)
- if (!flood_water(x, y+1, i, originaly, check))
- return 0;
- return 1;
-}
-
-//wrapper around create_part to create TESC with correct tmp value
-int create_part_add_props(int p, int x, int y, int tv, int rx, int ry)
-{
- p=create_part(p, x, y, tv);
- if (tv==PT_TESC)
- {
- parts[p].tmp=rx*4+ry*4+7;
- if (parts[p].tmp>300)
- parts[p].tmp=300;
- }
- return p;
-}
-
-//this creates particles from a brush, don't use if you want to create one particle
-int create_parts(int x, int y, int rx, int ry, int c, int flags, int fill)
-{
- int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0, p, fn;
-
- int wall = c - 100;
- if (c==SPC_WIND || c==PT_FIGH)
- return 0;
-
- if(c==SPC_PROP){
- prop_edit_ui(vid_buf, x, y);
- return 0;
- }
- if (c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM || c == SPC_PGRV || c == SPC_NGRV)
- fill = 1;
- for (r=UI_ACTUALSTART; r<=UI_ACTUALSTART+UI_WALLCOUNT; r++)
- {
- if (wall==r)
- {
- if (c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM || c == SPC_PGRV || c == SPC_NGRV || wall == WL_SIGN)
- break;
- if (wall == WL_ERASE)
- b = 0;
- else
- b = wall;
- dw = 1;
- }
- }
- if (c == WL_FANHELPER)
- {
- b = WL_FANHELPER;
- dw = 1;
- }
- if (wall == WL_GRAV)
- {
- gravwl_timeout = 60;
- }
- if (c==PT_LIGH)
- {
- if (lighting_recreate>0 && rx+ry>0)
- return 0;
- p=create_part(-2, x, y, c);
- if (p!=-1)
- {
- parts[p].life=rx+ry;
- if (parts[p].life>55)
- parts[p].life=55;
- parts[p].temp=parts[p].life*150; // temperature of the lighting shows the power of the lighting
- lighting_recreate+=parts[p].life/2+1;
- return 1;
- }
- else return 0;
- }
- if (c == PT_STKM || c == PT_STKM2 || c == PT_FIGH)
- rx = ry = 0;
-
- if (dw==1)
- {
- ry = ry/CELL;
- rx = rx/CELL;
- x = x/CELL;
- y = y/CELL;
- x -= rx/2;
- y -= ry/2;
- for (ox=x; ox<=x+rx; ox++)
- {
- for (oy=y; oy<=y+rx; oy++)
- {
- if (ox>=0&&ox<XRES/CELL&&oy>=0&&oy<YRES/CELL)
- {
- i = ox;
- j = oy;
- if ((flags&BRUSH_SPECIFIC_DELETE) && b!=WL_FANHELPER)
- {
- if (bmap[j][i]==SLALT-100)
- {
- b = 0;
- if (SLALT==WL_GRAV) gravwl_timeout = 60;
- }
- else
- continue;
- }
- if (b==WL_FAN)
- {
- fvx[j][i] = 0.0f;
- fvy[j][i] = 0.0f;
- }
- if (b==WL_STREAM)
- {
- i = x + rx/2;
- j = y + ry/2;
- for (v=-1; v<2; v++)
- for (u=-1; u<2; u++)
- if (i+u>=0 && i+u<XRES/CELL &&
- j+v>=0 && j+v<YRES/CELL &&
- bmap[j+v][i+u] == WL_STREAM)
- return 1;
- bmap[j][i] = WL_STREAM;
- continue;
- }
- if (b==0 && bmap[j][i]==WL_GRAV) gravwl_timeout = 60;
- bmap[j][i] = b;
- }
- }
- }
- return 1;
- }
-
- if (c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM || c == SPC_PGRV || c == SPC_NGRV)
- fn = 3;
- else if (c == 0 && !(flags&BRUSH_REPLACEMODE)) // delete
- fn = 0;
- else if ((flags&BRUSH_SPECIFIC_DELETE) && !(flags&BRUSH_REPLACEMODE)) // specific delete
- fn = 1;
- else if (flags&BRUSH_REPLACEMODE) // replace
- fn = 2;
- else // normal draw
- fn = 3;
-
- if (rx<=0) //workaround for rx == 0 crashing. todo: find a better fix later.
- {
- for (j = y - ry; j <= y + ry; j++)
- if (create_parts2(fn,x,j,c,rx,ry,flags))
- f = 1;
- }
- else
- {
- int tempy = y, i, j, jmax, oldy;
- // tempy is the smallest y value that is still inside the brush
- // jmax is the largest y value that is still inside the brush
- if (CURRENT_BRUSH == TRI_BRUSH)
- tempy = y + ry;
- for (i = x - rx; i <= x; i++) {
- oldy = tempy;
- // Fix a problem with the triangle brush which occurs if the bottom corner (the first point tested) isn't recognised as being inside the brush
- if (!InCurrentBrush(i-x,tempy-y,rx,ry))
- continue;
- while (InCurrentBrush(i-x,tempy-y,rx,ry))
- tempy = tempy - 1;
- tempy = tempy + 1;
- if (fill)
- {
- jmax = 2*y - tempy;
- if (CURRENT_BRUSH == TRI_BRUSH)
- jmax = y + ry;
- for (j = tempy; j <= jmax; j++) {
- if (create_parts2(fn,i,j,c,rx,ry,flags))
- f = 1;
- if (i!=x && create_parts2(fn,2*x-i,j,c,rx,ry,flags))
- f = 1;
- }
- }
- else
- {
- if ((oldy != tempy && CURRENT_BRUSH != SQUARE_BRUSH) || i == x-rx)
- oldy--;
- //if (CURRENT_BRUSH == TRI_BRUSH)
- // oldy = tempy;
- for (j = tempy; j <= oldy+1; j++) {
- int i2 = 2*x-i, j2 = 2*y-j;
- if (CURRENT_BRUSH == TRI_BRUSH)
- j2 = y+ry;
- if (create_parts2(fn,i,j,c,rx,ry,flags))
- f = 1;
- if (i2 != i && create_parts2(fn,i2,j,c,rx,ry,flags))
- f = 1;
- if (j2 != j && create_parts2(fn,i,j2,c,rx,ry,flags))
- f = 1;
- if (i2 != i && j2 != j && create_parts2(fn,i2,j2,c,rx,ry,flags))
- f = 1;
- }
- }
- }
- }
- return !f;
-}
-
-int create_parts2(int f, int x, int y, int c, int rx, int ry, int flags)
-{
- if (f == 0) //delete
- delete_part(x, y, 0);
- else if (f == 1) //specific delete
- delete_part(x, y, flags);
- else if (f == 2) //replace mode
- {
- if (x<0 || y<0 || x>=XRES || y>=YRES)
- return 0;
- if ((pmap[y][x]&0xFF)!=SLALT&&SLALT!=0)
- return 0;
- if ((pmap[y][x]))
- {
- delete_part(x, y, 0);
- if (c!=0)
- create_part_add_props(-2, x, y, c, rx, ry);
- }
- }
- else if (f == 3) //normal draw
- if (create_part_add_props(-2, x, y, c, rx, ry)==-1)
- return 1;
- return 0;
-}
-
-int InCurrentBrush(int i, int j, int rx, int ry)
-{
- switch(CURRENT_BRUSH)
- {
- case CIRCLE_BRUSH:
- return (pow((double)i,2)*pow((double)ry,2)+pow((double)j,2)*pow((double)rx,2)<=pow((double)rx,2)*pow((double)ry,2));
- break;
- case SQUARE_BRUSH:
- return (abs(i) <= rx && abs(j) <= ry);
- break;
- case TRI_BRUSH:
- return ((abs((rx+2*i)*ry+rx*j) + abs(2*rx*(j-ry)) + abs((rx-2*i)*ry+rx*j))<=(4*rx*ry));
- break;
- default:
- return 0;
- break;
- }
-}
-int get_brush_flags()
-{
- int flags = 0;
- if (REPLACE_MODE)
- flags |= BRUSH_REPLACEMODE;
- if (sdl_mod & (KMOD_CAPS))
- flags |= BRUSH_SPECIFIC_DELETE;
- if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL))
- flags |= BRUSH_SPECIFIC_DELETE;
- return flags;
-}
-void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags)
-{
- int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy, fill = 1;
- float e, de;
- if (c==SPC_PROP)
- return;
- if (cp)
- {
- y = x1;
- x1 = y1;
- y1 = y;
- y = x2;
- x2 = y2;
- y2 = y;
- }
- if (x1 > x2)
- {
- y = x1;
- x1 = x2;
- x2 = y;
- y = y1;
- y1 = y2;
- y2 = y;
- }
- dx = x2 - x1;
- dy = abs(y2 - y1);
- e = 0.0f;
- if (dx)
- de = dy/(float)dx;
- else
- de = 0.0f;
- y = y1;
- sy = (y1<y2) ? 1 : -1;
- for (x=x1; x<=x2; x++)
- {
- if (cp)
- create_parts(y, x, rx, ry, c, flags, fill);
- else
- create_parts(x, y, rx, ry, c, flags, fill);
- fill = 0;
- e += de;
- if (e >= 0.5f)
- {
- y += sy;
- if ((c==WL_EHOLE+100 || c==WL_ALLOWGAS+100 || c==WL_ALLOWENERGY+100 || c==WL_ALLOWALLELEC+100 || c==WL_ALLOWSOLID+100 || c==WL_ALLOWAIR+100 || c==WL_WALL+100 || c==WL_DESTROYALL+100 || c==WL_ALLOWLIQUID+100 || c==WL_FAN+100 || c==WL_STREAM+100 || c==WL_DETECT+100 || c==WL_EWALL+100 || c==WL_WALLELEC+100 || !(rx+ry))
- && ((y1<y2) ? (y<=y2) : (y>=y2)))
- {
- if (cp)
- create_parts(y, x, rx, ry, c, flags, fill);
- else
- create_parts(x, y, rx, ry, c, flags, fill);
- }
- e -= 1.0f;
- }
- }
-}
-
-#if defined(WIN32) && !defined(__GNUC__)
-void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[])
-#else
-inline void orbitalparts_get(int block1, int block2, int resblock1[], int resblock2[])
-#endif
-{
- resblock1[0] = (block1&0x000000FF);
- resblock1[1] = (block1&0x0000FF00)>>8;
- resblock1[2] = (block1&0x00FF0000)>>16;
- resblock1[3] = (block1&0xFF000000)>>24;
-
- resblock2[0] = (block2&0x000000FF);
- resblock2[1] = (block2&0x0000FF00)>>8;
- resblock2[2] = (block2&0x00FF0000)>>16;
- resblock2[3] = (block2&0xFF000000)>>24;
-}
-
-#if defined(WIN32) && !defined(__GNUC__)
-void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[])
-#else
-inline void orbitalparts_set(int *block1, int *block2, int resblock1[], int resblock2[])
-#endif
-{
- int block1tmp = 0;
- int block2tmp = 0;
-
- block1tmp = (resblock1[0]&0xFF);
- block1tmp |= (resblock1[1]&0xFF)<<8;
- block1tmp |= (resblock1[2]&0xFF)<<16;
- block1tmp |= (resblock1[3]&0xFF)<<24;
-
- block2tmp = (resblock2[0]&0xFF);
- block2tmp |= (resblock2[1]&0xFF)<<8;
- block2tmp |= (resblock2[2]&0xFF)<<16;
- block2tmp |= (resblock2[3]&0xFF)<<24;
-
- *block1 = block1tmp;
- *block2 = block2tmp;
-}
diff --git a/src/save.c b/src/save.c
deleted file mode 100644
index 499a8cc..0000000
--- a/src/save.c
+++ /dev/null
@@ -1,2503 +0,0 @@
-/**
- * Powder Toy - saving and loading functions
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <bzlib.h>
-#include <math.h>
-#include "defines.h"
-#include "powder.h"
-#include "save.h"
-#include "gravity.h"
-#include "BSON.h"
-#include "hmap.h"
-
-//Pop
-pixel *prerender_save(void *save, int size, int *width, int *height)
-{
- unsigned char * saveData = save;
- if (size<16)
- {
- return NULL;
- }
- if(saveData[0] == 'O' && saveData[1] == 'P' && saveData[2] == 'S')
- {
- return prerender_save_OPS(save, size, width, height);
- }
- else if((saveData[0]==0x66 && saveData[1]==0x75 && saveData[2]==0x43) || (saveData[0]==0x50 && saveData[1]==0x53 && saveData[2]==0x76))
- {
- return prerender_save_PSv(save, size, width, height);
- }
- return NULL;
-}
-
-void *build_save(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h, unsigned char bmap[YRES/CELL][XRES/CELL], float vx[YRES/CELL][XRES/CELL], float vy[YRES/CELL][XRES/CELL], float pv[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* partsptr)
-{
- return build_save_OPS(size, orig_x0, orig_y0, orig_w, orig_h, bmap, vx, vy, pv, fvx, fvy, signs, partsptr);
-}
-
-int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char bmap[YRES/CELL][XRES/CELL], float vx[YRES/CELL][XRES/CELL], float vy[YRES/CELL][XRES/CELL], float pv[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* partsptr, unsigned pmap[YRES][XRES])
-{
- unsigned char * saveData = save;
- if (size<16)
- {
- return 1;
- }
- force_stacking_check = 1;//check for excessive stacking of particles next time update_particles is run
- ppip_changed = 1;
- if(saveData[0] == 'O' && saveData[1] == 'P' && saveData[2] == 'S')
- {
- return parse_save_OPS(save, size, replace, x0, y0, bmap, vx, vy, pv, fvx, fvy, signs, partsptr, pmap);
- }
- else if((saveData[0]==0x66 && saveData[1]==0x75 && saveData[2]==0x43) || (saveData[0]==0x50 && saveData[1]==0x53 && saveData[2]==0x76))
- {
- return parse_save_PSv(save, size, replace, x0, y0, bmap, fvx, fvy, signs, partsptr, pmap);
- }
- return 1;
-}
-
-int change_wall(int wt)
-{
- if (wt == 1)
- return WL_WALL;
- else if (wt == 2)
- return WL_DESTROYALL;
- else if (wt == 3)
- return WL_ALLOWLIQUID;
- else if (wt == 4)
- return WL_FAN;
- else if (wt == 5)
- return WL_STREAM;
- else if (wt == 6)
- return WL_DETECT;
- else if (wt == 7)
- return WL_EWALL;
- else if (wt == 8)
- return WL_WALLELEC;
- else if (wt == 9)
- return WL_ALLOWAIR;
- else if (wt == 10)
- return WL_ALLOWSOLID;
- else if (wt == 11)
- return WL_ALLOWALLELEC;
- else if (wt == 12)
- return WL_EHOLE;
- else if (wt == 13)
- return WL_ALLOWGAS;
- return wt;
-}
-
-pixel *prerender_save_OPS(void *save, int size, int *width, int *height)
-{
- unsigned char * inputData = save, *bsonData = NULL, *partsData = NULL, *partsPosData = NULL, *wallData = NULL;
- int inputDataLen = size, bsonDataLen = 0, partsDataLen, partsPosDataLen, wallDataLen;
- int i, x, y, j, wt, pc, gc;
- int blockX, blockY, blockW, blockH, fullX, fullY, fullW, fullH;
- int bsonInitialised = 0;
- pixel * vidBuf = NULL;
- bson b;
- bson_iterator iter;
-
- //Block sizes
- blockX = 0;
- blockY = 0;
- blockW = inputData[6];
- blockH = inputData[7];
-
- //Full size, normalised
- fullX = 0;
- fullY = 0;
- fullW = blockW*CELL;
- fullH = blockH*CELL;
-
- //
- *width = fullW;
- *height = fullH;
-
- //From newer version
- if(inputData[4] > SAVE_VERSION)
- {
- fprintf(stderr, "Save from newer version\n");
- goto fail;
- }
-
- //Incompatible cell size
- if(inputData[5] > CELL)
- {
- fprintf(stderr, "Cell size mismatch\n");
- goto fail;
- }
-
- //Too large/off screen
- if(blockX+blockW > XRES/CELL || blockY+blockH > YRES/CELL)
- {
- fprintf(stderr, "Save too large\n");
- goto fail;
- }
-
- bsonDataLen = ((unsigned)inputData[8]);
- bsonDataLen |= ((unsigned)inputData[9]) << 8;
- bsonDataLen |= ((unsigned)inputData[10]) << 16;
- bsonDataLen |= ((unsigned)inputData[11]) << 24;
-
- bsonData = malloc(bsonDataLen+1);
- if(!bsonData)
- {
- fprintf(stderr, "Internal error while parsing save: could not allocate buffer\n");
- goto fail;
- }
- //Make sure bsonData is null terminated, since all string functions need null terminated strings
- //(bson_iterator_key returns a pointer into bsonData, which is then used with strcmp)
- bsonData[bsonDataLen] = 0;
-
- if (BZ2_bzBuffToBuffDecompress(bsonData, &bsonDataLen, inputData+12, inputDataLen-12, 0, 0))
- {
- fprintf(stderr, "Unable to decompress\n");
- goto fail;
- }
-
- bson_init_data(&b, bsonData);
- bsonInitialised = 1;
- bson_iterator_init(&iter, &b);
- while(bson_iterator_next(&iter))
- {
- if(strcmp(bson_iterator_key(&iter), "parts")==0)
- {
- if(bson_iterator_type(&iter)==BSON_BINDATA && ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER && (partsDataLen = bson_iterator_bin_len(&iter)) > 0)
- {
- partsData = bson_iterator_bin_data(&iter);
- }
- else
- {
- fprintf(stderr, "Invalid datatype of particle data: %d[%d] %d[%d] %d[%d]\n", bson_iterator_type(&iter), bson_iterator_type(&iter)==BSON_BINDATA, (unsigned char)bson_iterator_bin_type(&iter), ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER, bson_iterator_bin_len(&iter), bson_iterator_bin_len(&iter)>0);
- }
- }
- if(strcmp(bson_iterator_key(&iter), "partsPos")==0)
- {
- if(bson_iterator_type(&iter)==BSON_BINDATA && ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER && (partsPosDataLen = bson_iterator_bin_len(&iter)) > 0)
- {
- partsPosData = bson_iterator_bin_data(&iter);
- }
- else
- {
- fprintf(stderr, "Invalid datatype of particle position data: %d[%d] %d[%d] %d[%d]\n", bson_iterator_type(&iter), bson_iterator_type(&iter)==BSON_BINDATA, (unsigned char)bson_iterator_bin_type(&iter), ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER, bson_iterator_bin_len(&iter), bson_iterator_bin_len(&iter)>0);
- }
- }
- else if(strcmp(bson_iterator_key(&iter), "wallMap")==0)
- {
- if(bson_iterator_type(&iter)==BSON_BINDATA && ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER && (wallDataLen = bson_iterator_bin_len(&iter)) > 0)
- {
- wallData = bson_iterator_bin_data(&iter);
- }
- else
- {
- fprintf(stderr, "Invalid datatype of wall data: %d[%d] %d[%d] %d[%d]\n", bson_iterator_type(&iter), bson_iterator_type(&iter)==BSON_BINDATA, (unsigned char)bson_iterator_bin_type(&iter), ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER, bson_iterator_bin_len(&iter), bson_iterator_bin_len(&iter)>0);
- }
- }
- }
-
- vidBuf = calloc(fullW*fullH, PIXELSIZE);
-
- //Read wall and fan data
- if(wallData)
- {
- if(blockW * blockH > wallDataLen)
- {
- fprintf(stderr, "Not enough wall data\n");
- goto fail;
- }
- for(x = 0; x < blockW; x++)
- {
- for(y = 0; y < blockH; y++)
- {
- if(wallData[y*blockW+x])
- {
- wt = wallData[y*blockW+x];
- pc = wtypes[wt-UI_ACTUALSTART].colour;
- gc = wtypes[wt-UI_ACTUALSTART].eglow;
- if (wtypes[wt-UI_ACTUALSTART].drawstyle==1)
- {
- for (i=0; i<CELL; i+=2)
- for (j=(i>>1)&1; j<CELL; j+=2)
- vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc;
- }
- else if (wtypes[wt-UI_ACTUALSTART].drawstyle==2)
- {
- for (i=0; i<CELL; i+=2)
- for (j=0; j<CELL; j+=2)
- vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc;
- }
- else if (wtypes[wt-UI_ACTUALSTART].drawstyle==3)
- {
- for (i=0; i<CELL; i++)
- for (j=0; j<CELL; j++)
- vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc;
- }
- else if (wtypes[wt-UI_ACTUALSTART].drawstyle==4)
- {
- for (i=0; i<CELL; i++)
- for (j=0; j<CELL; j++)
- if(i == j)
- vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc;
- else if (j == i+1 || (j == 0 && i == CELL-1))
- vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = gc;
- else
- vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = PIXPACK(0x202020);
- }
-
- // special rendering for some walls
- if (wt==WL_EWALL)
- {
- for (i=0; i<CELL; i++)
- for (j=0; j<CELL; j++)
- if (!(i&j&1))
- vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc;
- }
- else if (wt==WL_WALLELEC)
- {
- for (i=0; i<CELL; i++)
- for (j=0; j<CELL; j++)
- {
- if (!((y*CELL+j)%2) && !((x*CELL+i)%2))
- vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc;
- else
- vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = PIXPACK(0x808080);
- }
- }
- else if (wt==WL_EHOLE)
- {
- for (i=0; i<CELL; i+=2)
- for (j=0; j<CELL; j+=2)
- vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = PIXPACK(0x242424);
- }
- }
- }
- }
- }
-
- //Read particle data
- if(partsData && partsPosData)
- {
- int fieldDescriptor;
- int posCount, posTotal, partsPosDataIndex = 0;
- int saved_x, saved_y;
- if(fullW * fullH * 3 > partsPosDataLen)
- {
- fprintf(stderr, "Not enough particle position data\n");
- goto fail;
- }
- i = 0;
- for (saved_y=0; saved_y<fullH; saved_y++)
- {
- for (saved_x=0; saved_x<fullW; saved_x++)
- {
- //Read total number of particles at this position
- posTotal = 0;
- posTotal |= partsPosData[partsPosDataIndex++]<<16;
- posTotal |= partsPosData[partsPosDataIndex++]<<8;
- posTotal |= partsPosData[partsPosDataIndex++];
- //Put the next posTotal particles at this position
- for (posCount=0; posCount<posTotal; posCount++)
- {
- //i+3 because we have 4 bytes of required fields (type (1), descriptor (2), temp (1))
- if (i+3 >= partsDataLen)
- goto fail;
- x = saved_x + fullX;
- y = saved_y + fullY;
- fieldDescriptor = partsData[i+1];
- fieldDescriptor |= partsData[i+2] << 8;
- if(x >= XRES || x < 0 || y >= YRES || y < 0)
- {
- fprintf(stderr, "Out of range [%d]: %d %d, [%d, %d], [%d, %d]\n", i, x, y, (unsigned)partsData[i+1], (unsigned)partsData[i+2], (unsigned)partsData[i+3], (unsigned)partsData[i+4]);
- goto fail;
- }
- if(partsData[i] >= PT_NUM)
- partsData[i] = PT_DMND; //Replace all invalid elements with diamond
-
- //Draw type
- if (partsData[i]==PT_STKM || partsData[i]==PT_STKM2 || partsData[i]==PT_FIGH)
- {
- pixel lc, hc=PIXRGB(255, 224, 178);
- if (partsData[i]==PT_STKM || partsData[i]==PT_FIGH) lc = PIXRGB(255, 255, 255);
- else lc = PIXRGB(100, 100, 255);
- //only need to check upper bound of y coord - lower bounds and x<w are checked in draw_line
- if (partsData[i]==PT_STKM || partsData[i]==PT_STKM2)
- {
- draw_line(vidBuf, x-2, y-2, x+2, y-2, PIXR(hc), PIXG(hc), PIXB(hc), *width);
- if (y+2<*height)
- {
- draw_line(vidBuf, x-2, y+2, x+2, y+2, PIXR(hc), PIXG(hc), PIXB(hc), *width);
- draw_line(vidBuf, x-2, y-2, x-2, y+2, PIXR(hc), PIXG(hc), PIXB(hc), *width);
- draw_line(vidBuf, x+2, y-2, x+2, y+2, PIXR(hc), PIXG(hc), PIXB(hc), *width);
- }
- }
- else if (y+2<*height)
- {
- draw_line(vidBuf, x-2, y, x, y-2, PIXR(hc), PIXG(hc), PIXB(hc), *width);
- draw_line(vidBuf, x-2, y, x, y+2, PIXR(hc), PIXG(hc), PIXB(hc), *width);
- draw_line(vidBuf, x, y-2, x+2, y, PIXR(hc), PIXG(hc), PIXB(hc), *width);
- draw_line(vidBuf, x, y+2, x+2, y, PIXR(hc), PIXG(hc), PIXB(hc), *width);
- }
- if (y+6<*height)
- {
- draw_line(vidBuf, x, y+3, x-1, y+6, PIXR(lc), PIXG(lc), PIXB(lc), *width);
- draw_line(vidBuf, x, y+3, x+1, y+6, PIXR(lc), PIXG(lc), PIXB(lc), *width);
- }
- if (y+12<*height)
- {
- draw_line(vidBuf, x-1, y+6, x-3, y+12, PIXR(lc), PIXG(lc), PIXB(lc), *width);
- draw_line(vidBuf, x+1, y+6, x+3, y+12, PIXR(lc), PIXG(lc), PIXB(lc), *width);
- }
- }
- else
- vidBuf[(fullY+y)*fullW+(fullX+x)] = ptypes[partsData[i]].pcolors;
- i+=3; //Skip Type and Descriptor
-
- //Skip temp
- if(fieldDescriptor & 0x01)
- {
- i+=2;
- }
- else
- {
- i++;
- }
-
- //Skip life
- if(fieldDescriptor & 0x02)
- {
- if(i++ >= partsDataLen) goto fail;
- if(fieldDescriptor & 0x04)
- {
- if(i++ >= partsDataLen) goto fail;
- }
- }
-
- //Skip tmp
- if(fieldDescriptor & 0x08)
- {
- if(i++ >= partsDataLen) goto fail;
- if(fieldDescriptor & 0x10)
- {
- if(i++ >= partsDataLen) goto fail;
- if(fieldDescriptor & 0x1000)
- {
- if(i+1 >= partsDataLen) goto fail;
- i += 2;
- }
- }
- }
-
- //Skip ctype
- if(fieldDescriptor & 0x20)
- {
- if(i++ >= partsDataLen) goto fail;
- if(fieldDescriptor & 0x200)
- {
- if(i+2 >= partsDataLen) goto fail;
- i+=3;
- }
- }
-
- //Read dcolour
- if(fieldDescriptor & 0x40)
- {
- unsigned char r, g, b;
- if(i+3 >= partsDataLen) goto fail;
- i++;//Skip alpha
- r = partsData[i++];
- g = partsData[i++];
- b = partsData[i++];
- vidBuf[(fullY+y)*fullW+(fullX+x)] = PIXRGB(r, g, b);
- }
-
- //Skip vx
- if(fieldDescriptor & 0x80)
- {
- if(i++ >= partsDataLen) goto fail;
- }
-
- //Skip vy
- if(fieldDescriptor & 0x100)
- {
- if(i++ >= partsDataLen) goto fail;
- }
-
- //Skip tmp2
- if(fieldDescriptor & 0x400)
- {
- if(i++ >= partsDataLen) goto fail;
- if(fieldDescriptor & 0x800)
- {
- if(i++ >= partsDataLen) goto fail;
- }
- }
- }
- }
- }
- }
- goto fin;
-fail:
- if(vidBuf)
- {
- free(vidBuf);
- vidBuf = NULL;
- }
-fin:
- //Don't call bson_destroy if bson_init wasn't called, or an uninitialised pointer (b.data) will be freed and the game will crash
- if (bsonInitialised)
- bson_destroy(&b);
- return vidBuf;
-}
-
-void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h, unsigned char bmap[YRES/CELL][XRES/CELL], float vx[YRES/CELL][XRES/CELL], float vy[YRES/CELL][XRES/CELL], float pv[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* o_partsptr)
-{
- particle *partsptr = o_partsptr;
- unsigned char *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *finalData = NULL, *outputData = NULL, *soapLinkData = NULL;
- unsigned *partsPosLink = NULL, *partsPosFirstMap = NULL, *partsPosCount = NULL, *partsPosLastMap = NULL;
- unsigned partsCount = 0, *partsSaveIndex = NULL;
- unsigned *elementCount = calloc(PT_NUM, sizeof(unsigned));
- int partsDataLen, partsPosDataLen, fanDataLen, wallDataLen, finalDataLen, outputDataLen, soapLinkDataLen;
- int blockX, blockY, blockW, blockH, fullX, fullY, fullW, fullH;
- int x, y, i, wallDataFound = 0;
- int posCount, signsCount;
- bson b;
-
- //Get coords in blocks
- blockX = orig_x0/CELL;
- blockY = orig_y0/CELL;
-
- //Snap full coords to block size
- fullX = blockX*CELL;
- fullY = blockY*CELL;
-
- //Original size + offset of original corner from snapped corner, rounded up by adding CELL-1
- blockW = (orig_w+orig_x0-fullX+CELL-1)/CELL;
- blockH = (orig_h+orig_y0-fullY+CELL-1)/CELL;
- fullW = blockW*CELL;
- fullH = blockH*CELL;
-
- //Copy fan and wall data
- wallData = malloc(blockW*blockH);
- wallDataLen = blockW*blockH;
- fanData = malloc((blockW*blockH)*2);
- fanDataLen = 0;
- if (!wallData || !fanData)
- {
- puts("Save Error, out of memory\n");
- outputData = NULL;
- goto fin;
- }
- for(x = blockX; x < blockX+blockW; x++)
- {
- for(y = blockY; y < blockY+blockH; y++)
- {
- wallData[(y-blockY)*blockW+(x-blockX)] = bmap[y][x];
- if(bmap[y][x] && !wallDataFound)
- wallDataFound = 1;
- if(bmap[y][x]==WL_FAN)
- {
- i = (int)(fvx[y][x]*64.0f+127.5f);
- if (i<0) i=0;
- if (i>255) i=255;
- fanData[fanDataLen++] = i;
- i = (int)(fvy[y][x]*64.0f+127.5f);
- if (i<0) i=0;
- if (i>255) i=255;
- fanData[fanDataLen++] = i;
- }
- }
- }
- if(!fanDataLen)
- {
- free(fanData);
- fanData = NULL;
- }
- if(!wallDataFound)
- {
- free(wallData);
- wallData = NULL;
- }
-
- //Index positions of all particles, using linked lists
- //partsPosFirstMap is pmap for the first particle in each position
- //partsPosLastMap is pmap for the last particle in each position
- //partsPosCount is the number of particles in each position
- //partsPosLink contains, for each particle, (i<<8)|1 of the next particle in the same position
- partsPosFirstMap = calloc(fullW*fullH, sizeof(unsigned));
- partsPosLastMap = calloc(fullW*fullH, sizeof(unsigned));
- partsPosCount = calloc(fullW*fullH, sizeof(unsigned));
- partsPosLink = calloc(NPART, sizeof(unsigned));
- if (!partsPosFirstMap || !partsPosLastMap || !partsPosCount || !partsPosLink)
- {
- puts("Save Error, out of memory\n");
- outputData = NULL;
- goto fin;
- }
- for(i = 0; i < NPART; i++)
- {
- if(partsptr[i].type)
- {
- x = (int)(partsptr[i].x+0.5f);
- y = (int)(partsptr[i].y+0.5f);
- if (x>=orig_x0 && x<orig_x0+orig_w && y>=orig_y0 && y<orig_y0+orig_h)
- {
- //Coordinates relative to top left corner of saved area
- x -= fullX;
- y -= fullY;
- if (!partsPosFirstMap[y*fullW + x])
- {
- //First entry in list
- partsPosFirstMap[y*fullW + x] = (i<<8)|1;
- partsPosLastMap[y*fullW + x] = (i<<8)|1;
- }
- else
- {
- //Add to end of list
- partsPosLink[partsPosLastMap[y*fullW + x]>>8] = (i<<8)|1;//link to current end of list
- partsPosLastMap[y*fullW + x] = (i<<8)|1;//set as new end of list
- }
- partsPosCount[y*fullW + x]++;
- }
- }
- }
-
- //Store number of particles in each position
- partsPosData = malloc(fullW*fullH*3);
- partsPosDataLen = 0;
- if (!partsPosData)
- {
- puts("Save Error, out of memory\n");
- outputData = NULL;
- goto fin;
- }
- for (y=0;y<fullH;y++)
- {
- for (x=0;x<fullW;x++)
- {
- posCount = partsPosCount[y*fullW + x];
- partsPosData[partsPosDataLen++] = (posCount&0x00FF0000)>>16;
- partsPosData[partsPosDataLen++] = (posCount&0x0000FF00)>>8;
- partsPosData[partsPosDataLen++] = (posCount&0x000000FF);
- }
- }
-
- //Copy parts data
- /* Field descriptor format:
- | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
- tmp[3+4] | tmp2[2] | tmp2[1] | ctype[2] | vy | vx | dcololour | ctype[1] | tmp[2] | tmp[1] | life[2] | life[1] | temp dbl len|
- life[2] means a second byte (for a 16 bit field) if life[1] is present
- */
- partsData = malloc(NPART * (sizeof(particle)+1));
- partsDataLen = 0;
- partsSaveIndex = calloc(NPART, sizeof(unsigned));
- partsCount = 0;
- if (!partsData || !partsSaveIndex)
- {
- puts("Save Error, out of memory\n");
- outputData = NULL;
- goto fin;
- }
- for (y=0;y<fullH;y++)
- {
- for (x=0;x<fullW;x++)
- {
- //Find the first particle in this position
- i = partsPosFirstMap[y*fullW + x];
-
- //Loop while there is a pmap entry
- while (i)
- {
- unsigned short fieldDesc = 0;
- int fieldDescLoc = 0, tempTemp, vTemp;
-
- //Turn pmap entry into a partsptr index
- i = i>>8;
-
- //Store saved particle index+1 for this partsptr index (0 means not saved)
- partsSaveIndex[i] = (partsCount++) + 1;
-
- //Type (required)
- partsData[partsDataLen++] = partsptr[i].type;
- elementCount[partsptr[i].type]++;
-
- //Location of the field descriptor
- fieldDescLoc = partsDataLen++;
- partsDataLen++;
-
- //Extra Temperature (2nd byte optional, 1st required), 1 to 2 bytes
- //Store temperature as an offset of 21C(294.15K) or go into a 16byte int and store the whole thing
- if(fabs(partsptr[i].temp-294.15f)<127)
- {
- tempTemp = (partsptr[i].temp-294.15f);
- partsData[partsDataLen++] = tempTemp;
- }
- else
- {
- fieldDesc |= 1;
- tempTemp = partsptr[i].temp;
- partsData[partsDataLen++] = tempTemp;
- partsData[partsDataLen++] = tempTemp >> 8;
- }
-
- //Life (optional), 1 to 2 bytes
- if(partsptr[i].life)
- {
- fieldDesc |= 1 << 1;
- partsData[partsDataLen++] = partsptr[i].life;
- if(partsptr[i].life > 255)
- {
- fieldDesc |= 1 << 2;
- partsData[partsDataLen++] = partsptr[i].life >> 8;
- }
- }
-
- //Tmp (optional), 1, 2 or 4 bytes
- if(partsptr[i].tmp)
- {
- fieldDesc |= 1 << 3;
- partsData[partsDataLen++] = partsptr[i].tmp;
- if(partsptr[i].tmp > 255)
- {
- fieldDesc |= 1 << 4;
- partsData[partsDataLen++] = partsptr[i].tmp >> 8;
- if(partsptr[i].tmp > 65535)
- {
- fieldDesc |= 1 << 12;
- partsData[partsDataLen++] = (partsptr[i].tmp&0xFF000000)>>24;
- partsData[partsDataLen++] = (partsptr[i].tmp&0x00FF0000)>>16;
- }
- }
- }
-
- //Ctype (optional), 1 or 4 bytes
- if(partsptr[i].ctype)
- {
- fieldDesc |= 1 << 5;
- partsData[partsDataLen++] = partsptr[i].ctype;
- if(partsptr[i].ctype > 255)
- {
- fieldDesc |= 1 << 9;
- partsData[partsDataLen++] = (partsptr[i].ctype&0xFF000000)>>24;
- partsData[partsDataLen++] = (partsptr[i].ctype&0x00FF0000)>>16;
- partsData[partsDataLen++] = (partsptr[i].ctype&0x0000FF00)>>8;
- }
- }
-
- //Dcolour (optional), 4 bytes
- if(partsptr[i].dcolour && (partsptr[i].dcolour & 0xFF000000))
- {
- fieldDesc |= 1 << 6;
- partsData[partsDataLen++] = (partsptr[i].dcolour&0xFF000000)>>24;
- partsData[partsDataLen++] = (partsptr[i].dcolour&0x00FF0000)>>16;
- partsData[partsDataLen++] = (partsptr[i].dcolour&0x0000FF00)>>8;
- partsData[partsDataLen++] = (partsptr[i].dcolour&0x000000FF);
- }
-
- //VX (optional), 1 byte
- if(fabs(partsptr[i].vx) > 0.001f)
- {
- fieldDesc |= 1 << 7;
- vTemp = (int)(partsptr[i].vx*16.0f+127.5f);
- if (vTemp<0) vTemp=0;
- if (vTemp>255) vTemp=255;
- partsData[partsDataLen++] = vTemp;
- }
-
- //VY (optional), 1 byte
- if(fabs(partsptr[i].vy) > 0.001f)
- {
- fieldDesc |= 1 << 8;
- vTemp = (int)(partsptr[i].vy*16.0f+127.5f);
- if (vTemp<0) vTemp=0;
- if (vTemp>255) vTemp=255;
- partsData[partsDataLen++] = vTemp;
- }
-
- //Tmp2 (optional), 1 or 2 bytes
- if(partsptr[i].tmp2)
- {
- fieldDesc |= 1 << 10;
- partsData[partsDataLen++] = partsptr[i].tmp2;
- if(partsptr[i].tmp2 > 255)
- {
- fieldDesc |= 1 << 11;
- partsData[partsDataLen++] = partsptr[i].tmp2 >> 8;
- }
- }
-
- //Write the field descriptor;
- partsData[fieldDescLoc] = fieldDesc;
- partsData[fieldDescLoc+1] = fieldDesc>>8;
-
- //Get the pmap entry for the next particle in the same position
- i = partsPosLink[i];
- }
- }
- }
-
- soapLinkData = malloc(3*elementCount[PT_SOAP]);
- soapLinkDataLen = 0;
- if (!soapLinkData)
- {
- puts("Save Error, out of memory\n");
- outputData = NULL;
- goto fin;
- }
- //Iterate through particles in the same order that they were saved
- for (y=0;y<fullH;y++)
- {
- for (x=0;x<fullW;x++)
- {
- //Find the first particle in this position
- i = partsPosFirstMap[y*fullW + x];
-
- //Loop while there is a pmap entry
- while (i)
- {
- //Turn pmap entry into a partsptr index
- i = i>>8;
-
- if (partsptr[i].type==PT_SOAP)
- {
- //Only save forward link for each particle, back links can be deduced from other forward links
- //linkedIndex is index within saved particles + 1, 0 means not saved or no link
- unsigned linkedIndex = 0;
- if ((partsptr[i].ctype&2) && partsptr[i].tmp>=0 && partsptr[i].tmp<NPART)
- {
- linkedIndex = partsSaveIndex[partsptr[i].tmp];
- }
- soapLinkData[soapLinkDataLen++] = (linkedIndex&0xFF0000)>>16;
- soapLinkData[soapLinkDataLen++] = (linkedIndex&0x00FF00)>>8;
- soapLinkData[soapLinkDataLen++] = (linkedIndex&0x0000FF);
- }
-
- //Get the pmap entry for the next particle in the same position
- i = partsPosLink[i];
- }
- }
- }
- if(!soapLinkDataLen)
- {
- free(soapLinkData);
- soapLinkData = NULL;
- }
- if(!partsDataLen)
- {
- free(partsData);
- partsData = NULL;
- }
-
- bson_init(&b);
- bson_append_bool(&b, "waterEEnabled", water_equal_test);
- bson_append_bool(&b, "legacyEnable", legacy_enable);
- bson_append_bool(&b, "gravityEnable", ngrav_enable);
- bson_append_bool(&b, "paused", sys_pause);
- bson_append_int(&b, "gravityMode", gravityMode);
- bson_append_int(&b, "airMode", airMode);
-
- //bson_append_int(&b, "leftSelectedElement", sl);
- //bson_append_int(&b, "rightSelectedElement", sr);
- bson_append_int(&b, "activeMenu", active_menu);
- if(partsData)
- bson_append_binary(&b, "parts", BSON_BIN_USER, partsData, partsDataLen);
- if(partsPosData)
- bson_append_binary(&b, "partsPos", BSON_BIN_USER, partsPosData, partsPosDataLen);
- if(wallData)
- bson_append_binary(&b, "wallMap", BSON_BIN_USER, wallData, wallDataLen);
- if(fanData)
- bson_append_binary(&b, "fanMap", BSON_BIN_USER, fanData, fanDataLen);
- if(soapLinkData)
- bson_append_binary(&b, "soapLinks", BSON_BIN_USER, soapLinkData, soapLinkDataLen);
- signsCount = 0;
- for(i = 0; i < MAXSIGNS; i++)
- {
- if(signs[i].text[0] && signs[i].x>=orig_x0 && signs[i].x<=orig_x0+orig_w && signs[i].y>=orig_y0 && signs[i].y<=orig_y0+orig_h)
- {
- signsCount++;
- }
- }
- if(signsCount)
- {
- bson_append_start_array(&b, "signs");
- for(i = 0; i < MAXSIGNS; i++)
- {
- if(signs[i].text[0] && signs[i].x>=orig_x0 && signs[i].x<=orig_x0+orig_w && signs[i].y>=orig_y0 && signs[i].y<=orig_y0+orig_h)
- {
- bson_append_start_object(&b, "sign");
- bson_append_string(&b, "text", signs[i].text);
- bson_append_int(&b, "justification", signs[i].ju);
- bson_append_int(&b, "x", signs[i].x-fullX);
- bson_append_int(&b, "y", signs[i].y-fullY);
- bson_append_finish_object(&b);
- }
- }
- bson_append_finish_array(&b);
- }
- bson_finish(&b);
- bson_print(&b);
-
- finalData = bson_data(&b);
- finalDataLen = bson_size(&b);
- outputDataLen = finalDataLen*2+12;
- outputData = (unsigned char*)malloc(outputDataLen);
- if (!outputData)
- {
- puts("Save Error, out of memory\n");
- outputData = NULL;
- goto fin;
- }
-
- outputData[0] = 'O';
- outputData[1] = 'P';
- outputData[2] = 'S';
- outputData[3] = '1';
- outputData[4] = SAVE_VERSION;
- outputData[5] = CELL;
- outputData[6] = blockW;
- outputData[7] = blockH;
- outputData[8] = finalDataLen;
- outputData[9] = finalDataLen >> 8;
- outputData[10] = finalDataLen >> 16;
- outputData[11] = finalDataLen >> 24;
-
- if (BZ2_bzBuffToBuffCompress(outputData+12, &outputDataLen, finalData, bson_size(&b), 9, 0, 0) != BZ_OK)
- {
- puts("Save Error\n");
- free(outputData);
- *size = 0;
- outputData = NULL;
- goto fin;
- }
-
- printf("compressed data: %d\n", outputDataLen);
- *size = outputDataLen + 12;
-
-fin:
- bson_destroy(&b);
- if(partsData)
- free(partsData);
- if(wallData)
- free(wallData);
- if(fanData)
- free(fanData);
- if (elementCount)
- free(elementCount);
- if (partsSaveIndex)
- free(partsSaveIndex);
- if (soapLinkData)
- free(soapLinkData);
-
- return outputData;
-}
-
-int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned char bmap[YRES/CELL][XRES/CELL], float vx[YRES/CELL][XRES/CELL], float vy[YRES/CELL][XRES/CELL], float pv[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* o_partsptr, unsigned pmap[YRES][XRES])
-{
- particle *partsptr = o_partsptr;
- unsigned char * inputData = save, *bsonData = NULL, *partsData = NULL, *partsPosData = NULL, *fanData = NULL, *wallData = NULL, *soapLinkData = NULL;
- int inputDataLen = size, bsonDataLen = 0, partsDataLen, partsPosDataLen, fanDataLen, wallDataLen, soapLinkDataLen;
- unsigned partsCount = 0, *partsSimIndex = NULL;
- int i, freeIndicesCount, x, y, returnCode = 0, j;
- int *freeIndices = NULL;
- int blockX, blockY, blockW, blockH, fullX, fullY, fullW, fullH;
- int saved_version = inputData[4];
- bson b;
- bson_iterator iter;
-
- //Block sizes
- blockX = x0/CELL;
- blockY = y0/CELL;
- blockW = inputData[6];
- blockH = inputData[7];
-
- //Full size, normalised
- fullX = blockX*CELL;
- fullY = blockY*CELL;
- fullW = blockW*CELL;
- fullH = blockH*CELL;
-
- //From newer version
- if(saved_version > SAVE_VERSION)
- {
- fprintf(stderr, "Save from newer version\n");
- return 2;
- }
-
- //Incompatible cell size
- if(inputData[5] > CELL)
- {
- fprintf(stderr, "Cell size mismatch\n");
- return 1;
- }
-
- //Too large/off screen
- if(blockX+blockW > XRES/CELL || blockY+blockH > YRES/CELL)
- {
- fprintf(stderr, "Save too large\n");
- return 1;
- }
-
- bsonDataLen = ((unsigned)inputData[8]);
- bsonDataLen |= ((unsigned)inputData[9]) << 8;
- bsonDataLen |= ((unsigned)inputData[10]) << 16;
- bsonDataLen |= ((unsigned)inputData[11]) << 24;
-
- bsonData = malloc(bsonDataLen+1);
- if(!bsonData)
- {
- fprintf(stderr, "Internal error while parsing save: could not allocate buffer\n");
- return 3;
- }
- //Make sure bsonData is null terminated, since all string functions need null terminated strings
- //(bson_iterator_key returns a pointer into bsonData, which is then used with strcmp)
- bsonData[bsonDataLen] = 0;
-
- if (BZ2_bzBuffToBuffDecompress(bsonData, &bsonDataLen, inputData+12, inputDataLen-12, 0, 0))
- {
- fprintf(stderr, "Unable to decompress\n");
- return 1;
- }
-
- if(replace)
- {
- //Remove everything
- clear_sim();
- erase_bframe();
- }
-
- bson_init_data(&b, bsonData);
- bson_iterator_init(&iter, &b);
- while(bson_iterator_next(&iter))
- {
- if(strcmp(bson_iterator_key(&iter), "signs")==0)
- {
- if(bson_iterator_type(&iter)==BSON_ARRAY)
- {
- bson_iterator subiter;
- bson_iterator_subiterator(&iter, &subiter);
- while(bson_iterator_next(&subiter))
- {
- if(strcmp(bson_iterator_key(&subiter), "sign")==0)
- {
- if(bson_iterator_type(&subiter)==BSON_OBJECT)
- {
- bson_iterator signiter;
- bson_iterator_subiterator(&subiter, &signiter);
- //Find a free sign ID
- for (i = 0; i < MAXSIGNS; i++)
- if (!signs[i].text[0])
- break;
- //Stop reading signs if we have no free spaces
- if(i >= MAXSIGNS)
- break;
- while(bson_iterator_next(&signiter))
- {
- if(strcmp(bson_iterator_key(&signiter), "text")==0 && bson_iterator_type(&signiter)==BSON_STRING)
- {
- strncpy(signs[i].text, bson_iterator_string(&signiter), 255);
- clean_text(signs[i].text, 158-14);
- }
- else if(strcmp(bson_iterator_key(&signiter), "justification")==0 && bson_iterator_type(&signiter)==BSON_INT)
- {
- signs[i].ju = bson_iterator_int(&signiter);
- }
- else if(strcmp(bson_iterator_key(&signiter), "x")==0 && bson_iterator_type(&signiter)==BSON_INT)
- {
- signs[i].x = bson_iterator_int(&signiter)+fullX;
- }
- else if(strcmp(bson_iterator_key(&signiter), "y")==0 && bson_iterator_type(&signiter)==BSON_INT)
- {
- signs[i].y = bson_iterator_int(&signiter)+fullY;
- }
- else
- {
- fprintf(stderr, "Unknown sign property %s\n", bson_iterator_key(&signiter));
- }
- }
- }
- else
- {
- fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&subiter));
- }
- }
- }
- }
- else
- {
- fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter));
- }
- }
- else if(strcmp(bson_iterator_key(&iter), "parts")==0)
- {
- if(bson_iterator_type(&iter)==BSON_BINDATA && ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER && (partsDataLen = bson_iterator_bin_len(&iter)) > 0)
- {
- partsData = bson_iterator_bin_data(&iter);
- }
- else
- {
- fprintf(stderr, "Invalid datatype of particle data: %d[%d] %d[%d] %d[%d]\n", bson_iterator_type(&iter), bson_iterator_type(&iter)==BSON_BINDATA, (unsigned char)bson_iterator_bin_type(&iter), ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER, bson_iterator_bin_len(&iter), bson_iterator_bin_len(&iter)>0);
- }
- }
- if(strcmp(bson_iterator_key(&iter), "partsPos")==0)
- {
- if(bson_iterator_type(&iter)==BSON_BINDATA && ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER && (partsPosDataLen = bson_iterator_bin_len(&iter)) > 0)
- {
- partsPosData = bson_iterator_bin_data(&iter);
- }
- else
- {
- fprintf(stderr, "Invalid datatype of particle position data: %d[%d] %d[%d] %d[%d]\n", bson_iterator_type(&iter), bson_iterator_type(&iter)==BSON_BINDATA, (unsigned char)bson_iterator_bin_type(&iter), ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER, bson_iterator_bin_len(&iter), bson_iterator_bin_len(&iter)>0);
- }
- }
- else if(strcmp(bson_iterator_key(&iter), "wallMap")==0)
- {
- if(bson_iterator_type(&iter)==BSON_BINDATA && ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER && (wallDataLen = bson_iterator_bin_len(&iter)) > 0)
- {
- wallData = bson_iterator_bin_data(&iter);
- }
- else
- {
- fprintf(stderr, "Invalid datatype of wall data: %d[%d] %d[%d] %d[%d]\n", bson_iterator_type(&iter), bson_iterator_type(&iter)==BSON_BINDATA, (unsigned char)bson_iterator_bin_type(&iter), ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER, bson_iterator_bin_len(&iter), bson_iterator_bin_len(&iter)>0);
- }
- }
- else if(strcmp(bson_iterator_key(&iter), "fanMap")==0)
- {
- if(bson_iterator_type(&iter)==BSON_BINDATA && ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER && (fanDataLen = bson_iterator_bin_len(&iter)) > 0)
- {
- fanData = bson_iterator_bin_data(&iter);
- }
- else
- {
- fprintf(stderr, "Invalid datatype of fan data: %d[%d] %d[%d] %d[%d]\n", bson_iterator_type(&iter), bson_iterator_type(&iter)==BSON_BINDATA, (unsigned char)bson_iterator_bin_type(&iter), ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER, bson_iterator_bin_len(&iter), bson_iterator_bin_len(&iter)>0);
- }
- }
- else if(strcmp(bson_iterator_key(&iter), "soapLinks")==0)
- {
- if(bson_iterator_type(&iter)==BSON_BINDATA && ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER && (soapLinkDataLen = bson_iterator_bin_len(&iter)) > 0)
- {
- soapLinkData = bson_iterator_bin_data(&iter);
- }
- else
- {
- fprintf(stderr, "Invalid datatype of soap data: %d[%d] %d[%d] %d[%d]\n", bson_iterator_type(&iter), bson_iterator_type(&iter)==BSON_BINDATA, (unsigned char)bson_iterator_bin_type(&iter), ((unsigned char)bson_iterator_bin_type(&iter))==BSON_BIN_USER, bson_iterator_bin_len(&iter), bson_iterator_bin_len(&iter)>0);
- }
- }
- else if(strcmp(bson_iterator_key(&iter), "legacyEnable")==0 && replace)
- {
- if(bson_iterator_type(&iter)==BSON_BOOL)
- {
- legacy_enable = ((int)bson_iterator_bool(&iter))?1:0;
- }
- else
- {
- fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter));
- }
- }
- else if(strcmp(bson_iterator_key(&iter), "gravityEnable")==0 && replace)
- {
- if(bson_iterator_type(&iter)==BSON_BOOL)
- {
- int tempGrav = ngrav_enable;
- tempGrav = ((int)bson_iterator_bool(&iter))?1:0;
-#ifndef RENDERER
- //Change the gravity state
- if(ngrav_enable != tempGrav)
- {
- if(tempGrav)
- start_grav_async();
- else
- stop_grav_async();
- }
-#endif
- }
- else
- {
- fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter));
- }
- }
- else if(strcmp(bson_iterator_key(&iter), "waterEEnabled")==0 && replace)
- {
- if(bson_iterator_type(&iter)==BSON_BOOL)
- {
- water_equal_test = ((int)bson_iterator_bool(&iter))?1:0;
- }
- else
- {
- fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter));
- }
- }
- else if(strcmp(bson_iterator_key(&iter), "paused")==0 && !sys_pause)
- {
- if(bson_iterator_type(&iter)==BSON_BOOL)
- {
- sys_pause = ((int)bson_iterator_bool(&iter))?1:0;
- }
- else
- {
- fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter));
- }
- }
- else if(strcmp(bson_iterator_key(&iter), "gravityMode")==0 && replace)
- {
- if(bson_iterator_type(&iter)==BSON_INT)
- {
- gravityMode = bson_iterator_int(&iter);
- }
- else
- {
- fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter));
- }
- }
- else if(strcmp(bson_iterator_key(&iter), "airMode")==0 && replace)
- {
- if(bson_iterator_type(&iter)==BSON_INT)
- {
- airMode = bson_iterator_int(&iter);
- }
- else
- {
- fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter));
- }
- }
- /*else if((strcmp(bson_iterator_key(&iter), "leftSelectedElement")==0 || strcmp(bson_iterator_key(&iter), "rightSelectedElement")) && replace)
- {
- if(bson_iterator_type(&iter)==BSON_INT && bson_iterator_int(&iter) > 0 && bson_iterator_int(&iter) < PT_NUM)
- {
- if(bson_iterator_key(&iter)[0] == 'l')
- {
- sl = bson_iterator_int(&iter);
- }
- else
- {
- sr = bson_iterator_int(&iter);
- }
- }
- else
- {
- fprintf(stderr, "Wrong type for %s\n", bson_iterator_key(&iter));
- }
- }*/
- else if(strcmp(bson_iterator_key(&iter), "activeMenu")==0 && replace)
- {
- if(bson_iterator_type(&iter)==BSON_INT && bson_iterator_int(&iter) >= 0 && bson_iterator_int(&iter) < SC_TOTAL && msections[bson_iterator_int(&iter)].doshow)
- {
- active_menu = bson_iterator_int(&iter);
- }
- else
- {
- fprintf(stderr, "Wrong value for %s\n", bson_iterator_key(&iter));
- }
- }
- }
-
- //Read wall and fan data
- if(wallData)
- {
- j = 0;
- if(blockW * blockH > wallDataLen)
- {
- fprintf(stderr, "Not enough wall data\n");
- goto fail;
- }
- for(x = 0; x < blockW; x++)
- {
- for(y = 0; y < blockH; y++)
- {
- if (wallData[y*blockW+x])
- bmap[blockY+y][blockX+x] = wallData[y*blockW+x];
- if (wallData[y*blockW+x] == WL_FAN && fanData)
- {
- if(j+1 >= fanDataLen)
- {
- fprintf(stderr, "Not enough fan data\n");
- }
- fvx[blockY+y][blockX+x] = (fanData[j++]-127.0f)/64.0f;
- fvy[blockY+y][blockX+x] = (fanData[j++]-127.0f)/64.0f;
- }
- }
- }
- gravity_mask();
- }
-
- //Read particle data
- if(partsData && partsPosData)
- {
- int newIndex = 0, fieldDescriptor, tempTemp;
- int posCount, posTotal, partsPosDataIndex = 0;
- int saved_x, saved_y;
- int freeIndicesIndex = 0;
- if(fullW * fullH * 3 > partsPosDataLen)
- {
- fprintf(stderr, "Not enough particle position data\n");
- goto fail;
- }
- parts_lastActiveIndex = NPART-1;
- freeIndicesCount = 0;
- freeIndices = calloc(sizeof(int), NPART);
- partsSimIndex = calloc(NPART, sizeof(unsigned));
- partsCount = 0;
- for (i = 0; i<NPART; i++)
- {
- //Ensure ALL parts (even photons) are in the pmap so we can overwrite, keep a track of indices we can use
- if (partsptr[i].type)
- {
- x = (int)(partsptr[i].x+0.5f);
- y = (int)(partsptr[i].y+0.5f);
- pmap[y][x] = (i<<8)|1;
- }
- else
- freeIndices[freeIndicesCount++] = i;
- }
- i = 0;
- for (saved_y=0; saved_y<fullH; saved_y++)
- {
- for (saved_x=0; saved_x<fullW; saved_x++)
- {
- //Read total number of particles at this position
- posTotal = 0;
- posTotal |= partsPosData[partsPosDataIndex++]<<16;
- posTotal |= partsPosData[partsPosDataIndex++]<<8;
- posTotal |= partsPosData[partsPosDataIndex++];
- //Put the next posTotal particles at this position
- for (posCount=0; posCount<posTotal; posCount++)
- {
- //i+3 because we have 4 bytes of required fields (type (1), descriptor (2), temp (1))
- if (i+3 >= partsDataLen)
- goto fail;
- x = saved_x + fullX;
- y = saved_y + fullY;
- fieldDescriptor = partsData[i+1];
- fieldDescriptor |= partsData[i+2] << 8;
- if(x >= XRES || x < 0 || y >= YRES || y < 0)
- {
- fprintf(stderr, "Out of range [%d]: %d %d, [%d, %d], [%d, %d]\n", i, x, y, (unsigned)partsData[i+1], (unsigned)partsData[i+2], (unsigned)partsData[i+3], (unsigned)partsData[i+4]);
- goto fail;
- }
- if(partsData[i] >= PT_NUM || !ptypes[partsData[i]].enabled)
- partsData[i] = PT_DMND; //Replace all invalid elements with diamond
- if(pmap[y][x] && posCount==0) // Check posCount to make sure an existing particle is not replaced twice if two particles are saved in that position
- {
- //Replace existing particle or allocated block
- newIndex = pmap[y][x]>>8;
- }
- else if(freeIndicesIndex<freeIndicesCount)
- {
- //Create new particle
- newIndex = freeIndices[freeIndicesIndex++];
- }
- else
- {
- //Nowhere to put new particle, tpt is sad :(
- break;
- }
- if(newIndex < 0 || newIndex >= NPART)
- goto fail;
-
- //Store partsptr index+1 for this saved particle index (0 means not loaded)
- partsSimIndex[partsCount++] = newIndex+1;
-
- //Clear the particle, ready for our new properties
- memset(&(partsptr[newIndex]), 0, sizeof(particle));
-
- //Required fields
- partsptr[newIndex].type = partsData[i];
- partsptr[newIndex].x = x;
- partsptr[newIndex].y = y;
- i+=3;
-
- //Read temp
- if(fieldDescriptor & 0x01)
- {
- //Full 16bit int
- tempTemp = partsData[i++];
- tempTemp |= (((unsigned)partsData[i++]) << 8);
- partsptr[newIndex].temp = tempTemp;
- }
- else
- {
- //1 Byte room temp offset
- tempTemp = (char)partsData[i++];
- partsptr[newIndex].temp = tempTemp+294.15f;
- }
-
- //Read life
- if(fieldDescriptor & 0x02)
- {
- if(i >= partsDataLen) goto fail;
- partsptr[newIndex].life = partsData[i++];
- //Read 2nd byte
- if(fieldDescriptor & 0x04)
- {
- if(i >= partsDataLen) goto fail;
- partsptr[newIndex].life |= (((unsigned)partsData[i++]) << 8);
- }
- }
-
- //Read tmp
- if(fieldDescriptor & 0x08)
- {
- if(i >= partsDataLen) goto fail;
- partsptr[newIndex].tmp = partsData[i++];
- //Read 2nd byte
- if(fieldDescriptor & 0x10)
- {
- if(i >= partsDataLen) goto fail;
- partsptr[newIndex].tmp |= (((unsigned)partsData[i++]) << 8);
- //Read 3rd and 4th bytes
- if(fieldDescriptor & 0x1000)
- {
- if(i+1 >= partsDataLen) goto fail;
- partsptr[newIndex].tmp |= (((unsigned)partsData[i++]) << 24);
- partsptr[newIndex].tmp |= (((unsigned)partsData[i++]) << 16);
- }
- }
- }
-
- //Read ctype
- if(fieldDescriptor & 0x20)
- {
- if(i >= partsDataLen) goto fail;
- partsptr[newIndex].ctype = partsData[i++];
- //Read additional bytes
- if(fieldDescriptor & 0x200)
- {
- if(i+2 >= partsDataLen) goto fail;
- partsptr[newIndex].ctype |= (((unsigned)partsData[i++]) << 24);
- partsptr[newIndex].ctype |= (((unsigned)partsData[i++]) << 16);
- partsptr[newIndex].ctype |= (((unsigned)partsData[i++]) << 8);
- }
- }
-
- //Read dcolour
- if(fieldDescriptor & 0x40)
- {
- if(i+3 >= partsDataLen) goto fail;
- partsptr[newIndex].dcolour = (((unsigned)partsData[i++]) << 24);
- partsptr[newIndex].dcolour |= (((unsigned)partsData[i++]) << 16);
- partsptr[newIndex].dcolour |= (((unsigned)partsData[i++]) << 8);
- partsptr[newIndex].dcolour |= ((unsigned)partsData[i++]);
- }
-
- //Read vx
- if(fieldDescriptor & 0x80)
- {
- if(i >= partsDataLen) goto fail;
- partsptr[newIndex].vx = (partsData[i++]-127.0f)/16.0f;
- }
-
- //Read vy
- if(fieldDescriptor & 0x100)
- {
- if(i >= partsDataLen) goto fail;
- partsptr[newIndex].vy = (partsData[i++]-127.0f)/16.0f;
- }
-
- //Read tmp2
- if(fieldDescriptor & 0x400)
- {
- if(i >= partsDataLen) goto fail;
- partsptr[newIndex].tmp2 = partsData[i++];
- //Read 2nd byte
- if(fieldDescriptor & 0x800)
- {
- if(i >= partsDataLen) goto fail;
- partsptr[newIndex].tmp2 |= (((unsigned)partsData[i++]) << 8);
- }
- }
-
-#ifdef OGLR
- partsptr[newIndex].lastX = partsptr[newIndex].x - partsptr[newIndex].vx;
- partsptr[newIndex].lastY = partsptr[newIndex].y - partsptr[newIndex].vy;
-#endif
-
- if ((player.spwn == 1 && partsptr[newIndex].type==PT_STKM) || (player2.spwn == 1 && partsptr[newIndex].type==PT_STKM2))
- {
- partsptr[newIndex].type = PT_NONE;
- }
- else if (partsptr[newIndex].type == PT_STKM)
- {
- STKM_init_legs(&player, newIndex);
- player.spwn = 1;
- player.elem = PT_DUST;
- }
- else if (partsptr[newIndex].type == PT_STKM2)
- {
- STKM_init_legs(&player2, newIndex);
- player2.spwn = 1;
- player2.elem = PT_DUST;
- }
- else if (partsptr[newIndex].type == PT_FIGH)
- {
- unsigned char fcount = 0;
- while (fcount < 100 && fcount < (fighcount+1) && fighters[fcount].spwn==1) fcount++;
- if (fcount < 100 && fighters[fcount].spwn==0)
- {
- partsptr[newIndex].tmp = fcount;
- fighters[fcount].spwn = 1;
- fighters[fcount].elem = PT_DUST;
- fighcount++;
- STKM_init_legs(&(fighters[fcount]), newIndex);
- }
- }
- else if (partsptr[newIndex].type == PT_SOAP)
- {
- //Clear soap links, links will be added back in if soapLinkData is present
- partsptr[newIndex].ctype &= ~6;
- }
- if (!ptypes[partsptr[newIndex].type].enabled)
- partsptr[newIndex].type = PT_NONE;
-
-
- if (saved_version<81)
- {
- if (partsptr[newIndex].type==PT_BOMB && partsptr[newIndex].tmp!=0)
- {
- partsptr[newIndex].type = PT_EMBR;
- partsptr[newIndex].ctype = 0;
- if (partsptr[newIndex].tmp==1)
- partsptr[newIndex].tmp = 0;
- }
- if (partsptr[newIndex].type==PT_DUST && partsptr[newIndex].life>0)
- {
- partsptr[newIndex].type = PT_EMBR;
- partsptr[newIndex].ctype = (partsptr[newIndex].tmp2<<16) | (partsptr[newIndex].tmp<<8) | partsptr[newIndex].ctype;
- partsptr[newIndex].tmp = 1;
- }
- if (partsptr[newIndex].type==PT_FIRW && partsptr[newIndex].tmp>=2)
- {
- int caddress = restrict_flt(restrict_flt((float)(partsptr[newIndex].tmp-4), 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
- partsptr[newIndex].type = PT_EMBR;
- partsptr[newIndex].tmp = 1;
- partsptr[newIndex].ctype = (((unsigned char)(firw_data[caddress]))<<16) | (((unsigned char)(firw_data[caddress+1]))<<8) | ((unsigned char)(firw_data[caddress+2]));
- }
- }
- }
- }
- }
- if (soapLinkData)
- {
- int soapLinkDataPos = 0;
- for (i=0; i<partsCount; i++)
- {
- if (partsSimIndex[i] && partsptr[partsSimIndex[i]-1].type == PT_SOAP)
- {
- // Get the index of the particle forward linked from this one, if present in the save data
- int linkedIndex = 0;
- if (soapLinkDataPos+3 > soapLinkDataLen) break;
- linkedIndex |= soapLinkData[soapLinkDataPos++]<<16;
- linkedIndex |= soapLinkData[soapLinkDataPos++]<<8;
- linkedIndex |= soapLinkData[soapLinkDataPos++];
- // All indexes in soapLinkData and partsSimIndex have 1 added to them (0 means not saved/loaded)
- if (!linkedIndex || linkedIndex-1>=partsCount || !partsSimIndex[linkedIndex-1])
- continue;
- linkedIndex = partsSimIndex[linkedIndex-1]-1;
- newIndex = partsSimIndex[i]-1;
-
- //Attach the two particles
- partsptr[newIndex].ctype |= 2;
- partsptr[newIndex].tmp = linkedIndex;
- partsptr[linkedIndex].ctype |= 4;
- partsptr[linkedIndex].tmp2 = newIndex;
- }
- }
- }
- }
- goto fin;
-fail:
- //Clean up everything
- returnCode = 1;
-fin:
- bson_destroy(&b);
- if(freeIndices)
- free(freeIndices);
- if(partsSimIndex)
- free(partsSimIndex);
- return returnCode;
-}
-
-//Old saving
-pixel *prerender_save_PSv(void *save, int size, int *width, int *height)
-{
- unsigned char *d,*c=save;
- int i,j,k,x,y,rx,ry,p=0, wt, pc, gc;
- int bw,bh,w,h,new_format = 0;
- pixel *fb;
-
- if (size<16)
- return NULL;
- if (!(c[2]==0x43 && c[1]==0x75 && c[0]==0x66) && !(c[2]==0x76 && c[1]==0x53 && c[0]==0x50))
- return NULL;
- if (c[2]==0x43 && c[1]==0x75 && c[0]==0x66) {
- new_format = 1;
- }
- if (c[4]>SAVE_VERSION)
- return NULL;
-
- bw = c[6];
- bh = c[7];
- w = bw*CELL;
- h = bh*CELL;
-
- if (c[5]!=CELL)
- return NULL;
-
- i = (unsigned)c[8];
- i |= ((unsigned)c[9])<<8;
- i |= ((unsigned)c[10])<<16;
- i |= ((unsigned)c[11])<<24;
- d = malloc(i);
- if (!d)
- return NULL;
- fb = calloc(w*h, PIXELSIZE);
- if (!fb)
- {
- free(d);
- return NULL;
- }
-
- if (BZ2_bzBuffToBuffDecompress((char *)d, (unsigned *)&i, (char *)(c+12), size-12, 0, 0))
- goto corrupt;
- size = i;
-
- if (size < bw*bh)
- goto corrupt;
-
- k = 0;
- for (y=0; y<bh; y++)
- for (x=0; x<bw; x++)
- {
- int wt = change_wall(d[p]);
- rx = x*CELL;
- ry = y*CELL;
- pc = wtypes[wt-UI_ACTUALSTART].colour;
- gc = wtypes[wt-UI_ACTUALSTART].eglow;
- if (wtypes[wt-UI_ACTUALSTART].drawstyle==1)
- {
- for (i=0; i<CELL; i+=2)
- for (j=(i>>1)&1; j<CELL; j+=2)
- fb[(i+ry)*w+(j+rx)] = pc;
- }
- else if (wtypes[wt-UI_ACTUALSTART].drawstyle==2)
- {
- for (i=0; i<CELL; i+=2)
- for (j=0; j<CELL; j+=2)
- fb[(i+ry)*w+(j+rx)] = pc;
- }
- else if (wtypes[wt-UI_ACTUALSTART].drawstyle==3)
- {
- for (i=0; i<CELL; i++)
- for (j=0; j<CELL; j++)
- fb[(i+ry)*w+(j+rx)] = pc;
- }
- else if (wtypes[wt-UI_ACTUALSTART].drawstyle==4)
- {
- for (i=0; i<CELL; i++)
- for (j=0; j<CELL; j++)
- if(i == j)
- fb[(i+ry)*w+(j+rx)] = pc;
- else if (j == i+1 || (j == 0 && i == CELL-1))
- fb[(i+ry)*w+(j+rx)] = gc;
- else
- fb[(i+ry)*w+(j+rx)] = PIXPACK(0x202020);
- }
-
- // special rendering for some walls
- if (wt==WL_EWALL)
- {
- for (i=0; i<CELL; i++)
- for (j=0; j<CELL; j++)
- if (!(i&j&1))
- fb[(i+ry)*w+(j+rx)] = pc;
- }
- else if (wt==WL_WALLELEC)
- {
- for (i=0; i<CELL; i++)
- for (j=0; j<CELL; j++)
- {
- if (!((y*CELL+j)%2) && !((x*CELL+i)%2))
- fb[(i+ry)*w+(j+rx)] = pc;
- else
- fb[(i+ry)*w+(j+rx)] = PIXPACK(0x808080);
- }
- }
- else if (wt==WL_EHOLE)
- {
- for (i=0; i<CELL; i+=2)
- for (j=0; j<CELL; j+=2)
- fb[(i+ry)*w+(j+rx)] = PIXPACK(0x242424);
- }
- else if (wt==WL_FAN)
- k++;
- p++;
- }
- p += 2*k;
- if (p>=size)
- goto corrupt;
-
- for (y=0; y<h; y++)
- for (x=0; x<w; x++)
- {
- if (p >= size)
- goto corrupt;
- j=d[p++];
- if (j<PT_NUM && j>0)
- {
- if (j==PT_STKM || j==PT_STKM2 || j==PT_FIGH)
- {
- pixel lc, hc=PIXRGB(255, 224, 178);
- if (j==PT_STKM || j==PT_FIGH) lc = PIXRGB(255, 255, 255);
- else lc = PIXRGB(100, 100, 255);
- //only need to check upper bound of y coord - lower bounds and x<w are checked in draw_line
- if (j==PT_STKM || j==PT_STKM2)
- {
- draw_line(fb , x-2, y-2, x+2, y-2, PIXR(hc), PIXG(hc), PIXB(hc), w);
- if (y+2<h)
- {
- draw_line(fb , x-2, y+2, x+2, y+2, PIXR(hc), PIXG(hc), PIXB(hc), w);
- draw_line(fb , x-2, y-2, x-2, y+2, PIXR(hc), PIXG(hc), PIXB(hc), w);
- draw_line(fb , x+2, y-2, x+2, y+2, PIXR(hc), PIXG(hc), PIXB(hc), w);
- }
- }
- else if (y+2<h)
- {
- draw_line(fb, x-2, y, x, y-2, PIXR(hc), PIXG(hc), PIXB(hc), w);
- draw_line(fb, x-2, y, x, y+2, PIXR(hc), PIXG(hc), PIXB(hc), w);
- draw_line(fb, x, y-2, x+2, y, PIXR(hc), PIXG(hc), PIXB(hc), w);
- draw_line(fb, x, y+2, x+2, y, PIXR(hc), PIXG(hc), PIXB(hc), w);
- }
- if (y+6<h)
- {
- draw_line(fb , x, y+3, x-1, y+6, PIXR(lc), PIXG(lc), PIXB(lc), w);
- draw_line(fb , x, y+3, x+1, y+6, PIXR(lc), PIXG(lc), PIXB(lc), w);
- }
- if (y+12<h)
- {
- draw_line(fb , x-1, y+6, x-3, y+12, PIXR(lc), PIXG(lc), PIXB(lc), w);
- draw_line(fb , x+1, y+6, x+3, y+12, PIXR(lc), PIXG(lc), PIXB(lc), w);
- }
- }
- else
- fb[y*w+x] = ptypes[j].pcolors;
- }
- }
-
- free(d);
- *width = w;
- *height = h;
- return fb;
-
-corrupt:
- free(d);
- free(fb);
- return NULL;
-}
-
-int parse_save_PSv(void *save, int size, int replace, int x0, int y0, unsigned char bmap[YRES/CELL][XRES/CELL], float fvx[YRES/CELL][XRES/CELL], float fvy[YRES/CELL][XRES/CELL], sign signs[MAXSIGNS], void* partsptr, unsigned pmap[YRES][XRES])
-{
- unsigned char *d=NULL,*c=save;
- int q,i,j,k,x,y,p=0,*m=NULL, ver, pty, ty, legacy_beta=0, tempGrav = 0;
- int bx0=x0/CELL, by0=y0/CELL, bw, bh, w, h;
- int nf=0, new_format = 0, ttv = 0;
- particle *parts = partsptr;
- int *fp = malloc(NPART*sizeof(int));
-
- //New file header uses PSv, replacing fuC. This is to detect if the client uses a new save format for temperatures
- //This creates a problem for old clients, that display and "corrupt" error instead of a "newer version" error
-
- if (size<16)
- return 1;
- if (!(c[2]==0x43 && c[1]==0x75 && c[0]==0x66) && !(c[2]==0x76 && c[1]==0x53 && c[0]==0x50))
- return 1;
- if (c[2]==0x76 && c[1]==0x53 && c[0]==0x50) {
- new_format = 1;
- }
- if (c[4]>SAVE_VERSION)
- return 2;
- ver = c[4];
-
- if (ver<34)
- {
- legacy_enable = 1;
- }
- else
- {
- if (ver>=44) {
- legacy_enable = c[3]&0x01;
- if (!sys_pause) {
- sys_pause = (c[3]>>1)&0x01;
- }
- if (ver>=46 && replace) {
- gravityMode = ((c[3]>>2)&0x03);// | ((c[3]>>2)&0x01);
- airMode = ((c[3]>>4)&0x07);// | ((c[3]>>4)&0x02) | ((c[3]>>4)&0x01);
- }
- if (ver>=49 && replace) {
- tempGrav = ((c[3]>>7)&0x01);
- }
- } else {
- if (c[3]==1||c[3]==0) {
- legacy_enable = c[3];
- } else {
- legacy_beta = 1;
- }
- }
- }
-
- bw = c[6];
- bh = c[7];
- if (bx0+bw > XRES/CELL)
- bx0 = XRES/CELL - bw;
- if (by0+bh > YRES/CELL)
- by0 = YRES/CELL - bh;
- if (bx0 < 0)
- bx0 = 0;
- if (by0 < 0)
- by0 = 0;
-
- if (c[5]!=CELL || bx0+bw>XRES/CELL || by0+bh>YRES/CELL)
- return 3;
- i = (unsigned)c[8];
- i |= ((unsigned)c[9])<<8;
- i |= ((unsigned)c[10])<<16;
- i |= ((unsigned)c[11])<<24;
- d = malloc(i);
- if (!d)
- return 1;
-
- if (BZ2_bzBuffToBuffDecompress((char *)d, (unsigned *)&i, (char *)(c+12), size-12, 0, 0))
- return 1;
- size = i;
-
- if (size < bw*bh)
- return 1;
-
- // normalize coordinates
- x0 = bx0*CELL;
- y0 = by0*CELL;
- w = bw *CELL;
- h = bh *CELL;
-
- if (replace)
- {
- if (ver<46) {
- gravityMode = 0;
- airMode = 0;
- }
- clear_sim();
- erase_bframe();
- }
- parts_lastActiveIndex = NPART-1;
- m = calloc(XRES*YRES, sizeof(int));
-
- // make a catalog of free parts
- //memset(pmap, 0, sizeof(pmap)); "Using sizeof for array given as function argument returns the size of pointer."
- memset(pmap, 0, sizeof(unsigned)*(XRES*YRES));
- for (i=0; i<NPART; i++)
- if (parts[i].type)
- {
- x = (int)(parts[i].x+0.5f);
- y = (int)(parts[i].y+0.5f);
- pmap[y][x] = (i<<8)|1;
- }
- else
- fp[nf++] = i;
-
- // load the required air state
- for (y=by0; y<by0+bh; y++)
- for (x=bx0; x<bx0+bw; x++)
- {
- if (d[p])
- {
- //In old saves, ignore walls created by sign tool bug
- //Not ignoring other invalid walls or invalid walls in new saves, so that any other bugs causing them are easier to notice, find and fix
- if (ver<71 && d[p]==WL_SIGN)
- {
- p++;
- continue;
- }
-
- bmap[y][x] = change_wall(d[p]);
- }
-
- p++;
- }
- for (y=by0; y<by0+bh; y++)
- for (x=bx0; x<bx0+bw; x++)
- if (d[(y-by0)*bw+(x-bx0)]==4||d[(y-by0)*bw+(x-bx0)]==WL_FAN)
- {
- if (p >= size)
- goto corrupt;
- fvx[y][x] = (d[p++]-127.0f)/64.0f;
- }
- for (y=by0; y<by0+bh; y++)
- for (x=bx0; x<bx0+bw; x++)
- if (d[(y-by0)*bw+(x-bx0)]==4||d[(y-by0)*bw+(x-bx0)]==WL_FAN)
- {
- if (p >= size)
- goto corrupt;
- fvy[y][x] = (d[p++]-127.0f)/64.0f;
- }
-
- // load the particle map
- i = 0;
- pty = p;
- for (y=y0; y<y0+h; y++)
- for (x=x0; x<x0+w; x++)
- {
- if (p >= size)
- goto corrupt;
- j=d[p++];
- if (j >= PT_NUM) {
- //TODO: Possibly some server side translation
- j = PT_DUST;//goto corrupt;
- }
- gol[y][x]=0;
- if (j)
- {
- if (pmap[y][x])
- {
- k = pmap[y][x]>>8;
- }
- else if (i<nf)
- {
- k = fp[i];
- i++;
- }
- else
- {
- m[(x-x0)+(y-y0)*w] = NPART+1;
- continue;
- }
- memset(parts+k, 0, sizeof(particle));
- parts[k].type = j;
- if (j == PT_COAL)
- parts[k].tmp = 50;
- if (j == PT_FUSE)
- parts[k].tmp = 50;
- if (j == PT_PHOT)
- parts[k].ctype = 0x3fffffff;
- if (j == PT_SOAP)
- parts[k].ctype = 0;
- if (j==PT_BIZR || j==PT_BIZRG || j==PT_BIZRS)
- parts[k].ctype = 0x47FFFF;
- parts[k].x = (float)x;
- parts[k].y = (float)y;
- m[(x-x0)+(y-y0)*w] = k+1;
- }
- }
-
- // load particle properties
- for (j=0; j<w*h; j++)
- {
- i = m[j];
- if (i)
- {
- i--;
- if (p+1 >= size)
- goto corrupt;
- if (i < NPART)
- {
- parts[i].vx = (d[p++]-127.0f)/16.0f;
- parts[i].vy = (d[p++]-127.0f)/16.0f;
-#ifdef OGLR
- parts[i].lastX = parts[i].x - parts[i].vx;
- parts[i].lastY = parts[i].y - parts[i].vy;
-#endif
- }
- else
- p += 2;
- }
- }
- for (j=0; j<w*h; j++)
- {
- i = m[j];
- if (i)
- {
- if (ver>=44) {
- if (p >= size) {
- goto corrupt;
- }
- if (i <= NPART) {
- ttv = (d[p++])<<8;
- ttv |= (d[p++]);
- parts[i-1].life = ttv;
- } else {
- p+=2;
- }
- } else {
- if (p >= size)
- goto corrupt;
- if (i <= NPART)
- parts[i-1].life = d[p++]*4;
- else
- p++;
- }
- }
- }
- if (ver>=44) {
- for (j=0; j<w*h; j++)
- {
- i = m[j];
- if (i)
- {
- if (p >= size) {
- goto corrupt;
- }
- if (i <= NPART) {
- ttv = (d[p++])<<8;
- ttv |= (d[p++]);
- parts[i-1].tmp = ttv;
- if (ver<53 && !parts[i-1].tmp)
- for (q = 1; q<=NGOLALT; q++) {
- if (parts[i-1].type==goltype[q-1] && grule[q][9]==2)
- parts[i-1].tmp = grule[q][9]-1;
- }
- if (ver>=51 && ver<53 && parts[i-1].type==PT_PBCN)
- {
- parts[i-1].tmp2 = parts[i-1].tmp;
- parts[i-1].tmp = 0;
- }
- } else {
- p+=2;
- }
- }
- }
- }
- if (ver>=53) {
- for (j=0; j<w*h; j++)
- {
- i = m[j];
- ty = d[pty+j];
- if (i && (ty==PT_PBCN || (ty==PT_TRON && ver>=77)))
- {
- if (p >= size)
- goto corrupt;
- if (i <= NPART)
- parts[i-1].tmp2 = d[p++];
- else
- p++;
- }
- }
- }
- //Read ALPHA component
- for (j=0; j<w*h; j++)
- {
- i = m[j];
- if (i)
- {
- if (ver>=49) {
- if (p >= size) {
- goto corrupt;
- }
- if (i <= NPART) {
- parts[i-1].dcolour = d[p++]<<24;
- } else {
- p++;
- }
- }
- }
- }
- //Read RED component
- for (j=0; j<w*h; j++)
- {
- i = m[j];
- if (i)
- {
- if (ver>=49) {
- if (p >= size) {
- goto corrupt;
- }
- if (i <= NPART) {
- parts[i-1].dcolour |= d[p++]<<16;
- } else {
- p++;
- }
- }
- }
- }
- //Read GREEN component
- for (j=0; j<w*h; j++)
- {
- i = m[j];
- if (i)
- {
- if (ver>=49) {
- if (p >= size) {
- goto corrupt;
- }
- if (i <= NPART) {
- parts[i-1].dcolour |= d[p++]<<8;
- } else {
- p++;
- }
- }
- }
- }
- //Read BLUE component
- for (j=0; j<w*h; j++)
- {
- i = m[j];
- if (i)
- {
- if (ver>=49) {
- if (p >= size) {
- goto corrupt;
- }
- if (i <= NPART) {
- parts[i-1].dcolour |= d[p++];
- } else {
- p++;
- }
- }
- }
- }
- for (j=0; j<w*h; j++)
- {
- i = m[j];
- ty = d[pty+j];
- if (i)
- {
- if (ver>=34&&legacy_beta==0)
- {
- if (p >= size)
- {
- goto corrupt;
- }
- if (i <= NPART)
- {
- if (ver>=42) {
- if (new_format) {
- ttv = (d[p++])<<8;
- ttv |= (d[p++]);
- if (parts[i-1].type==PT_PUMP) {
- parts[i-1].temp = ttv + 0.15;//fix PUMP saved at 0, so that it loads at 0.
- } else {
- parts[i-1].temp = ttv;
- }
- } else {
- parts[i-1].temp = (d[p++]*((MAX_TEMP+(-MIN_TEMP))/255))+MIN_TEMP;
- }
- } else {
- parts[i-1].temp = ((d[p++]*((O_MAX_TEMP+(-O_MIN_TEMP))/255))+O_MIN_TEMP)+273;
- }
- }
- else
- {
- p++;
- if (new_format) {
- p++;
- }
- }
- }
- else
- {
- parts[i-1].temp = ptypes[parts[i-1].type].heat;
- }
- }
- }
- for (j=0; j<w*h; j++)
- {
- int gnum = 0;
- i = m[j];
- ty = d[pty+j];
- if (i && (ty==PT_CLNE || (ty==PT_PCLN && ver>=43) || (ty==PT_BCLN && ver>=44) || (ty==PT_SPRK && ver>=21) || (ty==PT_LAVA && ver>=34) || (ty==PT_PIPE && ver>=43) || (ty==PT_LIFE && ver>=51) || (ty==PT_PBCN && ver>=52) || (ty==PT_WIRE && ver>=55) || (ty==PT_STOR && ver>=59) || (ty==PT_CONV && ver>=60)))
- {
- if (p >= size)
- goto corrupt;
- if (i <= NPART)
- parts[i-1].ctype = d[p++];
- else
- p++;
- }
- // no more particle properties to load, so we can change type here without messing up loading
- if (i && i<=NPART)
- {
- if ((player.spwn == 1 && ty==PT_STKM) || (player2.spwn == 1 && ty==PT_STKM2))
- {
- parts[i-1].type = PT_NONE;
- }
- else if (parts[i-1].type == PT_STKM)
- {
- STKM_init_legs(&player, i-1);
- player.spwn = 1;
- player.elem = PT_DUST;
- }
- else if (parts[i-1].type == PT_STKM2)
- {
- STKM_init_legs(&player2, i-1);
- player2.spwn = 1;
- player2.elem = PT_DUST;
- }
- else if (parts[i-1].type == PT_FIGH)
- {
- unsigned char fcount = 0;
- while (fcount < 100 && fcount < (fighcount+1) && fighters[fcount].spwn==1) fcount++;
- if (fcount < 100 && fighters[fcount].spwn==0)
- {
- parts[i-1].tmp = fcount;
- fighters[fcount].spwn = 1;
- fighters[fcount].elem = PT_DUST;
- fighcount++;
- STKM_init_legs(&(fighters[fcount]), i-1);
- }
- }
- else if (ver<79 && parts[i-1].type == PT_SPNG)
- {
- if (fabs(parts[i-1].vx)>0.0f || fabs(parts[i-1].vy)>0.0f)
- parts[i-1].flags |= FLAG_MOVABLE;
- }
-
- if (ver<48 && (ty==OLD_PT_WIND || (ty==PT_BRAY&&parts[i-1].life==0)))
- {
- // Replace invisible particles with something sensible and add decoration to hide it
- x = (int)(parts[i-1].x+0.5f);
- y = (int)(parts[i-1].y+0.5f);
- parts[i-1].dcolour = 0xFF000000;
- parts[i-1].type = PT_DMND;
- }
- if(ver<51 && ((ty>=78 && ty<=89) || (ty>=134 && ty<=146 && ty!=141))){
- //Replace old GOL
- parts[i-1].type = PT_LIFE;
- for (gnum = 0; gnum<NGOLALT; gnum++){
- if (ty==goltype[gnum])
- parts[i-1].ctype = gnum;
- }
- ty = PT_LIFE;
- }
- if(ver<52 && (ty==PT_CLNE || ty==PT_PCLN || ty==PT_BCLN)){
- //Replace old GOL ctypes in clone
- for (gnum = 0; gnum<NGOLALT; gnum++){
- if (parts[i-1].ctype==goltype[gnum])
- {
- parts[i-1].ctype = PT_LIFE;
- parts[i-1].tmp = gnum;
- }
- }
- }
- if(ty==PT_LCRY){
- if(ver<67)
- {
- //New LCRY uses TMP not life
- if(parts[i-1].life>=10)
- {
- parts[i-1].life = 10;
- parts[i-1].tmp2 = 10;
- parts[i-1].tmp = 3;
- }
- else if(parts[i-1].life<=0)
- {
- parts[i-1].life = 0;
- parts[i-1].tmp2 = 0;
- parts[i-1].tmp = 0;
- }
- else if(parts[i-1].life < 10 && parts[i-1].life > 0)
- {
- parts[i-1].tmp = 1;
- }
- }
- else
- {
- parts[i-1].tmp2 = parts[i-1].life;
- }
- }
- if (!ptypes[parts[i-1].type].enabled)
- parts[i-1].type = PT_NONE;
-
- if (ver<81)
- {
- if (parts[i-1].type==PT_BOMB && parts[i-1].tmp!=0)
- {
- parts[i-1].type = PT_EMBR;
- parts[i-1].ctype = 0;
- if (parts[i-1].tmp==1)
- parts[i-1].tmp = 0;
- }
- if (parts[i-1].type==PT_DUST && parts[i-1].life>0)
- {
- parts[i-1].type = PT_EMBR;
- parts[i-1].ctype = (parts[i-1].tmp2<<16) | (parts[i-1].tmp<<8) | parts[i-1].ctype;
- parts[i-1].tmp = 1;
- }
- if (parts[i-1].type==PT_FIRW && parts[i-1].tmp>=2)
- {
- int caddress = restrict_flt(restrict_flt((float)(parts[i-1].tmp-4), 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3);
- parts[i-1].type = PT_EMBR;
- parts[i-1].tmp = 1;
- parts[i-1].ctype = (((unsigned char)(firw_data[caddress]))<<16) | (((unsigned char)(firw_data[caddress+1]))<<8) | ((unsigned char)(firw_data[caddress+2]));
- }
- }
- }
- }
-
- #ifndef RENDERER
- //Change the gravity state
- if(ngrav_enable != tempGrav && replace)
- {
- if(tempGrav)
- start_grav_async();
- else
- stop_grav_async();
- }
- #endif
-
- gravity_mask();
-
- if (p >= size)
- goto version1;
- j = d[p++];
- for (i=0; i<j; i++)
- {
- if (p+6 > size)
- goto corrupt;
- for (k=0; k<MAXSIGNS; k++)
- if (!signs[k].text[0])
- break;
- x = d[p++];
- x |= ((unsigned)d[p++])<<8;
- if (k<MAXSIGNS)
- signs[k].x = x+x0;
- x = d[p++];
- x |= ((unsigned)d[p++])<<8;
- if (k<MAXSIGNS)
- signs[k].y = x+y0;
- x = d[p++];
- if (k<MAXSIGNS)
- signs[k].ju = x;
- x = d[p++];
- if (p+x > size)
- goto corrupt;
- if (k<MAXSIGNS)
- {
- memcpy(signs[k].text, d+p, x);
- signs[k].text[x] = 0;
- clean_text(signs[k].text, 158-14 /* Current max sign length */);
- }
- p += x;
- }
-
-version1:
- if (m) free(m);
- if (d) free(d);
- if (fp) free(fp);
-
- return 0;
-
-corrupt:
- if (m) free(m);
- if (d) free(d);
- if (fp) free(fp);
- if (replace)
- {
- legacy_enable = 0;
- clear_sim();
- erase_bframe();
- }
- return 1;
-}
-
-void *build_thumb(int *size, int bzip2)
-{
- unsigned char *d=calloc(1,XRES*YRES), *c;
- int i,j,x,y;
- for (i=0; i<NPART; i++)
- if (parts[i].type)
- {
- x = (int)(parts[i].x+0.5f);
- y = (int)(parts[i].y+0.5f);
- if (x>=0 && x<XRES && y>=0 && y<YRES)
- d[x+y*XRES] = parts[i].type;
- }
- for (y=0; y<YRES/CELL; y++)
- for (x=0; x<XRES/CELL; x++)
- if (bmap[y][x])
- for (j=0; j<CELL; j++)
- for (i=0; i<CELL; i++)
- d[x*CELL+i+(y*CELL+j)*XRES] = 0xFF;
- j = XRES*YRES;
-
- if (bzip2)
- {
- i = (j*101+99)/100 + 608;
- c = malloc(i);
-
- c[0] = 0x53;
- c[1] = 0x68;
- c[2] = 0x49;
- c[3] = 0x74;
- c[4] = PT_NUM;
- c[5] = CELL;
- c[6] = XRES/CELL;
- c[7] = YRES/CELL;
-
- i -= 8;
-
- if (BZ2_bzBuffToBuffCompress((char *)(c+8), (unsigned *)&i, (char *)d, j, 9, 0, 0) != BZ_OK)
- {
- free(d);
- free(c);
- return NULL;
- }
- free(d);
- *size = i+8;
- return c;
- }
-
- *size = j;
- return d;
-}
-
-void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate)
-{
- void *ndata;
- unsigned char (*bmapo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(unsigned char));
- unsigned char (*bmapn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(unsigned char));
- particle *partst = calloc(sizeof(particle), NPART);
- sign *signst = calloc(MAXSIGNS, sizeof(sign));
- unsigned (*pmapt)[XRES] = calloc(YRES*XRES, sizeof(unsigned));
- float (*fvxo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float));
- float (*fvyo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float));
- float (*fvxn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float));
- float (*fvyn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float));
- float (*vxo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float));
- float (*vyo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float));
- float (*vxn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float));
- float (*vyn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float));
- float (*pvo)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float));
- float (*pvn)[XRES/CELL] = calloc((YRES/CELL)*(XRES/CELL), sizeof(float));
- int i, x, y, nx, ny, w, h, nw, nh;
- vector2d pos, tmp, ctl, cbr;
- vector2d vel;
- vector2d cornerso[4];
- unsigned char *odatac = odata;
- if (parse_save(odata, *size, 0, 0, 0, bmapo, vxo, vyo, pvo, fvxo, fvyo, signst, partst, pmapt))
- {
- free(bmapo);
- free(bmapn);
- free(partst);
- free(signst);
- free(pmapt);
- free(fvxo);
- free(fvyo);
- free(fvxn);
- free(fvyn);
- free(vxo);
- free(vyo);
- free(vxn);
- free(vyn);
- free(pvo);
- free(pvn);
- return odata;
- }
- w = odatac[6]*CELL;
- h = odatac[7]*CELL;
- // undo any translation caused by rotation
- cornerso[0] = v2d_new(0,0);
- cornerso[1] = v2d_new(w-1,0);
- cornerso[2] = v2d_new(0,h-1);
- cornerso[3] = v2d_new(w-1,h-1);
- for (i=0; i<4; i++)
- {
- tmp = m2d_multiply_v2d(transform,cornerso[i]);
- if (i==0) ctl = cbr = tmp; // top left, bottom right corner
- if (tmp.x<ctl.x) ctl.x = tmp.x;
- if (tmp.y<ctl.y) ctl.y = tmp.y;
- if (tmp.x>cbr.x) cbr.x = tmp.x;
- if (tmp.y>cbr.y) cbr.y = tmp.y;
- }
- // casting as int doesn't quite do what we want with negative numbers, so use floor()
- tmp = v2d_new(floor(ctl.x+0.5f),floor(ctl.y+0.5f));
- translate = v2d_sub(translate,tmp);
- nw = floor(cbr.x+0.5f)-floor(ctl.x+0.5f)+1;
- nh = floor(cbr.y+0.5f)-floor(ctl.y+0.5f)+1;
- if (nw>XRES) nw = XRES;
- if (nh>YRES) nh = YRES;
- // rotate and translate signs, parts, walls
- for (i=0; i<MAXSIGNS; i++)
- {
- if (!signst[i].text[0]) continue;
- pos = v2d_new(signst[i].x, signst[i].y);
- pos = v2d_add(m2d_multiply_v2d(transform,pos),translate);
- nx = floor(pos.x+0.5f);
- ny = floor(pos.y+0.5f);
- if (nx<0 || nx>=nw || ny<0 || ny>=nh)
- {
- signst[i].text[0] = 0;
- continue;
- }
- signst[i].x = nx;
- signst[i].y = ny;
- }
- for (i=0; i<NPART; i++)
- {
- if (!partst[i].type) continue;
- pos = v2d_new(partst[i].x, partst[i].y);
- pos = v2d_add(m2d_multiply_v2d(transform,pos),translate);
- nx = floor(pos.x+0.5f);
- ny = floor(pos.y+0.5f);
- if (nx<0 || nx>=nw || ny<0 || ny>=nh)
- {
- partst[i].type = PT_NONE;
- continue;
- }
- partst[i].x = nx;
- partst[i].y = ny;
- vel = v2d_new(partst[i].vx, partst[i].vy);
- vel = m2d_multiply_v2d(transform, vel);
- partst[i].vx = vel.x;
- partst[i].vy = vel.y;
- }
- for (y=0; y<YRES/CELL; y++)
- for (x=0; x<XRES/CELL; x++)
- {
- pos = v2d_new(x*CELL+CELL*0.4f, y*CELL+CELL*0.4f);
- pos = v2d_add(m2d_multiply_v2d(transform,pos),translate);
- nx = pos.x/CELL;
- ny = pos.y/CELL;
- if (nx<0 || nx>=nw/CELL || ny<0 || ny>=nh/CELL)
- continue;
- if (bmapo[y][x])
- {
- bmapn[ny][nx] = bmapo[y][x];
- if (bmapo[y][x]==WL_FAN)
- {
- vel = v2d_new(fvxo[y][x], fvyo[y][x]);
- vel = m2d_multiply_v2d(transform, vel);
- fvxn[ny][nx] = vel.x;
- fvyn[ny][nx] = vel.y;
- }
- }
- vel = v2d_new(vxo[y][x], vyo[y][x]);
- vel = m2d_multiply_v2d(transform, vel);
- vxn[ny][nx] = vel.x;
- vyn[ny][nx] = vel.y;
- pvn[ny][nx] = pvo[y][x];
- }
- ndata = build_save(size,0,0,nw,nh,bmapn,vxn,vyn,pvn,fvxn,fvyn,signst,partst);
- free(bmapo);
- free(bmapn);
- free(partst);
- free(signst);
- free(pmapt);
- free(fvxo);
- free(fvyo);
- free(fvxn);
- free(fvyn);
- free(vxo);
- free(vyo);
- free(vxn);
- free(vyn);
- free(pvo);
- free(pvn);
- return ndata;
-}
diff --git a/src/update.c b/src/update.c
deleted file mode 100644
index be78347..0000000
--- a/src/update.c
+++ /dev/null
@@ -1,203 +0,0 @@
-/**
- * Powder Toy - Update Helper
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#ifndef WIN32
-#include <sys/param.h>
-#endif
-#if !defined(MACOSX) && !defined(BSD)
-#include <malloc.h>
-#endif
-#include <string.h>
-
-#ifdef WIN32
-#include <windows.h>
-#else
-#include <unistd.h>
-#include <sys/stat.h>
-#endif
-#ifdef MACOSX
-#include <mach-o/dyld.h>
-#include <errno.h>
-#endif
-
-#include <update.h>
-
-char *exe_name(void)
-{
-#if defined WIN32
- char *name= (char *)malloc(64);
- DWORD max=64, res;
- while ((res = GetModuleFileName(NULL, name, max)) >= max)
- {
-#elif defined MACOSX
- char *fn=malloc(64),*name=malloc(PATH_MAX);
- uint32_t max=64, res;
- if (_NSGetExecutablePath(fn, &max) != 0)
- {
- fn = realloc(fn, max);
- _NSGetExecutablePath(fn, &max);
- }
- if (realpath(fn, name) == NULL)
- {
- free(fn);
- free(name);
- return NULL;
- }
- res = 1;
-#else
- char fn[64], *name=malloc(64);
- size_t max=64, res;
- sprintf(fn, "/proc/self/exe");
- memset(name, 0, max);
- while ((res = readlink(fn, name, max)) >= max-1)
- {
-#endif
-#ifndef MACOSX
- max *= 2;
- name = realloc(name, max);
- memset(name, 0, max);
- }
-#endif
- if (res <= 0)
- {
- free(name);
- return NULL;
- }
- return name;
-}
-
-int update_start(char *data, int len)
-{
- char *self=exe_name(), *temp;
-#ifdef WIN32
- char *p;
-#endif
- FILE *f;
- int res = 1;
-
- if (!self)
- return 1;
-
-#ifdef WIN32
- temp = malloc(strlen(self)+12);
- strcpy(temp, self);
- p = temp + strlen(temp) - 4;
- if (_stricmp(p, ".exe"))
- p += 4;
- strcpy(p, "_update.exe");
-
- if (!MoveFile(self, temp))
- goto fail;
-
- f = fopen(self, "wb");
- if (!f)
- goto fail;
- if (fwrite(data, 1, len, f) != len)
- {
- fclose(f);
- DeleteFile(self);
- goto fail;
- }
- fclose(f);
-
- if ((int)ShellExecute(NULL, "open", self, NULL, NULL, SW_SHOWNORMAL) <= 32)
- {
- DeleteFile(self);
- goto fail;
- }
-
- return 0;
-#else
- temp = malloc(strlen(self)+8);
- strcpy(temp, self);
- strcat(temp, "-update");
-
- f = fopen(temp, "w");
- if (!f)
- goto fail;
- if (fwrite(data, 1, len, f) != len)
- {
- fclose(f);
- unlink(temp);
- goto fail;
- }
- fclose(f);
-
- if (chmod(temp, 0755))
- {
- unlink(temp);
- goto fail;
- }
-
- if (rename(temp, self))
- {
- unlink(temp);
- goto fail;
- }
-
- execl(self, "powder-update", NULL);
-#endif
-
-fail:
- free(temp);
- free(self);
- return res;
-}
-
-int update_finish(void)
-{
-#ifdef WIN32
- char *temp, *self=exe_name(), *p;
- int timeout = 60, err;
-
- temp = malloc(strlen(self)+12);
- strcpy(temp, self);
- p = temp + strlen(temp) - 4;
- if (_stricmp(p, ".exe"))
- p += 4;
- strcpy(p, "_update.exe");
-
- while (!DeleteFile(temp))
- {
- err = GetLastError();
- if (err == ERROR_FILE_NOT_FOUND)
- {
- // just as well, then
- free(temp);
- return 0;
- }
- Sleep(500);
- timeout--;
- if (timeout <= 0)
- {
- free(temp);
- return 1;
- }
- }
- free(temp);
-#endif
- return 0;
-}
-
-void update_cleanup(void)
-{
-#ifdef WIN32
- update_finish();
-#endif
-}