4 #include "../dpdefs/dpextensions.qc"
6 #include "autocvars.qh"
21 float tet_vs_current_id;
22 float tet_vs_current_timeout;
23 .float tet_vs_id, tet_vs_addlines;
24 .float tet_highest_line;
25 .float tetris_on, tet_gameovertime, tet_drawtime, tet_autodown;
27 .float piece_type, next_piece, tet_score, tet_lines;
28 .float tet_piece_bucket;
33 // 3 = waiting for VS players
35 float tet_high_score = 0;
37 const vector TET_START_PIECE_POS = '5 1 0';
38 const float TET_LINES = 22;
39 const float TET_DISPLAY_LINES = 20;
40 const float TET_WIDTH = 10;
41 const string TET_EMPTY_LINE = "0000000000"; // must match TET_WIDTH
43 const float TET_BORDER = 139;
44 const float TET_BLOCK = 133;
45 const float TET_SPACE = 160; // blankness
49 const float TETKEY_UP = 1;
50 const float TETKEY_DOWN = 2;
51 const float TETKEY_LEFT = 4;
52 const float TETKEY_RIGHT = 8;
53 const float TETKEY_ROTLEFT = 16;
54 const float TETKEY_ROTRIGHT = 32;
55 const float TETKEY_DROP = 64;
56 const string TET_PADDING_RIGHT = "\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0\xA0"; // get away from crosshair
58 const float PIECES = 7;
62 float SVC_CENTERPRINTa = 26;
66 return ((floor((self.tet_lines / 10)) + 1));
69 void tetsnd(string snd)
71 play2(self, strcat("sounds/tetris/", snd));
75 *********************************
79 *********************************
81 void SetLine(float ln, string vl)
83 if(ln < 1 || ln > TET_LINES)
85 bufstr_set(tet_line_buf, ln + TET_LINES * num_for_edict(self), vl);
88 string GetLine(float ln)
90 if(ln < 1 || ln > TET_LINES)
92 if(ln < 1 || ln > TET_LINES)
93 return TET_EMPTY_LINE;
94 return bufstr_get(tet_line_buf, ln + TET_LINES * num_for_edict(self));
97 float GetXBlock(float x, string dat)
99 if(x < 1 || x > TET_WIDTH)
101 return stof(substring(dat, x-1, 1));
104 string SetXBlock(float x, string dat, float new)
107 substring(dat, 0, x-1),
109 substring(dat, x, -1)
114 float GetSquare(float x, float y)
116 return GetXBlock(x, GetLine(y));
119 void SetSquare(float x, float y, float val)
123 dat = SetXBlock(x, dat, val);
127 float PieceColor(float pc)
134 return 7; // L // we don't have orange, let's use white instead!
146 vector PieceShape(float pc)
149 return '20 20 0'; // O
151 return '1 21 0'; // J
153 return '16 21 0'; // L
155 return '0 85 0'; // I
157 return '5 20 0'; // Z
159 return '20 5 0'; // S
161 return '4 21 0'; // T
165 vector PieceSize(float pc)
184 vector PieceCenter(float pc)
187 return '2.5 1.5 0'; // O
193 return '2.5 2.5 0'; // I
204 // do x 1..4 and y 1..4 in case of rotation
205 float PieceMetric(float x, float y, float rot, float pc)
210 // return bits of a piece
211 ce = PieceCenter(pc);
212 if (rot == 1) // 90 degrees
214 // x+cx, y+cy -> -y+cx, x+cy
215 // X, Y -> -Y+cy+cx, X-cx+cy
220 x = -t + ce.x + ce.y;
222 else if (rot == 2)//180
227 else if (rot == 3) // 270
229 // x+cx, y+cy -> y+cx, -x+cy
230 // X, Y -> Y-cy+cx, -X+cx+cy
234 y = -x + ce.y + ce.x;
237 if (x < 1 || y < 1 || x > 4 || y > 2)
241 return !!(ce.x & pow(4, x-1)); // first row
243 return !!(ce.y & pow(4, x-1)); // second row
245 return 0; // illegal parms
247 vector tet_piecemins;
248 vector tet_piecemaxs;
249 void PieceMinsMaxs(float rot, float pc)
256 ce = PieceCenter(pc);
261 tet_piecemins_x = floor(3.0 - sz.x * 0.5);
262 tet_piecemaxs_x = floor(2.0 + sz.x * 0.5);
265 // special case for "I"
266 tet_piecemins_y = tet_piecemaxs_y = 2;
271 tet_piecemaxs_y = sz.y;
273 //printf("ce%v sz%v mi%v ma%v\n", ce, sz, tet_piecemins, tet_piecemaxs);
274 if (rot == 1) // 90 degrees
277 tet_piecemins_y = -tet_piecemins.x + ce.y + ce.x;
278 tet_piecemins_x = t - ce.y + ce.x;
280 tet_piecemaxs_y = -tet_piecemaxs.x + ce.y + ce.x;
281 tet_piecemaxs_x = t - ce.y + ce.x;
282 // swap mins_y, maxs_y
284 tet_piecemins_y = tet_piecemaxs.y;
288 else if (rot == 2)//180
291 tet_piecemins = 2 * ce - tet_piecemaxs;
292 tet_piecemaxs = 2 * ce - v;
294 else if (rot == 3) // 270
297 tet_piecemins_y = tet_piecemins.x - ce.x + ce.y;
298 tet_piecemins_x = -t + ce.x + ce.y;
300 tet_piecemaxs_y = tet_piecemaxs.x - ce.x + ce.y;
301 tet_piecemaxs_x = -t + ce.x + ce.y;
302 // swap mins_x, maxs_x
304 tet_piecemins_x = tet_piecemaxs.x;
309 print(vtos(tet_piecemins), "-");
310 print(vtos(tet_piecemaxs), "\n");
311 if(tet_piecemins.x > tet_piecemaxs.x)
312 error("inconsistent mins/maxs");
313 if(tet_piecemins.y > tet_piecemaxs.y)
314 error("inconsistent mins/maxs");
316 vector realmins, realmaxs;
319 for(i = 1; i <= 4; ++i)
320 for(j = 1; j <= 4; ++j)
321 if(PieceMetric(i, j, rot, pc))
323 realmins_x = min(realmins.x, i);
324 realmins_y = min(realmins.y, j);
325 realmaxs_x = max(realmaxs.x, i);
326 realmaxs_y = max(realmaxs.y, j);
328 if(realmins != tet_piecemins || realmaxs != tet_piecemaxs)
329 error(sprintf("incorrect mins/maxs: %v %v in %d rot %d mins %v maxs %v\n", realmins, realmaxs, rot, pc, tet_piecemins, tet_piecemaxs));
333 *********************************
337 *********************************
341 /* some prydon gate functions to make life easier....
343 somewhat modified because we don't need all the fanciness Prydon Gate is capable of
347 void WriteTetrisString(string s)
349 WriteUnterminatedString(MSG_ONE, strconv(0, 2, 2, s));
352 float pnum(float num, float dig)
357 WriteChar(MSG_ONE, 173);
361 num = num - (f * 10);
363 dig = pnum(f, dig+1);
367 for (i = 0; i < (5 - dig); i = i + 1)
368 WriteChar(MSG_ONE, TET_SPACE);
370 WriteChar(MSG_ONE, 176 + num);
374 void DrawLine(float ln)
377 WriteChar(MSG_ONE, TET_BORDER);
379 for (x = 1; x <= TET_WIDTH; x = x + 1)
381 d = GetSquare(x, ln + TET_LINES - TET_DISPLAY_LINES);
384 WriteChar(MSG_ONE, '^');
385 WriteChar(MSG_ONE, d + '0');
386 WriteChar(MSG_ONE, TET_BLOCK);
389 WriteChar(MSG_ONE, TET_SPACE);
391 WriteChar(MSG_ONE, '^');
392 WriteChar(MSG_ONE, '7');
393 WriteChar(MSG_ONE, TET_BORDER);
396 void DrawPiece(float pc, float ln)
398 float x, d, piece_ln, pcolor;
400 pcolor = PieceColor(pc);
401 WriteChar(MSG_ONE, TET_SPACE); // pad to 6
403 piece_dat = PieceShape(pc);
405 piece_ln = piece_dat.x;
407 piece_ln = piece_dat.y;
408 for (x = 1; x <= 4; x = x + 1)
410 if (piece_ln & pow(4, x-1))
412 WriteChar(MSG_ONE, '^');
413 WriteChar(MSG_ONE, pcolor + '0');
414 WriteChar(MSG_ONE, TET_BLOCK);
417 WriteChar(MSG_ONE, TET_SPACE);
419 WriteChar(MSG_ONE, TET_SPACE); // pad to 6
426 WriteChar(MSG_ONE, SVC_CENTERPRINTa);
427 if(autocvar_g_bastet)
429 WriteTetrisString("NEVER GONNA GIVE YOU");
430 WriteChar(MSG_ONE, 10);
433 for (i = 1; i <= (TET_WIDTH + 2); i = i + 1)
434 WriteChar(MSG_ONE, TET_BORDER);
435 WriteTetrisString(" ");
436 WriteUnterminatedString(MSG_ONE, TET_PADDING_RIGHT);
437 WriteChar(MSG_ONE, 10);
438 for (i = 1; i <= TET_DISPLAY_LINES; i = i + 1)
440 if(self.tetris_on == 2)
441 WriteTetrisString(" GAME OVER ");
442 else if(self.tetris_on == 3)
443 WriteTetrisString("PLEASE WAIT");
447 WriteTetrisString(autocvar_g_bastet ? " THAT " : " NEXT ");
449 DrawPiece(self.next_piece, 1);
451 DrawPiece(self.next_piece, 2);
453 WriteTetrisString(" LINES");
455 pnum(self.tet_lines, 0);
457 WriteTetrisString(" SCORE");
459 pnum(self.tet_score, 0);
461 WriteTetrisString(" HIGH ");
463 WriteTetrisString(" SCORE");
465 pnum(tet_high_score, 0);
467 WriteTetrisString(" LEVEL");
469 pnum(Tetris_Level(), 0);
471 WriteTetrisString(" ");
472 WriteUnterminatedString(MSG_ONE, TET_PADDING_RIGHT);
473 WriteChar(MSG_ONE, 10);
477 for (i = 1; i <= (TET_WIDTH + 2); i = i + 1)
478 WriteChar(MSG_ONE, TET_BORDER);
479 WriteTetrisString(" ");
480 WriteUnterminatedString(MSG_ONE, TET_PADDING_RIGHT);
481 WriteChar(MSG_ONE, 10);
486 WriteChar(MSG_ONE, 10);
487 WriteChar(MSG_ONE, 10);
488 if(self.tetris_on == 3)
490 WriteUnterminatedString(MSG_ONE, strcat("WAITING FOR OTHERS (", ftos(ceil(tet_vs_current_timeout - time)), " SEC)\n"));
493 WriteChar(MSG_ONE, 10);
494 FOR_EACH_REALCLIENT(head) if(head.tetris_on) if(head.tet_vs_id == self.tet_vs_id)
497 WriteUnterminatedString(MSG_ONE, ">");
499 WriteUnterminatedString(MSG_ONE, " ");
500 if(head.tetris_on == 2)
501 WriteUnterminatedString(MSG_ONE, " X_X");
503 pnum(head.tet_highest_line, 0);
504 WriteUnterminatedString(MSG_ONE, " ");
505 WriteUnterminatedString(MSG_ONE, head.netname);
506 WriteChar(MSG_ONE, 10);
510 WriteChar(MSG_ONE, 0);
513 *********************************
517 *********************************
526 tet_line_buf = buf_create();
528 for (i=1; i<=TET_LINES; i = i + 1)
529 SetLine(i, TET_EMPTY_LINE);
530 self.piece_pos = '0 0 0';
532 self.next_piece = self.tet_lines = self.tet_score = 0;
533 self.tet_piece_bucket = 0;
538 centerprint(self, " ");
542 self.movetype = MOVETYPE_WALK;
549 for(r = 1; r <= TET_LINES; ++r)
553 for(c = 1; c <= TET_WIDTH; ++c)
555 print(ftos(GetXBlock(c, l)));
561 float BastetEvaluate()
566 float score, score_save;
567 string occupied, occupied_save;
568 float occupied_count, occupied_count_save;
573 // adds a bonus for each free dot above the occupied blocks profile
574 occupied = TET_EMPTY_LINE;
575 occupied_count = TET_WIDTH;
578 for(i = 1; i <= TET_LINES; ++i)
581 if(l == TET_EMPTY_LINE)
587 occupied_save = occupied;
588 occupied_count_save = occupied_count;
590 for(j = 1; j <= TET_WIDTH; ++j)
594 if(!GetXBlock(j, occupied))
596 occupied = SetXBlock(j, occupied, 1);
602 score += 10000 * occupied_count;
606 occupied = occupied_save;
607 occupied_count = occupied_count_save;
608 score = score_save + 100000000 + 10000 * TET_WIDTH + 1000;
613 score += 1000 * height;
618 float CheckMetrics(float piece, float orgx, float orgy, float rot);
619 void ClearPiece(float piece, float orgx, float orgy, float rot);
620 void CementPiece(float piece, float orgx, float orgy, float rot);
621 float bastet_profile_evaluate_time;
622 float bastet_profile_checkmetrics_time;
623 float BastetSearch(float buf, float pc, float x, float y, float rot, float move_bias)
624 // returns best score, or -1 if position is impossible
632 return 0; // DO NOT WANT
634 if(x < 1 || x > TET_WIDTH || y < 1 || y > TET_LINES)
635 return -1; // impossible
639 // did we already try?
640 b = x + (TET_WIDTH+2) * (y + (TET_LINES+2) * rot);
641 r = bufstr_get(buf, b);
642 if(r != "") // already tried
645 bufstr_set(buf, b, "0"); // in case we READ that, not that bad - we already got that value in another branch then anyway
649 t1 = gettime(GETTIME_HIRES);
650 if(CheckMetrics(pc, x, y, rot))
652 t2 = gettime(GETTIME_HIRES);
653 bastet_profile_checkmetrics_time += (t2 - t1);
656 s = BastetSearch(buf, pc, x-1, y, rot, move_bias - 1); if(s > sm) sm = s;
657 s = BastetSearch(buf, pc, x+1, y, rot, move_bias - 1); if(s > sm) sm = s;
658 s = BastetSearch(buf, pc, x, y, rot+1, move_bias - 1); if(s > sm) sm = s;
659 s = BastetSearch(buf, pc, x, y, rot-1, move_bias - 1); if(s > sm) sm = s;
661 s = BastetSearch(buf, pc, x, y+1, rot, move_bias + 2); if(s > sm) sm = s;
664 //printf("MAY CEMENT AT: %d %d %d\n", x, y, rot);
665 // moving down did not work - that means we can fixate the block here
666 t1 = gettime(GETTIME_HIRES);
668 CementPiece(pc, x, y, rot);
669 s = BastetEvaluate();
670 ClearPiece(pc, x, y, rot);
672 t2 = gettime(GETTIME_HIRES);
673 bastet_profile_evaluate_time += (t2 - t1);
680 t2 = gettime(GETTIME_HIRES);
681 bastet_profile_checkmetrics_time += (t2 - t1);
682 sm = -1; // impassible
685 bufstr_set(buf, b, ftos(sm));
690 float bastet_piece[7];
691 float bastet_score[7];
692 float bastet_piecetime[7];
697 bastet_profile_evaluate_time = 0;
698 bastet_profile_checkmetrics_time = 0;
699 float t1 = gettime(GETTIME_HIRES);
701 b = buf_create(); bastet_piece[0] = 1; bastet_score[0] = BastetSearch(b, 1, TET_START_PIECE_POS_x, 1+TET_START_PIECE_POS_y, TET_START_PIECE_POS_y, TET_WIDTH) + 100 * random() + bastet_piecetime[0]; buf_del(b);
702 b = buf_create(); bastet_piece[1] = 2; bastet_score[1] = BastetSearch(b, 2, TET_START_PIECE_POS_x, 1+TET_START_PIECE_POS_y, TET_START_PIECE_POS_y, TET_WIDTH) + 100 * random() + bastet_piecetime[1]; buf_del(b);
703 b = buf_create(); bastet_piece[2] = 3; bastet_score[2] = BastetSearch(b, 3, TET_START_PIECE_POS_x, 1+TET_START_PIECE_POS_y, TET_START_PIECE_POS_y, TET_WIDTH) + 100 * random() + bastet_piecetime[2]; buf_del(b);
704 b = buf_create(); bastet_piece[3] = 4; bastet_score[3] = BastetSearch(b, 4, TET_START_PIECE_POS_x, 1+TET_START_PIECE_POS_y, TET_START_PIECE_POS_y, TET_WIDTH) + 100 * random() + bastet_piecetime[3]; buf_del(b);
705 b = buf_create(); bastet_piece[4] = 5; bastet_score[4] = BastetSearch(b, 5, TET_START_PIECE_POS_x, 1+TET_START_PIECE_POS_y, TET_START_PIECE_POS_y, TET_WIDTH) + 100 * random() + bastet_piecetime[4]; buf_del(b);
706 b = buf_create(); bastet_piece[5] = 6; bastet_score[5] = BastetSearch(b, 6, TET_START_PIECE_POS_x, 1+TET_START_PIECE_POS_y, TET_START_PIECE_POS_y, TET_WIDTH) + 100 * random() + bastet_piecetime[5]; buf_del(b);
707 b = buf_create(); bastet_piece[6] = 7; bastet_score[6] = BastetSearch(b, 7, TET_START_PIECE_POS_x, 1+TET_START_PIECE_POS_y, TET_START_PIECE_POS_y, TET_WIDTH) + 100 * random() + bastet_piecetime[6]; buf_del(b);
709 float t2 = gettime(GETTIME_HIRES);
710 dprintf("Time taken: %.6f seconds (of this, ev = %.2f%%, cm = %.2f%%)\n", t2 - t1, 100 * bastet_profile_evaluate_time / (t2 - t1), 100 * bastet_profile_checkmetrics_time / (t2 - t1));
716 for(i = 0; i < 7; ++i)
718 printf("piece %s value = %d\n", substring("OJLIZST", bastet_piece[i]-1, 1), bastet_score[i]);
722 for(i = 0; i < 7; ++i)
727 for(j = i + 1; j < 7; ++j)
729 if(bastet_score[j] < s)
738 bastet_score[k] = bastet_score[i];
739 bastet_piece[k] = bastet_piece[i];
756 for(i = 0; i < 7; ++i)
759 bastet_piecetime[i] = 0.2 * bastet_piecetime[i];
761 bastet_piecetime[i] = 1.8 * bastet_piecetime[i] + 1000;
769 *********************************
773 *********************************
775 .float tet_piece_bucket;
783 if(self.tet_piece_bucket > 1)
785 p = mod(self.tet_piece_bucket, 7);
786 self.tet_piece_bucket = floor(self.tet_piece_bucket / 7);
791 p = floor(random() * 7);
794 for(i = 6; i > 0; --i)
796 q = floor(random() * i);
797 for(j = 0; j <= q; ++j)
808 self.tet_piece_bucket = b;
813 void TetAddScore(float n)
815 self.tet_score = self.tet_score + n * Tetris_Level();
816 if (self.tet_score > tet_high_score)
817 tet_high_score = self.tet_score;
819 float CheckMetrics(float piece, float orgx, float orgy, float rot) /*FIXDECL*/
821 // check to see if the piece, if moved to the locations will overlap
825 // why did I start counting from 1, damnit
829 PieceMinsMaxs(rot, piece);
830 if (tet_piecemins.x+orgx<1 || tet_piecemaxs.x+orgx > TET_WIDTH || tet_piecemins.y+orgy<1 || tet_piecemaxs.y+orgy> TET_LINES)
831 return false; // ouside the level
832 for (y = tet_piecemins.y; y <= tet_piecemaxs.y; y = y + 1)
834 l = GetLine(y + orgy);
835 if(l != TET_EMPTY_LINE)
836 for (x = tet_piecemins.x; x <= tet_piecemaxs.x; x = x + 1)
837 if (PieceMetric(x, y, rot, piece))
838 if (GetXBlock(x + orgx, l))
839 return false; // uhoh, gonna hit something.
844 void ClearPiece(float piece, float orgx, float orgy, float rot) /*FIXDECL*/
847 // why did I start counting from 1, damnit
851 PieceMinsMaxs(rot, piece);
852 for (y = tet_piecemins.y; y <= tet_piecemaxs.y; y = y + 1)
854 for (x = tet_piecemins.x; x <= tet_piecemaxs.x; x = x + 1)
856 if (PieceMetric(x, y, rot, piece))
858 SetSquare(x + orgx, y + orgy, 0);
863 void CementPiece(float piece, float orgx, float orgy, float rot) /*FIXDECL*/
867 // why did I start counting from 1, damnit
871 pcolor = PieceColor(piece);
873 PieceMinsMaxs(rot, piece);
874 for (y = tet_piecemins.y; y <= tet_piecemaxs.y; y = y + 1)
876 for (x = tet_piecemins.x; x <= tet_piecemaxs.x; x = x + 1)
878 if (PieceMetric(x, y, rot, piece))
880 SetSquare(x + orgx, y + orgy, pcolor);
886 const float LINE_LOW = 349525;
887 const float LINE_HIGH = 699050; // above number times 2
889 void AddLines(float n)
894 FOR_EACH_REALCLIENT(head) if(head != self) if(head.tetris_on) if(head.tet_vs_id == self.tet_vs_id)
895 head.tet_vs_addlines += n;
898 void CompletedLines()
900 float y, cleared, added, pos, i;
908 if(strstrofs(ln, "0", 0) < 0)
909 cleared = cleared + 1;
917 ln = GetLine(y - cleared);
923 else if(cleared >= 1)
924 AddLines(cleared - 1);
926 self.tet_lines = self.tet_lines + cleared;
927 TetAddScore(cleared * cleared * 10);
929 added = self.tet_vs_addlines;
930 self.tet_vs_addlines = 0;
934 for(y = 1; y <= TET_LINES - added; ++y)
936 SetLine(y, GetLine(y + added));
938 for(y = max(1, TET_LINES - added + 1); y <= TET_LINES; ++y)
940 pos = floor(random() * TET_WIDTH);
942 for(i = 1; i <= TET_WIDTH; ++i)
944 ln = SetXBlock(i, ln, floor(random() * 7 + 1));
949 self.tet_highest_line = 0;
950 for(y = 1; y <= TET_LINES; ++y)
951 if(GetLine(y) != TET_EMPTY_LINE)
953 self.tet_highest_line = TET_LINES + 1 - y;
959 else if(cleared >= 4)
967 void HandleGame(float keyss)
970 // first off, we need to see if we need a new piece
979 if (self.piece_type == 0)
981 self.piece_pos = TET_START_PIECE_POS; // that's about middle top, we count from 1 ARGH
983 if(autocvar_g_bastet)
985 self.piece_type = BastetPiece();
986 self.next_piece = bastet_piece[6];
991 self.piece_type = self.next_piece;
993 self.piece_type = RandomPiece();
994 self.next_piece = RandomPiece();
996 keyss = 0; // no movement first frame
997 self.tet_autodown = time + 0.2;
1001 ClearPiece(self.piece_type, self.piece_pos.x, self.piece_pos.y, self.piece_pos.z);
1003 // next we need to check the piece metrics against what's on the level
1004 // based on the key order
1006 old_pos = check_pos = self.piece_pos;
1010 if (keyss & TETKEY_RIGHT)
1012 check_pos_x = check_pos.x + 1;
1015 else if (keyss & TETKEY_LEFT)
1017 check_pos_x = check_pos.x - 1;
1020 else if (keyss & TETKEY_ROTRIGHT)
1022 check_pos_z = check_pos.z + 1;
1023 piece_data = PieceShape(self.piece_type);
1027 else if (keyss & TETKEY_ROTLEFT)
1029 check_pos_z = check_pos.z - 1;
1030 piece_data = PieceShape(self.piece_type);
1035 if (check_pos.z > 3)
1037 else if (check_pos.z < 0)
1041 if (CheckMetrics(self.piece_type, check_pos.x, check_pos.y, check_pos.z))
1042 self.piece_pos = check_pos;
1046 self.tet_gameovertime = time + 5;
1051 for(i = 1; i <= nudge; ++i)
1053 if(CheckMetrics(self.piece_type, check_pos.x + i, check_pos.y, check_pos.z))
1054 self.piece_pos = check_pos + '1 0 0' * i;
1055 else if(CheckMetrics(self.piece_type, check_pos.x - i, check_pos.y, check_pos.z))
1056 self.piece_pos = check_pos - '1 0 0' * i;
1062 check_pos = self.piece_pos;
1063 if(keyss & TETKEY_DROP)
1065 // drop to bottom, but do NOT cement it yet
1066 // this allows sliding it
1068 while(CheckMetrics(self.piece_type, check_pos.x, check_pos.y + 1, check_pos.z))
1070 self.tet_autodown = time + 2 / (1 + Tetris_Level());
1072 else if (keyss & TETKEY_DOWN)
1074 check_pos_y = check_pos.y + 1;
1075 self.tet_autodown = time + 2 / (1 + Tetris_Level());
1077 else if (self.tet_autodown < time)
1079 check_pos_y = check_pos.y + 1;
1080 self.tet_autodown = time + 2 / (1 + Tetris_Level());
1082 if (CheckMetrics(self.piece_type, check_pos.x, check_pos.y, check_pos.z))
1084 if(old_pos != check_pos)
1085 self.tet_drawtime = 0;
1086 self.piece_pos = check_pos;
1090 CementPiece(self.piece_type, self.piece_pos.x, self.piece_pos.y, self.piece_pos.z);
1093 self.piece_type = 0;
1094 self.tet_drawtime = 0;
1097 CementPiece(self.piece_type, self.piece_pos.x, self.piece_pos.y, self.piece_pos.z);
1101 *********************************
1103 Important Linking Into Quake stuff
1105 *********************************
1109 void TetrisImpulse()
1111 if(self.tetris_on == 0 || self.tetris_on == 2) // from "off" or "game over"
1115 if(time < tet_vs_current_timeout)
1118 self.tet_vs_id = tet_vs_current_id;
1122 // start new VS game
1123 ++tet_vs_current_id;
1124 tet_vs_current_timeout = time + 15;
1125 self.tet_vs_id = tet_vs_current_id;
1126 bprint("^1TET^7R^1IS: ", self.netname, "^1 started a new game. Do ^7impulse 100^1 to join.\n");
1128 self.tet_highest_line = 0;
1130 self.tet_org = self.origin;
1131 self.movetype = MOVETYPE_NOCLIP;
1133 else if(self.tetris_on == 1) // from "on"
1141 float TetrisPreFrame()
1143 if (!self.tetris_on)
1146 self.tet_org = self.origin;
1147 if (self.tet_drawtime > time)
1150 if(self.tetris_on == 3)
1151 self.tet_drawtime = ceil(time - tet_vs_current_timeout + 0.1) + tet_vs_current_timeout;
1153 self.tet_drawtime = time + 0.5;
1156 float frik_anglemoda(float v)
1158 return v - floor(v/360) * 360;
1160 float angcompa(float y1, float y2)
1162 y1 = frik_anglemoda(y1);
1163 y2 = frik_anglemoda(y2);
1168 answer = answer - 360;
1169 else if (answer < -180)
1170 answer = answer + 360;
1174 .float tetkey_down, tetkey_rotright, tetkey_left, tetkey_right, tetkey_rotleft, tetkey_drop;
1176 float TetrisKeyRepeat(.float fld, float f)
1180 if(self.fld == 0) // initial key press
1182 self.fld = time + 0.3;
1185 else if(time > self.fld)
1187 self.fld = time + 0.1;
1192 // repeating too fast
1203 float TetrisPostFrame()
1209 if (!self.tetris_on)
1212 if(self.tetris_on == 2 && time > self.tet_gameovertime)
1218 if(self.tetris_on == 3 && time > tet_vs_current_timeout)
1220 self.tetris_on = 1; // start VS game
1221 self.tet_drawtime = 0;
1224 setorigin(self, self.tet_org);
1225 self.movetype = MOVETYPE_NONE;
1227 if(self.tetris_on == 1)
1229 if(TetrisKeyRepeat(tetkey_down, self.movement.x < 0))
1230 keysa |= TETKEY_DOWN;
1232 if(TetrisKeyRepeat(tetkey_rotright, self.movement.x > 0))
1233 keysa |= TETKEY_ROTRIGHT;
1235 if(TetrisKeyRepeat(tetkey_left, self.movement.y < 0))
1236 keysa |= TETKEY_LEFT;
1238 if(TetrisKeyRepeat(tetkey_right, self.movement.y > 0))
1239 keysa |= TETKEY_RIGHT;
1241 if(TetrisKeyRepeat(tetkey_rotleft, self.BUTTON_CROUCH))
1242 keysa |= TETKEY_ROTLEFT;
1244 if(TetrisKeyRepeat(tetkey_drop, self.BUTTON_JUMP))
1245 keysa |= TETKEY_DROP;
1255 float TetrisPostFrame()
1257 if (autocvar_g_bastet)
1259 cvar_set("g_bastet", "0");
1260 print("The useless cvar has been toggled.\n");