Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <ctime> //used to initilize the random number generator
- #include <cstdlib> //used for the random numbers
- #include <curses.h> //display
- #include <cmath>
- using namespace std;
- /***************************/
- #define forDiagonal(w) {int xdir[]={-1,-1,1,1};int ydir[]={-1,1,-1,1};int A;int B;int shuffled[]={0,1,2,3};shuffle(shuffled,4);for(int i=0;i<4;i++){A=ydir[shuffled[i]];B=xdir[shuffled[i]];if(legal(y+A,x+B)){w}}}
- #define forOrthogonal(w) {int xdir[]={-1,0,1,0};int ydir[]={0,-1,0,1};int A;int B;int shuffled[]={0,1,2,3};shuffle(shuffled,4);for(int i=0;i<4;i++){A=ydir[shuffled[i]];B=xdir[shuffled[i]];if(legal(y+A,x+B)){w}}}
- #define forTouching(w) {int xdir[]={-1,-1,-1,0,1,1,1,0};int ydir[]={-1,0,1,1,1,0,-1,-1};int A;int B;int shuffled[]={0,1,2,3,4,5,6,7,};shuffle(shuffled,8);for(int i=0;i<8;i++){A=ydir[shuffled[i]];B=xdir[shuffled[i]];if(legal(y+A,x+B)){w}}}
- #define show(w,z) else if(a&(w)){ return z; }
- #define put(a,b) else if(inchar==a){ TILES[playerY][playerX]^=b; }
- #define record_name(x) add_names_to_list(x,#x)
- #define currentlyAt(y,x,thing) (tiles[y][x]&thing)
- #define remove(y,x,thing) (subtract[y][x]&= ~thing)
- #define addAt(y,x,thing) (tiles[y][x]|=thing)
- /***************************/
- const int Y=40; //height of world
- const int X=80; //width of world
- const int size_of_int = 32;
- const int names_width=20;
- char NAMES[size_of_int][names_width];
- enum{
- // to add a new thing
- // add its name to the enum
- // add function void Thing(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- // add record_name( thing ); to init
- // add "show(thing,t)" to tile_creature
- // in EXACTLY the same place add "show(thing, <int> )" to color_creature
- // add "put('T',thing)" to input
- // add "if(isAt(y,x,thing)) Thing(y,x,tiles,subtract);" to tick
- // create Thing function
- // and you're done
- numFields =0,
- //each thing is a bit
- wall= 1<<0,
- dwarf1= 1<<1,
- dwarf2= 1<<2,
- previous= 1<<3,
- door= 1<<4,
- dragon= 1<<5,
- grass= 1<<6,
- tallgrass= 1<<7,
- fire= 1<<8,
- stickybush= 1<<9,
- lichen= 1<<10,
- moss= 1<<11,
- mold= 1<<12,
- moldseed= 1<<13,
- slime= 1<<14,
- jelly= 1<<15,
- grazer= 1<<16,
- runner= 1<<17,
- predator= 1<<18,
- stickyseed= 1<<19,
- bloat= 1<<20,
- coral= 1<<21,
- plankton= 1<<22,
- youngcoral= 1<<23,
- fireweed= 1<<24,
- fireweedseed=1<<25,
- larva= 1<<26,
- treeseed= 1<<27,
- sapling= 1<<28,
- tree= 1<<29,
- ant= 1<<30,//
- busheater= 1<<31,
- //not enough bits for these
- reed= 0,
- sedge= 0,
- daisy= 0,
- thing1= 0,
- thing2= 0,
- sage= 0,
- sand= 0,
- flower= 0,
- shrub= 0,
- livevine= 0,
- vine= 0,
- vineroot= 0,
- paralyze= 0,
- seeds=(stickyseed |fireweedseed |moldseed |treeseed |plankton),
- creature=(dwarf1 |dwarf2 |dragon |jelly |runner |grazer |ant |larva |busheater),
- plant=(grass |tallgrass |slime |stickybush |fireweed |lichen |mold |vine |vineroot |tree |daisy |coral |sapling),
- flamable=(tallgrass |stickybush |vine |fireweed |mold |shrub |daisy |moss), //supports flames
- explosive=(fireweed), //spreads flame to all surrounding tiles
- hardtoburn=(slime |tree |sapling |lichen |coral |youngcoral), //burns slowly
- burnable=(seeds |flamable |hardtoburn |grass |fireweed |jelly |dwarf2 |dwarf1 |lichen |moss |mold |grazer |vineroot |door |flower |sage), //gets burnt up
- endolithic=(lichen |moss |slime |mold),
- pickupable=(stickyseed |fireweedseed |moldseed),
- bush=(fireweed |stickybush |sage |vine |vineroot |coral),
- };
- /***************************/
- int COLOR[Y][X]; //the color of the tiles
- char VIEW[Y][X]; //the charecter
- bool visible[Y][X];
- int TILES[Y][X];
- int GOLD[Y][X];
- int DISTURBANCE[Y][X]; //how long since something disturbed this tile
- bool quit;
- bool xray;
- char inchar;
- bool paused;
- bool looking;
- bool showing_instructions;
- int playerY;
- int playerX;
- int turncount;
- /***************************/
- int bit_number(int a);
- bool legal(int w,int g);
- bool superlegal(int w,int g);
- bool supersuperlegal(int w,int g);
- bool blocked(int w,int g);
- bool notblocked(int w,int g);
- bool isAt(int y, int x,int thing);
- int color_creature(int a, int gold);
- char tile_creature(int a, int gold);
- void display();
- void init();
- void input();
- void tick();
- void Bloat(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Thing1(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Thing2(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Reed(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Sedge(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Coral(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Plankton(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Youngcoral(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Tree(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Sapling(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Treeseed(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Shrub(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Flower(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Busheater(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Ant(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Vineroot(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Vine(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Grazer(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Larva(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Fireweedseed(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Fireweed(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Lichen(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Moldseed(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Mold(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Moss(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Stickyseed(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- int power(int a, int b);
- void Stickybush(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Runner(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Predator(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Jelly(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Slime(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Sage(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Fire(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Grass(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Tallgrass(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Dwarf1(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Dwarf2(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- void Dragon(int y, int x, int tiles[Y][X],int subtract[Y][X]);
- int touching(int y, int x, int item);
- int touchingNot(int y, int x, int item);
- int diagonal(int y, int x, int item);
- int diagonalNot(int y, int x, int item);
- int orthogonal(int y, int x, int item);
- int orthogonalNot(int y, int x, int item);
- bool koolaidman(int y, int x);
- bool antikoolaidman(int y, int x);
- bool nocorner(int y, int x);
- void swap(int &a,int &b);
- bool bresenham(int y0,int y1,int x0,int x1);
- void shuffle(int arry[],int length);
- int sign(int a);
- void look_tile(int tile,char creatures[size_of_int][names_width]);
- void add_names_to_list(int creach, char* name);
- /***************************/
- /***************************/
- void add_names_to_list(int creach, char* name){
- int i=bit_number(creach);
- if(i!=-1){
- NAMES[i][0]=' ';
- NAMES[i][1]= tile_creature(creach,0);
- NAMES[i][2]=' ';
- int j=3;
- for(; j<names_width && name[j-3]!='\0'; j++){
- NAMES[i][j]=name[j-3];
- }
- for(; j<names_width; j++){
- NAMES[i][j]=' ';
- }
- return;
- }
- }
- int bit_number(int a){
- for(int i=0; i<size_of_int; i++){
- if((1<<i)==a) return i;
- }
- return -1;
- }
- bool legal(int w,int g){ return w>=0 && w<Y && g>=0 && g<X; }
- bool superlegal(int w,int g){ return w>0 && w<(Y-1) && g>0 && g<(X-1);}
- bool supersuperlegal(int w,int g){ return w>1 && w<(Y-2) && g>1 && g<(X-2);}
- bool notblocked(int w,int g){
- return legal(w,g) && !isAt(w,g,wall); //within bounds of the map array
- }
- bool blocked(int w,int g){
- return legal(w,g) || isAt(w,g,wall); //within bounds of the map array
- }
- int main()
- {
- init();
- while(!quit) //press q to quit
- {
- display();
- input();
- if(!paused && !looking){
- tick();
- }
- }
- refresh();
- echo(); // turn echoing back on before exiting
- endwin(); // end curses control of the window
- }
- /***************************/
- void init()
- {
- xray=true;
- looking=false;
- quit=false;
- paused=true;
- turncount=0;
- showing_instructions=false;
- initscr();
- nodelay(initscr(),true); // don't wait for user input
- srand(time(NULL)); // initializes the random number generator
- clear(); // clear the window
- noecho(); // don't show typed characters on the screen
- start_color();
- init_pair(0, COLOR_WHITE, COLOR_BLACK);
- init_pair(1, COLOR_WHITE, COLOR_RED);
- init_pair(2, COLOR_WHITE, COLOR_BLUE);
- init_pair(3, COLOR_WHITE, COLOR_GREEN);
- init_pair(4, COLOR_WHITE, COLOR_YELLOW);
- init_pair(5, COLOR_RED, COLOR_YELLOW);
- init_pair(6, COLOR_GREEN, COLOR_BLACK);
- init_pair(7, COLOR_BLUE, COLOR_BLACK);
- init_pair(8, COLOR_CYAN, COLOR_BLACK);
- init_pair(9, COLOR_YELLOW, COLOR_BLACK);
- init_pair(10, COLOR_RED, COLOR_BLACK);
- init_pair(11, COLOR_WHITE, COLOR_CYAN);
- init_pair(12, COLOR_WHITE, COLOR_MAGENTA);
- init_pair(13, COLOR_BLACK, COLOR_WHITE);
- init_pair(14, COLOR_MAGENTA, COLOR_WHITE);
- for(int y=0; y<Y; y++)
- {
- for(int x=0; x<X; x++)
- {
- COLOR[y][x]=0;
- VIEW[y][x]=' ';
- TILES[y][x] = wall;
- GOLD[y][x] = (rand()%16==0);
- DISTURBANCE[y][x]=0;
- visible[y][x]=false;
- }
- }
- TILES[Y/2][X/2]|=dwarf1;
- playerY=Y/2;
- playerX=X/2;
- record_name(wall);
- record_name(dwarf1);
- record_name(dwarf2);
- record_name(previous);
- record_name(door);
- record_name(dragon);
- record_name(grass);
- record_name(tallgrass);
- record_name(fire);
- record_name(flower);
- record_name(lichen);
- record_name(moss);
- record_name(mold);
- record_name(moldseed);
- record_name(slime);
- record_name(jelly);
- record_name(grazer);
- record_name(runner);
- record_name(predator);
- record_name(paralyze);
- record_name(shrub);
- record_name(vine);
- record_name(vineroot);
- record_name(coral);
- record_name(plankton);
- record_name(youngcoral);
- record_name(fireweed);
- record_name(fireweedseed);
- record_name(larva);
- record_name(treeseed);
- record_name(sapling);
- record_name(tree);
- record_name(ant);
- record_name(busheater);
- record_name(stickybush);
- record_name(stickyseed);
- record_name(reed);
- record_name(sedge);
- record_name(daisy);
- record_name(thing1);
- record_name(thing2);
- record_name(sage);
- record_name(sand);
- record_name(bloat);
- }
- bool isAt(int y, int x,int thing){
- if(legal(y,x)){ return (TILES[y][x]&thing); }
- else{ return 0;}
- }
- char tile_creature(int a,int gold){
- //order matters; the ones on top display over the ones lower down
- if(false){}
- show(busheater,'X')
- show(ant,'A')
- show(dragon,'D')
- show(dwarf1,'d')
- show(dwarf2,'d')
- show(fire,'*')
- show(jelly,' ')
- show(runner,'R')
- show(bloat,'b')
- show(predator,'p')
- show(grazer,'G')
- show(larva,'~')
- show(vine,'$')
- show(fireweed,'&')
- show(flower,'*')
- show(vineroot,'%')
- show(door,'+')
- show(sage,'^')
- show(thing1,' ')
- show(thing2,' ')
- else if(gold>0){return '0'+gold; }
- show(moss,'$')
- show(stickybush,'%')
- show(tree,'T')
- show(sapling,'t')
- show(coral,'^')
- show(youngcoral,'|')
- show(plankton,'.')
- show(shrub,'%')
- show(reed,'|')
- show(sedge,'|')
- show(lichen,'#')
- show(mold,'#')
- show(slime,'#')
- show(daisy,'*')
- show(tallgrass,';')
- show(grass,',')
- show(stickyseed,'.')
- show(moldseed,'.')
- show(fireweedseed,'.')
- show(wall,'#')
- show(sand,'=')
- else
- return '.';
- }
- int color_creature(int a, int gold){
- if(false){}
- show(busheater,4)
- show(ant,10)
- show(dragon,1)
- show(dwarf1,1)
- show(dwarf2,0)
- show(fire,5)
- show(jelly,1)
- show(runner,0)
- show(bloat,14)
- show(predator,0)
- show(grazer,10)
- show(larva,8)
- show(vine,3)
- show(fireweed,10)
- show(flower,8)
- show(vineroot,3)
- show(door,9)
- show(sage,8)
- show(thing1,4)
- show(thing2,2)
- else if(gold>0){ return 4;}
- show(moss,8)
- show(stickybush,7)
- show(tree,6)
- show(sapling,6)
- show(coral,10)
- show(youngcoral,10)
- show(plankton,10)
- show(shrub,6)
- show(reed,8)
- show(sedge,6)
- show(lichen,9)
- show(mold,2)
- show(slime,6)
- show(daisy,10)
- show(tallgrass,9)
- show(grass,9)
- show(stickyseed,7)
- show(moldseed,2)
- show(fireweedseed,9)
- show(wall,0)
- show(sand,0)
- show(paralyze,1)
- else
- return 0;
- }
- void look_tile(int tile,char creatures[size_of_int][names_width]){
- int place =0;
- for(int i=0; i<size_of_int; i++){
- if(tile&(1<<i)){
- for(int j=0; j<names_width; j++){
- creatures[place][j] = NAMES[i][j];
- }
- place++;
- }
- }
- for(; place<size_of_int; place++){
- for(int j=0; j<names_width; j++){
- creatures[place][j] = ' ';
- }
- }
- }
- void look_color(int tile,int* colors){
- int place =0;
- for(int i=0; i<size_of_int; i++){
- if(tile&(1<<i)){
- colors[place] = color_creature((1<<i),0);
- place++;
- }
- }
- for(;place < size_of_int; place++){
- colors[place] = 0;
- }
- }
- /***************************/
- void display()
- {
- for(int y=-1; y<=Y; y++)//I have to do this to include the corners
- {
- bresenham(playerY,y,playerX,X);
- bresenham(playerY,y,playerX,-1);
- }
- for(int x=-1; x<=X; x++)
- {
- bresenham(playerY,Y,playerX,x);
- bresenham(playerY,-1,playerX,x);
- }
- for(int y=0; y<Y; y++)
- {
- for(int x=0; x<X; x++)
- {
- if(showing_instructions){
- char instructions[8][41] = {
- " move around with the numpad ",
- "q or Q quits ",
- "S saves game to a file, / loads it ",
- "l shows you what is on the tile ",
- "x turns on and off the xray vision ",
- "P pauses and unpauses the game ",
- "spacebar advances one tick ",
- "for the rest check the input function "};
- int i=y-Y/2+4;
- int j=x-X/2+20;
- COLOR[y][x]=0;
- if(i>=0 && i<8 && j>=0 && j<39){
- VIEW[y][x]=instructions[i][j];
- }else{
- VIEW[y][x]=' ';
- }
- }else{
- COLOR[y][x]=0;
- VIEW[y][x]=' ';
- if(visible[y][x] || xray){
- VIEW[y][x] = tile_creature(TILES[y][x],GOLD[y][x]);
- COLOR[y][x] = color_creature(TILES[y][x],GOLD[y][x]);
- if(y==playerY && x==playerX){
- VIEW[y][x]='@';
- COLOR[y][x]=0;
- }
- }
- if(looking){
- char creatures[size_of_int][names_width];
- int all_colors_at[size_of_int];
- int g=0;
- look_tile(TILES[playerY][playerX], creatures);
- look_color(TILES[playerY][playerX], all_colors_at);
- if(GOLD[playerY][playerX]>0){ //a hack to make gold look like everything else
- g=1;
- char goldmsg[]={" 0 gold "};
- for(int j= 0; j<names_width; j++){
- VIEW[0][j+X-names_width]=goldmsg[j];
- COLOR[0][j+X-names_width]=0;
- }
- VIEW[0][X+1-names_width]='0'+GOLD[playerY][playerX];
- COLOR[0][X+1-names_width]=color_creature(0,1);
- }
- for(int i= 0; i<Y && i<size_of_int; i++){
- for(int j= 0; j<names_width; j++){
- VIEW[i+g][j+X-names_width]=creatures[i][j];
- COLOR[i+g][j+X-names_width]=0;
- }
- COLOR[i+g][X+1-names_width]=all_colors_at[i];
- }
- }
- }
- attrset(COLOR_PAIR(COLOR[y][x]));
- mvaddch(y, x, VIEW[y][x]); //multiply x by 2 to get a square aspect ratio
- /* mvaddch(y, x*2 +1, ' '); */ //also uncoment this line
- visible[y][x]=false;
- }
- }
- refresh(); // refresh the screen
- }
- /***************************/
- void input()
- {
- int newY=0;
- int newX=0;
- inchar = getch();
- if(inchar != ERR)
- {
- if(inchar=='?' || showing_instructions){ showing_instructions=!showing_instructions;}
- else if(inchar==' '){ tick(); }
- else if(inchar>='0' && inchar <='9'){
- if(inchar=='7' || inchar=='8' || inchar=='9'){ newY=-1; }
- if(inchar=='1' || inchar=='2' || inchar=='3'){ newY=1; }
- if(inchar=='7' || inchar=='4' || inchar=='1'){ newX=-1; }
- if(inchar=='9' || inchar=='6' || inchar=='3'){ newX=1; }
- }
- put('A',ant)
- put('B',bloat)
- put('b',busheater)
- put('c',coral)
- put('D',dwarf1)
- put('d',dwarf2)
- put('e',sedge)
- put('f',fire)
- put('G',grazer)
- put('g',grass)
- put('j',jelly)
- put('L',larva)
- else if(inchar=='l'){ looking=!looking; }
- put('M',lichen)
- put('m',mold)
- else if(inchar=='P'){
- paused = !(looking || paused);
- looking = false;
- }
- put('p',predator)
- else if(inchar=='q' || inchar=='Q'){ quit=true; }
- put('R',reed)
- put('r',runner)
- put('s',slime)
- put('T',tree)
- put('t',shrub)
- put('V',vineroot)
- put('w',sage)
- else if(inchar=='x'){ xray=!xray; }
- put('z',wall)
- put('%',stickybush)
- put('$',moss)
- put('&',fireweed)
- else if(inchar=='S'){
- ofstream myfile;
- myfile.open("dungeonsave.txt");
- for(int y=0;y<Y;y++)
- for(int x=0;x<X;x++)
- myfile << TILES[y][x] << "\n";
- myfile.close();
- }
- else if(inchar=='/'){
- ifstream myfile;
- myfile.open ("dungeonsave.txt");
- for(int y=0;y<Y;y++)
- for(int x=0;x<X;x++)
- myfile >> TILES[y][x];
- myfile.close();
- }
- if(legal(playerY+newY,playerX+newX)){
- playerY+=newY;
- playerX+=newX;
- }
- }
- }
- /***************************/
- void tick() //this advances the game one step
- {
- if(showing_instructions){ return;}
- turncount++;
- int tiles[Y][X];
- int subtract[Y][X];
- for(int y=0; y<Y; y++){
- for(int x=0; x<X; x++){
- tiles[y][x]=0;
- subtract[y][x]= ~0;
- }
- }
- if(rand()%50==0){ //to keep things from getting stagnant it adds random things to a tile
- tiles[rand()%Y][rand()%X]|=1<<(rand()%size_of_int);
- }
- int initialX=0,finalX=X-1,xinc;
- int initialY=0,finalY=Y-1,yinc;
- if(turncount%2) swap(initialY,finalY);
- if(turncount%4/2) swap(initialX,finalX);
- yinc=sign(finalY-initialY);
- xinc=sign(finalX-initialX);
- for(int y=initialY; y!=finalY+yinc; y+=yinc){
- for(int x=initialX; x!=finalX+xinc; x+=xinc){ //this prevents pervasive biases towards the top
- if(isAt(y,x,wall)) tiles[y][x]|=wall;
- if(isAt(y,x,daisy)) tiles[y][x]|=daisy;
- if(isAt(y,x,bloat)) Bloat(y,x,tiles,subtract);
- if(isAt(y,x,thing1)) Thing1(y,x,tiles,subtract);
- if(isAt(y,x,thing2)) Thing2(y,x,tiles,subtract);
- if(isAt(y,x,reed)) Reed(y,x,tiles,subtract);
- if(isAt(y,x,sedge)) Sedge(y,x,tiles,subtract);
- if(isAt(y,x,coral)) Coral(y,x,tiles,subtract);
- if(isAt(y,x,youngcoral)) Youngcoral(y,x,tiles,subtract);
- if(isAt(y,x,plankton)) Plankton(y,x,tiles,subtract);
- if(isAt(y,x,tree)) Tree(y,x,tiles,subtract);
- if(isAt(y,x,sapling)) Sapling(y,x,tiles,subtract);
- if(isAt(y,x,treeseed)) Treeseed(y,x,tiles,subtract);
- if(isAt(y,x,shrub)) Shrub(y,x,tiles,subtract);
- if(isAt(y,x,flower)) Flower(y,x,tiles,subtract);
- if(isAt(y,x,sand)) tiles[y][x]|=sand;
- if(isAt(y,x,door) && !isAt(y,x,wall)) tiles[y][x]|=door;
- if(isAt(y,x,sage)) Sage(y,x,tiles,subtract);
- if(isAt(y,x,predator)) Predator(y,x,tiles,subtract);
- if(isAt(y,x,slime)) Slime(y,x,tiles,subtract);
- if(isAt(y,x,grass)) Grass(y,x,tiles,subtract);
- if(isAt(y,x,tallgrass)) Tallgrass(y,x,tiles,subtract);
- if(isAt(y,x,jelly)) Jelly(y,x,tiles,subtract);
- if(isAt(y,x,dragon)) Dragon(y,x,tiles,subtract);
- if(isAt(y,x,dwarf1)) Dwarf1(y,x,tiles,subtract);
- if(isAt(y,x,dwarf2)) Dwarf2(y,x,tiles,subtract);
- if(isAt(y,x,fire)) Fire(y,x,tiles,subtract);
- if(isAt(y,x,stickybush)) Stickybush(y,x,tiles,subtract);
- if(isAt(y,x,stickyseed)) Stickyseed(y,x,tiles,subtract);
- if(isAt(y,x,runner)) Runner(y,x,tiles,subtract);
- if(isAt(y,x,moss)) Moss(y,x,tiles,subtract);
- if(isAt(y,x,moldseed)) Moldseed(y,x,tiles,subtract);
- if(isAt(y,x,mold)) Mold(y,x,tiles,subtract);
- if(isAt(y,x,lichen)) Lichen(y,x,tiles,subtract);
- if(isAt(y,x,fireweed)) Fireweed(y,x,tiles,subtract);
- if(isAt(y,x,fireweedseed)) Fireweedseed(y,x,tiles,subtract);
- if(isAt(y,x,larva)) Larva(y,x,tiles,subtract);
- if(isAt(y,x,grazer)) Grazer(y,x,tiles,subtract);
- if(isAt(y,x,vineroot)) Vineroot(y,x,tiles,subtract);
- if(isAt(y,x,vine)) Vine(y,x,tiles,subtract);
- if(isAt(y,x,ant)) Ant(y,x,tiles,subtract);
- if(isAt(y,x,busheater)) Busheater(y,x,tiles,subtract);
- if(GOLD[y][x]>5){
- if(notblocked(y+1,x)){GOLD[y][x]--;GOLD[y+1][x]++;}
- if(notblocked(y-1,x)){GOLD[y][x]--;GOLD[y-1][x]++;}
- if(notblocked(y,x+1)){GOLD[y][x]--;GOLD[y][x+1]++;}
- if(notblocked(y,x-1)){GOLD[y][x]--;GOLD[y][x-1]++;}
- }
- }
- }
- for(int y=0; y<Y; y++)
- for(int x=0; x<X; x++){
- TILES[y][x]=tiles[y][x]&subtract[y][x];
- DISTURBANCE[y][x]++;
- if(tiles[y][x]&fire ||tiles[y][x]&creature)
- DISTURBANCE[y][x]=0;
- }
- DISTURBANCE[playerY][playerX]=0;
- }
- /***************************/
- void Bloat(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- tiles[y][x]|=bloat;
- }
- /***************************/
- void Thing1(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- forOrthogonal(
- if(!isAt(y+A,x+B,thing2) && notblocked(y+A,x+B) && rand()%20==0){
- tiles[y+A][x+B]|=thing1;
- }else if(touching(y+A,x+B,thing2)==0 && touching(y+A,x+B,thing1)<3 && rand()%10==0){
- tiles[y][x]|=thing2;
- }
- )
- if(notblocked(y,x))
- tiles[y][x]|=thing1;
- }
- /***************************/
- void Thing2(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- forOrthogonal(
- if(!isAt(y+A,x+B,thing1) && notblocked(y+A,x+B) && rand()%20==0 && orthogonal(y+A,x+B,thing2)<4){
- tiles[y+A][x+B]|=thing2;
- }
- )
- if(orthogonal(y,x,thing2)>3 && rand()%10==0)
- tiles[y][x]|=thing1;
- else if(notblocked(y,x) && (orthogonal(y,x,thing2)!=0 || orthogonal(y,x,thing1)==0) )
- tiles[y][x]|=thing2;
- }
- /***************************/
- void Sedge(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- forTouching(
- if(notblocked(y+A,x+B) &&rand()%15==0 && touchingNot(y+A,x+B,sedge|wall)>1){
- tiles[y+A][x+B]|=sedge;
- }
- )
- if(notblocked(y,x) && (touchingNot(y,x,sedge|wall)>0 || rand()%10))
- tiles[y][x]|=sedge;
- }
- /***************************/
- void Coral(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- if(rand()%16==0){
- tiles[y][x]|=plankton;
- }
- bool test=false;
- if(rand()%100==0 && DISTURBANCE[y][x]>500){
- forTouching(
- if(blocked(y,x) || isAt(y,x,coral|youngcoral)){
- test=true;
- }
- )
- }
- if(test){
- tiles[y][x]|=wall;
- }
- else if(notblocked(y,x)){
- tiles[y][x]|=coral;
- }
- }
- /***************************/
- void Youngcoral(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- if(rand()%500==0){
- tiles[y][x]|=coral;
- DISTURBANCE[y][x]=0;
- }
- if(notblocked(y,x)){
- tiles[y][x]|=youngcoral;
- }
- }
- /***************************/
- void Plankton(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;
- int b=0;
- forTouching(
- if(notblocked(y+A,x+B)){
- a=A;
- b=B;
- }
- )
- if(rand()%50==0 && orthogonal(y,x,wall|youngcoral|coral) && !isAt(y,x,youngcoral)){
- tiles[y][x]|=youngcoral;
- }else if(notblocked(y,x)) {
- tiles[y+a][x+b]|=plankton;
- }
- }
- /***************************/
- void Tree(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- forTouching(
- if(notblocked(y+A,x+B) && touching(y+A,x+B,wall)<=2 && rand()%50==0){
- tiles[y+A][x+B]|=treeseed;
- }
- else if( touching(y+A,x+B,wall)<=2 ){ subtract[y+A][x+B]&=~wall; }
- )
- if(notblocked(y,x)){
- tiles[y][x]|=tree;
- // subtract[y][x]&= ~plant;
- // subtract[y][x]|= tree;
- }
- }
- /***************************/
- void Sapling(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- if(notblocked(y,x) && rand()%100==0 && touching(y,x,tree)<=1){ tiles[y][x]|=tree; }
- else if(notblocked(y,x)){
- tiles[y][x]|=sapling;
- }
- }
- /***************************/
- void Treeseed(int y, int x, int tiles[Y][X],int subtract[Y][X]){
- if(notblocked(y,x) && rand()%50==0 &&
- (!isAt(y,x,plant) || (isAt(y,x,tallgrass)&& rand()%10==0)) && touching(y,x,tree|sapling)<3){
- tiles[y][x]|=sapling;
- }
- else{ tiles[y][x]|=treeseed; }
- }
- /***************************/
- void Reed(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- forTouching(
- if(notblocked(y+A,x+B) && (orthogonal(y+A,x+B,wall)%2==0) && touching(y+A,x+B,wall) && rand()%40==0){
- tiles[y+A][x+B]|=reed;
- }
- )
- if(notblocked(y,x) && touching(y,x,wall))
- tiles[y][x]|=reed;
- }
- /***************************/
- void Shrub(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- forTouching(
- if(notblocked(y+A,x+B) && (orthogonal(y+A,x+B,wall)%2==1) && rand()%20==0){
- tiles[y+A][x+B]|=shrub;
- }
- )
- if(notblocked(y,x) && touching(y,x,wall))
- tiles[y][x]|=shrub;
- }
- /***************************/
- void Flower(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- forTouching(
- if(notblocked(y+A,x+B) && orthogonal(y+A,x+B,flower)<=1 && touching(y+A,x+B,flower)<=3){
- if(rand()%5==0){
- tiles[y+A][x+B]|=flower;
- }
- }
- )
- if(notblocked(y,x) && orthogonal(y,x,flower)<=1 && touching(y,x,flower)<=3)
- tiles[y][x]|=flower;
- }
- /***************************/
- void Busheater(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;
- int b=0;
- bool food=false;
- if(rand()%4)
- subtract[y][x]&=~bush;
- forTouching(
- if(notblocked(y+A,x+B) && (!food || (isAt(y+A,x+B,bush) || orthogonal(y+A,x+B,bush)))){
- a=A;
- b=B;
- if(!food && (isAt(y+A,x+B,bush) || orthogonal(y+A,x+B,bush))){
- food=true;
- }
- }
- if(isAt(y+A,x+B,wall) && 2>touching(y+A,x+B,wall) && rand()%2==0){
- subtract[y+A][x+B]&= ~wall;
- }
- )
- if(isAt(y,x,paralyze)){
- a=0;
- b=0;
- }
- if(isAt(y+a,x+b,bush) || rand()%1000){
- tiles[y+a][x+b]|=busheater;
- if(food && rand()%50==0){
- tiles[y][x]|=busheater;
- }
- if(rand()%2){
- tiles[y+a][x+b]|= (tiles[y][x]&pickupable);
- subtract[y][x]&= ~pickupable;
- subtract[y][x]&= ~youngcoral;
- }
- }
- }
- /***************************/
- void Ant(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;
- int b=0;
- bool test=false;
- forOrthogonal(
- if( (legal(y+A,x+B) &&
- isAt(y+A+2*B, x+B+2*A, wall)&& isAt(y+A-2*B, x+B-2*A, wall) &&
- isAt(y+A+B, x+B+A, wall)&& isAt(y+A-B, x+B-A, wall))
- || notblocked(y+A,x+B)){
- a=A;
- b=B;
- }
- )
- if(isAt(y,x,paralyze)){
- a=0;
- b=0;
- }
- if(orthogonal(y,x,ant)>0 && orthogonal(y,x,wall)>=2)
- forTouching( if(legal(y+A,x+B)){ subtract[y+A][x+B]&=~wall; })
- tiles[y+a][x+b]|=ant;
- if(rand()%2){
- tiles[y+a][x+b]|= (tiles[y][x]&pickupable);
- subtract[y][x]&= ~pickupable;
- }
- subtract[y+a][x+b]&=~wall;
- }
- /***************************/
- void Vine(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- tiles[y][x]|=livevine;
- if(notblocked(y,x))
- tiles[y][x]|=vine;
- forTouching(
- if(GOLD[y+A][x+B]>0 && !(tiles[y+A][x+B]¶lyze)&& !isAt(y+A,x+B,vineroot) && !touching(y+A,x+B,vineroot)){
- GOLD[y+A][x+B]--;
- GOLD[y][x]++;
- tiles[y][x]|=paralyze;
- subtract[y][x]&=~vine;
- }
- if(!isAt(y+A,x+B,vine) && isAt(y+A,x+B,livevine) && !touching(y+A,x+B,vineroot)){ //vine just died
- subtract[y][x]&=~vine;
- }
- )
- if(!isAt(y,x,fire))
- forTouching(
- if(notblocked(y+A,x+B) && !isAt(y+A,x+B,vineroot) && rand()%50==0)
- if(touching(y+A,x+B,(vine|vineroot))<2)
- tiles[y+A][x+B]|=vine;
- )
- }
- /***************************/
- void Vineroot(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;
- int b=0;
- forTouching(
- if(notblocked(y+A,x+B) && rand()%10==0 &&!isAt(y+A,x+B,vineroot)&&!isAt(y+A,x+B,fire) && touching(y+A,x+B,vine)<3 )
- tiles[y+A][x+B]|=vine;
- if(notblocked(y+A,x+B) && GOLD[y+A][x+B]>0 && GOLD[y][x]<8 && !(tiles[y+A][x+B]¶lyze) && !isAt(y+A,x+B,vineroot) && rand()%5==0){
- GOLD[y+A][x+B]--;
- GOLD[y][x]++;
- tiles[y+A][x+B]|=paralyze;
- }
- if(notblocked(y+A,x+B) && GOLD[y+A][x+B]>1 && rand()%30==0)
- tiles[y+A][x+B]|=vineroot;
- )
- if(GOLD[y][x]>0)
- tiles[y][x]|=vineroot;
- }
- /***************************/
- void Grazer(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;
- int b=0;
- subtract[y][x]&=~grass;
- forTouching(
- if(legal(y+A,x+B) && (((isAt(y+A,x+B,tallgrass)||orthogonal(y+A,x+B,tallgrass))&& notblocked(y+A,x+B))
- ||(orthogonal(y,x,wall)==3 && !koolaidman(y+A,x+B)))){
- a=A;
- b=B;
- if(rand()%50==0)
- tiles[y][x]|=grazer;
- }
- if(rand()%2){
- subtract[y+A][x+B]&=~tallgrass;
- subtract[y+A][x+B]&=~sapling;
- }
- )
- if(isAt(y,x,paralyze)){
- a=0;
- b=0;
- }
- if(isAt(y+a,x+b,grass) || rand()%100){
- tiles[y+a][x+b]|=grazer;
- if(rand()%2){
- tiles[y+a][x+b]|= (tiles[y][x]&pickupable);
- subtract[y][x]&= ~pickupable;
- }
- }
- subtract[y+a][x+b]&=~wall;
- }
- /***************************/
- void Larva(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;int b=0;
- forOrthogonal(
- if(legal(y+A,x+B) && (!isAt(y+A, x+B, wall) || (orthogonal(y+A,x+B,wall)>=3 && //either empty space or unexplored territory
- legal(y+2*A+B,x+2*B+A) && isAt(y+2*A+B, x+2*B+A, wall) &&
- legal(y+2*A-B,x+2*B-A) && isAt(y+2*A-B, x+2*B-A, wall)))){
- a=A;
- b=B;
- }
- )
- subtract[y+a][x+b]&=~wall;
- tiles[y+a][x+b]|=larva;
- }
- /***************************/
- void Fireweedseed(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- if(notblocked(y,x) && !isAt(y,x,plant) && rand()%30==0 && !touching(y,x,fireweed))
- tiles[y][x]|=fireweed;
- else if( notblocked(y,x) )
- tiles[y][x]|=fireweedseed;
- }
- /***************************/
- void Fireweed(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- forTouching(
- if(notblocked(y+A,x+B) && rand()%15==0 && isAt(y+A, x+B, grass))
- tiles[y+A][x+B]|=fireweedseed;
- )
- if(notblocked(y,x) && (!touching(y,x,fireweed) || rand()%15))
- tiles[y][x]|=fireweed;
- }
- /***************************/
- void Lichen(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- if(isAt(y,x,wall)){
- if(touching(y,x,endolithic)<6)// && (isAt(y,x,endolithic)==lichen || rand()%5))
- {
- if(!touchingNot(y,x,wall)){
- forTouching(
- if(rand()%15==0 && touching(y+A,x+B,endolithic)<=2 && !touchingNot(y,x,wall))
- tiles[y+A][x+B]|=lichen;
- )
- tiles[y][x]|=lichen;
- }
- }
- }
- }
- /***************************/
- void Mold(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- forTouching(
- if(legal(y+A,x+B) && !isAt(y+A, x+B, wall) && rand()%80==0){
- tiles[y+A][x+B]|=moldseed;
- }
- )
- if(isAt(y, x, wall) && !isAt(y,x,(endolithic & ~mold)))
- tiles[y][x]|=mold;
- }
- /***************************/
- void Moldseed(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- bool sprout=false;
- int a=0,b=0;
- forTouching(
- if(legal(y+A,x+B) && isAt(y+A, x+B, wall)&& !isAt(y+A, x+B, endolithic) && rand()%80==0){
- sprout=true;
- a=A;
- b=B;
- }
- )
- if(sprout){ tiles[y+a][x+b]|=mold;}
- else{ tiles[y][x]|=moldseed; }
- }
- /***************************/
- void Moss(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;int b=0;
- if(touchingNot(y,x,wall) && (isAt(y,x,endolithic)==moss || rand()%15)){
- forTouching(
- if(legal(y+A,x+B) && isAt(y+A, x+B, wall) && !orthogonalNot(y+A,x+B,wall) && rand()%10==0){
- tiles[y+A][x+B]|=moss;
- }else if(orthogonalNot(y+A,x+B,wall)==1 && rand()%50==0){
- tiles[y+A][x+B]|=wall;
- }
- )
- }
- else{
- forTouching(
- if(legal(y+A,x+B) && isAt(y+A, x+B, wall) && !isAt(y+A, x+B, endolithic)){
- a=A;
- b=B;
- }
- )
- }
- if(isAt(y+a, x+b, wall))
- tiles[y+a][x+b]|=moss;
- }
- /***************************/
- void Stickyseed(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;
- int b=0;
- forOrthogonal(
- if(notblocked(y+A,x+B)){
- a=A;
- b=B;
- }
- )
- if(rand()%10==0 && !orthogonal(y,x,(wall|stickybush)))
- tiles[y+a][x+b]|=stickybush;
- else
- tiles[y+a][x+b]|=stickyseed;
- }
- /***************************/
- int power(int a, int b)
- {
- int c=1;
- for(int i=0;i<b;i++)
- c*=a;
- return c;
- }
- void Stickybush(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;
- int b=0;
- if(( rand() % power(50,orthogonal(y,x,(wall|stickybush)) )<1) && rand()%2){
- forOrthogonal(
- if(notblocked(y+A,x+B) && !isAt(y+A, x+B, bush)){
- a=A;
- b=B;
- break;
- }
- )
- }else if(touching(y,x,(wall|stickybush)) &&rand()%20==0){ //reproduce
- tiles[y][x]|=stickyseed;
- }
- if(orthogonal(y,x,(wall|stickybush))==4 && !antikoolaidman(y,x)){
- tiles[y][x]|=wall;
- }else
- tiles[y+a][x+b]|=stickybush;
- }
- /***************************/
- void Predator(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;
- int b=0;
- int best=DISTURBANCE[y][x];
- forTouching(
- if(notblocked(y+A,x+B) && DISTURBANCE[y+A][x+B]<best
- && !isAt(y+A, x+B, predator) && !(tiles[y+A][x+B]&predator)){
- a=A;
- b=B;
- best=DISTURBANCE[y+A][x+B];
- }
- )
- int worst=DISTURBANCE[y][x];
- forTouching( if(legal(y+A,x+B) && DISTURBANCE[y+A][x+B]>worst){ worst=DISTURBANCE[y+A][x+B]; } )
- if(a==0 && b==0){
- DISTURBANCE[y][x]=worst+1;
- }
- if(isAt(y+a, x+b, creature) && rand()%100==0 && legal(y-a,x-b))
- tiles[y-a][x-b]|=predator;
- subtract[y][x]&=~creature;
- if(rand()%1000)
- tiles[y+a][x+b]|=predator;
- tiles[y+a][x+b]|=paralyze;
- }
- /***************************/
- void Runner(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;
- int b=0;
- int best=0;
- forTouching(
- if(legal(y+A,x+B) &&
- ( (notblocked(y+A,x+B)
- ||((isAt(y+A+1, x+B, wall)==isAt(y+A-1, x+B, wall))
- && (isAt(y+A, x+B+1, wall)==isAt(y+A, x+B-1, wall))
- && (isAt(y+A+1, x+B, wall)!=isAt(y+A, x+B-1, wall))) )
- && DISTURBANCE[y+A][x+B]>best && touching(y+A, x+B, runner)<=1 )){
- a=A;
- b=B;
- best=DISTURBANCE[y+A][x+B];
- }
- if(legal(y+A,x+B) && isAt(y+A, x+B, pickupable)){
- subtract[y+A][x+B]&= ~pickupable;
- if(rand()%400==0){
- tiles[y][x]|=runner;
- }
- }
- )
- if(isAt(y,x,paralyze)){
- a=0;
- b=0;
- }
- if(rand()%1024)
- tiles[y+a][x+b]|=runner;
- subtract[y+a][x+b]&=~wall;
- // subtract[y][x+b]&=~wall;
- // subtract[y+a][x]&=~wall;
- }
- /***************************/
- void Jelly(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;
- int b=0;
- bool food=false;
- int best=0;
- forTouching(
- if(notblocked(y+A,x+B) && orthogonal(y+A,x+B,wall) && !isAt(y+A, x+B, jelly)/* && touching(y+A,x+B,jelly)<=1 */){
- if((orthogonal(y+A,x+B,endolithic)&&(!food || DISTURBANCE[y+A][x+B]>best)) || (!food && DISTURBANCE[y+A][x+B]>best)){
- a=A;
- b=B;
- best=DISTURBANCE[y+A][x+B];
- if(orthogonal(y+A,x+B,endolithic))
- food=true;
- }
- }
- )
- if(isAt(y,x,paralyze)){
- a=0;
- b=0;
- }
- if(touching(y,x,predator)){ tiles[y][x]|=wall;}
- if(rand()%500){
- tiles[y+a][x+b]|=jelly;
- if(rand()%2){
- tiles[y+a][x+b]|= (tiles[y][x]&pickupable);
- subtract[y][x]&= ~pickupable;
- }
- }
- for(int i=-1;i<=1;i++)
- for(int j=-1;j<=1;j++){
- if(isAt(y+i, x+j, endolithic) &&rand()%6==0){
- if(rand()%30==0)
- tiles[y][x]|=jelly;
- subtract[y+i][x+j]&=~endolithic;
- }
- }
- }
- /***************************/
- void Slime(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- if(isAt(y,x,wall) && orthogonalNot(y,x,wall))
- tiles[y][x]|=slime;
- forTouching(
- if(touchingNot(y+A,x+B,wall) &&isAt(y+A, x+B, wall) &&rand()%10==0){ //used to be orthagonal
- tiles[y+A][x+B]|=slime;
- //}else if(orthogonal(y+A,x+B,slime)==4 && antikoolaidman(y+A,x+B)){
- // tiles[y+A][x+B]|=wall;
- }
- )
- }
- /***************************/
- void Sage(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- forTouching(
- if(notblocked(y+A,x+B) && rand()%50==0 && touching(y+A,x+B,bush)<=2){ tiles[y+A][x+B]|=sage; }
- )
- if(notblocked(y,x) && (isAt(y,x,sand) || rand()%100==0)){ tiles[y][x]|=sage; }
- }
- /***************************/
- void Fire(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- if(isAt(y,x,burnable))
- tiles[y][x]|=fire;
- subtract[y][x]&=~burnable;
- forTouching(
- if(legal(y+A,x+B) && (isAt(y+A, x+B, flamable) || (rand()%6==0 && isAt(y+A, x+B, hardtoburn))))
- tiles[y+A][x+B]|=fire;
- )
- if(isAt(y,x,explosive))
- forOrthogonal(
- if(notblocked(y+A,x+B))
- tiles[y+A][x+B]|=fire;
- )
- }
- /***************************/
- void Tallgrass(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- if(DISTURBANCE[y][x]>0 && notblocked(y,x) && !isAt(y,x,(plant & ~(grass|tallgrass))))
- tiles[y][x]|=tallgrass;
- forTouching(
- if(notblocked(y+A,x+B) && !isAt(y+A, x+B, plant) &&rand()%5==0)
- tiles[y+A][x+B]|=grass;
- )
- }
- /***************************/
- void Grass(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- if(rand()%50==0)
- tiles[y][x]|=tallgrass;
- if(notblocked(y,x) && !isAt(y,x,(plant & ~(grass|tallgrass))))
- tiles[y][x]|=grass;
- forOrthogonal(
- if(notblocked(y+A,x+B) && !isAt(y+A, x+B, plant) &&rand()%30==0)
- tiles[y+A][x+B]|=grass;
- )
- if(rand()%50==0 && touching(y,x,plant&(~grass)&(~tallgrass))<=0){ tiles[y][x]|=daisy; }
- }
- /***************************/
- void Dwarf2(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a=0;
- int b=0;
- forOrthogonal(
- if(legal(y+A,x+B)
- &&(!isAt(y+A, x+B, wall) /*|| !koolaidman(y+A,x+B)*/
- ||((isAt(y+A+1, x+B, wall) != isAt(y+A-1, x+B, wall))
- &&( isAt(y+A, x+B+1, wall) != isAt(y+A, x+B-1, wall)))
- && !orthogonal(y+A,x+B,door))
- ){
- a=A;b=B;
- }
- )
- if( ((isAt(y+1, x, wall) && isAt(y-1, x, wall)) //it is between two walls
- ||(isAt(y, x+1, wall) && isAt(y, x-1, wall))) &&
- !(isAt(y+1, x+1, wall)&& isAt(y+1, x-1, wall)&& //and is protecting a corner
- isAt(y-1, x+1, wall)&& isAt(y-1, x-1, wall)) )//&&
- //!touching(y-1,x-1,door))
- {
- if(rand()%4)
- tiles[y][x]|=door;
- }
- else subtract[y][x]&=~door;
- if(isAt(y,x,paralyze)){
- a=0;
- b=0;
- }
- tiles[y+a][x+b]|=dwarf2;
- subtract[y+a][x+b] &= ~wall;
- if(GOLD[y][x]>0 && rand()%GOLD[y][x]==0){
- GOLD[y][x]--;
- GOLD[y+a][x+b]++;
- }
- }
- /***************************/
- void Dwarf1(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- forOrthogonal(
- )
- int A,B,a,b;
- A=B=a=b=0;
- if(isAt((y+1)%Y, x, previous)) { A=1; a=-1;}
- else if(isAt((y+Y-1)%Y, x, previous)){ A=-1; a=1;}
- else if(isAt(y, (x+1)%X, previous)) { B=1; b=-1;}
- else if(isAt(y, (x+X-1)%X, previous)){ B=-1; b=1;}
- else{
- if(rand()%2) a=rand()%2*2-1;
- else b=rand()%2*2-1;
- }
- if(!supersuperlegal(y+a,x+b))
- if(rand()%2) {a=rand()%2*2-1;b=0;}
- else {b=rand()%2*2-1;a=0;}
- if(b!=0){
- if(GOLD[(y+1)%Y][x]>0) { a=1; b=0;}
- else if(GOLD[(y+Y-1)%Y][x]>0){ a=-1; b=0;}
- }
- else{
- if(GOLD[y][(x+1)%X]>0) { b=1; a=0;}
- else if(GOLD[y][(x+X-1)%X]>0){ b=-1; a=0;}
- }
- if(isAt(y,x,paralyze)){
- a=0;
- b=0;
- }
- /* if(rand()%15){
- tiles[y][x]|=dwarf1;
- tiles[y+A][x+B]|=previous;
- }else
- */ {
- if(!superlegal(y+a,x+b)){a=0; b=0;}
- if(GOLD[y][x]>0){
- if(GOLD[y][x]>4 && rand()%3==0){
- subtract[y][x]&=(~wall);
- tiles[y][x]|=dragon;
- tiles[y][x]|=vineroot;
- return;
- }
- if(rand()%GOLD[y][x]==0){
- GOLD[y][x]--;
- GOLD[y+a][x+b]++;
- }
- else
- tiles[y][x]|=dwarf2;
- }
- subtract[y][x] &= ~wall;
- //if(rand()%50 || 2<orthogonal(y,x,wall)){
- tiles[y+a][x+b]|=dwarf1;
- tiles[y][x]|=previous;
- //}
- }
- }
- /***************************/
- void Dragon(int y, int x, int tiles[Y][X],int subtract[Y][X])
- {
- int a,b;
- a=b=0;
- bool test=false;
- if(!isAt(y,x,paralyze))
- forTouching(
- if(notblocked(y+A,x+B) && (rand()%15==0 || !test || GOLD[y+A][x+B]>0)){
- a=A;
- b=B;
- test=true;
- }
- )
- /* if(GOLD[y][x]==0 && max(abs(playerY-y),abs(playerX-x))<10){
- int A=sign(playerY-y);
- int B=sign(playerX-x);
- if(notblocked(y+A,x+B)){
- a=A;
- b=B;
- }
- }
- */ if(GOLD[y][x]>0 && rand()%GOLD[y][x]==0){
- GOLD[y][x]--;
- GOLD[y+a][x+b]++;
- }
- // if(max(abs(playerY-y),abs(playerX-x))<5 && rand()%5==0)
- // tiles[y+a][x+b]|=fire;
- if(rand()%100 || GOLD[y+a][x+a]>2){
- tiles[y+a][x+b]|=dragon;
- }
- }
- /***************************/
- int touchingNot(int y, int x, int item)
- {
- int count=0;
- for(int a=-1;a<=1;a++)
- for(int b=-1;b<=1;b++)
- if((a!=0 || b!=0) && legal(y+a,x+b) && !isAt(y+a, x+b, item))
- count++;
- return count;
- }
- int touching(int y, int x, int item)
- {
- int count=0;
- for(int a=-1;a<=1;a++)
- for(int b=-1;b<=1;b++)
- if((a!=0 || b!=0) && legal(y+a,x+b) && isAt(y+a, x+b, item))
- count++;
- return count;
- }
- int diagonalNot(int y, int x, int item)
- {
- int count=0;
- int xdir[]={-1,-1,1,1};
- int ydir[]={1,-1,1,-1};
- for(int i=0;i<4;i++)
- if(legal(y+xdir[i],x+ydir[i]) && !isAt(y+xdir[i], x+ydir[i], item))
- count++;
- return count;
- }
- int diagonal(int y, int x, int item)
- {
- int count=0;
- int xdir[]={-1,-1,1,1};
- int ydir[]={1,-1,1,-1};
- for(int i=0;i<4;i++)
- if(legal(y+ydir[i],x+xdir[i]) && isAt(y+ydir[i], x+xdir[i], item))
- count++;
- return count;
- }
- int orthogonalNot(int y, int x, int item)
- {
- int count=0;
- int xdir[]={-1,0,1,0};
- int ydir[]={0,-1,0,1};
- for(int i=0;i<4;i++)
- if(legal(y+xdir[i],x+ydir[i]) && !isAt(y+xdir[i], x+ydir[i], item))
- count++;
- return count;
- }
- int orthogonal(int y, int x, int item)
- {
- int count=0;
- int ydir[]={-1,0,1,0};
- int xdir[]={0,-1,0,1};
- for(int i=0;i<4;i++)
- if(legal(y+ydir[i],x+xdir[i]) && isAt(y+ydir[i], x+xdir[i], item))
- count++;
- return count;
- }
- bool antikoolaidman(int y, int x)
- {
- if(blocked(y,x))
- return false;
- int ydir[]={-1,-1,1,1};
- int xdir[]={-1,1,-1,1};
- for(int i=0;i<4;i++){
- if(notblocked(y+ydir[i],x+xdir[i]) &&
- (notblocked(y,x-xdir[i])||notblocked(y-ydir[i],x-xdir[i])||notblocked(y-ydir[i],x)) &&
- !notblocked(y,x+xdir[i]) && !notblocked(y+ydir[i],x))
- return true;
- }
- if(!notblocked(y+1,x) && !notblocked(y-1,x) &&
- ((notblocked(y,x+1) && notblocked(y,x-1)) ||
- (notblocked(y+1,x+1) && notblocked(y+1,x-1)) ||
- (notblocked(y-1,x+1) && notblocked(y-1,x-1))))
- return true;
- if(!notblocked(y,x+1) && !notblocked(y,x-1) &&
- ((notblocked(y+1,x) && notblocked(y-1,x)) ||
- (notblocked(y+1,x+1) && notblocked(y-1,x+1)) ||
- (notblocked(y+1,x-1) && notblocked(y-1,x-1))))
- return true;
- return false;
- }
- bool koolaidman(int y, int x)
- {
- if(notblocked(y,x))
- return false;
- int ydir[]={-1,-1,1,1};
- int xdir[]={-1,1,-1,1};
- for(int i=0;i<4;i++){
- if(notblocked(y+ydir[i],x+xdir[i]) &&
- (notblocked(y,x-xdir[i])||notblocked(y-ydir[i],x-xdir[i])||notblocked(y-ydir[i],x)) &&
- blocked(y,x+xdir[i]) && blocked(y+ydir[i],x))
- return true;
- }
- if(blocked(y+1,x) && blocked(y-1,x) &&
- ((notblocked(y,x+1) && notblocked(y,x-1)) ||
- (notblocked(y+1,x+1) && notblocked(y+1,x-1)) ||
- (notblocked(y-1,x+1) && notblocked(y-1,x-1))))
- return true;
- if(blocked(y,x+1) && blocked(y,x-1) &&
- ((notblocked(y+1,x) && notblocked(y-1,x)) ||
- (notblocked(y+1,x+1) && notblocked(y-1,x+1)) ||
- (notblocked(y+1,x-1) && notblocked(y-1,x-1))))
- return true;
- return false;
- }
- bool nocorner(int y, int x)
- {
- if(!isAt(y,x,wall))
- return true;
- forDiagonal(
- if(!isAt(y+A, x+B, wall) &&isAt(y, x+B, wall) &&isAt(y+A, x, wall))
- return false;
- )
- return true;
- }
- /***************************/
- void swap(int &a,int &b)
- {
- int temp=a;
- a=b;
- b=temp;
- }
- bool bresenham(int y0,int y1,int x0,int x1)
- {
- bool steep = abs(y1 - y0) > abs(x1 - x0);
- if(steep)
- {
- swap(x0, y0);
- swap(x1, y1);
- }
- int ystep=1;
- if (y0 > y1) ystep = -1;
- int dir=1;
- if(x0 > x1) dir = -1;
- int deltay = abs(y1 - y0);
- int deltax = dir*(x1 - x0);
- int error = deltax / 2;
- int y = y0;
- for(int x=x0; x!=x1; x+=dir)
- {
- if(steep && legal(x,y))
- {
- visible[x][y]=true;
- if(isAt(x,y,wall))
- return false;
- }
- else if(legal(y,x))
- {
- visible[y][x]=true;
- if(isAt(y,x,wall))
- return false;
- }
- error -= deltay;
- if(error < 0)
- {
- y += ystep;
- error += deltax;
- }
- }
- return true;
- }
- /***************************/
- void shuffle(int arry[],int length)
- {
- for(int k,j,i=0;i<length;i++){
- j=i+rand()%(length-i);
- swap(arry[j],arry[i]);
- }
- }/***************************/
- int sign(int a)
- {
- return (a>0)-(a<0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement