
void dopan(float x) {
	pan = (int)((x - screencenterx) * 0.2 + 128);
	if(pan > 255) pan = 255;
	if(pan < 0) pan = 0;
}

void dovol(float x, float k) {
	vol = (int)(255 - abs(x - screencenterx) * k);
	if(vol < 0) vol = 0;
}

void dopanvol(float x, float k) {
	pan = (int)((x - screencenterx) * 0.2 + 128);
	if(pan > 255) pan = 255;
	if(pan < 0) pan = 0;
	vol = 255 - abs((int)(x - screencenterx)) * k;
	if(vol < 0) vol = 0;
}

void setupgrid(float aposx[100][100], float aposy[100][100]) {
	int x, y;
	for(x = 0; x < 100; x++) {
		for(y = 0; y < 100; y++) {
			aposx[x][y] = (float)(x * 10);
			aposy[x][y] = (float)(y * 10);
		}
	}
}

void setupmass(float amass[100][100]) {
	int x, y;
	for(x = 0; x < 100; x++) {
		for(y = 0; y < 100; y++) {
			amass[x][y] = 1;
		}
	}
}


/*		**LEVELS**

  0: Nothing interacts with this. Used for debris
  1: The human player
  2: The upper part of buildings (that the player cannot walk through)
  3: The human's bullets
  4: The lower part of buildings (that the player can walk through)
  5: Enemy soldiers
  6: Enemy bullets
  7: Empty vehicles
  8: Corpses
  9: Acts like bullets (bomb bullets)
  10: Personnel bullets
  11: Friendly controlled vehicles
  12: Enemy controlled vehicles
  13: Friendly bombs
  14: Enemy bombs
  15: Gravity-less, non-interacting atoms (Plane's wheel)
  16: Rope
  17: Rung
  18: Letter
  19: Noninteracting letter
  20: Menu atom - everything interacts
 
*/

void settmplevels() {
	int i;	
	for(i = 1; i < MAXLEVELS; i++) {
		tmplevels[i] = true;
	}
	tmplevels[0] = false;
	tmplevels[8] = false;
	tmplevels[10] = false;
	tmplevels[15] = false;
	tmplevels[16] = false;
}

void cleartmplevels() {
	int i;	
	for(i = 0; i < MAXLEVELS; i++) {
		tmplevels[i] = false;
	}
}

void adddebris(atom *a, bool accrue) {
	//destroyatom(a);
	//return;
	if(a->fixed) return;
	debrisitem *d;
	int i;

	d = &(debris[0]);
	for(i = 0; i < MAXDEBRIS; i++) {
		if(!d->on) {
			d->me = a;
			d->on = true;
			//d->me->bmp = create_bitmap_ex(32, 16, 16);
			//putpixel(d->me->bmp, 10, 10, getpixel(ground, 100, 100));
			d->me->debris = true;
			d->me->level = 0;
			d->me->d = d;
			//if(d->me->bmp == NULL) exit(0);
			d->accrue = accrue;
			for(i = 0; i < MAXLEVELS; i++) {
				d->me->levels[i] = false;
			}
			break;
		}
		d++;
	}
}

void readpath(char *file) {
     ifstream iff;
     iff.open(file);
     
     int read = 0, last = -1, pos = 0;

     int tmp;
     iff >> tmp;
     while(pos < tmp) {
         last = read;
         iff >> read;
         path[pos] = (600.0 / 480.0) * read;
         debrislev[pos] = (600.0 / 480.0) * read - 7;
         pos++;
     }

	 iff.close();
}

void drawdebris() {
	debrisitem *d;
	int i;
	d = &(debris[0]);
	for(i = 0; i < MAXDEBRIS; i++) {
		if(d->on) {
			d->draw();
		}
		d++;
	}
}

void erasedebris() {
	debrisitem *d;
	int i;
	d = &(debris[0]);
	for(i = 0; i < MAXDEBRIS; i++) {
		if(d->on) {
			d->erase();
		}
		d++;
	}
}
