///////////////////////////////
#include <acknex.h>
#include <default.c>
///////////////////////////////
typedef struct PREPIPE
{
ENTITY* cell;
ENTITY* pipes[7];
var futureZ;
var rnd;
struct PREPIPE* next;
struct PREPIPE* before;
}PREPIPE;
typedef struct PIPE
{
ENTITY* cell;
ENTITY* pipes[11];
var active;
struct PIPE* slots[4];
int connected;
}PIPE;
void initLevel();
void createPrePipe();
void preMove(PREPIPE* pre);
void eventClick();
void resetPrePipe();
ENTITY* border;
ENTITY* borderPrev;
ENTITY* arrowsPrev;
PREPIPE preview[5];
PIPE board[10][7];
PREPIPE* active;
PREPIPE* last;
void main()
{
video_switch(8, 32, 8);
wait(1);
level_load("");
wait(1);
initLevel();
wait(-1);
createPrePipe();
}
void initLevel()
{
int x; int y; int i;
VECTOR ta;
mouse_mode = 4;
mouse_pointer = 2;
mouse_sync = 1;
mouse_range = 8000;
sun_angle.pan = 275;
sun_angle.tilt = 60;
camera.pan = 90;
camera.y = -2048;
camera.x = 576;
camera.z = 384;
set(camera, ISOMETRIC);
camera.arc = 80;
border = ent_create("border.mdl", nullvector, NULL);
borderPrev = ent_create("borderPrev.mdl", nullvector, NULL);
arrowsPrev = ent_create("arrowsPrev.mdl", nullvector, NULL);
for(x=0; x<10; x++)
{
for(y=0; y<7; y++)
{
zero(board[x][y]);
vec_set(ta, vector(x * 128, 0, y * 128));
board[x][y].cell = ent_create("cell.mdl", ta, NULL);
board[x][y].cell.emask |= ENABLE_CLICK;
board[x][y].cell.event = eventClick;
board[x][y].cell.skill1 = x;
board[x][y].cell.skill2 = y;
board[x][y].cell.skill3 = 0;
board[x][y].pipes[0] = ent_create("pStartRight.mdl", ta, NULL);
board[x][y].pipes[1] = ent_create("pStartTop.mdl", ta, NULL);
board[x][y].pipes[2] = ent_create("pStartLeft.mdl", ta, NULL);
board[x][y].pipes[3] = ent_create("pStartBottom.mdl", ta, NULL);
board[x][y].pipes[4] = ent_create("pHor.mdl", ta, NULL);
board[x][y].pipes[5] = ent_create("pVert.mdl", ta, NULL);
board[x][y].pipes[6] = ent_create("pCornerTopLeft.mdl", ta, NULL);
board[x][y].pipes[7] = ent_create("pCornerLeftBottom.mdl", ta, NULL);
board[x][y].pipes[8] = ent_create("pCornerBottomRight.mdl", ta, NULL);
board[x][y].pipes[9] = ent_create("pCornerRightTop.mdl", ta, NULL);
board[x][y].pipes[10] = ent_create("pCross.mdl", ta, NULL);
for(i=0; i<11; i++)
{
set(board[x][y].pipes[i], INVISIBLE);
}
}
}
x = integer(random(10));
y = integer(random(7));
i = integer(random(4));
reset(board[x][y].pipes[i], INVISIBLE);
board[x][y].cell.skill3 = 1;
}
void preMove(PREPIPE* pre)
{
int i;
var acc = 4;
var fall = 0;
reset(pre.cell, INVISIBLE);
reset(pre.pipes[pre.rnd], INVISIBLE);
if(pre.next == NULL){pre.futureZ = 256;}else{pre.futureZ = pre.next.futureZ + 128;}
while(pre.cell.z > pre.futureZ)
{
accelerate(fall, acc, 0);
pre.cell.z -= fall * time_step;
for(i=0; i<7; i++)
{
pre.pipes[i].z -= fall * time_step;
}
wait(1);
}
pre.cell.z = pre.futureZ;
}
void createPrePipe()
{
int i; int l;
var rnd = 0;
for(i=0; i<5; i++)
{
zero(preview[i]);
preview[i].cell = ent_create("cell.mdl", vector(-160, 0, 928), NULL);
preview[i].pipes[0] = ent_create("pHor.mdl", vector(-160, -32, 928), NULL);
preview[i].pipes[1] = ent_create("pVert.mdl", vector(-160, -32, 928), NULL);
preview[i].pipes[2] = ent_create("pCornerTopLeft.mdl", vector(-160, -32, 928), NULL);
preview[i].pipes[3] = ent_create("pCornerLeftBottom.mdl", vector(-160, -32, 928), NULL);
preview[i].pipes[4] = ent_create("pCornerBottomRight.mdl", vector(-160, -32, 928), NULL);
preview[i].pipes[5] = ent_create("pCornerRightTop.mdl", vector(-160, -32, 928), NULL);
preview[i].pipes[6] = ent_create("pCross.mdl", vector(-160, -32, 928), NULL);
for(l=0; l<7; l++)
{
set(preview[i].pipes[l], INVISIBLE);
}
set(preview[i].cell, INVISIBLE);
rnd = integer(random(7));
preview[i].rnd = rnd;
}
preview[0].next = NULL;
for(i=1; i<6; i++){preview[i].next = &preview[i -1];}
for(i=0; i<5; i++){preview[i].before = &preview[i + 1];}
preview[5].before = NULL;
for(i=0; i<5; i++)
{
wait(-0.5);
preMove(&preview[i]);
}
active = &preview[0];
last = &preview[5];
}
void eventClick()
{
if(my.skill3 == 0)
{
int x = my.skill1;
int y = my.skill2;
reset(board[x][y].pipes[active.rnd + 4], INVISIBLE);
my.skill3 = 1;
resetPrePipe();
}
}
void resetPrePipe()
{
int i;
PREPIPE* tmp;
wait(1);
//set(active.pipes[active.rnd], INVISIBLE);
//set(active.cell, INVISIBLE);
//active.rnd = integer(random(7));
// vec_set(active.cell.x, vector(-160, 0, 928));
// for(i=0; i<7; i++)
// {
// vec_set(active.pipes[i].x, vector(-160, -32, 928));
// }
// tmp = active.before;
// active.next = last;
// tmp.next = NULL;
// last.before = active;
// last = active;
// active = tmp;
//
// wait(-0.5);
// preMove(tmp);
// for(i=0; i<4; i++)
// {
// if(tmp.before != NULL)
// {
// wait(-0.5);
// tmp = tmp.before;
// preMove(tmp);
// }
// else
// {
// break;
// }
// }
}