ref: dda59f415a96c28133fe0214786055f4260a43d8
parent: be15c241daa91595963dd986f7cbfcbc904557ba
author: mkf <mkf@cloud9p.org>
date: Wed Dec 11 07:54:38 EST 2024
*.c: use new enum names
--- a/engine.c
+++ b/engine.c
@@ -14,7 +14,7 @@
for(x = 0; x < SzX; x++)
for(y = 0; y < SzY; y++)
- game->ogrid[x][y] = Prev;
+ game->ogrid[x][y] = PIECE_PREV;
switch(game->difficulty)
{
@@ -32,7 +32,7 @@
cnt = 0;
break;
}
- game->ogrid[SzX/2][SzY/2] = Glenda;
+ game->ogrid[SzX/2][SzY/2] = PIECE_GLENDA;
setmap:
for(i = 0 ; i < cnt ; i++)
@@ -42,15 +42,15 @@
{
x = nrand(SzX);
y = nrand(SzY);
- }while(game->ogrid[x][y] == Glenda || game->ogrid[x][y] == Wall);
- game->ogrid[x][y] = Wall;
+ }while(game->ogrid[x][y] == PIECE_GLENDA || game->ogrid[x][y] == PIECE_WALL);
+ game->ogrid[x][y] = PIECE_WALL;
}
/* ensure we don't make an unfair map */
- if(checkstate(game) == Won && findmin(game, Pt(SzX/2, SzY/2)) > 100)
+ if(checkstate(game) == STATE_WON && findmin(game, Pt(SzX/2, SzY/2)) > 100)
goto setmap;
memcpy(game->grid, game->ogrid, sizeof(game->grid));
- game->state = Start;
+ game->state = STATE_START;
game->turn = 0;
}
@@ -111,14 +111,14 @@
src = findglenda(game);
dst = movedir(dir, src);
- if(game->grid[dst.x][dst.y] == Wall)
- return Wall;
+ if(game->grid[dst.x][dst.y] == PIECE_WALL)
+ return PIECE_WALL;
if(game->networked)
return netmove(dir);
- game->grid[dst.x][dst.y] = Glenda;
- game->grid[src.x][src.y] = Prev;
+ game->grid[dst.x][dst.y] = PIECE_GLENDA;
+ game->grid[src.x][src.y] = PIECE_PREV;
game->turn++;
@@ -138,11 +138,11 @@
if(p.x > SzX || p.x < 0 || p.y > SzY || p.y < 0)
return Err;
- if(game->grid[p.x][p.y] == Wall)
- return Wall;
+ if(game->grid[p.x][p.y] == PIECE_WALL)
+ return PIECE_WALL;
- if(game->grid[p.x][p.y] == Glenda)
- return Glenda;
+ if(game->grid[p.x][p.y] == PIECE_GLENDA)
+ return PIECE_GLENDA;
if(game->networked)
return netput(p.x, p.y);
@@ -149,18 +149,18 @@
/* take a copy for undo */
memcpy(game->pgrid, game->grid, sizeof(game->grid));
- game->grid[p.x][p.y] = Wall;
+ game->grid[p.x][p.y] = PIECE_WALL;
/* assumes defenders start game first */
- if(game->state == Start)
- game->state = Playing;
+ if(game->state == STATE_START)
+ game->state = STATE_PLAYING;
game->turn++;
/* reset the board scores */
for(int x = 0; x < SzX; x++)
for(int y = 0; y < SzY; y++)
- if(game->grid[x][y] != Wall && game->grid[x][y] != Glenda)
+ if(game->grid[x][y] != PIECE_WALL && game->grid[x][y] != PIECE_GLENDA)
game->grid[x][y] = 100;
/* we need it to check game state, even if not playing with computer */
@@ -224,7 +224,7 @@
for(int i = 0; i < SzX; i++)
for(int x = i; x < SzX-i; x++)
for(int y = i; y < SzY-i; y++)
- if(game->grid[x][y] != Wall && game->grid[x][y] != Glenda)
+ if(game->grid[x][y] != PIECE_WALL && game->grid[x][y] != PIECE_GLENDA)
game->grid[x][y] = score1(game, Pt(x, y));
}
@@ -278,13 +278,13 @@
nextdir = (nrand(++count) == 0) ? dir : nextdir;
}
if(min > 100)
- game->state = Won;
+ game->state = STATE_WON;
else
domove(game, nextdir);
p = findglenda(game);
if(p.x == 0 || p.x == SzX-1 || p.y == 0 || p.y == SzY-1)
- game->state = Lost;
+ game->state = STATE_LOST;
}
/*
@@ -300,9 +300,9 @@
calc(game);
if(findmin(game, p) > 100)
- game->state = Won;
+ game->state = STATE_WON;
if(p.x == 0 || p.x == SzX-1 || p.y == 0 || p.y == SzY-1)
- game->state = Lost;
+ game->state = STATE_LOST;
return game->state;
}
@@ -315,7 +315,7 @@
{
game->turn = 0;
memcpy(game->grid, game->ogrid, sizeof(game->grid));
- game->state = Start;
+ game->state = STATE_START;
}
/*
@@ -326,7 +326,7 @@
{
int g[SzX][SzY];
- if(game->state == Start || game->turn < 2)
+ if(game->state == STATE_START || game->turn < 2)
return;
/* revert turn counter, can be abused by one side */
@@ -341,5 +341,5 @@
int
isplaying(Game *game)
{
- return game->state == Playing || game->state == Start;
+ return game->state == STATE_PLAYING || game->state == STATE_START;
}
--- a/gui9.c
+++ b/gui9.c
@@ -168,9 +168,9 @@
int x, y, rx, ry, d;
char *s = nil;
- if(game.state == Won)
+ if(game.state == STATE_WON)
draw(screen, screen->r, won, nil, ZP);
- else if(game.state == Lost)
+ else if(game.state == STATE_LOST)
draw(screen, screen->r, lost, nil, ZP);
else
draw(screen, screen->r, bg, nil, ZP);
@@ -185,10 +185,10 @@
p = board2pix(x, y);
switch(game.grid[x][y])
{
- case Wall:
+ case PIECE_WALL:
fillellipse(screen, addpt(screen->r.min, p), rx, ry, cc, ZP);
break;
- case Glenda:
+ case PIECE_GLENDA:
p = addpt(screen->r.min, p);
fillellipse(screen, p, rx, ry, ec, ZP);
p = subpt(p, Pt(24, 24));
@@ -222,7 +222,7 @@
p = pix2board(nm.x, nm.y);
g = findglenda(&game);
- dir = pointdir(g, p);
+ dir = finddir(g, p);
if(game.grid[p.x][p.y] >= 999 || dir == Err)
return;
--- a/netclient.c
+++ b/netclient.c
@@ -78,7 +78,7 @@
/* otherwise client wont read socket to confirm */
waitbit = 1;
free(msg);
- game->state = Init;
+ game->state = STATE_INIT;
return Ok;
}
@@ -123,7 +123,7 @@
static void
netproc(Game *game, Netmsg *msg, char *in)
{
- int i = 0, dir;
+ int i, dir;
char *tmp, *xpos, *ypos;
char **tokens = (char**)emalloc(64 * sizeof(char*));
Point p;
@@ -167,8 +167,8 @@
else if(!strcmp(tokens[0], "INIT"))
{
waitbit = 0;
- game->state = Init;
- while(game->state == Init)
+ game->state = STATE_INIT;
+ while(game->state == STATE_INIT)
{
tmp = netread();
/* lots of assuming goes here,
@@ -186,7 +186,7 @@
p.x = atoi(xpos);
p.y = atoi(ypos);
- game->grid[p.x][p.y] = Wall;
+ game->grid[p.x][p.y] = PIECE_WALL;
break;
case 'g':
xpos = strtok(nil, " ");
@@ -197,11 +197,11 @@
p.x = atoi(xpos);
p.y = atoi(ypos);
- game->grid[p.x][p.y] = Glenda;
+ game->grid[p.x][p.y] = PIECE_GLENDA;
break;
default:
if(!strcmp("SENT", tmp))
- game->state = Start;
+ game->state = STATE_START;
else
dprint("netproc(): Init: unknown command: %s\n", tmp);
@@ -217,8 +217,8 @@
else if(!strcmp(tokens[0], "SYNC"))
{
- if(game->state == Start)
- game->state = Playing;
+ if(game->state == STATE_START)
+ game->state = STATE_PLAYING;
if(msg->ntoken < 2)
sysfatal("netproc(): not enough toknes?");
@@ -242,11 +242,11 @@
}
else if(!strcmp(tokens[0], "WON"))
{
- msg->err = Won;
+ msg->err = STATE_WON;
}
else if(!strcmp(tokens[0], "LOST"))
{
- msg->err = Lost;
+ msg->err = STATE_LOST;
}
else
sysfatal("netproc(): unkown message: 0x%x %s", *tokens[0], tokens[0]);
@@ -279,7 +279,7 @@
msg = (Netmsg*)emalloc(sizeof(Netmsg));
- game->state = Connect;
+ game->state = STATE_CONNECT;
nethi(game, pnick, 0, pside, 0);
for(;;)