/* Make C-Evo epic: 7x tech cost and 2.5 size increase for foodboxes.  
 * This allows there to be more wars and considerably slows down development.
 * combined with a 230% map size, you can have a C-Evo game last weeks! */

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

int main(int argc, char **argv) {
	FILE *cevo, *cevohack = 0;
	int a,b,c;
	int offset;
	uint8_t *d;
	float cost[3] = {14.0, 16.1, 18.2};
	int32_t foodbox[3] = {74,100,126};
	int32_t num = 30;
	float fnum = 0;
	if(argc != 1 && argc != 4) {
		printf("Epic: Make a Cevo-epic.exe file with 7x tech cost\n"
	        "and 2.5x foodbox (storage) size for very long C-Evo games.\n"
		"This program needs to be run in the same\n"
		"directory as C-Evo 1.1.1's Cevo.exe, and creates a file\n"
		"named Cevo-epic.exe.\n\n");
	exit(0);
	}
	d = (uint8_t *)&num;
	cevohack = fopen("cevo-epic.exe","wb");
	cevo = fopen("Cevo.exe","rb");
	if(cevo == 0) {
		printf("Could not find Cevo.exe!\n");
		exit(1);
	}
	for(a=0;a<0xc4e10;a++) {
		b = getc(cevo);	
		if(feof(cevo)) {
			printf("This is too small!\n");
			exit(2);
		}
		if(cevohack != 0) {
			putc(b,cevohack);
		}
	}
	/* Foodbox */
	for(a=0;a<3;a++) {
		if(cevohack == 0) {
			foodbox[a] = 0;
		}
		num = foodbox[a];
		for(c=0;c<4;c++) {
			b = getc(cevo);
			if(cevohack != 0) {
				/* d points to where num is */
				b = ((d[c]) & 0xff);
				putc(b,cevohack);
			} else {
				d[c] = b;
			}
		}
		foodbox[a] = num;
	}
	/* Tech cost */
	for(a=0;a<3;a++) {
		if(cevohack == 0) {
			cost[a] = 0;
		}
		d = (uint8_t *)&fnum;
		fnum = cost[a];
		for(c=0;c<4;c++) {
			b = getc(cevo);
			if(cevohack != 0) {
				/* d points to where num is */
				b = ((d[c]) & 0xff);
				putc(b,cevohack);
			} else {
				d[c] = b;
			}
		}
		cost[a] = fnum;
	}
	while(!feof(cevo)) {
		b = getc(cevo);
		if(cevohack != 0 && !feof(cevo)) {
			putc(b,cevohack);
		}
	}
	fclose(cevo);
	if(cevohack != 0) {
		fclose(cevohack);
		printf("cevo-epic.exe made\n");
	}
}
