git repos / blockattack-game

blame: source/code/BlockGame.cpp

normal view · raw

17916a2e sago007 2010-11-07 11:26 1
/*
c53e6443 sago007 2012-04-17 11:04 2
===========================================================================
c53e6443 sago007 2012-04-17 11:04 3
blockattack - Block Attack - Rise of the Blocks
c53e6443 sago007 2012-04-17 11:04 4
Copyright (C) 2005-2012 Poul Sander
c53e6443 sago007 2012-04-17 11:04 5
c53e6443 sago007 2012-04-17 11:04 6
This program is free software: you can redistribute it and/or modify
c53e6443 sago007 2012-04-17 11:04 7
it under the terms of the GNU General Public License as published by
c53e6443 sago007 2012-04-17 11:04 8
the Free Software Foundation, either version 2 of the License, or
c53e6443 sago007 2012-04-17 11:04 9
(at your option) any later version.
c53e6443 sago007 2012-04-17 11:04 10
c53e6443 sago007 2012-04-17 11:04 11
This program is distributed in the hope that it will be useful,
c53e6443 sago007 2012-04-17 11:04 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
c53e6443 sago007 2012-04-17 11:04 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c53e6443 sago007 2012-04-17 11:04 14
GNU General Public License for more details.
c53e6443 sago007 2012-04-17 11:04 15
c53e6443 sago007 2012-04-17 11:04 16
You should have received a copy of the GNU General Public License
c53e6443 sago007 2012-04-17 11:04 17
along with this program.  If not, see http://www.gnu.org/licenses/
c53e6443 sago007 2012-04-17 11:04 18
c53e6443 sago007 2012-04-17 11:04 19
Source information and contacts persons can be found at
021de090 sago007 2015-12-30 18:56 20
http://blockattack.net
c53e6443 sago007 2012-04-17 11:04 21
===========================================================================
c53e6443 sago007 2012-04-17 11:04 22
*/
c53e6443 sago007 2012-04-17 11:04 23
229e212d sago007 2015-08-22 17:14 24
//Some definitions
229e212d sago007 2015-08-22 17:14 25
//The game is divided in frames. FALLTIME means the blocks will fall one block every FRAMELENGTH*FALLTIME millisecond
229e212d sago007 2015-08-22 17:14 26
#define FRAMELENGTH 50
229e212d sago007 2015-08-22 17:14 27
#define HANGTIME 40
229e212d sago007 2015-08-22 17:14 28
#define FALLTIME 20
229e212d sago007 2015-08-22 17:14 29
//Don't change the following, they are fundamental and later some functions are hardcoded
82a819c4 Poul Sander 2025-12-14 11:33 30
#define BLOCKHANG 1000
229e212d sago007 2015-08-22 17:14 31
#define BLOCKFALL 10000
82a819c4 Poul Sander 2025-12-14 11:33 32
#define BLOCKWAIT 100000
229e212d sago007 2015-08-22 17:14 33
#define GARBAGE 1000000
229e212d sago007 2015-08-22 17:14 34
#define CHAINPLACE 10000000
17916a2e sago007 2010-11-07 11:26 35
82a819c4 Poul Sander 2025-12-14 11:33 36
#define GARBAGE_NORMAL 1
82a819c4 Poul Sander 2025-12-14 11:33 37
#define GARBAGE_GRAY 2
82a819c4 Poul Sander 2025-12-14 11:33 38
1176ee18 sago007 2017-08-19 16:10 39
// The game uses a very special  base-10 pack system
1176ee18 sago007 2017-08-19 16:10 40
// int  999999999999
1176ee18 sago007 2017-08-19 16:10 41
//      YYYYYGWBHTTC
1176ee18 sago007 2017-08-19 16:10 42
// YYYY = Chain
1176ee18 sago007 2017-08-19 16:10 43
// G = Garbage, 1= NORMAL, 2=GRAY
1176ee18 sago007 2017-08-19 16:10 44
// W = Waiting (A bomb is on it)
1176ee18 sago007 2017-08-19 16:10 45
// B = 1 if the block is falling
1176ee18 sago007 2017-08-19 16:10 46
// H = Block is hanging after garbage (Get Ready text on it)
1176ee18 sago007 2017-08-19 16:10 47
// TT = Time (in steps) until something happens
1176ee18 sago007 2017-08-19 16:10 48
// C = color
1176ee18 sago007 2017-08-19 16:10 49
82a819c4 Poul Sander 2025-12-14 11:33 50
static int getBlockChain(int block) {
82a819c4 Poul Sander 2025-12-14 11:33 51
	return (block / CHAINPLACE) % 1000;
82a819c4 Poul Sander 2025-12-14 11:33 52
}
82a819c4 Poul Sander 2025-12-14 11:33 53
82a819c4 Poul Sander 2025-12-14 11:33 54
static int getBlockGarbage(int block) {
82a819c4 Poul Sander 2025-12-14 11:33 55
	return (block / GARBAGE) % 10;
82a819c4 Poul Sander 2025-12-14 11:33 56
}
82a819c4 Poul Sander 2025-12-14 11:33 57
82a819c4 Poul Sander 2025-12-14 11:33 58
static int getStepsUntilEvent(int block) {
82a819c4 Poul Sander 2025-12-14 11:33 59
	return (block / 10) % 100;
82a819c4 Poul Sander 2025-12-14 11:33 60
}
82a819c4 Poul Sander 2025-12-14 11:33 61
82a819c4 Poul Sander 2025-12-14 11:33 62
static int getBlockColor(int block) {
82a819c4 Poul Sander 2025-12-14 11:33 63
	return block % 10;
82a819c4 Poul Sander 2025-12-14 11:33 64
}
82a819c4 Poul Sander 2025-12-14 11:33 65
82a819c4 Poul Sander 2025-12-14 11:33 66
static bool isWaiting(int block) {
82a819c4 Poul Sander 2025-12-14 11:33 67
	return (block / BLOCKWAIT) % 10;
82a819c4 Poul Sander 2025-12-14 11:33 68
}
82a819c4 Poul Sander 2025-12-14 11:33 69
82a819c4 Poul Sander 2025-12-14 11:33 70
static bool isHanging(int block) {
82a819c4 Poul Sander 2025-12-14 11:33 71
	return (block / BLOCKHANG) % 10;
82a819c4 Poul Sander 2025-12-14 11:33 72
}
82a819c4 Poul Sander 2025-12-14 11:33 73
1176ee18 sago007 2017-08-19 16:10 74
static bool block_isFalling(int block) {
1176ee18 sago007 2017-08-19 16:10 75
	return (block/BLOCKFALL)%10;
1176ee18 sago007 2017-08-19 16:10 76
}
1176ee18 sago007 2017-08-19 16:10 77
82a819c4 Poul Sander 2025-12-14 11:33 78
static int getBlockWithoutChain(int block) {
82a819c4 Poul Sander 2025-12-14 11:33 79
	return block % CHAINPLACE;
82a819c4 Poul Sander 2025-12-14 11:33 80
}
82a819c4 Poul Sander 2025-12-14 11:33 81
1176ee18 sago007 2017-08-19 16:10 82
static void block_setFalling(int& block, bool value) {
1176ee18 sago007 2017-08-19 16:10 83
	if (value) {
1176ee18 sago007 2017-08-19 16:10 84
		if (!block_isFalling(block)) {
1176ee18 sago007 2017-08-19 16:10 85
			block += BLOCKFALL;
1176ee18 sago007 2017-08-19 16:10 86
		}
1176ee18 sago007 2017-08-19 16:10 87
	}
1176ee18 sago007 2017-08-19 16:10 88
	else {
1176ee18 sago007 2017-08-19 16:10 89
		if (block_isFalling(block)) {
1176ee18 sago007 2017-08-19 16:10 90
			block -= BLOCKFALL;
1176ee18 sago007 2017-08-19 16:10 91
		}
1176ee18 sago007 2017-08-19 16:10 92
	}
1176ee18 sago007 2017-08-19 16:10 93
}
1176ee18 sago007 2017-08-19 16:10 94
17916a2e sago007 2010-11-07 11:26 95
#include "BlockGame.hpp"
055218be sago007 2015-08-22 18:44 96
#include "puzzlehandler.hpp"
ae5d6381 sago007 2015-12-29 13:26 97
#include "stageclearhandler.hpp"
63763043 sago007 2016-04-09 16:45 98
#include <sstream>
4a6d425b sago007 2016-06-05 16:23 99
#include <deque>
17916a2e sago007 2010-11-07 11:26 100
17916a2e sago007 2010-11-07 11:26 101
a1072daf sago007 2016-02-20 12:47 102
//Function to convert numbers to string (2 diget)
f10b1d3c Poul Sander 2020-08-08 17:34 103
static std::string itoa2(int num) {
e35fb006 sago007 2016-06-05 13:53 104
	char buffer[20];
e35fb006 sago007 2016-06-05 13:53 105
	snprintf(buffer, sizeof(buffer), "%02i", num);
e35fb006 sago007 2016-06-05 13:53 106
	return buffer;
a1072daf sago007 2016-02-20 12:47 107
}
a1072daf sago007 2016-02-20 12:47 108
b69f7fad sago007 2016-08-27 12:35 109
/**
b69f7fad sago007 2016-08-27 12:35 110
 * This function tells how long the game may pause the rise of the blocks.
b69f7fad sago007 2016-08-27 12:35 111
 * This decreases as the game progresses.
092bdebe sago007 2017-03-19 14:39 112
 * @param stops In out variable. If larger than the max allowed
b69f7fad sago007 2016-08-27 12:35 113
 * @param ticks Ticks since the game was started
b69f7fad sago007 2016-08-27 12:35 114
 * @param gameStartedAt Tick the game was started at.
b69f7fad sago007 2016-08-27 12:35 115
 */
b69f7fad sago007 2016-08-27 12:35 116
static void capMaxStops(int& stops, unsigned int ticks, unsigned int gameStartedAt) {
7d43dc59 sago007 2016-08-31 21:26 117
	if (ticks < gameStartedAt || stops == 0) {
b69f7fad sago007 2016-08-27 12:35 118
		//Game not started or not stops, do nothing
b69f7fad sago007 2016-08-27 12:35 119
		return;
b69f7fad sago007 2016-08-27 12:35 120
	}
b69f7fad sago007 2016-08-27 12:35 121
	unsigned int gameTime = gameStartedAt - ticks;
092bdebe sago007 2017-03-19 14:39 122
b69f7fad sago007 2016-08-27 12:35 123
	int maxSeconds = 10-( (gameTime/1000) % 30 );
b69f7fad sago007 2016-08-27 12:35 124
	if (maxSeconds < 3) {
b69f7fad sago007 2016-08-27 12:35 125
		maxSeconds = 1;
b69f7fad sago007 2016-08-27 12:35 126
	}
b69f7fad sago007 2016-08-27 12:35 127
	int cappedStops = maxSeconds * 1000;
b69f7fad sago007 2016-08-27 12:35 128
	if (stops > cappedStops) {
b69f7fad sago007 2016-08-27 12:35 129
		stops = cappedStops;
b69f7fad sago007 2016-08-27 12:35 130
	}
b69f7fad sago007 2016-08-27 12:35 131
}
b69f7fad sago007 2016-08-27 12:35 132
a1072daf sago007 2016-02-20 12:47 133
stageButton stageButtonStatus;
a1072daf sago007 2016-02-20 12:47 134
63c773dd sago007 2016-01-24 11:47 135
static std::stringstream ss; //Used for internal formatting
444cec07 sago007 2012-05-05 16:42 136
17916a2e sago007 2010-11-07 11:26 137
////////////////////////////////////////////////////////////////////////////////
17916a2e sago007 2010-11-07 11:26 138
//The BloackGame class represents a board, score, time etc. for a single player/
17916a2e sago007 2010-11-07 11:26 139
////////////////////////////////////////////////////////////////////////////////
63c773dd sago007 2016-01-24 11:47 140
int BlockGame::rand2() {
c53e6443 sago007 2012-04-17 11:04 141
	nextRandomNumber = nextRandomNumber*1103515245 + 12345;
63c773dd sago007 2016-01-24 11:47 142
	return ((int)(nextRandomNumber/65536)) % 32768;
c53e6443 sago007 2012-04-17 11:04 143
}
c53e6443 sago007 2012-04-17 11:04 144
ecef5838 sago007 2015-11-24 20:01 145
int BlockGame::firstUnusedChain() {
c53e6443 sago007 2012-04-17 11:04 146
	bool found=false;
c53e6443 sago007 2012-04-17 11:04 147
	int i = 0;
ecef5838 sago007 2015-11-24 20:01 148
	while (!found) {
ecef5838 sago007 2015-11-24 20:01 149
		if (!chainUsed[++i]) {
c53e6443 sago007 2012-04-17 11:04 150
			found=true;
ecef5838 sago007 2015-11-24 20:01 151
		}
ecef5838 sago007 2015-11-24 20:01 152
		if (i>NUMBEROFCHAINS-2) {
c53e6443 sago007 2012-04-17 11:04 153
			found=true;
ecef5838 sago007 2015-11-24 20:01 154
		}
c53e6443 sago007 2012-04-17 11:04 155
	}
c53e6443 sago007 2012-04-17 11:04 156
	return i;
c53e6443 sago007 2012-04-17 11:04 157
}
c53e6443 sago007 2012-04-17 11:04 158
c53e6443 sago007 2012-04-17 11:04 159
//Constructor
ecef5838 sago007 2015-11-24 20:01 160
BlockGame::BlockGame() {
c53e6443 sago007 2012-04-17 11:04 161
	AI_MoveSpeed=100;
c53e6443 sago007 2012-04-17 11:04 162
	baseSpeed = 0.5;           //All other speeds are relative to this
c53e6443 sago007 2012-04-17 11:04 163
	speed = baseSpeed;
c53e6443 sago007 2012-04-17 11:04 164
	speedLevel = 1;
c53e6443 sago007 2012-04-17 11:04 165
	ticks = 0;
c53e6443 sago007 2012-04-17 11:04 166
	gameStartedAt = ticks;
c53e6443 sago007 2012-04-17 11:04 167
	gameEndedAfter = 0;
c53e6443 sago007 2012-04-17 11:04 168
	pushedPixelAt = gameStartedAt;
c53e6443 sago007 2012-04-17 11:04 169
	nextGarbageNumber = 10;
4ce4646e Poul Sander 2024-03-27 17:45 170
	basicBlockVariants = 6;
c53e6443 sago007 2012-04-17 11:04 171
	handicap=0;
c98e567e sago007 2016-03-25 09:39 172
	for (int i=0; i<7; i++) {
ecef5838 sago007 2015-11-24 20:01 173
		for (int j=0; j<30; j++) {
c53e6443 sago007 2012-04-17 11:04 174
			board[i][j] = -1;
c53e6443 sago007 2012-04-17 11:04 175
		}
c98e567e sago007 2016-03-25 09:39 176
	}
c53e6443 sago007 2012-04-17 11:04 177
	lastCounter = -1;           //To prevent the final chunk to be played when stating the program
ecef5838 sago007 2015-11-24 20:01 178
}   //Constructor
c53e6443 sago007 2012-04-17 11:04 179
c53e6443 sago007 2012-04-17 11:04 180
63c773dd sago007 2016-01-24 11:47 181
void BlockGame::setGameSpeed(int globalSpeedLevel) {
ecef5838 sago007 2015-11-24 20:01 182
	switch (globalSpeedLevel) {
c53e6443 sago007 2012-04-17 11:04 183
	case 0:
c53e6443 sago007 2012-04-17 11:04 184
		baseSpeed=0.5;
c53e6443 sago007 2012-04-17 11:04 185
		break;
c53e6443 sago007 2012-04-17 11:04 186
	case 1:
38fbf4d7 sago007 2019-02-09 18:10 187
		baseSpeed=0.1;
c53e6443 sago007 2012-04-17 11:04 188
		break;
c53e6443 sago007 2012-04-17 11:04 189
	case 2:
38fbf4d7 sago007 2019-02-09 18:10 190
		baseSpeed=0.07;
c53e6443 sago007 2012-04-17 11:04 191
		break;
c53e6443 sago007 2012-04-17 11:04 192
	case 3:
38fbf4d7 sago007 2019-02-09 18:10 193
		baseSpeed=0.04;
c53e6443 sago007 2012-04-17 11:04 194
		break;
c53e6443 sago007 2012-04-17 11:04 195
	case 4:
38fbf4d7 sago007 2019-02-09 18:10 196
		baseSpeed=0.015;
c53e6443 sago007 2012-04-17 11:04 197
		break;
c53e6443 sago007 2012-04-17 11:04 198
	default:
38fbf4d7 sago007 2019-02-09 18:10 199
		baseSpeed=0.005;
c53e6443 sago007 2012-04-17 11:04 200
		break;
c53e6443 sago007 2012-04-17 11:04 201
	};
c53e6443 sago007 2012-04-17 11:04 202
}
c53e6443 sago007 2012-04-17 11:04 203
63c773dd sago007 2016-01-24 11:47 204
void BlockGame::setHandicap(int globalHandicap) {
63c773dd sago007 2016-01-24 11:47 205
	handicap=1000*((int)globalHandicap);
c53e6443 sago007 2012-04-17 11:04 206
}
c53e6443 sago007 2012-04-17 11:04 207
c53e6443 sago007 2012-04-17 11:04 208
//Set the move speed of the AI based on the aiLevel parameter
c53e6443 sago007 2012-04-17 11:04 209
//Also enables AI
63c773dd sago007 2016-01-24 11:47 210
void BlockGame::setAIlevel(int aiLevel) {
c53e6443 sago007 2012-04-17 11:04 211
	AI_MoveSpeed=120-(20*(aiLevel-3));
c53e6443 sago007 2012-04-17 11:04 212
};
c53e6443 sago007 2012-04-17 11:04 213
63c773dd sago007 2016-01-24 11:47 214
int BlockGame::getAIlevel() const {
c53e6443 sago007 2012-04-17 11:04 215
	return (120-AI_MoveSpeed)/20+3;
c53e6443 sago007 2012-04-17 11:04 216
}
c53e6443 sago007 2012-04-17 11:04 217
ecef5838 sago007 2015-11-24 20:01 218
int BlockGame::GetScore() const {
c53e6443 sago007 2012-04-17 11:04 219
	return score;
c53e6443 sago007 2012-04-17 11:04 220
}
c53e6443 sago007 2012-04-17 11:04 221
ecef5838 sago007 2015-11-24 20:01 222
int BlockGame::GetHandicap() const {
c53e6443 sago007 2012-04-17 11:04 223
	return handicap;
c53e6443 sago007 2012-04-17 11:04 224
}
c53e6443 sago007 2012-04-17 11:04 225
ecef5838 sago007 2015-11-24 20:01 226
bool BlockGame::isGameOver() const {
c53e6443 sago007 2012-04-17 11:04 227
	return bGameOver;
c53e6443 sago007 2012-04-17 11:04 228
}
c53e6443 sago007 2012-04-17 11:04 229
63c773dd sago007 2016-01-24 11:47 230
int BlockGame::GetGameStartedAt() const {
c53e6443 sago007 2012-04-17 11:04 231
	return gameStartedAt;
c53e6443 sago007 2012-04-17 11:04 232
}
c53e6443 sago007 2012-04-17 11:04 233
63c773dd sago007 2016-01-24 11:47 234
int BlockGame::GetGameEndedAt() const {
c53e6443 sago007 2012-04-17 11:04 235
	return gameEndedAfter;
c53e6443 sago007 2012-04-17 11:04 236
}
c53e6443 sago007 2012-04-17 11:04 237
ecef5838 sago007 2015-11-24 20:01 238
bool BlockGame::isTimeTrial() const {
c53e6443 sago007 2012-04-17 11:04 239
	return timetrial;
c53e6443 sago007 2012-04-17 11:04 240
}
c53e6443 sago007 2012-04-17 11:04 241
ecef5838 sago007 2015-11-24 20:01 242
bool BlockGame::isStageClear() const {
c53e6443 sago007 2012-04-17 11:04 243
	return stageClear;
c53e6443 sago007 2012-04-17 11:04 244
}
c53e6443 sago007 2012-04-17 11:04 245
ecef5838 sago007 2015-11-24 20:01 246
bool BlockGame::isVsMode() const {
c53e6443 sago007 2012-04-17 11:04 247
	return vsMode;
c53e6443 sago007 2012-04-17 11:04 248
}
c53e6443 sago007 2012-04-17 11:04 249
ecef5838 sago007 2015-11-24 20:01 250
bool BlockGame::isPuzzleMode() const {
c53e6443 sago007 2012-04-17 11:04 251
	return puzzleMode;
c53e6443 sago007 2012-04-17 11:04 252
}
c53e6443 sago007 2012-04-17 11:04 253
ecef5838 sago007 2015-11-24 20:01 254
int BlockGame::GetLinesCleared() const {
c53e6443 sago007 2012-04-17 11:04 255
	return linesCleared;
c53e6443 sago007 2012-04-17 11:04 256
}
c53e6443 sago007 2012-04-17 11:04 257
ecef5838 sago007 2015-11-24 20:01 258
int BlockGame::GetStageClearLimit() const {
c53e6443 sago007 2012-04-17 11:04 259
	return stageClearLimit;
c53e6443 sago007 2012-04-17 11:04 260
}
c53e6443 sago007 2012-04-17 11:04 261
ecef5838 sago007 2015-11-24 20:01 262
int BlockGame::GetChains() const {
c53e6443 sago007 2012-04-17 11:04 263
	return chain;
c53e6443 sago007 2012-04-17 11:04 264
}
c53e6443 sago007 2012-04-17 11:04 265
ecef5838 sago007 2015-11-24 20:01 266
int BlockGame::GetPixels() const {
c53e6443 sago007 2012-04-17 11:04 267
	return pixels;
c53e6443 sago007 2012-04-17 11:04 268
}
c53e6443 sago007 2012-04-17 11:04 269
ecef5838 sago007 2015-11-24 20:01 270
int BlockGame::GetSpeedLevel() const {
c53e6443 sago007 2012-04-17 11:04 271
	return speedLevel;
c53e6443 sago007 2012-04-17 11:04 272
}
c53e6443 sago007 2012-04-17 11:04 273
ecef5838 sago007 2015-11-24 20:01 274
int BlockGame::GetTowerHeight() const {
c53e6443 sago007 2012-04-17 11:04 275
	return TowerHeight;
c53e6443 sago007 2012-04-17 11:04 276
}
c53e6443 sago007 2012-04-17 11:04 277
ecef5838 sago007 2015-11-24 20:01 278
int BlockGame::GetCursorX() const {
c53e6443 sago007 2012-04-17 11:04 279
	return cursorx;
c53e6443 sago007 2012-04-17 11:04 280
}
c53e6443 sago007 2012-04-17 11:04 281
ecef5838 sago007 2015-11-24 20:01 282
int BlockGame::GetCursorY() const {
c53e6443 sago007 2012-04-17 11:04 283
	return cursory;
c53e6443 sago007 2012-04-17 11:04 284
}
c53e6443 sago007 2012-04-17 11:04 285
ecef5838 sago007 2015-11-24 20:01 286
void BlockGame::MoveCursorTo(int x, int y) {
c53e6443 sago007 2012-04-17 11:04 287
	cursorx = x;
c53e6443 sago007 2012-04-17 11:04 288
	cursory = y;
c53e6443 sago007 2012-04-17 11:04 289
}
c53e6443 sago007 2012-04-17 11:04 290
ecef5838 sago007 2015-11-24 20:01 291
bool BlockGame::GetIsWinner()  const {
c53e6443 sago007 2012-04-17 11:04 292
	return hasWonTheGame;
c53e6443 sago007 2012-04-17 11:04 293
}
17916a2e sago007 2010-11-07 11:26 294
c7f2082f sago007 2016-03-13 11:48 295
void BlockGame::NewGame(const BlockGameStartInfo& s) {
4a6d425b sago007 2016-06-05 16:23 296
	replayInfo.startInfo = s;
4a6d425b sago007 2016-06-05 16:23 297
	replayInfo.actions.clear();
50cf6485 sago007 2016-03-21 19:11 298
	this->recordStats = s.recordStats;
ae5fb2bb sago007 2016-03-22 18:00 299
	if (s.AI) {
ae5fb2bb sago007 2016-03-22 18:00 300
		recordStats = false;
ae5fb2bb sago007 2016-03-22 18:00 301
	}
4379ec19 Poul Sander 2019-01-30 18:27 302
	NewGameInternal(s.ticks);
b76e0075 Poul Sander 2024-03-31 20:09 303
	basicBlockVariants = s.basicBlockVariants;
5159dd90 sago007 2016-02-21 15:50 304
	if (s.timeTrial) {
5159dd90 sago007 2016-02-21 15:50 305
		timetrial = true;
5159dd90 sago007 2016-02-21 15:50 306
		putStartBlocks();
5159dd90 sago007 2016-02-21 15:50 307
	}
b1fe2ae5 sago007 2016-02-21 16:01 308
	if (s.stageClear) {
b1fe2ae5 sago007 2016-02-21 16:01 309
		if (s.level > -1) {
b1fe2ae5 sago007 2016-02-21 16:01 310
			stageClear = true;
b1fe2ae5 sago007 2016-02-21 16:01 311
			Level = s.level;
b1fe2ae5 sago007 2016-02-21 16:01 312
			Stats::getInstance()->addOne("PlayedStageLevel"+itoa2(s.level));
b1fe2ae5 sago007 2016-02-21 16:01 313
			stageClearLimit = 30+(Level%6)*10;
b1fe2ae5 sago007 2016-02-21 16:01 314
			baseSpeed = 0.5/((double)(Level*0.5)+1.0);
b1fe2ae5 sago007 2016-02-21 16:01 315
			speed = baseSpeed;
b1fe2ae5 sago007 2016-02-21 16:01 316
		}
b1fe2ae5 sago007 2016-02-21 16:01 317
	}
b256fda5 sago007 2016-02-21 16:21 318
	if (s.puzzleMode) {
b256fda5 sago007 2016-02-21 16:21 319
		if (s.level>-1) {
b256fda5 sago007 2016-02-21 16:21 320
			puzzleMode = true;
b256fda5 sago007 2016-02-21 16:21 321
			Level = s.level;
b256fda5 sago007 2016-02-21 16:21 322
			MovesLeft = PuzzleNumberOfMovesAllowed(Level);
549ecfae sago007 2016-10-09 08:37 323
			for (int i=0; i<6; i++) {
b256fda5 sago007 2016-02-21 16:21 324
				for (int j=0; j<12; j++) {
b256fda5 sago007 2016-02-21 16:21 325
					board[i][j+1] = PuzzleGetBrick(Level,i,j);
b256fda5 sago007 2016-02-21 16:21 326
				}
549ecfae sago007 2016-10-09 08:37 327
			}
b256fda5 sago007 2016-02-21 16:21 328
			baseSpeed = 100000;
b256fda5 sago007 2016-02-21 16:21 329
			speed = 100000;
b256fda5 sago007 2016-02-21 16:21 330
b256fda5 sago007 2016-02-21 16:21 331
			//Now push the blines up
285a976a sago007 2016-04-13 17:16 332
			for (int i=19; i>0; i--) {
b256fda5 sago007 2016-02-21 16:21 333
				for (int j=0; j<6; j++) {
b256fda5 sago007 2016-02-21 16:21 334
					board[j][i] = board[j][i-1];
b256fda5 sago007 2016-02-21 16:21 335
				}
285a976a sago007 2016-04-13 17:16 336
			}
b256fda5 sago007 2016-02-21 16:21 337
			for (int j=0; j<6; j++) {
092bdebe sago007 2017-03-19 14:39 338
				board[j][0] = 5;
b256fda5 sago007 2016-02-21 16:21 339
			}
b256fda5 sago007 2016-02-21 16:21 340
		}
83e4f8fe sago007 2016-02-22 19:22 341
		this->singlePuzzle = s.singlePuzzle;
b256fda5 sago007 2016-02-21 16:21 342
	}
1e5aff60 sago007 2016-02-21 18:23 343
	if (s.vsMode) {
1e5aff60 sago007 2016-02-21 18:23 344
		vsMode = true;
1e5aff60 sago007 2016-02-21 18:23 345
		AI_Enabled = s.AI;
50cf6485 sago007 2016-03-21 19:11 346
		if (recordStats) {
1e5aff60 sago007 2016-02-21 18:23 347
			Stats::getInstance()->addOne("VSgamesStarted");
1e5aff60 sago007 2016-02-21 18:23 348
		}
ae5fb2bb sago007 2016-03-22 18:00 349
		if (s.vsAI) {
ae5fb2bb sago007 2016-03-22 18:00 350
			setAIlevel(s.level);
ae5fb2bb sago007 2016-03-22 18:00 351
			vsAI = true;
ae5fb2bb sago007 2016-03-22 18:00 352
		}
50cf6485 sago007 2016-03-21 19:11 353
		if (AI_Enabled) {
1e5aff60 sago007 2016-02-21 18:23 354
			name = "CPU";
6d6b2788 sago007 2016-02-21 18:51 355
			setAIlevel(s.level);
1e5aff60 sago007 2016-02-21 18:23 356
		}
1e5aff60 sago007 2016-02-21 18:23 357
		putStartBlocks();
1e5aff60 sago007 2016-02-21 18:23 358
	}
917dac61 sago007 2016-02-21 20:01 359
	if (s.startBlocks >= 0) {
917dac61 sago007 2016-02-21 20:01 360
		putStartBlocks(s.startBlocks);
917dac61 sago007 2016-02-21 20:01 361
	}
3e7b8813 sago007 2016-02-22 19:45 362
	if (s.handicap > 0) {
3e7b8813 sago007 2016-02-22 19:45 363
		setHandicap(s.handicap);
3e7b8813 sago007 2016-02-22 19:45 364
	}
3e7b8813 sago007 2016-02-22 19:45 365
	if (s.gameSpeed > 0) {
3e7b8813 sago007 2016-02-22 19:45 366
		setGameSpeed(s.gameSpeed);
4379ec19 Poul Sander 2019-01-30 18:27 367
		speed = baseSpeed;
3e7b8813 sago007 2016-02-22 19:45 368
	}
5159dd90 sago007 2016-02-21 15:50 369
}
5159dd90 sago007 2016-02-21 15:50 370
c53e6443 sago007 2012-04-17 11:04 371
//Instead of creating new object new game is called, to prevent memory leaks
4379ec19 Poul Sander 2019-01-30 18:27 372
void BlockGame::NewGameInternal( unsigned int ticks) {
c53e6443 sago007 2012-04-17 11:04 373
	this->ticks = ticks;
c53e6443 sago007 2012-04-17 11:04 374
	stageButtonStatus = SBdontShow;
c53e6443 sago007 2012-04-17 11:04 375
	nrFellDown = 0;
c53e6443 sago007 2012-04-17 11:04 376
	nrPushedPixel = 0;
c53e6443 sago007 2012-04-17 11:04 377
	nrStops = 0;
c53e6443 sago007 2012-04-17 11:04 378
	cursorx = 2;
c53e6443 sago007 2012-04-17 11:04 379
	cursory = 3;
c53e6443 sago007 2012-04-17 11:04 380
	stop = 0;
c53e6443 sago007 2012-04-17 11:04 381
	pixels = 0;
c53e6443 sago007 2012-04-17 11:04 382
	score = 0;
c53e6443 sago007 2012-04-17 11:04 383
	bGameOver = false;
c53e6443 sago007 2012-04-17 11:04 384
	bDraw = false;
c53e6443 sago007 2012-04-17 11:04 385
	timetrial = false;
c53e6443 sago007 2012-04-17 11:04 386
	stageClear = false;
c53e6443 sago007 2012-04-17 11:04 387
	linesCleared = 0;
c53e6443 sago007 2012-04-17 11:04 388
	hasWonTheGame = false;
c53e6443 sago007 2012-04-17 11:04 389
	vsMode = false;
c53e6443 sago007 2012-04-17 11:04 390
	puzzleMode = false;
c53e6443 sago007 2012-04-17 11:04 391
	combo=0;
c53e6443 sago007 2012-04-17 11:04 392
	chain=0;
c53e6443 sago007 2012-04-17 11:04 393
	AI_Enabled = false;
c53e6443 sago007 2012-04-17 11:04 394
	baseSpeed= 0.5;
c53e6443 sago007 2012-04-17 11:04 395
	speed = baseSpeed;
c53e6443 sago007 2012-04-17 11:04 396
	speedLevel = 1;
c53e6443 sago007 2012-04-17 11:04 397
	gameStartedAt = ticks+3000;
c53e6443 sago007 2012-04-17 11:04 398
	pushedPixelAt = gameStartedAt;
c53e6443 sago007 2012-04-17 11:04 399
	nextGarbageNumber = 10;
c53e6443 sago007 2012-04-17 11:04 400
	handicap=0;
549ecfae sago007 2016-10-09 08:37 401
	for (int i=0; i<7; i++) {
ecef5838 sago007 2015-11-24 20:01 402
		for (int j=0; j<30; j++) {
c53e6443 sago007 2012-04-17 11:04 403
			board[i][j] = -1;
c53e6443 sago007 2012-04-17 11:04 404
		}
549ecfae sago007 2016-10-09 08:37 405
	}
ecef5838 sago007 2015-11-24 20:01 406
	for (int i=0; i<NUMBEROFCHAINS; i++) {
c53e6443 sago007 2012-04-17 11:04 407
		chainUsed[i]=false;
c53e6443 sago007 2012-04-17 11:04 408
		chainSize[i] = 0;
c53e6443 sago007 2012-04-17 11:04 409
	}
c53e6443 sago007 2012-04-17 11:04 410
	lastAImove = ticks+3000;
ecef5838 sago007 2015-11-24 20:01 411
}   //NewGame
c53e6443 sago007 2012-04-17 11:04 412
1fd8156c sago007 2016-06-07 16:41 413
void BlockGame::FinalizeBlockGameInfo() {
1fd8156c sago007 2016-06-07 16:41 414
	replayInfo.extra.name = name;
1fd8156c sago007 2016-06-07 16:41 415
	replayInfo.extra.score = score;
1fd8156c sago007 2016-06-07 16:41 416
	replayInfo.extra.seconds = gameEndedAfter;
1fd8156c sago007 2016-06-07 16:41 417
}
17916a2e sago007 2010-11-07 11:26 418
c53e6443 sago007 2012-04-17 11:04 419
//Prints "winner" and ends game
ecef5838 sago007 2015-11-24 20:01 420
void BlockGame::setPlayerWon() {
ecef5838 sago007 2015-11-24 20:01 421
	if (!bGameOver || !hasWonTheGame) {
c53e6443 sago007 2012-04-17 11:04 422
		gameEndedAfter = ticks-gameStartedAt; //We game ends now!
50cf6485 sago007 2016-03-21 19:11 423
		if (recordStats) {
17916a2e sago007 2010-11-07 11:26 424
			TimeHandler::addTime("playTime",TimeHandler::ms2ct(gameEndedAfter));
17916a2e sago007 2010-11-07 11:26 425
		}
e68d08eb sago007 2013-11-15 22:33 426
		bGameOver = true;
313ecd1b sago007 2015-08-22 20:38 427
		PlayerWonEvent();
50cf6485 sago007 2016-03-21 19:11 428
		if (recordStats) {
e68d08eb sago007 2013-11-15 22:33 429
			Stats::getInstance()->addOne("totalWins");
ae5fb2bb sago007 2016-03-22 18:00 430
			if (vsAI) {
e68d08eb sago007 2013-11-15 22:33 431
				//We have defeated an AI
549ecfae sago007 2016-10-09 08:37 432
				Stats::getInstance()->addOne("defeatedAI"+std::to_string(getAIlevel()));
e68d08eb sago007 2013-11-15 22:33 433
			}
e68d08eb sago007 2013-11-15 22:33 434
		}
ae5fb2bb sago007 2016-03-22 18:00 435
		if (AI_Enabled && vsAI) {
e68d08eb sago007 2013-11-15 22:33 436
			//The AI have defeated a human player
549ecfae sago007 2016-10-09 08:37 437
			Stats::getInstance()->addOne("defeatedByAI"+std::to_string(getAIlevel()));
c53e6443 sago007 2012-04-17 11:04 438
		}
1fd8156c sago007 2016-06-07 16:41 439
		FinalizeBlockGameInfo();
c53e6443 sago007 2012-04-17 11:04 440
	}
e68d08eb sago007 2013-11-15 22:33 441
	hasWonTheGame = true;
c53e6443 sago007 2012-04-17 11:04 442
}
c53e6443 sago007 2012-04-17 11:04 443
c53e6443 sago007 2012-04-17 11:04 444
//Prints "draw" and ends the game
ecef5838 sago007 2015-11-24 20:01 445
void BlockGame::setDraw() {
c53e6443 sago007 2012-04-17 11:04 446
	bGameOver = true;
50cf6485 sago007 2016-03-21 19:11 447
	if (recordStats) {
17916a2e sago007 2010-11-07 11:26 448
		TimeHandler::addTime("playTime",TimeHandler::ms2ct(gameEndedAfter));
17916a2e sago007 2010-11-07 11:26 449
	}
c53e6443 sago007 2012-04-17 11:04 450
	hasWonTheGame = false;
c53e6443 sago007 2012-04-17 11:04 451
	bDraw = true;
027b5cfd sago007 2015-08-23 14:27 452
	DrawEvent();
50cf6485 sago007 2016-03-21 19:11 453
	if (recordStats) {
c53e6443 sago007 2012-04-17 11:04 454
		Stats::getInstance()->addOne("totalDraws");
027b5cfd sago007 2015-08-23 14:27 455
	}
1fd8156c sago007 2016-06-07 16:41 456
	FinalizeBlockGameInfo();
c53e6443 sago007 2012-04-17 11:04 457
}
c53e6443 sago007 2012-04-17 11:04 458
c53e6443 sago007 2012-04-17 11:04 459
c53e6443 sago007 2012-04-17 11:04 460
//Test if LineNr is an empty line, returns false otherwise.
ecef5838 sago007 2015-11-24 20:01 461
bool BlockGame::LineEmpty(int lineNr) const {
c53e6443 sago007 2012-04-17 11:04 462
	bool empty = true;
549ecfae sago007 2016-10-09 08:37 463
	for (int i = 0; i <7; i++) {
ecef5838 sago007 2015-11-24 20:01 464
		if (board[i][lineNr] != -1) {
c53e6443 sago007 2012-04-17 11:04 465
			empty = false;
ecef5838 sago007 2015-11-24 20:01 466
		}
549ecfae sago007 2016-10-09 08:37 467
	}
c53e6443 sago007 2012-04-17 11:04 468
	return empty;
c53e6443 sago007 2012-04-17 11:04 469
}
c53e6443 sago007 2012-04-17 11:04 470
c53e6443 sago007 2012-04-17 11:04 471
//Test if the entire board is empty (used for Puzzles)
ecef5838 sago007 2015-11-24 20:01 472
bool BlockGame::BoardEmpty() const {
c53e6443 sago007 2012-04-17 11:04 473
	bool empty = true;
549ecfae sago007 2016-10-09 08:37 474
	for (int i=0; i<6; i++) {
549ecfae sago007 2016-10-09 08:37 475
		for (int j=1; j<13; j++) {
ecef5838 sago007 2015-11-24 20:01 476
			if (board[i][j] != -1) {
c53e6443 sago007 2012-04-17 11:04 477
				empty = false;
ecef5838 sago007 2015-11-24 20:01 478
			}
549ecfae sago007 2016-10-09 08:37 479
		}
549ecfae sago007 2016-10-09 08:37 480
	}
c53e6443 sago007 2012-04-17 11:04 481
	return empty;
c53e6443 sago007 2012-04-17 11:04 482
}
c53e6443 sago007 2012-04-17 11:04 483
c53e6443 sago007 2012-04-17 11:04 484
//Anything that the user can't move? In that case Game Over cannot occur
ecef5838 sago007 2015-11-24 20:01 485
bool BlockGame::hasStaticContent() const {
549ecfae sago007 2016-10-09 08:37 486
	for (int i=0; i<6; i++) {
549ecfae sago007 2016-10-09 08:37 487
		for (int j=1; j<13; j++) {
ecef5838 sago007 2015-11-24 20:01 488
			if (board[i][j] >= 10000000) {  //Higher than this means combos (garbage is static, but the stack is static but nothing to do about it)
ecef5838 sago007 2015-11-24 20:01 489
				return true;    //They are static
ecef5838 sago007 2015-11-24 20:01 490
			}
549ecfae sago007 2016-10-09 08:37 491
		}
549ecfae sago007 2016-10-09 08:37 492
	}
ecef5838 sago007 2015-11-24 20:01 493
	return false;                   //Return false if no static object found
c53e6443 sago007 2012-04-17 11:04 494
}
c53e6443 sago007 2012-04-17 11:04 495
10a4aa95 Poul Sander 2023-10-31 20:39 496
void BlockGame::putSampleBlocks() {
10a4aa95 Poul Sander 2023-10-31 20:39 497
	//row 0 (hidden):
10a4aa95 Poul Sander 2023-10-31 20:39 498
	board[0][0]=0;
10a4aa95 Poul Sander 2023-10-31 20:39 499
	board[1][0]=1;
10a4aa95 Poul Sander 2023-10-31 20:39 500
	board[2][0]=2;
10a4aa95 Poul Sander 2023-10-31 20:39 501
	board[3][0]=3;
10a4aa95 Poul Sander 2023-10-31 20:39 502
	board[4][0]=4;
10a4aa95 Poul Sander 2023-10-31 20:39 503
	board[5][0]=5;
10a4aa95 Poul Sander 2023-10-31 20:39 504
	//row 1:
10a4aa95 Poul Sander 2023-10-31 20:39 505
	board[0][1]=0;
10a4aa95 Poul Sander 2023-10-31 20:39 506
	board[1][1]=1;
10a4aa95 Poul Sander 2023-10-31 20:39 507
	board[2][1]=2;
10a4aa95 Poul Sander 2023-10-31 20:39 508
	board[3][1]=3;
10a4aa95 Poul Sander 2023-10-31 20:39 509
	board[4][1]=4;
10a4aa95 Poul Sander 2023-10-31 20:39 510
	board[5][1]=5;
10a4aa95 Poul Sander 2023-10-31 20:39 511
	//row 2+:
10a4aa95 Poul Sander 2023-10-31 20:39 512
	board[0][2]=6;
10a4aa95 Poul Sander 2023-10-31 20:39 513
	board[0][3]=1;
10a4aa95 Poul Sander 2023-10-31 20:39 514
	board[0][4]=2;
10a4aa95 Poul Sander 2023-10-31 20:39 515
	for ( size_t i = 0; i < 4; i++) {
10a4aa95 Poul Sander 2023-10-31 20:39 516
		board[i][5]=GARBAGE;
10a4aa95 Poul Sander 2023-10-31 20:39 517
	}
10a4aa95 Poul Sander 2023-10-31 20:39 518
	for (size_t i = 0; i < 6; i++) {
10a4aa95 Poul Sander 2023-10-31 20:39 519
		for (size_t j = 6; j < 9; j++) {
10a4aa95 Poul Sander 2023-10-31 20:39 520
			board[i][j] = GARBAGE+1;
10a4aa95 Poul Sander 2023-10-31 20:39 521
		}
10a4aa95 Poul Sander 2023-10-31 20:39 522
		for (size_t j = 9; j < 12; j++) {
10a4aa95 Poul Sander 2023-10-31 20:39 523
			board[i][j] = GARBAGE+2;
10a4aa95 Poul Sander 2023-10-31 20:39 524
		}
10a4aa95 Poul Sander 2023-10-31 20:39 525
	}
10a4aa95 Poul Sander 2023-10-31 20:39 526
}
10a4aa95 Poul Sander 2023-10-31 20:39 527
ecef5838 sago007 2015-11-24 20:01 528
void BlockGame::putStartBlocks() {
c53e6443 sago007 2012-04-17 11:04 529
	putStartBlocks(time(0));
c53e6443 sago007 2012-04-17 11:04 530
}
c53e6443 sago007 2012-04-17 11:04 531
63c773dd sago007 2016-01-24 11:47 532
void BlockGame::putStartBlocks(int n) {
571b4d47 sago007 2015-12-05 16:02 533
	for (int i=0; i<7; i++) {
ecef5838 sago007 2015-11-24 20:01 534
		for (int j=0; j<30; j++) {
c53e6443 sago007 2012-04-17 11:04 535
			board[i][j] = -1;
c53e6443 sago007 2012-04-17 11:04 536
		}
571b4d47 sago007 2015-12-05 16:02 537
	}
c53e6443 sago007 2012-04-17 11:04 538
	nextRandomNumber = n;
c53e6443 sago007 2012-04-17 11:04 539
	int choice = rand2()%3; //Pick a random layout
ecef5838 sago007 2015-11-24 20:01 540
	switch (choice) {
c53e6443 sago007 2012-04-17 11:04 541
	case 0:
c53e6443 sago007 2012-04-17 11:04 542
		//row 0:
c53e6443 sago007 2012-04-17 11:04 543
		board[0][0]=1;
c53e6443 sago007 2012-04-17 11:04 544
		board[1][0]=0;
c53e6443 sago007 2012-04-17 11:04 545
		board[2][0]=4;
c53e6443 sago007 2012-04-17 11:04 546
		board[3][0]=3;
c53e6443 sago007 2012-04-17 11:04 547
		board[4][0]=3;
421e71ed Poul Sander 2024-03-25 22:30 548
		board[5][0]=4;
c53e6443 sago007 2012-04-17 11:04 549
		//row 1:
c53e6443 sago007 2012-04-17 11:04 550
		board[0][1]=1;
c53e6443 sago007 2012-04-17 11:04 551
		board[1][1]=4;
c53e6443 sago007 2012-04-17 11:04 552
		board[2][1]=2;
c53e6443 sago007 2012-04-17 11:04 553
		board[3][1]=0;
c53e6443 sago007 2012-04-17 11:04 554
		board[4][1]=4;
421e71ed Poul Sander 2024-03-25 22:30 555
		board[5][1]=4;
c53e6443 sago007 2012-04-17 11:04 556
		//row 2:
c53e6443 sago007 2012-04-17 11:04 557
		board[0][2]=2;
c53e6443 sago007 2012-04-17 11:04 558
		board[1][2]=3;
c53e6443 sago007 2012-04-17 11:04 559
		board[2][2]=0;
c53e6443 sago007 2012-04-17 11:04 560
		board[3][2]=4;
c53e6443 sago007 2012-04-17 11:04 561
		board[4][2]=1;
c53e6443 sago007 2012-04-17 11:04 562
		board[5][2]=1;
c53e6443 sago007 2012-04-17 11:04 563
		//row 3:
c53e6443 sago007 2012-04-17 11:04 564
		board[0][3]=3;
c53e6443 sago007 2012-04-17 11:04 565
		board[1][3]=2;
c53e6443 sago007 2012-04-17 11:04 566
		board[2][3]=3;
c53e6443 sago007 2012-04-17 11:04 567
		board[3][3]=1;
c53e6443 sago007 2012-04-17 11:04 568
		board[4][3]=0;
c53e6443 sago007 2012-04-17 11:04 569
		board[5][3]=4;
c53e6443 sago007 2012-04-17 11:04 570
		//row 4:
c53e6443 sago007 2012-04-17 11:04 571
		board[0][4]=2;
c53e6443 sago007 2012-04-17 11:04 572
		board[1][4]=3;
c53e6443 sago007 2012-04-17 11:04 573
		board[2][4]=3;
c53e6443 sago007 2012-04-17 11:04 574
		board[3][4]=1;
c53e6443 sago007 2012-04-17 11:04 575
		board[4][4]=4;
c53e6443 sago007 2012-04-17 11:04 576
		board[5][4]=0;
c53e6443 sago007 2012-04-17 11:04 577
		//row 5:
c53e6443 sago007 2012-04-17 11:04 578
		board[0][5]=-1;
421e71ed Poul Sander 2024-03-25 22:30 579
		board[1][5]=4;
421e71ed Poul Sander 2024-03-25 22:30 580
		board[2][5]=4;
c53e6443 sago007 2012-04-17 11:04 581
		board[3][5]=-1;
c53e6443 sago007 2012-04-17 11:04 582
		board[4][5]=1;
c53e6443 sago007 2012-04-17 11:04 583
		board[5][5]=-1;
c53e6443 sago007 2012-04-17 11:04 584
		break;
c53e6443 sago007 2012-04-17 11:04 585
	case 1:
c53e6443 sago007 2012-04-17 11:04 586
		//row 0:
c53e6443 sago007 2012-04-17 11:04 587
		board[0][0]=3;
421e71ed Poul Sander 2024-03-25 22:30 588
		board[1][0]=1;
c53e6443 sago007 2012-04-17 11:04 589
		board[2][0]=0;
c53e6443 sago007 2012-04-17 11:04 590
		board[3][0]=0;
c53e6443 sago007 2012-04-17 11:04 591
		board[4][0]=4;
c53e6443 sago007 2012-04-17 11:04 592
		board[5][0]=2;
c53e6443 sago007 2012-04-17 11:04 593
		//row 1:
c53e6443 sago007 2012-04-17 11:04 594
		board[0][1]=3;
421e71ed Poul Sander 2024-03-25 22:30 595
		board[1][1]=1;
c53e6443 sago007 2012-04-17 11:04 596
		board[2][1]=-1;
421e71ed Poul Sander 2024-03-25 22:30 597
		board[3][1]=1;
c53e6443 sago007 2012-04-17 11:04 598
		board[4][1]=4;
c53e6443 sago007 2012-04-17 11:04 599
		board[5][1]=2;
c53e6443 sago007 2012-04-17 11:04 600
		//row 2:
c53e6443 sago007 2012-04-17 11:04 601
		board[0][2]=2;
c53e6443 sago007 2012-04-17 11:04 602
		board[1][2]=-1;
c53e6443 sago007 2012-04-17 11:04 603
		board[2][2]=-1;
c53e6443 sago007 2012-04-17 11:04 604
		board[3][2]=4;
c53e6443 sago007 2012-04-17 11:04 605
		board[4][2]=0;
c53e6443 sago007 2012-04-17 11:04 606
		board[5][2]=3;
c53e6443 sago007 2012-04-17 11:04 607
		//row 3:
c53e6443 sago007 2012-04-17 11:04 608
		board[0][3]=2;
c53e6443 sago007 2012-04-17 11:04 609
		board[5][3]=3;
c53e6443 sago007 2012-04-17 11:04 610
		break;
c53e6443 sago007 2012-04-17 11:04 611
	default:
c53e6443 sago007 2012-04-17 11:04 612
		//row 0:
c53e6443 sago007 2012-04-17 11:04 613
		board[0][0]=4;
1b403c4a Poul Sander 2024-04-14 14:57 614
		board[1][0]=1;
c53e6443 sago007 2012-04-17 11:04 615
		board[2][0]=2;
c53e6443 sago007 2012-04-17 11:04 616
		board[3][0]=0;
c53e6443 sago007 2012-04-17 11:04 617
		board[4][0]=1;
421e71ed Poul Sander 2024-03-25 22:30 618
		board[5][0]=3;
c53e6443 sago007 2012-04-17 11:04 619
		//row 1:
c53e6443 sago007 2012-04-17 11:04 620
		board[0][1]=4;
421e71ed Poul Sander 2024-03-25 22:30 621
		board[1][1]=3;
c53e6443 sago007 2012-04-17 11:04 622
		board[2][1]=2;
c53e6443 sago007 2012-04-17 11:04 623
		board[3][1]=1;
c53e6443 sago007 2012-04-17 11:04 624
		board[4][1]=0;
c53e6443 sago007 2012-04-17 11:04 625
		board[5][1]=2;
c53e6443 sago007 2012-04-17 11:04 626
		//row 2:
c53e6443 sago007 2012-04-17 11:04 627
		board[0][2]=2;
c53e6443 sago007 2012-04-17 11:04 628
		board[1][2]=4;
c53e6443 sago007 2012-04-17 11:04 629
		board[2][2]=-1;
c53e6443 sago007 2012-04-17 11:04 630
		board[3][2]=0;
c53e6443 sago007 2012-04-17 11:04 631
		board[4][2]=1;
421e71ed Poul Sander 2024-03-25 22:30 632
		board[5][2]=3;
c53e6443 sago007 2012-04-17 11:04 633
		//row 3:
c53e6443 sago007 2012-04-17 11:04 634
		board[0][3]=4;
c53e6443 sago007 2012-04-17 11:04 635
		board[1][3]=2;
c53e6443 sago007 2012-04-17 11:04 636
		board[2][3]=-1;
c53e6443 sago007 2012-04-17 11:04 637
		board[3][3]=1;
c53e6443 sago007 2012-04-17 11:04 638
		board[4][3]=0;
c53e6443 sago007 2012-04-17 11:04 639
		board[5][3]=2;
c53e6443 sago007 2012-04-17 11:04 640
		//row 4:
c53e6443 sago007 2012-04-17 11:04 641
		board[0][4]=4;
c53e6443 sago007 2012-04-17 11:04 642
		board[1][4]=2;
c53e6443 sago007 2012-04-17 11:04 643
		board[2][4]=-1;
c53e6443 sago007 2012-04-17 11:04 644
		board[3][4]=0;
c53e6443 sago007 2012-04-17 11:04 645
		board[4][4]=1;
c53e6443 sago007 2012-04-17 11:04 646
		board[5][4]=-1;
c53e6443 sago007 2012-04-17 11:04 647
		break;
c53e6443 sago007 2012-04-17 11:04 648
	};
c53e6443 sago007 2012-04-17 11:04 649
}
c53e6443 sago007 2012-04-17 11:04 650
c53e6443 sago007 2012-04-17 11:04 651
//decreases hang for all hanging blocks and wait for waiting blocks
ecef5838 sago007 2015-11-24 20:01 652
void BlockGame::ReduceStuff() {
63c773dd sago007 2016-01-24 11:47 653
	int howMuchHang = (ticks - FRAMELENGTH*hangTicks)/FRAMELENGTH;
ecef5838 sago007 2015-11-24 20:01 654
	if (howMuchHang>0) {
549ecfae sago007 2016-10-09 08:37 655
		for (int i=0; i<7; i++) {
ecef5838 sago007 2015-11-24 20:01 656
			for (int j=0; j<30; j++) {
82a819c4 Poul Sander 2025-12-14 11:33 657
				if (isHanging(board[i][j])) {
82a819c4 Poul Sander 2025-12-14 11:33 658
					int hangNumber = getStepsUntilEvent(board[i][j]);
ecef5838 sago007 2015-11-24 20:01 659
					if (hangNumber<=howMuchHang) {
c53e6443 sago007 2012-04-17 11:04 660
						board[i][j]-=BLOCKHANG;
c53e6443 sago007 2012-04-17 11:04 661
						board[i][j]-=hangNumber*10;
c53e6443 sago007 2012-04-17 11:04 662
					}
ecef5838 sago007 2015-11-24 20:01 663
					else {
c53e6443 sago007 2012-04-17 11:04 664
						board[i][j]-=10*howMuchHang;
c53e6443 sago007 2012-04-17 11:04 665
					}
c53e6443 sago007 2012-04-17 11:04 666
				}
82a819c4 Poul Sander 2025-12-14 11:33 667
				if (isWaiting(board[i][j])) {
82a819c4 Poul Sander 2025-12-14 11:33 668
					int hangNumber = getStepsUntilEvent(board[i][j]);
ecef5838 sago007 2015-11-24 20:01 669
					if (hangNumber<=howMuchHang) {
c53e6443 sago007 2012-04-17 11:04 670
						//The blocks must be cleared
c53e6443 sago007 2012-04-17 11:04 671
						board[i][j]-=hangNumber*10;
c53e6443 sago007 2012-04-17 11:04 672
					}
ecef5838 sago007 2015-11-24 20:01 673
					else {
c53e6443 sago007 2012-04-17 11:04 674
						board[i][j]-=10*howMuchHang;
c53e6443 sago007 2012-04-17 11:04 675
					}
c53e6443 sago007 2012-04-17 11:04 676
				}
c53e6443 sago007 2012-04-17 11:04 677
			}
549ecfae sago007 2016-10-09 08:37 678
		}
c53e6443 sago007 2012-04-17 11:04 679
	}
c53e6443 sago007 2012-04-17 11:04 680
	hangTicks+=howMuchHang;
c53e6443 sago007 2012-04-17 11:04 681
}
c53e6443 sago007 2012-04-17 11:04 682
c53e6443 sago007 2012-04-17 11:04 683
//Creates garbage using a given wide and height
ecef5838 sago007 2015-11-24 20:01 684
bool BlockGame::CreateGarbage(int wide, int height) {
c53e6443 sago007 2012-04-17 11:04 685
	{
ecef5838 sago007 2015-11-24 20:01 686
		if (wide>6) {
ecef5838 sago007 2015-11-24 20:01 687
			wide = 6;
ecef5838 sago007 2015-11-24 20:01 688
		}
ecef5838 sago007 2015-11-24 20:01 689
		if (height>12) {
ecef5838 sago007 2015-11-24 20:01 690
			height = 12;
ecef5838 sago007 2015-11-24 20:01 691
		}
c53e6443 sago007 2012-04-17 11:04 692
		int startPosition = 12;
42c2d161 sago007 2016-04-13 19:14 693
		while ( startPosition <= 29 && !LineEmpty(startPosition)) {
c53e6443 sago007 2012-04-17 11:04 694
			startPosition++;
ecef5838 sago007 2015-11-24 20:01 695
		}
42c2d161 sago007 2016-04-13 19:14 696
		if (startPosition >= 29) {
ecef5838 sago007 2015-11-24 20:01 697
			return false;    //failed to place blocks
ecef5838 sago007 2015-11-24 20:01 698
		}
ecef5838 sago007 2015-11-24 20:01 699
		if (29-startPosition<height) {
ecef5838 sago007 2015-11-24 20:01 700
			return false;    //not enough space
ecef5838 sago007 2015-11-24 20:01 701
		}
42c2d161 sago007 2016-04-13 19:14 702
		int start = 0;
42c2d161 sago007 2016-04-13 19:14 703
		int end = 6;
ecef5838 sago007 2015-11-24 20:01 704
		if (bGarbageFallLeft) {
c53e6443 sago007 2012-04-17 11:04 705
			start=0;
c53e6443 sago007 2012-04-17 11:04 706
			end=start+wide;
c53e6443 sago007 2012-04-17 11:04 707
			bGarbageFallLeft = false;
c53e6443 sago007 2012-04-17 11:04 708
		}
ecef5838 sago007 2015-11-24 20:01 709
		else {
c53e6443 sago007 2012-04-17 11:04 710
			start=6-wide;
c53e6443 sago007 2012-04-17 11:04 711
			end = 6;
c53e6443 sago007 2012-04-17 11:04 712
			bGarbageFallLeft = true;
c53e6443 sago007 2012-04-17 11:04 713
		}
42c2d161 sago007 2016-04-13 19:14 714
		for (int i = startPosition; i <startPosition+height; i++) {
ecef5838 sago007 2015-11-24 20:01 715
			for (int j = start; j < end; j++) {
c53e6443 sago007 2012-04-17 11:04 716
				board[j][i] = 1000000+nextGarbageNumber;
c53e6443 sago007 2012-04-17 11:04 717
			}
42c2d161 sago007 2016-04-13 19:14 718
		}
c53e6443 sago007 2012-04-17 11:04 719
		nextGarbageNumber++;
ecef5838 sago007 2015-11-24 20:01 720
		if (nextGarbageNumber>999999) {
ecef5838 sago007 2015-11-24 20:01 721
			nextGarbageNumber = 10;
ecef5838 sago007 2015-11-24 20:01 722
		}
c53e6443 sago007 2012-04-17 11:04 723
		return true;
c53e6443 sago007 2012-04-17 11:04 724
	}
80b830cd sago007 2012-08-19 17:51 725
	return false;
c53e6443 sago007 2012-04-17 11:04 726
}
c53e6443 sago007 2012-04-17 11:04 727
c53e6443 sago007 2012-04-17 11:04 728
//Creates garbage using a given wide and height
ecef5838 sago007 2015-11-24 20:01 729
bool BlockGame::CreateGreyGarbage() {
ca486238 sago007 2015-08-23 15:12 730
	int startPosition = 12;
405b6531 sago007 2016-04-13 19:11 731
	while ( startPosition <= 29 && !LineEmpty(startPosition) ) {
ca486238 sago007 2015-08-23 15:12 732
		startPosition++;
ecef5838 sago007 2015-11-24 20:01 733
	}
405b6531 sago007 2016-04-13 19:11 734
	if (startPosition >= 29) {
ecef5838 sago007 2015-11-24 20:01 735
		return false;    //failed to place blocks
ecef5838 sago007 2015-11-24 20:01 736
	}
405b6531 sago007 2016-04-13 19:11 737
	int start = 0;
405b6531 sago007 2016-04-13 19:11 738
	int end = 6;
ecef5838 sago007 2015-11-24 20:01 739
	for (int i = startPosition; i <startPosition+1; i++) {
ecef5838 sago007 2015-11-24 20:01 740
		for (int j = start; j < end; j++) {
ca486238 sago007 2015-08-23 15:12 741
			board[j][i] = 2*1000000+nextGarbageNumber;
80b830cd sago007 2012-08-19 17:51 742
		}
c53e6443 sago007 2012-04-17 11:04 743
	}
ca486238 sago007 2015-08-23 15:12 744
	nextGarbageNumber++;
ecef5838 sago007 2015-11-24 20:01 745
	if (nextGarbageNumber>999999) {
ca486238 sago007 2015-08-23 15:12 746
		nextGarbageNumber = 10;
ecef5838 sago007 2015-11-24 20:01 747
	}
ca486238 sago007 2015-08-23 15:12 748
	return true;
c53e6443 sago007 2012-04-17 11:04 749
}
c53e6443 sago007 2012-04-17 11:04 750
c53e6443 sago007 2012-04-17 11:04 751
c53e6443 sago007 2012-04-17 11:04 752
//Clears garbage, must take one the lower left corner!
ecef5838 sago007 2015-11-24 20:01 753
int BlockGame::GarbageClearer(int x, int y, int number, bool aLineToClear, int chain) {
ecef5838 sago007 2015-11-24 20:01 754
	if ((board[x][y])%1000000 != number) {
ecef5838 sago007 2015-11-24 20:01 755
		return -1;
ecef5838 sago007 2015-11-24 20:01 756
	}
ecef5838 sago007 2015-11-24 20:01 757
	if (aLineToClear) {
4ce4646e Poul Sander 2024-03-27 17:45 758
		board[x][y] = this->rand2() % basicBlockVariants;
c53e6443 sago007 2012-04-17 11:04 759
		board[x][y] += 10*HANGTIME+BLOCKHANG+CHAINPLACE*chain;
c53e6443 sago007 2012-04-17 11:04 760
	}
c53e6443 sago007 2012-04-17 11:04 761
	garbageToBeCleared[x][y] = false;
c53e6443 sago007 2012-04-17 11:04 762
	GarbageClearer(x+1, y, number, aLineToClear, chain);
c53e6443 sago007 2012-04-17 11:04 763
	GarbageClearer(x, y+1, number, false, chain);
c53e6443 sago007 2012-04-17 11:04 764
	return 1;
c53e6443 sago007 2012-04-17 11:04 765
}
c53e6443 sago007 2012-04-17 11:04 766
c53e6443 sago007 2012-04-17 11:04 767
//Marks garbage that must be cleared
ecef5838 sago007 2015-11-24 20:01 768
int BlockGame::GarbageMarker(int x, int y) {
ecef5838 sago007 2015-11-24 20:01 769
	if ((x>6)||(x<0)||(y<0)||(y>29)) {
ecef5838 sago007 2015-11-24 20:01 770
		return -1;
ecef5838 sago007 2015-11-24 20:01 771
	}
ecef5838 sago007 2015-11-24 20:01 772
	if (((board[x][y])/1000000 == 1)&&(garbageToBeCleared[x][y] == false)) {
c53e6443 sago007 2012-04-17 11:04 773
		garbageToBeCleared[x][y] = true;
c53e6443 sago007 2012-04-17 11:04 774
		//Float fill
c53e6443 sago007 2012-04-17 11:04 775
		GarbageMarker(x-1, y);
c53e6443 sago007 2012-04-17 11:04 776
		GarbageMarker(x+1, y);
c53e6443 sago007 2012-04-17 11:04 777
		GarbageMarker(x, y-1);
c53e6443 sago007 2012-04-17 11:04 778
		GarbageMarker(x, y+1);
c53e6443 sago007 2012-04-17 11:04 779
	}
c53e6443 sago007 2012-04-17 11:04 780
	return 1;
c53e6443 sago007 2012-04-17 11:04 781
}
c53e6443 sago007 2012-04-17 11:04 782
ecef5838 sago007 2015-11-24 20:01 783
int BlockGame::FirstGarbageMarker(int x, int y) {
ecef5838 sago007 2015-11-24 20:01 784
	if ((x>6)||(x<0)||(y<0)||(y>29)) {
ecef5838 sago007 2015-11-24 20:01 785
		return -1;
ecef5838 sago007 2015-11-24 20:01 786
	}
ecef5838 sago007 2015-11-24 20:01 787
	if (((board[x][y])/1000000 == 2)&&(garbageToBeCleared[x][y] == false)) {
ecef5838 sago007 2015-11-24 20:01 788
		for (int i=0; i<6; i++) {
c53e6443 sago007 2012-04-17 11:04 789
			garbageToBeCleared[i][y] = true;
ecef5838 sago007 2015-11-24 20:01 790
		}
c53e6443 sago007 2012-04-17 11:04 791
	}
ecef5838 sago007 2015-11-24 20:01 792
	else if (((board[x][y])/1000000 == 1)&&(garbageToBeCleared[x][y] == false)) {
c53e6443 sago007 2012-04-17 11:04 793
		garbageToBeCleared[x][y] = true;
c53e6443 sago007 2012-04-17 11:04 794
		//Float fill
c53e6443 sago007 2012-04-17 11:04 795
		GarbageMarker(x-1, y);
c53e6443 sago007 2012-04-17 11:04 796
		GarbageMarker(x+1, y);
c53e6443 sago007 2012-04-17 11:04 797
		GarbageMarker(x, y-1);
c53e6443 sago007 2012-04-17 11:04 798
		GarbageMarker(x, y+1);
c53e6443 sago007 2012-04-17 11:04 799
	}
c53e6443 sago007 2012-04-17 11:04 800
	return 1;
c53e6443 sago007 2012-04-17 11:04 801
}
c53e6443 sago007 2012-04-17 11:04 802
c53e6443 sago007 2012-04-17 11:04 803
//Clear Blocks if 3 or more is alligned (naive implemented)
ecef5838 sago007 2015-11-24 20:01 804
void BlockGame::ClearBlocks() {
c53e6443 sago007 2012-04-17 11:04 805
c53e6443 sago007 2012-04-17 11:04 806
	bool toBeCleared[7][30]; //true if blok must be removed
c53e6443 sago007 2012-04-17 11:04 807
c53e6443 sago007 2012-04-17 11:04 808
	int previus=-1; //the last block checked
c53e6443 sago007 2012-04-17 11:04 809
	int combo=0;
c53e6443 sago007 2012-04-17 11:04 810
	for (int i=0; i<30; i++)
ecef5838 sago007 2015-11-24 20:01 811
		for (int j=0; j<7; j++) {
c53e6443 sago007 2012-04-17 11:04 812
			toBeCleared[j][i] = false;
c53e6443 sago007 2012-04-17 11:04 813
			garbageToBeCleared[j][i] = false;
c53e6443 sago007 2012-04-17 11:04 814
		}
ecef5838 sago007 2015-11-24 20:01 815
	for (int i=0; i<7; i++) {
c53e6443 sago007 2012-04-17 11:04 816
		bool faaling = false;
ecef5838 sago007 2015-11-24 20:01 817
		for (int j=0; j<30; j++) {
82a819c4 Poul Sander 2025-12-14 11:33 818
			if ((faaling)&&(board[i][j]>-1)&&(getBlockWithoutChain(board[i][j])<7)) {
1176ee18 sago007 2017-08-19 16:10 819
				block_setFalling(board[i][j], true);
c53e6443 sago007 2012-04-17 11:04 820
			}
82a819c4 Poul Sander 2025-12-14 11:33 821
			if ((!faaling)&&(block_isFalling(board[i][j]))) {
1176ee18 sago007 2017-08-19 16:10 822
				block_setFalling(board[i][j], false);
ecef5838 sago007 2015-11-24 20:01 823
			}
82a819c4 Poul Sander 2025-12-14 11:33 824
			if (!((board[i][j]>-1)&&(getBlockWithoutChain(board[i][j])<7))) {
c53e6443 sago007 2012-04-17 11:04 825
				faaling=true;
ecef5838 sago007 2015-11-24 20:01 826
			}
82a819c4 Poul Sander 2025-12-14 11:33 827
			if ((getBlockGarbage(board[i][j])==GARBAGE_NORMAL)||(getBlockGarbage(board[i][j])==GARBAGE_GRAY)||isHanging(board[i][j])||isWaiting(board[i][j])) {
c53e6443 sago007 2012-04-17 11:04 828
				faaling = false;
ecef5838 sago007 2015-11-24 20:01 829
			}
c53e6443 sago007 2012-04-17 11:04 830
		}
c53e6443 sago007 2012-04-17 11:04 831
	}
c53e6443 sago007 2012-04-17 11:04 832
c53e6443 sago007 2012-04-17 11:04 833
ecef5838 sago007 2015-11-24 20:01 834
	for (int j=0; j<7; j++) {
c53e6443 sago007 2012-04-17 11:04 835
		previus = -1;
c53e6443 sago007 2012-04-17 11:04 836
		combo=0;
c53e6443 sago007 2012-04-17 11:04 837
ecef5838 sago007 2015-11-24 20:01 838
		for (int i=1; i<30; i++) {
82a819c4 Poul Sander 2025-12-14 11:33 839
			if ((board[j][i]>-1)&&(getBlockWithoutChain(board[j][i])<7)) {
82a819c4 Poul Sander 2025-12-14 11:33 840
				if (getBlockWithoutChain(board[j][i]) == previus) {
c53e6443 sago007 2012-04-17 11:04 841
					combo++;
c53e6443 sago007 2012-04-17 11:04 842
				}
ecef5838 sago007 2015-11-24 20:01 843
				else {
549ecfae sago007 2016-10-09 08:37 844
					if (combo>2) {
ecef5838 sago007 2015-11-24 20:01 845
						for (int k = i-combo; k<i; k++) {
c53e6443 sago007 2012-04-17 11:04 846
							toBeCleared[j][k] = true;
c53e6443 sago007 2012-04-17 11:04 847
						}
549ecfae sago007 2016-10-09 08:37 848
					}
c53e6443 sago007 2012-04-17 11:04 849
					combo=1;
82a819c4 Poul Sander 2025-12-14 11:33 850
					previus = getBlockWithoutChain(board[j][i]);
c53e6443 sago007 2012-04-17 11:04 851
				}
c53e6443 sago007 2012-04-17 11:04 852
			} //if board
ecef5838 sago007 2015-11-24 20:01 853
			else {
549ecfae sago007 2016-10-09 08:37 854
				if (combo>2) {
ecef5838 sago007 2015-11-24 20:01 855
					for (int k = i-combo; k<i; k++) {
c53e6443 sago007 2012-04-17 11:04 856
						toBeCleared[j][k] = true;
c53e6443 sago007 2012-04-17 11:04 857
					}
549ecfae sago007 2016-10-09 08:37 858
				}
c53e6443 sago007 2012-04-17 11:04 859
				combo = 0;
c53e6443 sago007 2012-04-17 11:04 860
				previus = -1;
c53e6443 sago007 2012-04-17 11:04 861
			}
c53e6443 sago007 2012-04-17 11:04 862
c53e6443 sago007 2012-04-17 11:04 863
		} //for i
c53e6443 sago007 2012-04-17 11:04 864
	} //for j
c53e6443 sago007 2012-04-17 11:04 865
c53e6443 sago007 2012-04-17 11:04 866
	chain = 0;
549ecfae sago007 2016-10-09 08:37 867
	for (int i=0; i<6; i++) {
ecef5838 sago007 2015-11-24 20:01 868
		for (int j=0; j<30; j++) {
c53e6443 sago007 2012-04-17 11:04 869
			//Clears blocks marked for clearing
63c773dd sago007 2016-01-24 11:47 870
			int temp=board[i][j];
82a819c4 Poul Sander 2025-12-14 11:33 871
			if (isWaiting(temp)) {
82a819c4 Poul Sander 2025-12-14 11:33 872
				if (getStepsUntilEvent(temp)==0) {
82a819c4 Poul Sander 2025-12-14 11:33 873
					if (chainSize[chain]<chainSize[getBlockChain(board[i][j])]) {
82a819c4 Poul Sander 2025-12-14 11:33 874
						chain = getBlockChain(board[i][j]);
ecef5838 sago007 2015-11-24 20:01 875
					}
c53e6443 sago007 2012-04-17 11:04 876
82a819c4 Poul Sander 2025-12-14 11:33 877
					AddBall(i, j, true, getBlockColor(board[i][j]));
82a819c4 Poul Sander 2025-12-14 11:33 878
					AddBall(i, j, false, getBlockColor(board[i][j]));
229e212d sago007 2015-08-22 17:14 879
					AddExplosion(i, j);
c53e6443 sago007 2012-04-17 11:04 880
					board[i][j]=-2;
c53e6443 sago007 2012-04-17 11:04 881
				}
549ecfae sago007 2016-10-09 08:37 882
			}
c53e6443 sago007 2012-04-17 11:04 883
		}
549ecfae sago007 2016-10-09 08:37 884
	}
ecef5838 sago007 2015-11-24 20:01 885
	for (int i=0; i<7; i++) {
c53e6443 sago007 2012-04-17 11:04 886
		bool setChain=false;
ecef5838 sago007 2015-11-24 20:01 887
		for (int j=0; j<30; j++) {
ecef5838 sago007 2015-11-24 20:01 888
			if (board[i][j]==-1) {
c53e6443 sago007 2012-04-17 11:04 889
				setChain=false;
ecef5838 sago007 2015-11-24 20:01 890
			}
ecef5838 sago007 2015-11-24 20:01 891
			if (board[i][j]==-2) {
c53e6443 sago007 2012-04-17 11:04 892
				board[i][j]=-1;
c53e6443 sago007 2012-04-17 11:04 893
				setChain=true;
313ecd1b sago007 2015-08-22 20:38 894
				BlockPopEvent();
c53e6443 sago007 2012-04-17 11:04 895
			}
549ecfae sago007 2016-10-09 08:37 896
			if (board[i][j]!=-1) {
82a819c4 Poul Sander 2025-12-14 11:33 897
				if ((setChain)&&(getBlockGarbage(board[i][j])!=GARBAGE_NORMAL)&&(getBlockGarbage(board[i][j])!=GARBAGE_GRAY)) {
82a819c4 Poul Sander 2025-12-14 11:33 898
					board[i][j]=((getBlockWithoutChain(board[i][j]))+CHAINPLACE*chain);
c53e6443 sago007 2012-04-17 11:04 899
				}
549ecfae sago007 2016-10-09 08:37 900
			}
c53e6443 sago007 2012-04-17 11:04 901
		}
c53e6443 sago007 2012-04-17 11:04 902
	}
c53e6443 sago007 2012-04-17 11:04 903
	int startvalue;
ecef5838 sago007 2015-11-24 20:01 904
	if (pixels == 0) {
c53e6443 sago007 2012-04-17 11:04 905
		startvalue=1;
ecef5838 sago007 2015-11-24 20:01 906
	}
ecef5838 sago007 2015-11-24 20:01 907
	else {
c53e6443 sago007 2012-04-17 11:04 908
		startvalue=0;
ecef5838 sago007 2015-11-24 20:01 909
	}
ecef5838 sago007 2015-11-24 20:01 910
	for (int i=startvalue; i<30; i++) {
c53e6443 sago007 2012-04-17 11:04 911
		previus=-1;
c53e6443 sago007 2012-04-17 11:04 912
		combo=0;
ecef5838 sago007 2015-11-24 20:01 913
		for (int j=0; j<7; j++) {
82a819c4 Poul Sander 2025-12-14 11:33 914
			if (((board[j][i]>-1)&&(getBlockWithoutChain(board[j][i])<7))) {
82a819c4 Poul Sander 2025-12-14 11:33 915
				if (getBlockWithoutChain(board[j][i]) == previus) {
c53e6443 sago007 2012-04-17 11:04 916
					combo++;
c53e6443 sago007 2012-04-17 11:04 917
				}
ecef5838 sago007 2015-11-24 20:01 918
				else {
b539639c sago007 2015-12-29 11:51 919
					if (combo>2) {
ecef5838 sago007 2015-11-24 20:01 920
						for (int k = j-combo; k<j; k++) {
c53e6443 sago007 2012-04-17 11:04 921
							toBeCleared[k][i] = true;
c53e6443 sago007 2012-04-17 11:04 922
						}
b539639c sago007 2015-12-29 11:51 923
					}
c53e6443 sago007 2012-04-17 11:04 924
					combo=1;
82a819c4 Poul Sander 2025-12-14 11:33 925
					previus = getBlockWithoutChain(board[j][i]);
c53e6443 sago007 2012-04-17 11:04 926
				}
c53e6443 sago007 2012-04-17 11:04 927
			} //if board
ecef5838 sago007 2015-11-24 20:01 928
			else {
b539639c sago007 2015-12-29 11:51 929
				if (combo>2) {
ecef5838 sago007 2015-11-24 20:01 930
					for (int k = j-combo; k<j; k++) {
c53e6443 sago007 2012-04-17 11:04 931
						toBeCleared[k][i] = true;
c53e6443 sago007 2012-04-17 11:04 932
					}
b539639c sago007 2015-12-29 11:51 933
				}
c53e6443 sago007 2012-04-17 11:04 934
				combo = 0;
c53e6443 sago007 2012-04-17 11:04 935
				previus = -1;
c53e6443 sago007 2012-04-17 11:04 936
			}
c53e6443 sago007 2012-04-17 11:04 937
c53e6443 sago007 2012-04-17 11:04 938
		} //for j
c53e6443 sago007 2012-04-17 11:04 939
	} //for i
c53e6443 sago007 2012-04-17 11:04 940
c53e6443 sago007 2012-04-17 11:04 941
	combo = 0;
c53e6443 sago007 2012-04-17 11:04 942
	chain = 0;
c53e6443 sago007 2012-04-17 11:04 943
	int grey = 0;
b539639c sago007 2015-12-29 11:51 944
	for (int i=0; i<30; i++) {
b539639c sago007 2015-12-29 11:51 945
		for (int j=0; j<6; j++) {
ecef5838 sago007 2015-11-24 20:01 946
			if (toBeCleared[j][i]) {
c53e6443 sago007 2012-04-17 11:04 947
				//see if any garbage is around:
c53e6443 sago007 2012-04-17 11:04 948
				FirstGarbageMarker(j-1, i);
c53e6443 sago007 2012-04-17 11:04 949
				FirstGarbageMarker(j+1, i);
c53e6443 sago007 2012-04-17 11:04 950
				FirstGarbageMarker(j, i-1);
c53e6443 sago007 2012-04-17 11:04 951
				FirstGarbageMarker(j, i+1);
c53e6443 sago007 2012-04-17 11:04 952
				//that is checked now :-)
82a819c4 Poul Sander 2025-12-14 11:33 953
				if (getBlockWithoutChain(board[j][i])==6) {
c53e6443 sago007 2012-04-17 11:04 954
					grey++;
ecef5838 sago007 2015-11-24 20:01 955
				}
82a819c4 Poul Sander 2025-12-14 11:33 956
				if ((vsMode) && (grey>2) && (getBlockWithoutChain(board[j][i])==6)) {
3d12f4a8 sago007 2016-03-21 18:40 957
					GarbageStruct s;
3d12f4a8 sago007 2016-03-21 18:40 958
					s.setGarbage(6, 1, true);
3d12f4a8 sago007 2016-03-21 18:40 959
					this->garbageSendQueue.push_back(s);
ecef5838 sago007 2015-11-24 20:01 960
				}
82a819c4 Poul Sander 2025-12-14 11:33 961
				if ((board[j][i]>-1)&&(getBlockWithoutChain(board[j][i])<7)) {
c53e6443 sago007 2012-04-17 11:04 962
					board[j][i]+=BLOCKWAIT+10*FALLTIME;
ecef5838 sago007 2015-11-24 20:01 963
				}
c53e6443 sago007 2012-04-17 11:04 964
82a819c4 Poul Sander 2025-12-14 11:33 965
				if (chainSize[getBlockChain(board[j][i])]>chainSize[chain]) {
82a819c4 Poul Sander 2025-12-14 11:33 966
					chain=getBlockChain(board[j][i]);
ecef5838 sago007 2015-11-24 20:01 967
				}
c53e6443 sago007 2012-04-17 11:04 968
				combo++;
c53e6443 sago007 2012-04-17 11:04 969
				stop+=140*combo;
c53e6443 sago007 2012-04-17 11:04 970
				score +=10;
ecef5838 sago007 2015-11-24 20:01 971
				if (combo>3) {
ecef5838 sago007 2015-11-24 20:01 972
					score+=3*combo;    //More points if more cleared simontanously
ecef5838 sago007 2015-11-24 20:01 973
				}
c53e6443 sago007 2012-04-17 11:04 974
			}
b539639c sago007 2015-12-29 11:51 975
		}
b539639c sago007 2015-12-29 11:51 976
	}
c53e6443 sago007 2012-04-17 11:04 977
	score+=chainSize[chain]*100;
ecef5838 sago007 2015-11-24 20:01 978
	if (chain==0) {
c53e6443 sago007 2012-04-17 11:04 979
		chain=firstUnusedChain();
c53e6443 sago007 2012-04-17 11:04 980
		chainSize[chain]=0;
c53e6443 sago007 2012-04-17 11:04 981
		chainUsed[chain]=true;
c53e6443 sago007 2012-04-17 11:04 982
	}
c53e6443 sago007 2012-04-17 11:04 983
	chainSize[chain]++;
b539639c sago007 2015-12-29 11:51 984
	for (int i=0; i<30; i++) {
ecef5838 sago007 2015-11-24 20:01 985
		for (int j=0; j<6; j++) {
ecef5838 sago007 2015-11-24 20:01 986
			if (toBeCleared[j][i]) {
82a819c4 Poul Sander 2025-12-14 11:33 987
				board[j][i]=(getBlockWithoutChain(board[j][i]))+chain*CHAINPLACE;
c53e6443 sago007 2012-04-17 11:04 988
			}
c53e6443 sago007 2012-04-17 11:04 989
		}
b539639c sago007 2015-12-29 11:51 990
	}
c53e6443 sago007 2012-04-17 11:04 991
c53e6443 sago007 2012-04-17 11:04 992
	{
c53e6443 sago007 2012-04-17 11:04 993
		//This is here we add text to screen!
c53e6443 sago007 2012-04-17 11:04 994
		bool dead = false;
b539639c sago007 2015-12-29 11:51 995
		for (int i=29; i>=0; i--) {
b539639c sago007 2015-12-29 11:51 996
			for (int j=0; j<6; j++) {
ecef5838 sago007 2015-11-24 20:01 997
				if (toBeCleared[j][i]) {
ecef5838 sago007 2015-11-24 20:01 998
					if (!dead) {
c53e6443 sago007 2012-04-17 11:04 999
						dead=true;
229e212d sago007 2015-08-22 17:14 1000
						if (chainSize[chain]>1) {
3f3ff0b6 sago007 2018-03-30 12:59 1001
							AddText(j, i, chainSize[chain], 1000);
229e212d sago007 2015-08-22 17:14 1002
						}
c53e6443 sago007 2012-04-17 11:04 1003
					}
c53e6443 sago007 2012-04-17 11:04 1004
				}
b539639c sago007 2015-12-29 11:51 1005
			}
b539639c sago007 2015-12-29 11:51 1006
		}
c53e6443 sago007 2012-04-17 11:04 1007
	} //This was there text was added
c53e6443 sago007 2012-04-17 11:04 1008
3d12f4a8 sago007 2016-03-21 18:40 1009
	if (vsMode) {
3d12f4a8 sago007 2016-03-21 18:40 1010
		GarbageStruct s;
ecef5838 sago007 2015-11-24 20:01 1011
		switch (combo) {
c53e6443 sago007 2012-04-17 11:04 1012
		case 0:
c53e6443 sago007 2012-04-17 11:04 1013
		case 1:
c53e6443 sago007 2012-04-17 11:04 1014
		case 2:
c53e6443 sago007 2012-04-17 11:04 1015
		case 3:
c53e6443 sago007 2012-04-17 11:04 1016
			break;
c53e6443 sago007 2012-04-17 11:04 1017
		case 4:
3d12f4a8 sago007 2016-03-21 18:40 1018
			s.setGarbage(3,1);
c53e6443 sago007 2012-04-17 11:04 1019
			break;
c53e6443 sago007 2012-04-17 11:04 1020
		case 5:
3d12f4a8 sago007 2016-03-21 18:40 1021
			s.setGarbage(4,1);
c53e6443 sago007 2012-04-17 11:04 1022
			break;
c53e6443 sago007 2012-04-17 11:04 1023
		case 6:
3d12f4a8 sago007 2016-03-21 18:40 1024
			s.setGarbage(5,1);
c53e6443 sago007 2012-04-17 11:04 1025
			break;
c53e6443 sago007 2012-04-17 11:04 1026
		case 7:
3d12f4a8 sago007 2016-03-21 18:40 1027
			s.setGarbage(6,1);
c53e6443 sago007 2012-04-17 11:04 1028
			break;
c53e6443 sago007 2012-04-17 11:04 1029
		case 8:
3d12f4a8 sago007 2016-03-21 18:40 1030
			s.setGarbage(4,1);
3d12f4a8 sago007 2016-03-21 18:40 1031
			s.setGarbage(4,1);
c53e6443 sago007 2012-04-17 11:04 1032
			break;
c53e6443 sago007 2012-04-17 11:04 1033
		case 9:
3d12f4a8 sago007 2016-03-21 18:40 1034
			s.setGarbage(5,1);
3d12f4a8 sago007 2016-03-21 18:40 1035
			s.setGarbage(4,1);
c53e6443 sago007 2012-04-17 11:04 1036
			break;
c53e6443 sago007 2012-04-17 11:04 1037
		case 10:
3d12f4a8 sago007 2016-03-21 18:40 1038
			s.setGarbage(5,1);
3d12f4a8 sago007 2016-03-21 18:40 1039
			s.setGarbage(5,1);
c53e6443 sago007 2012-04-17 11:04 1040
			break;
c53e6443 sago007 2012-04-17 11:04 1041
		case 11:
3d12f4a8 sago007 2016-03-21 18:40 1042
			s.setGarbage(6,1);
3d12f4a8 sago007 2016-03-21 18:40 1043
			s.setGarbage(5,1);
c53e6443 sago007 2012-04-17 11:04 1044
			break;
c53e6443 sago007 2012-04-17 11:04 1045
		case 12:
3d12f4a8 sago007 2016-03-21 18:40 1046
			s.setGarbage(6,1);
3d12f4a8 sago007 2016-03-21 18:40 1047
			s.setGarbage(6,1);
c53e6443 sago007 2012-04-17 11:04 1048
			break;
c53e6443 sago007 2012-04-17 11:04 1049
		case 13:
3d12f4a8 sago007 2016-03-21 18:40 1050
			s.setGarbage(5,1);
3d12f4a8 sago007 2016-03-21 18:40 1051
			s.setGarbage(5,1);
3d12f4a8 sago007 2016-03-21 18:40 1052
			s.setGarbage(4,1);
c53e6443 sago007 2012-04-17 11:04 1053
			break;
c53e6443 sago007 2012-04-17 11:04 1054
		default:
3d12f4a8 sago007 2016-03-21 18:40 1055
			s.setGarbage(5,1);
3d12f4a8 sago007 2016-03-21 18:40 1056
			s.setGarbage(5,1);
3d12f4a8 sago007 2016-03-21 18:40 1057
			s.setGarbage(4,1);
c53e6443 sago007 2012-04-17 11:04 1058
			break;
c53e6443 sago007 2012-04-17 11:04 1059
		}
3d12f4a8 sago007 2016-03-21 18:40 1060
		if (s.width > 0) {
3d12f4a8 sago007 2016-03-21 18:40 1061
			garbageSendQueue.push_back(s);
3d12f4a8 sago007 2016-03-21 18:40 1062
		}
3d12f4a8 sago007 2016-03-21 18:40 1063
	}
3d12f4a8 sago007 2016-03-21 18:40 1064
	for (int i=0; i<30; i++) {
3d12f4a8 sago007 2016-03-21 18:40 1065
		for (int j=0; j<6; j++) {
ecef5838 sago007 2015-11-24 20:01 1066
			if (garbageToBeCleared[j][i]) {
82a819c4 Poul Sander 2025-12-14 11:33 1067
				GarbageClearer(j, i, getBlockWithoutChain(board[j][i]) % 1000, true, chain); //Clears the blocks and all blocks connected to it.
c53e6443 sago007 2012-04-17 11:04 1068
			}
3d12f4a8 sago007 2016-03-21 18:40 1069
		}
3d12f4a8 sago007 2016-03-21 18:40 1070
	}
c53e6443 sago007 2012-04-17 11:04 1071
c53e6443 sago007 2012-04-17 11:04 1072
	chain=0;
c53e6443 sago007 2012-04-17 11:04 1073
c53e6443 sago007 2012-04-17 11:04 1074
	//Break chains (if a block is stable it is resetted to (chain == 0)):
ecef5838 sago007 2015-11-24 20:01 1075
	for (int i=0; i<7; i++) {
c53e6443 sago007 2012-04-17 11:04 1076
		bool faaling = false;  //In the beginning we are NOT falling
ecef5838 sago007 2015-11-24 20:01 1077
		for (int j=0; j<30; j++) {
ecef5838 sago007 2015-11-24 20:01 1078
			if ((faaling)&&(board[i][j]>-1)&&(board[i][j]<7)) {
1176ee18 sago007 2017-08-19 16:10 1079
				block_setFalling(board[i][j], true);
c53e6443 sago007 2012-04-17 11:04 1080
			}
1176ee18 sago007 2017-08-19 16:10 1081
			if (!faaling) {
1176ee18 sago007 2017-08-19 16:10 1082
				block_setFalling(board[i][j], false);
ecef5838 sago007 2015-11-24 20:01 1083
			}
82a819c4 Poul Sander 2025-12-14 11:33 1084
			if ((!faaling)&&(board[i][j]>0)&&(getBlockChain(board[i][j])!=0)&&!isWaiting(board[i][j])&&!isHanging(board[i][j])) {
82a819c4 Poul Sander 2025-12-14 11:33 1085
				if (chainSize[getBlockChain(board[i][j])]>chainSize[chain]) {
82a819c4 Poul Sander 2025-12-14 11:33 1086
					chain=getBlockChain(board[i][j]);
ecef5838 sago007 2015-11-24 20:01 1087
				}
82a819c4 Poul Sander 2025-12-14 11:33 1088
				board[i][j]=getBlockWithoutChain(board[i][j]);
c53e6443 sago007 2012-04-17 11:04 1089
			}
ecef5838 sago007 2015-11-24 20:01 1090
			if (!((board[i][j]>-1)&&(board[i][j]<7))) {
c53e6443 sago007 2012-04-17 11:04 1091
				faaling=true;
ecef5838 sago007 2015-11-24 20:01 1092
			}
82a819c4 Poul Sander 2025-12-14 11:33 1093
			if ((getBlockGarbage(board[i][j])==GARBAGE_NORMAL)||isHanging(board[i][j])||isWaiting(board[i][j])) {
c53e6443 sago007 2012-04-17 11:04 1094
				faaling = false;
ecef5838 sago007 2015-11-24 20:01 1095
			}
c53e6443 sago007 2012-04-17 11:04 1096
		}
c53e6443 sago007 2012-04-17 11:04 1097
	}
c53e6443 sago007 2012-04-17 11:04 1098
c53e6443 sago007 2012-04-17 11:04 1099
	//Calculate chain
c53e6443 sago007 2012-04-17 11:04 1100
	chain=0;
b539639c sago007 2015-12-29 11:51 1101
	for (int i=0; i<6; i++) {
ecef5838 sago007 2015-11-24 20:01 1102
		for (int j=0; j<30; j++) {
82a819c4 Poul Sander 2025-12-14 11:33 1103
			if (chainSize[getBlockChain(board[i][j])]>chain) {
82a819c4 Poul Sander 2025-12-14 11:33 1104
				chain=chainSize[getBlockChain(board[i][j])];
ecef5838 sago007 2015-11-24 20:01 1105
			}
c53e6443 sago007 2012-04-17 11:04 1106
		}
b539639c sago007 2015-12-29 11:51 1107
	}
c53e6443 sago007 2012-04-17 11:04 1108
c53e6443 sago007 2012-04-17 11:04 1109
	//Make space in table for more things
b539639c sago007 2015-12-29 11:51 1110
	if (chain==0) {
b539639c sago007 2015-12-29 11:51 1111
		for (int i=0; i<NUMBEROFCHAINS; i++) {
ecef5838 sago007 2015-11-24 20:01 1112
			if (chainUsed[i]==true) {
ecef5838 sago007 2015-11-24 20:01 1113
				if ((vsMode)&&(chainSize[i]>1)) {
3d12f4a8 sago007 2016-03-21 18:40 1114
					GarbageStruct s;
3d12f4a8 sago007 2016-03-21 18:40 1115
					s.setGarbage(6,chainSize[i]-1);
3d12f4a8 sago007 2016-03-21 18:40 1116
					this->garbageSendQueue.push_back(s);
ecef5838 sago007 2015-11-24 20:01 1117
				}
313ecd1b sago007 2015-08-22 20:38 1118
				if (chainSize[i]>4) {
313ecd1b sago007 2015-08-22 20:38 1119
					LongChainDoneEvent();
313ecd1b sago007 2015-08-22 20:38 1120
				}
50cf6485 sago007 2016-03-21 19:11 1121
				if (chainSize[i]>1 && !puzzleMode && recordStats) {
f10b1d3c Poul Sander 2020-08-08 17:34 1122
					Stats::getInstance()->addOne((std::string)"chainX"+std::to_string(chainSize[i]));
ecef5838 sago007 2015-11-24 20:01 1123
				}
c53e6443 sago007 2012-04-17 11:04 1124
				chainUsed[i]=false;
c53e6443 sago007 2012-04-17 11:04 1125
			}
b539639c sago007 2015-12-29 11:51 1126
		}
b539639c sago007 2015-12-29 11:51 1127
	}
c53e6443 sago007 2012-04-17 11:04 1128
} //ClearBlocks
c53e6443 sago007 2012-04-17 11:04 1129
c53e6443 sago007 2012-04-17 11:04 1130
//prints "Game Over" and ends game
ecef5838 sago007 2015-11-24 20:01 1131
void BlockGame::SetGameOver() {
ca486238 sago007 2015-08-23 15:12 1132
	if (!bGameOver) {
c53e6443 sago007 2012-04-17 11:04 1133
		gameEndedAfter = ticks-gameStartedAt; //We game ends now!
50cf6485 sago007 2016-03-21 19:11 1134
		if (recordStats) {
17916a2e sago007 2010-11-07 11:26 1135
			TimeHandler::addTime("playTime",TimeHandler::ms2ct(gameEndedAfter));
17916a2e sago007 2010-11-07 11:26 1136
		}
1fd8156c sago007 2016-06-07 16:41 1137
		FinalizeBlockGameInfo();
17916a2e sago007 2010-11-07 11:26 1138
	}
c53e6443 sago007 2012-04-17 11:04 1139
	bGameOver = true;
ecef5838 sago007 2015-11-24 20:01 1140
	if (stageClear) {
c53e6443 sago007 2012-04-17 11:04 1141
		stageButtonStatus = SBstageClear;
ecef5838 sago007 2015-11-24 20:01 1142
	}
c53e6443 sago007 2012-04-17 11:04 1143
}
c53e6443 sago007 2012-04-17 11:04 1144
6b5b6bf4 sago007 2016-02-21 15:30 1145
bool BlockGame::GetAIenabled() const {
c53e6443 sago007 2012-04-17 11:04 1146
	return AI_Enabled;
c53e6443 sago007 2012-04-17 11:04 1147
}
c53e6443 sago007 2012-04-17 11:04 1148
c53e6443 sago007 2012-04-17 11:04 1149
c53e6443 sago007 2012-04-17 11:04 1150
//Moves all peaces a spot down if possible
ecef5838 sago007 2015-11-24 20:01 1151
int BlockGame::FallBlock(int x, int y, int number) {
ecef5838 sago007 2015-11-24 20:01 1152
	if (y == 0) {
ecef5838 sago007 2015-11-24 20:01 1153
		return -1;
ecef5838 sago007 2015-11-24 20:01 1154
	}
b539639c sago007 2015-12-29 11:51 1155
	if (x>0) {
ecef5838 sago007 2015-11-24 20:01 1156
		if (board[x-1][y] == number) {
c53e6443 sago007 2012-04-17 11:04 1157
			return -1;
ecef5838 sago007 2015-11-24 20:01 1158
		}
b539639c sago007 2015-12-29 11:51 1159
	}
c53e6443 sago007 2012-04-17 11:04 1160
	int i=x;
c53e6443 sago007 2012-04-17 11:04 1161
	bool canFall = true;
c53e6443 sago007 2012-04-17 11:04 1162
	//checks a line of a garbage block and see if something is under it
ecef5838 sago007 2015-11-24 20:01 1163
	while ((board[i][y] == number)&&(canFall)&&(i<6)) {
ecef5838 sago007 2015-11-24 20:01 1164
		if (board[i][y-1] != -1) {
ecef5838 sago007 2015-11-24 20:01 1165
			canFall = false;
ecef5838 sago007 2015-11-24 20:01 1166
		}
c53e6443 sago007 2012-04-17 11:04 1167
		i++;
c53e6443 sago007 2012-04-17 11:04 1168
	}
ecef5838 sago007 2015-11-24 20:01 1169
	if (canFall) {
161a010c sago007 2016-05-06 14:00 1170
		//cout << "Now falling" << "\n";
ecef5838 sago007 2015-11-24 20:01 1171
		for (int j = x; j<i; j++) {
c53e6443 sago007 2012-04-17 11:04 1172
			board[j][y-1] = board[j][y];
c53e6443 sago007 2012-04-17 11:04 1173
			board[j][y] = -1;
c53e6443 sago007 2012-04-17 11:04 1174
		}
c53e6443 sago007 2012-04-17 11:04 1175
	}
c53e6443 sago007 2012-04-17 11:04 1176
	return 0;
ecef5838 sago007 2015-11-24 20:01 1177
}   //FallBlock
c53e6443 sago007 2012-04-17 11:04 1178
c53e6443 sago007 2012-04-17 11:04 1179
c53e6443 sago007 2012-04-17 11:04 1180
//Makes all Garbage fall one spot
ecef5838 sago007 2015-11-24 20:01 1181
void BlockGame::GarbageFall() {
b539639c sago007 2015-12-29 11:51 1182
	for (int i=0; i<30; i++) {
ecef5838 sago007 2015-11-24 20:01 1183
		for (int j=0; j<7; j++) {
82a819c4 Poul Sander 2025-12-14 11:33 1184
			if ((getBlockGarbage(board[j][i]) == GARBAGE_NORMAL)||(getBlockGarbage(board[j][i]) == GARBAGE_GRAY)) {
c53e6443 sago007 2012-04-17 11:04 1185
				FallBlock(j, i, board[j][i]);
ecef5838 sago007 2015-11-24 20:01 1186
			}
c53e6443 sago007 2012-04-17 11:04 1187
		}
b539639c sago007 2015-12-29 11:51 1188
	}
c53e6443 sago007 2012-04-17 11:04 1189
}
c53e6443 sago007 2012-04-17 11:04 1190
c53e6443 sago007 2012-04-17 11:04 1191
//Makes the blocks fall (it doesn't test time, this must be done before hand)
ecef5838 sago007 2015-11-24 20:01 1192
void BlockGame::FallDown() {
c53e6443 sago007 2012-04-17 11:04 1193
	bool falling =false;        //nothing is moving unless proven otherwise
b539639c sago007 2015-12-29 11:51 1194
	for (int i=0; i<29; i++) {
ecef5838 sago007 2015-11-24 20:01 1195
		for (int j=0; j<6; j++) {
82a819c4 Poul Sander 2025-12-14 11:33 1196
			if ((board[j][i]==-1) && (board[j][i+1]!=-1) && (getBlockWithoutChain(board[j][i+1]) % BLOCKFALL<7)) {
c53e6443 sago007 2012-04-17 11:04 1197
				board[j][i] = board[j][i+1];
c53e6443 sago007 2012-04-17 11:04 1198
				board[j][i+1] = -1;
c53e6443 sago007 2012-04-17 11:04 1199
				falling = true;              //something is moving!
c53e6443 sago007 2012-04-17 11:04 1200
			}
82a819c4 Poul Sander 2025-12-14 11:33 1201
			if (isWaiting(board[j][i])) {
c53e6443 sago007 2012-04-17 11:04 1202
				falling=true;
ecef5838 sago007 2015-11-24 20:01 1203
			}
c53e6443 sago007 2012-04-17 11:04 1204
		}
b539639c sago007 2015-12-29 11:51 1205
	}
ecef5838 sago007 2015-11-24 20:01 1206
	if (!falling) { //If nothing is falling
ecef5838 sago007 2015-11-24 20:01 1207
		if ((puzzleMode)&&(!bGameOver)&&(MovesLeft==0)&&(!(BoardEmpty()))) {
c53e6443 sago007 2012-04-17 11:04 1208
			//Puzzle not won
c53e6443 sago007 2012-04-17 11:04 1209
			SetGameOver();
c53e6443 sago007 2012-04-17 11:04 1210
			stageButtonStatus = SBpuzzleMode;
c53e6443 sago007 2012-04-17 11:04 1211
		}
c53e6443 sago007 2012-04-17 11:04 1212
	}
ecef5838 sago007 2015-11-24 20:01 1213
	GarbageFall();      //Makes the garbage fall
c53e6443 sago007 2012-04-17 11:04 1214
	nrFellDown++;      //Sets number of this fall, so we know then the next will occur
c53e6443 sago007 2012-04-17 11:04 1215
}
c53e6443 sago007 2012-04-17 11:04 1216
c53e6443 sago007 2012-04-17 11:04 1217
//Moves the cursor, receaves N,S,E or W as a char an moves as desired
ecef5838 sago007 2015-11-24 20:01 1218
void BlockGame::MoveCursor(char way) {
ecef5838 sago007 2015-11-24 20:01 1219
	if (!bGameOver) {     //If game over nothing happends
ecef5838 sago007 2015-11-24 20:01 1220
		if ((way == 'N') && ((cursory<10)||(TowerHeight>12) ||(((pixels==bsize)||(pixels==0)) && (cursory<11)))) {
c53e6443 sago007 2012-04-17 11:04 1221
			cursory++;
ecef5838 sago007 2015-11-24 20:01 1222
		}
ecef5838 sago007 2015-11-24 20:01 1223
		if ((way == 'S') && (cursory>0)) {
c53e6443 sago007 2012-04-17 11:04 1224
			cursory--;
ecef5838 sago007 2015-11-24 20:01 1225
		}
ecef5838 sago007 2015-11-24 20:01 1226
		if ((way == 'W') && (cursorx>0)) {
c53e6443 sago007 2012-04-17 11:04 1227
			cursorx--;
ecef5838 sago007 2015-11-24 20:01 1228
		}
ecef5838 sago007 2015-11-24 20:01 1229
		if ((way == 'E') && (cursorx<4)) {
c53e6443 sago007 2012-04-17 11:04 1230
			cursorx++;
ecef5838 sago007 2015-11-24 20:01 1231
		}
c53e6443 sago007 2012-04-17 11:04 1232
	}
c53e6443 sago007 2012-04-17 11:04 1233
}
c53e6443 sago007 2012-04-17 11:04 1234
c53e6443 sago007 2012-04-17 11:04 1235
//switches the two blocks at the cursor position, unless game over
ecef5838 sago007 2015-11-24 20:01 1236
void BlockGame::SwitchAtCursor() {
ce444d3b sago007 2016-04-02 18:59 1237
	if (bGameOver) {
ce444d3b sago007 2016-04-02 18:59 1238
		return;
ce444d3b sago007 2016-04-02 18:59 1239
	}
ce444d3b sago007 2016-04-02 18:59 1240
	ClearBlocks();  //Ensure that everything that floats are marked as floating
ce444d3b sago007 2016-04-02 18:59 1241
	if ((board[cursorx][cursory+1]<7) && (board[cursorx+1][cursory+1]<7) && ((!puzzleMode)||(MovesLeft>0)) && (gameStartedAt<ticks)) {
c53e6443 sago007 2012-04-17 11:04 1242
		int temp = board[cursorx][cursory+1];
c53e6443 sago007 2012-04-17 11:04 1243
		board[cursorx][cursory+1] = board[cursorx+1][cursory+1];
c53e6443 sago007 2012-04-17 11:04 1244
		board[cursorx+1][cursory+1] = temp;
c53e6443 sago007 2012-04-17 11:04 1245
	}
ecef5838 sago007 2015-11-24 20:01 1246
	if ((puzzleMode)&&(gameStartedAt<ticks)&&(MovesLeft>0)) {
ecef5838 sago007 2015-11-24 20:01 1247
		MovesLeft--;
ecef5838 sago007 2015-11-24 20:01 1248
	}
c53e6443 sago007 2012-04-17 11:04 1249
}
c53e6443 sago007 2012-04-17 11:04 1250
ecef5838 sago007 2015-11-24 20:01 1251
void BlockGame::PushLine() {
79d3c1d3 sago007 2012-05-05 15:54 1252
	PushLineInternal();
79d3c1d3 sago007 2012-05-05 15:54 1253
}
79d3c1d3 sago007 2012-05-05 15:54 1254
79d3c1d3 sago007 2012-05-05 15:54 1255
//Generates a new line and moves the field one block up (restart puzzle mode)
ecef5838 sago007 2015-11-24 20:01 1256
void BlockGame::PushLineInternal() {
c53e6443 sago007 2012-04-17 11:04 1257
	//If not game over, not high tower and not puzzle mode
ecef5838 sago007 2015-11-24 20:01 1258
	if ((!bGameOver) && TowerHeight<13 && (!puzzleMode) && (gameStartedAt<ticks)&&(chain==0)) {
b539639c sago007 2015-12-29 11:51 1259
		for (int i=19; i>0; i--) {
ecef5838 sago007 2015-11-24 20:01 1260
			for (int j=0; j<6; j++) {
c53e6443 sago007 2012-04-17 11:04 1261
				board[j][i] = board[j][i-1];
c53e6443 sago007 2012-04-17 11:04 1262
			}
b539639c sago007 2015-12-29 11:51 1263
		}
ecef5838 sago007 2015-11-24 20:01 1264
		for (int j=0; j<6; j++) {
c53e6443 sago007 2012-04-17 11:04 1265
			board[j][0] = rand2() % 4;
ecef5838 sago007 2015-11-24 20:01 1266
			if (j > 0) {
ecef5838 sago007 2015-11-24 20:01 1267
				if (board[j][0] == board[j-1][0]) {
4ce4646e Poul Sander 2024-03-27 17:45 1268
					board[j][0] = rand2() % basicBlockVariants;
ecef5838 sago007 2015-11-24 20:01 1269
				}
c53e6443 sago007 2012-04-17 11:04 1270
			}
ecef5838 sago007 2015-11-24 20:01 1271
			if (board[j][0] == board[j][1]) {
4ce4646e Poul Sander 2024-03-27 17:45 1272
				board[j][0] = rand2() % basicBlockVariants;
ecef5838 sago007 2015-11-24 20:01 1273
			}
ecef5838 sago007 2015-11-24 20:01 1274
			if (board[j][0] == board[j][1]) {
4ce4646e Poul Sander 2024-03-27 17:45 1275
				board[j][0] = rand2() % basicBlockVariants;
ecef5838 sago007 2015-11-24 20:01 1276
			}
ecef5838 sago007 2015-11-24 20:01 1277
			while ((j>0)&&(board[j][0]==board[j-1][0])) {
4ce4646e Poul Sander 2024-03-27 17:45 1278
				board[j][0] = rand2() % basicBlockVariants;
ecef5838 sago007 2015-11-24 20:01 1279
			}
c53e6443 sago007 2012-04-17 11:04 1280
		}
c53e6443 sago007 2012-04-17 11:04 1281
		score+=1;
ca486238 sago007 2015-08-23 15:12 1282
		MoveCursor('N'); //Workaround for this being done registred too
ca486238 sago007 2015-08-23 15:12 1283
		if (vsMode) {
ecef5838 sago007 2015-11-24 20:01 1284
			if (rand2()%6==1) {
c53e6443 sago007 2012-04-17 11:04 1285
				board[rand2()%6][0]=6;
ecef5838 sago007 2015-11-24 20:01 1286
			}
c53e6443 sago007 2012-04-17 11:04 1287
		}
c53e6443 sago007 2012-04-17 11:04 1288
		pixels = 0;
c53e6443 sago007 2012-04-17 11:04 1289
		stop=0;
c53e6443 sago007 2012-04-17 11:04 1290
		pushedPixelAt = ticks;
c53e6443 sago007 2012-04-17 11:04 1291
		linesCleared++;
c53e6443 sago007 2012-04-17 11:04 1292
		AI_LineOffset++;
c53e6443 sago007 2012-04-17 11:04 1293
		nrPushedPixel=(int)((double)(pushedPixelAt-gameStartedAt)/(1000.0*speed));
c53e6443 sago007 2012-04-17 11:04 1294
50cf6485 sago007 2016-03-21 19:11 1295
		if (recordStats) {
c53e6443 sago007 2012-04-17 11:04 1296
			Stats::getInstance()->addOne("linesPushed");
c53e6443 sago007 2012-04-17 11:04 1297
		}
c53e6443 sago007 2012-04-17 11:04 1298
	} //if !bGameOver
c53e6443 sago007 2012-04-17 11:04 1299
c53e6443 sago007 2012-04-17 11:04 1300
	//Restart Puzzle mode
ecef5838 sago007 2015-11-24 20:01 1301
	if (puzzleMode && !bGameOver) {
c53e6443 sago007 2012-04-17 11:04 1302
		//Reloads level
055218be sago007 2015-08-22 18:44 1303
		MovesLeft = PuzzleNumberOfMovesAllowed(Level);
b539639c sago007 2015-12-29 11:51 1304
		for (int i=0; i<6; i++) {
ecef5838 sago007 2015-11-24 20:01 1305
			for (int j=0; j<12; j++) {
055218be sago007 2015-08-22 18:44 1306
				board[i][j+1] = PuzzleGetBrick(Level,i,j);
c53e6443 sago007 2012-04-17 11:04 1307
			}
b539639c sago007 2015-12-29 11:51 1308
		}
c53e6443 sago007 2012-04-17 11:04 1309
		score=0;
c53e6443 sago007 2012-04-17 11:04 1310
		bGameOver=false;
c53e6443 sago007 2012-04-17 11:04 1311
	}
c53e6443 sago007 2012-04-17 11:04 1312
ecef5838 sago007 2015-11-24 20:01 1313
	if ((TowerHeight>12) && (!puzzleMode)&&(!bGameOver)&&(chain==0)) {
c53e6443 sago007 2012-04-17 11:04 1314
		SetGameOver();
c53e6443 sago007 2012-04-17 11:04 1315
	}
c53e6443 sago007 2012-04-17 11:04 1316
c53e6443 sago007 2012-04-17 11:04 1317
c53e6443 sago007 2012-04-17 11:04 1318
}//PushLine
c53e6443 sago007 2012-04-17 11:04 1319
c53e6443 sago007 2012-04-17 11:04 1320
//Pushes a single pixel, so it appears to scrool
ecef5838 sago007 2015-11-24 20:01 1321
void BlockGame::PushPixels() {
c53e6443 sago007 2012-04-17 11:04 1322
	nrPushedPixel++;
ecef5838 sago007 2015-11-24 20:01 1323
	if ((pixels < bsize) && TowerHeight<13) {
c53e6443 sago007 2012-04-17 11:04 1324
		pixels++;
c53e6443 sago007 2012-04-17 11:04 1325
	}
ecef5838 sago007 2015-11-24 20:01 1326
	else {
79d3c1d3 sago007 2012-05-05 15:54 1327
		PushLineInternal();
ecef5838 sago007 2015-11-24 20:01 1328
	}
ecef5838 sago007 2015-11-24 20:01 1329
	if (pixels>bsize) {
c53e6443 sago007 2012-04-17 11:04 1330
		pixels=0;
ecef5838 sago007 2015-11-24 20:01 1331
	}
c53e6443 sago007 2012-04-17 11:04 1332
}
c53e6443 sago007 2012-04-17 11:04 1333
c53e6443 sago007 2012-04-17 11:04 1334
c53e6443 sago007 2012-04-17 11:04 1335
//See how high the tower is, saved in integer TowerHeight
ecef5838 sago007 2015-11-24 20:01 1336
void BlockGame::FindTowerHeight() {
c53e6443 sago007 2012-04-17 11:04 1337
	/*
c53e6443 sago007 2012-04-17 11:04 1338
	 * Old implementation, used until I find the bug in the other.
c53e6443 sago007 2012-04-17 11:04 1339
	 * This function has a bug in stage clear! if an empty line appears.
c53e6443 sago007 2012-04-17 11:04 1340
	 */
c53e6443 sago007 2012-04-17 11:04 1341
	prevTowerHeight = TowerHeight;
c53e6443 sago007 2012-04-17 11:04 1342
	bool found = false;
c53e6443 sago007 2012-04-17 11:04 1343
	TowerHeight = 0;
ecef5838 sago007 2015-11-24 20:01 1344
	while (!found) {
c53e6443 sago007 2012-04-17 11:04 1345
		found = true;
c53e6443 sago007 2012-04-17 11:04 1346
		for (int j=0; j<6; j++)
ecef5838 sago007 2015-11-24 20:01 1347
			if (board[j][TowerHeight] != -1) {
c53e6443 sago007 2012-04-17 11:04 1348
				found = false;
ecef5838 sago007 2015-11-24 20:01 1349
			}
c53e6443 sago007 2012-04-17 11:04 1350
		TowerHeight++;
c53e6443 sago007 2012-04-17 11:04 1351
	}
c53e6443 sago007 2012-04-17 11:04 1352
	TowerHeight--;
c53e6443 sago007 2012-04-17 11:04 1353
}
17916a2e sago007 2010-11-07 11:26 1354
17916a2e sago007 2010-11-07 11:26 1355
///////////////////////////////////////////////////////////////////////////
17916a2e sago007 2010-11-07 11:26 1356
/////////////////////////// AI starts here! ///////////////////////////////
17916a2e sago007 2010-11-07 11:26 1357
///////////////////////////////////////////////////////////////////////////
c53e6443 sago007 2012-04-17 11:04 1358
//First the helpet functions:
ecef5838 sago007 2015-11-24 20:01 1359
int BlockGame::nrOfType(int line, int type) {
c53e6443 sago007 2012-04-17 11:04 1360
	int counter = 0;
c53e6443 sago007 2012-04-17 11:04 1361
	for (int i=0; i<6; i++)
ecef5838 sago007 2015-11-24 20:01 1362
		if (board[i][line]==type) {
ecef5838 sago007 2015-11-24 20:01 1363
			counter++;
ecef5838 sago007 2015-11-24 20:01 1364
		}
c53e6443 sago007 2012-04-17 11:04 1365
	return counter;
c53e6443 sago007 2012-04-17 11:04 1366
}
c53e6443 sago007 2012-04-17 11:04 1367
c53e6443 sago007 2012-04-17 11:04 1368
c53e6443 sago007 2012-04-17 11:04 1369
//See if a combo can be made in this line
ecef5838 sago007 2015-11-24 20:01 1370
int BlockGame::horiInLine(int line) {
c53e6443 sago007 2012-04-17 11:04 1371
	int nrOfType[7] = {0, 0, 0, 0, 0, 0, 0};
c53e6443 sago007 2012-04-17 11:04 1372
	int max = 0;
ecef5838 sago007 2015-11-24 20:01 1373
	for (int i=0; i<6; i++) {
7013ad1a sago007 2018-03-25 09:55 1374
		int iTemp = board[i][line];
ecef5838 sago007 2015-11-24 20:01 1375
		if ((iTemp>-1)&&(iTemp<7)) {
c53e6443 sago007 2012-04-17 11:04 1376
			nrOfType[iTemp]++;
ecef5838 sago007 2015-11-24 20:01 1377
		}
c53e6443 sago007 2012-04-17 11:04 1378
	}
ecef5838 sago007 2015-11-24 20:01 1379
	for (int j=0; j<7; j++) {
ecef5838 sago007 2015-11-24 20:01 1380
		if (nrOfType[j]>max) {
c53e6443 sago007 2012-04-17 11:04 1381
			max = nrOfType[j];
c53e6443 sago007 2012-04-17 11:04 1382
			AIcolorToClear = j;
c53e6443 sago007 2012-04-17 11:04 1383
		}
c53e6443 sago007 2012-04-17 11:04 1384
	}
c53e6443 sago007 2012-04-17 11:04 1385
	return max;
c53e6443 sago007 2012-04-17 11:04 1386
}
c53e6443 sago007 2012-04-17 11:04 1387
ecef5838 sago007 2015-11-24 20:01 1388
bool BlockGame::horiClearPossible() {
c53e6443 sago007 2012-04-17 11:04 1389
	int i=13;
c53e6443 sago007 2012-04-17 11:04 1390
	bool solutionFound = false;
ecef5838 sago007 2015-11-24 20:01 1391
	do {
ecef5838 sago007 2015-11-24 20:01 1392
		if (horiInLine(i)>2) {
c53e6443 sago007 2012-04-17 11:04 1393
			AI_LineOffset = 0;
c53e6443 sago007 2012-04-17 11:04 1394
			AIlineToClear = i;
c53e6443 sago007 2012-04-17 11:04 1395
			solutionFound = true;
c53e6443 sago007 2012-04-17 11:04 1396
		}
c53e6443 sago007 2012-04-17 11:04 1397
		i--;
c53e6443 sago007 2012-04-17 11:04 1398
	}
c53e6443 sago007 2012-04-17 11:04 1399
	while ((!solutionFound)&&(i>0));
c53e6443 sago007 2012-04-17 11:04 1400
	return solutionFound;
c53e6443 sago007 2012-04-17 11:04 1401
}
c53e6443 sago007 2012-04-17 11:04 1402
c53e6443 sago007 2012-04-17 11:04 1403
//the Line Has Unmoveable Objects witch might stall the AI
ecef5838 sago007 2015-11-24 20:01 1404
bool BlockGame::lineHasGarbage(int line) {
b539639c sago007 2015-12-29 11:51 1405
	for (int i=0; i<6; i++) {
ecef5838 sago007 2015-11-24 20:01 1406
		if (board[i][line]>1000000) {
c53e6443 sago007 2012-04-17 11:04 1407
			return true;
ecef5838 sago007 2015-11-24 20:01 1408
		}
b539639c sago007 2015-12-29 11:51 1409
	}
c53e6443 sago007 2012-04-17 11:04 1410
	return false;
c53e6443 sago007 2012-04-17 11:04 1411
}
c53e6443 sago007 2012-04-17 11:04 1412
c53e6443 sago007 2012-04-17 11:04 1413
//Types 0..6 in line
ecef5838 sago007 2015-11-24 20:01 1414
int BlockGame::nrOfRealTypes(int line) {
c53e6443 sago007 2012-04-17 11:04 1415
	int counter = 0;
b539639c sago007 2015-12-29 11:51 1416
	for (int i=0; i<6; i++) {
ecef5838 sago007 2015-11-24 20:01 1417
		if ((board[i][line]>-1)&&(board[i][line]<7)) {
ecef5838 sago007 2015-11-24 20:01 1418
			counter++;
ecef5838 sago007 2015-11-24 20:01 1419
		}
b539639c sago007 2015-12-29 11:51 1420
	}
c53e6443 sago007 2012-04-17 11:04 1421
	return counter;
c53e6443 sago007 2012-04-17 11:04 1422
}
c53e6443 sago007 2012-04-17 11:04 1423
c53e6443 sago007 2012-04-17 11:04 1424
//See if there is a tower
ecef5838 sago007 2015-11-24 20:01 1425
bool BlockGame::ThereIsATower() {
c53e6443 sago007 2012-04-17 11:04 1426
	bool bThereIsATower = false; //Unless proven otherwise!
c53e6443 sago007 2012-04-17 11:04 1427
	bool topReached = false; //If we have reached the top
c53e6443 sago007 2012-04-17 11:04 1428
	int lineNumber = 0;
c53e6443 sago007 2012-04-17 11:04 1429
	bool emptySpacesFound = false;
ecef5838 sago007 2015-11-24 20:01 1430
	do {
ecef5838 sago007 2015-11-24 20:01 1431
		if ((emptySpacesFound) && (nrOfRealTypes(lineNumber)>0)&&(nrOfType(lineNumber, -1)>0)) {
c53e6443 sago007 2012-04-17 11:04 1432
			AIlineToClear = lineNumber;
ecef5838 sago007 2015-11-24 20:01 1433
			if (lineHasGarbage(lineNumber)) {
c53e6443 sago007 2012-04-17 11:04 1434
				return false;
ecef5838 sago007 2015-11-24 20:01 1435
			}
ecef5838 sago007 2015-11-24 20:01 1436
			else {
c53e6443 sago007 2012-04-17 11:04 1437
				bThereIsATower = true;
ecef5838 sago007 2015-11-24 20:01 1438
			}
c53e6443 sago007 2012-04-17 11:04 1439
		}
ecef5838 sago007 2015-11-24 20:01 1440
		else {
c53e6443 sago007 2012-04-17 11:04 1441
			emptySpacesFound=false;
ecef5838 sago007 2015-11-24 20:01 1442
		}
ecef5838 sago007 2015-11-24 20:01 1443
		if ((!emptySpacesFound)&&(nrOfType(lineNumber, -1)>0)) {
c53e6443 sago007 2012-04-17 11:04 1444
			emptySpacesFound = true;
ecef5838 sago007 2015-11-24 20:01 1445
		}
ecef5838 sago007 2015-11-24 20:01 1446
		if (lineNumber<12) {
c53e6443 sago007 2012-04-17 11:04 1447
			lineNumber++;
ecef5838 sago007 2015-11-24 20:01 1448
		}
ecef5838 sago007 2015-11-24 20:01 1449
		else {
c53e6443 sago007 2012-04-17 11:04 1450
			topReached = true;
ecef5838 sago007 2015-11-24 20:01 1451
		}
c53e6443 sago007 2012-04-17 11:04 1452
	}
c53e6443 sago007 2012-04-17 11:04 1453
	while ((!bThereIsATower)&&(!topReached));
c53e6443 sago007 2012-04-17 11:04 1454
	return bThereIsATower;
c53e6443 sago007 2012-04-17 11:04 1455
}
c53e6443 sago007 2012-04-17 11:04 1456
ecef5838 sago007 2015-11-24 20:01 1457
double BlockGame::firstInLine1(int line) {
ecef5838 sago007 2015-11-24 20:01 1458
	if (line > 20 || line < 0) {
f10b1d3c Poul Sander 2020-08-08 17:34 1459
		std::cerr << "Warning: first in Line1: " << line << "\n";
56241205 sago007 2012-08-05 11:15 1460
		return 3.0;
56241205 sago007 2012-08-05 11:15 1461
	}
b539639c sago007 2015-12-29 11:51 1462
	for (int i=0; i<6; i++) {
ecef5838 sago007 2015-11-24 20:01 1463
		if ((board[i][line]>-1)&&(board[i][line]<7)) {
c53e6443 sago007 2012-04-17 11:04 1464
			return (double)i;
ecef5838 sago007 2015-11-24 20:01 1465
		}
b539639c sago007 2015-12-29 11:51 1466
	}
c53e6443 sago007 2012-04-17 11:04 1467
	return 3.0;
c53e6443 sago007 2012-04-17 11:04 1468
}
c53e6443 sago007 2012-04-17 11:04 1469
c53e6443 sago007 2012-04-17 11:04 1470
//returns the first coordinate of the block of type
ecef5838 sago007 2015-11-24 20:01 1471
double BlockGame::firstInLine(int line, int type) {
ecef5838 sago007 2015-11-24 20:01 1472
	if (line > 20 || line < 0) {
f10b1d3c Poul Sander 2020-08-08 17:34 1473
		std::cerr << "Warning: first in Line: " << line << "\n";
56241205 sago007 2012-08-05 11:15 1474
		return 3.0;
56241205 sago007 2012-08-05 11:15 1475
	}
549ecfae sago007 2016-10-09 08:37 1476
	for (int i=0; i<6; i++) {
ecef5838 sago007 2015-11-24 20:01 1477
		if (board[i][line]==type) {
c53e6443 sago007 2012-04-17 11:04 1478
			return (double)i;
ecef5838 sago007 2015-11-24 20:01 1479
		}
549ecfae sago007 2016-10-09 08:37 1480
	}
c53e6443 sago007 2012-04-17 11:04 1481
	return 3.0;
c53e6443 sago007 2012-04-17 11:04 1482
}
c53e6443 sago007 2012-04-17 11:04 1483
c53e6443 sago007 2012-04-17 11:04 1484
//There in the line shall we move
ecef5838 sago007 2015-11-24 20:01 1485
int BlockGame::closestTo(int line, int place) {
ecef5838 sago007 2015-11-24 20:01 1486
	if ((int)firstInLine1(line)>place) {
c53e6443 sago007 2012-04-17 11:04 1487
		return (int)firstInLine1(line)-1;
ecef5838 sago007 2015-11-24 20:01 1488
	}
ecef5838 sago007 2015-11-24 20:01 1489
	for (int i=place; i>=0; i--) {
ecef5838 sago007 2015-11-24 20:01 1490
		if ((board[i][line]>-1)&&(board[i][line]<7)) {
c53e6443 sago007 2012-04-17 11:04 1491
			return i;
ecef5838 sago007 2015-11-24 20:01 1492
		}
c53e6443 sago007 2012-04-17 11:04 1493
	}
c53e6443 sago007 2012-04-17 11:04 1494
	AIstatus=0;
c53e6443 sago007 2012-04-17 11:04 1495
	return place;
c53e6443 sago007 2012-04-17 11:04 1496
}
c53e6443 sago007 2012-04-17 11:04 1497
c53e6443 sago007 2012-04-17 11:04 1498
//The AI will remove a tower
ecef5838 sago007 2015-11-24 20:01 1499
void BlockGame::AI_ClearTower() {
c53e6443 sago007 2012-04-17 11:04 1500
	int place = (int)firstInLine(AIlineToClear-1, -1); //Find an empty field to frop a brick into
c53e6443 sago007 2012-04-17 11:04 1501
	int xplace = closestTo(AIlineToClear, place); //Find the brick to drop in it
ecef5838 sago007 2015-11-24 20:01 1502
	if (cursory+1<AIlineToClear) {
c53e6443 sago007 2012-04-17 11:04 1503
		MoveCursor('N');
ecef5838 sago007 2015-11-24 20:01 1504
	}
ecef5838 sago007 2015-11-24 20:01 1505
	else if (cursory+1>AIlineToClear) {
c53e6443 sago007 2012-04-17 11:04 1506
		MoveCursor('S');
ecef5838 sago007 2015-11-24 20:01 1507
	}
ecef5838 sago007 2015-11-24 20:01 1508
	else if (cursorx<xplace) {
c53e6443 sago007 2012-04-17 11:04 1509
		MoveCursor('E');
ecef5838 sago007 2015-11-24 20:01 1510
	}
ecef5838 sago007 2015-11-24 20:01 1511
	else if (cursorx>xplace) {
c53e6443 sago007 2012-04-17 11:04 1512
		MoveCursor('W');
ecef5838 sago007 2015-11-24 20:01 1513
	}
ecef5838 sago007 2015-11-24 20:01 1514
	else {
c53e6443 sago007 2012-04-17 11:04 1515
		SwitchAtCursor();
ecef5838 sago007 2015-11-24 20:01 1516
	}
ecef5838 sago007 2015-11-24 20:01 1517
	if (!ThereIsATower()) {
c53e6443 sago007 2012-04-17 11:04 1518
		AIstatus = 0;
ecef5838 sago007 2015-11-24 20:01 1519
	}
c53e6443 sago007 2012-04-17 11:04 1520
}
c53e6443 sago007 2012-04-17 11:04 1521
c53e6443 sago007 2012-04-17 11:04 1522
//The AI will try to clear block horisontally
ecef5838 sago007 2015-11-24 20:01 1523
void BlockGame::AI_ClearHori() {
c53e6443 sago007 2012-04-17 11:04 1524
	int lowestLine = AIlineToClear;
ecef5838 sago007 2015-11-24 20:01 1525
	for (int i=0; i<7; i++) {
ecef5838 sago007 2015-11-24 20:01 1526
		if (nrOfType(lowestLine, i)>2) {
c53e6443 sago007 2012-04-17 11:04 1527
			AIcolorToClear = i;
ecef5838 sago007 2015-11-24 20:01 1528
		}
c53e6443 sago007 2012-04-17 11:04 1529
	}
9f2c006a sago007 2016-03-24 21:15 1530
	if (cursory>lowestLine-1) {
9f2c006a sago007 2016-03-24 21:15 1531
		MoveCursor('S');
9f2c006a sago007 2016-03-24 21:15 1532
	}
9f2c006a sago007 2016-03-24 21:15 1533
	else if (cursory<lowestLine-1) {
9f2c006a sago007 2016-03-24 21:15 1534
		MoveCursor('N');
9f2c006a sago007 2016-03-24 21:15 1535
	}
9f2c006a sago007 2016-03-24 21:15 1536
	else if (nrOfType(lowestLine, AIcolorToClear)>2) {
9f2c006a sago007 2016-03-24 21:15 1537
		int left=0, right=0;
9f2c006a sago007 2016-03-24 21:15 1538
		if (board[0][lowestLine]==AIcolorToClear) {
9f2c006a sago007 2016-03-24 21:15 1539
			left++;
ecef5838 sago007 2015-11-24 20:01 1540
		}
9f2c006a sago007 2016-03-24 21:15 1541
		if (board[1][lowestLine]==AIcolorToClear) {
9f2c006a sago007 2016-03-24 21:15 1542
			left++;
ecef5838 sago007 2015-11-24 20:01 1543
		}
9f2c006a sago007 2016-03-24 21:15 1544
		if (board[2][lowestLine]==AIcolorToClear) {
9f2c006a sago007 2016-03-24 21:15 1545
			left++;
9f2c006a sago007 2016-03-24 21:15 1546
		}
9f2c006a sago007 2016-03-24 21:15 1547
		if (board[3][lowestLine]==AIcolorToClear) {
9f2c006a sago007 2016-03-24 21:15 1548
			right++;
9f2c006a sago007 2016-03-24 21:15 1549
		}
9f2c006a sago007 2016-03-24 21:15 1550
		if (board[4][lowestLine]==AIcolorToClear) {
9f2c006a sago007 2016-03-24 21:15 1551
			right++;
9f2c006a sago007 2016-03-24 21:15 1552
		}
9f2c006a sago007 2016-03-24 21:15 1553
		if (board[5][lowestLine]==AIcolorToClear) {
9f2c006a sago007 2016-03-24 21:15 1554
			right++;
9f2c006a sago007 2016-03-24 21:15 1555
		}
9f2c006a sago007 2016-03-24 21:15 1556
		int xplace = 0;
9f2c006a sago007 2016-03-24 21:15 1557
		if (left<right) {
9f2c006a sago007 2016-03-24 21:15 1558
			int count=0;
549ecfae sago007 2016-10-09 08:37 1559
			for (int i=0; (i<4)&&(count<1); i++) {
9f2c006a sago007 2016-03-24 21:15 1560
				if ((board[i][lowestLine]==AIcolorToClear)&&((i==0)||(board[i+1][lowestLine]!=AIcolorToClear))) {
9f2c006a sago007 2016-03-24 21:15 1561
					count++;
9f2c006a sago007 2016-03-24 21:15 1562
					xplace = i;
9f2c006a sago007 2016-03-24 21:15 1563
				}
549ecfae sago007 2016-10-09 08:37 1564
			}
9f2c006a sago007 2016-03-24 21:15 1565
		}
9f2c006a sago007 2016-03-24 21:15 1566
		else {
9f2c006a sago007 2016-03-24 21:15 1567
			int count=0;
9f2c006a sago007 2016-03-24 21:15 1568
			for (int i=3; (i<=5)&&(count<1); i++) {
9f2c006a sago007 2016-03-24 21:15 1569
				if ((board[i][lowestLine]==AIcolorToClear)&&(board[i-1][lowestLine]!=AIcolorToClear)) {
9f2c006a sago007 2016-03-24 21:15 1570
					count++;
9f2c006a sago007 2016-03-24 21:15 1571
					xplace = --i;
9f2c006a sago007 2016-03-24 21:15 1572
				}
ecef5838 sago007 2015-11-24 20:01 1573
			}
c53e6443 sago007 2012-04-17 11:04 1574
		}
9f2c006a sago007 2016-03-24 21:15 1575
		if (cursorx<xplace) {
9f2c006a sago007 2016-03-24 21:15 1576
			MoveCursor('E');
9f2c006a sago007 2016-03-24 21:15 1577
		}
9f2c006a sago007 2016-03-24 21:15 1578
		else if (cursorx>xplace) {
9f2c006a sago007 2016-03-24 21:15 1579
			MoveCursor('W');
9f2c006a sago007 2016-03-24 21:15 1580
		}
9f2c006a sago007 2016-03-24 21:15 1581
		else if (cursorx==xplace) {
9f2c006a sago007 2016-03-24 21:15 1582
			SwitchAtCursor();
9f2c006a sago007 2016-03-24 21:15 1583
		}
ecef5838 sago007 2015-11-24 20:01 1584
		else {
c53e6443 sago007 2012-04-17 11:04 1585
			AIstatus = 0;
ecef5838 sago007 2015-11-24 20:01 1586
		}
c53e6443 sago007 2012-04-17 11:04 1587
	}
ecef5838 sago007 2015-11-24 20:01 1588
	else {
c53e6443 sago007 2012-04-17 11:04 1589
		AIstatus = 0;
ecef5838 sago007 2015-11-24 20:01 1590
	}
c53e6443 sago007 2012-04-17 11:04 1591
}
c53e6443 sago007 2012-04-17 11:04 1592
c53e6443 sago007 2012-04-17 11:04 1593
//Test if vertical clear is possible
ecef5838 sago007 2015-11-24 20:01 1594
bool BlockGame::veriClearPossible() {
c53e6443 sago007 2012-04-17 11:04 1595
	bool found=false;
c53e6443 sago007 2012-04-17 11:04 1596
	int colors[7] = {0, 0, 0, 0, 0, 0, 0};
ecef5838 sago007 2015-11-24 20:01 1597
	for (int i=12; (i>0)&&(!found); i--) {
ecef5838 sago007 2015-11-24 20:01 1598
		for (int j=0; j<7; j++) {
ecef5838 sago007 2015-11-24 20:01 1599
			if (nrOfType(i, j)==0) {
c53e6443 sago007 2012-04-17 11:04 1600
				colors[j]=0;
ecef5838 sago007 2015-11-24 20:01 1601
			}
ecef5838 sago007 2015-11-24 20:01 1602
			else if (++colors[j]>2) {
c53e6443 sago007 2012-04-17 11:04 1603
				AIcolorToClear = j;
c53e6443 sago007 2012-04-17 11:04 1604
				AIlineToClear = i;
c53e6443 sago007 2012-04-17 11:04 1605
				found=true;
c53e6443 sago007 2012-04-17 11:04 1606
			}
c53e6443 sago007 2012-04-17 11:04 1607
		}
c53e6443 sago007 2012-04-17 11:04 1608
	}
c53e6443 sago007 2012-04-17 11:04 1609
	return found;
c53e6443 sago007 2012-04-17 11:04 1610
}
c53e6443 sago007 2012-04-17 11:04 1611
c53e6443 sago007 2012-04-17 11:04 1612
c53e6443 sago007 2012-04-17 11:04 1613
c53e6443 sago007 2012-04-17 11:04 1614
//There in the line shall we move
ecef5838 sago007 2015-11-24 20:01 1615
int BlockGame::closestTo(int line, int type, int place) {
ecef5838 sago007 2015-11-24 20:01 1616
	if ((int)firstInLine(line, type)>place) {
c53e6443 sago007 2012-04-17 11:04 1617
		return (int)firstInLine(line, type)-1;
ecef5838 sago007 2015-11-24 20:01 1618
	}
ecef5838 sago007 2015-11-24 20:01 1619
	for (int i=place; i>=0; i--) {
ecef5838 sago007 2015-11-24 20:01 1620
		if (board[i][line]==type) {
c53e6443 sago007 2012-04-17 11:04 1621
			return i;
ecef5838 sago007 2015-11-24 20:01 1622
		}
c53e6443 sago007 2012-04-17 11:04 1623
	}
c53e6443 sago007 2012-04-17 11:04 1624
	AIstatus=0;
c53e6443 sago007 2012-04-17 11:04 1625
	return place;
c53e6443 sago007 2012-04-17 11:04 1626
}
c53e6443 sago007 2012-04-17 11:04 1627
c53e6443 sago007 2012-04-17 11:04 1628
//The AI will try to clear blocks vertically
ecef5838 sago007 2015-11-24 20:01 1629
void BlockGame::AI_ClearVertical() {
c53e6443 sago007 2012-04-17 11:04 1630
	//First we find the place there we will align the bricks
c53e6443 sago007 2012-04-17 11:04 1631
	int placeToCenter = (int)(firstInLine(AIlineToClear, AIcolorToClear)/3.0+firstInLine(AIlineToClear+1, AIcolorToClear)/3.0+firstInLine(AIlineToClear+2, AIcolorToClear)/3.0);
c53e6443 sago007 2012-04-17 11:04 1632
	int unlimitedLoop=0;
ecef5838 sago007 2015-11-24 20:01 1633
	if (AIlineToClear < 0 || AIlineToClear > 20) {
f10b1d3c Poul Sander 2020-08-08 17:34 1634
		std::cerr << "AIlineToClear out of range: " << AIlineToClear << "\n";
56241205 sago007 2012-08-05 11:15 1635
		return;
56241205 sago007 2012-08-05 11:15 1636
	}
ecef5838 sago007 2015-11-24 20:01 1637
	if (placeToCenter<0 || placeToCenter > 5) {
f10b1d3c Poul Sander 2020-08-08 17:34 1638
		std::cerr << "placeToCenter out of range: " << placeToCenter << "\n";
56241205 sago007 2012-08-05 11:15 1639
		return;
56241205 sago007 2012-08-05 11:15 1640
	}
ecef5838 sago007 2015-11-24 20:01 1641
	while (((board[placeToCenter][AIlineToClear]>1000000)||(board[placeToCenter][AIlineToClear+1]>1000000)||(board[placeToCenter][AIlineToClear+2]>1000000))&&(unlimitedLoop<10)) {
c53e6443 sago007 2012-04-17 11:04 1642
		unlimitedLoop++;
c53e6443 sago007 2012-04-17 11:04 1643
		placeToCenter++;
ecef5838 sago007 2015-11-24 20:01 1644
		if (placeToCenter>5) {
c53e6443 sago007 2012-04-17 11:04 1645
			placeToCenter=0;
ecef5838 sago007 2015-11-24 20:01 1646
		}
c53e6443 sago007 2012-04-17 11:04 1647
	}
ecef5838 sago007 2015-11-24 20:01 1648
	if (unlimitedLoop>9) {
c53e6443 sago007 2012-04-17 11:04 1649
		AIstatus = 0;
56241205 sago007 2012-08-05 11:15 1650
		return;
c53e6443 sago007 2012-04-17 11:04 1651
	}
ecef5838 sago007 2015-11-24 20:01 1652
	if (cursory+1>AIlineToClear+2) {
c53e6443 sago007 2012-04-17 11:04 1653
		MoveCursor('S');
c53e6443 sago007 2012-04-17 11:04 1654
	}
ecef5838 sago007 2015-11-24 20:01 1655
	if (cursory+1<AIlineToClear) {
c53e6443 sago007 2012-04-17 11:04 1656
		MoveCursor('N');
ecef5838 sago007 2015-11-24 20:01 1657
	}
c53e6443 sago007 2012-04-17 11:04 1658
	bool toAlign[3]= {true, true, true};
ecef5838 sago007 2015-11-24 20:01 1659
	if (board[placeToCenter][AIlineToClear+0]==AIcolorToClear) {
c53e6443 sago007 2012-04-17 11:04 1660
		toAlign[0]=false;
ecef5838 sago007 2015-11-24 20:01 1661
	}
ecef5838 sago007 2015-11-24 20:01 1662
	if (board[placeToCenter][AIlineToClear+1]==AIcolorToClear) {
c53e6443 sago007 2012-04-17 11:04 1663
		toAlign[1]=false;
ecef5838 sago007 2015-11-24 20:01 1664
	}
ecef5838 sago007 2015-11-24 20:01 1665
	if (board[placeToCenter][AIlineToClear+2]==AIcolorToClear) {
c53e6443 sago007 2012-04-17 11:04 1666
		toAlign[2]=false;
ecef5838 sago007 2015-11-24 20:01 1667
	}
ecef5838 sago007 2015-11-24 20:01 1668
	if (cursory+1==AIlineToClear) {
ecef5838 sago007 2015-11-24 20:01 1669
		if (toAlign[0]==false) {
c53e6443 sago007 2012-04-17 11:04 1670
			MoveCursor('N');
ecef5838 sago007 2015-11-24 20:01 1671
		}
ecef5838 sago007 2015-11-24 20:01 1672
		else {
ecef5838 sago007 2015-11-24 20:01 1673
			if (cursorx>closestTo(AIlineToClear, AIcolorToClear, placeToCenter)) {
c53e6443 sago007 2012-04-17 11:04 1674
				MoveCursor('W');
ecef5838 sago007 2015-11-24 20:01 1675
			}
ecef5838 sago007 2015-11-24 20:01 1676
			else if (cursorx<closestTo(AIlineToClear, AIcolorToClear, placeToCenter)) {
c53e6443 sago007 2012-04-17 11:04 1677
				MoveCursor('E');
ecef5838 sago007 2015-11-24 20:01 1678
			}
ecef5838 sago007 2015-11-24 20:01 1679
			else {
c53e6443 sago007 2012-04-17 11:04 1680
				SwitchAtCursor();
ecef5838 sago007 2015-11-24 20:01 1681
			}
c53e6443 sago007 2012-04-17 11:04 1682
		}
c53e6443 sago007 2012-04-17 11:04 1683
	}
ecef5838 sago007 2015-11-24 20:01 1684
	else if (cursory+1==AIlineToClear+1) {
ecef5838 sago007 2015-11-24 20:01 1685
		if (toAlign[1]==false) {
ecef5838 sago007 2015-11-24 20:01 1686
			if (toAlign[2]) {
c53e6443 sago007 2012-04-17 11:04 1687
				MoveCursor('N');
ecef5838 sago007 2015-11-24 20:01 1688
			}
ecef5838 sago007 2015-11-24 20:01 1689
			else {
c53e6443 sago007 2012-04-17 11:04 1690
				MoveCursor('S');
ecef5838 sago007 2015-11-24 20:01 1691
			}
c53e6443 sago007 2012-04-17 11:04 1692
		}
ecef5838 sago007 2015-11-24 20:01 1693
		else {
ecef5838 sago007 2015-11-24 20:01 1694
			if (cursorx>closestTo(AIlineToClear+1, AIcolorToClear, placeToCenter)) {
c53e6443 sago007 2012-04-17 11:04 1695
				MoveCursor('W');
ecef5838 sago007 2015-11-24 20:01 1696
			}
ecef5838 sago007 2015-11-24 20:01 1697
			else if (cursorx<closestTo(AIlineToClear+1, AIcolorToClear, placeToCenter)) {
c53e6443 sago007 2012-04-17 11:04 1698
				MoveCursor('E');
ecef5838 sago007 2015-11-24 20:01 1699
			}
ecef5838 sago007 2015-11-24 20:01 1700
			else {
c53e6443 sago007 2012-04-17 11:04 1701
				SwitchAtCursor();
ecef5838 sago007 2015-11-24 20:01 1702
			}
c53e6443 sago007 2012-04-17 11:04 1703
		}
c53e6443 sago007 2012-04-17 11:04 1704
	}
ecef5838 sago007 2015-11-24 20:01 1705
	else if (cursory+1==AIlineToClear+2) {
ecef5838 sago007 2015-11-24 20:01 1706
		if (toAlign[2]==false) {
c53e6443 sago007 2012-04-17 11:04 1707
			MoveCursor('S');
ecef5838 sago007 2015-11-24 20:01 1708
		}
ecef5838 sago007 2015-11-24 20:01 1709
		else {
ecef5838 sago007 2015-11-24 20:01 1710
			if (cursorx>closestTo(AIlineToClear+2, AIcolorToClear, placeToCenter)) {
c53e6443 sago007 2012-04-17 11:04 1711
				MoveCursor('W');
ecef5838 sago007 2015-11-24 20:01 1712
			}
ecef5838 sago007 2015-11-24 20:01 1713
			else if (cursorx<closestTo(AIlineToClear+2, AIcolorToClear, placeToCenter)) {
c53e6443 sago007 2012-04-17 11:04 1714
				MoveCursor('E');
ecef5838 sago007 2015-11-24 20:01 1715
			}
ecef5838 sago007 2015-11-24 20:01 1716
			else {
c53e6443 sago007 2012-04-17 11:04 1717
				SwitchAtCursor();
ecef5838 sago007 2015-11-24 20:01 1718
			}
c53e6443 sago007 2012-04-17 11:04 1719
		}
c53e6443 sago007 2012-04-17 11:04 1720
	}
c53e6443 sago007 2012-04-17 11:04 1721
ecef5838 sago007 2015-11-24 20:01 1722
	if ((!toAlign[0])&&(!toAlign[1])&&(!toAlign[2])) {
c53e6443 sago007 2012-04-17 11:04 1723
		AIstatus = 0;
ecef5838 sago007 2015-11-24 20:01 1724
	}
ecef5838 sago007 2015-11-24 20:01 1725
	if ((nrOfType(AIlineToClear, AIcolorToClear)==0)||(nrOfType(AIlineToClear+1, AIcolorToClear)==0)||(nrOfType(AIlineToClear+2, AIcolorToClear)==0)) {
c53e6443 sago007 2012-04-17 11:04 1726
		AIstatus = 0;
ecef5838 sago007 2015-11-24 20:01 1727
	}
c53e6443 sago007 2012-04-17 11:04 1728
}
c53e6443 sago007 2012-04-17 11:04 1729
c53e6443 sago007 2012-04-17 11:04 1730
ecef5838 sago007 2015-11-24 20:01 1731
void BlockGame::AI_Move() {
ecef5838 sago007 2015-11-24 20:01 1732
	switch (AIstatus) {
c53e6443 sago007 2012-04-17 11:04 1733
	case 1:
ecef5838 sago007 2015-11-24 20:01 1734
		if (TowerHeight<8) {
ecef5838 sago007 2015-11-24 20:01 1735
			PushLine();
ecef5838 sago007 2015-11-24 20:01 1736
		}
ecef5838 sago007 2015-11-24 20:01 1737
		else {
ecef5838 sago007 2015-11-24 20:01 1738
			AIstatus = 0;
ecef5838 sago007 2015-11-24 20:01 1739
		}
c53e6443 sago007 2012-04-17 11:04 1740
		break;
c53e6443 sago007 2012-04-17 11:04 1741
	case 2:
c53e6443 sago007 2012-04-17 11:04 1742
		AI_ClearTower();
c53e6443 sago007 2012-04-17 11:04 1743
		break;
c53e6443 sago007 2012-04-17 11:04 1744
	case 3:
c53e6443 sago007 2012-04-17 11:04 1745
		AI_ClearHori();
c53e6443 sago007 2012-04-17 11:04 1746
		break;
c53e6443 sago007 2012-04-17 11:04 1747
	case 4:
c53e6443 sago007 2012-04-17 11:04 1748
		AI_ClearVertical();
c53e6443 sago007 2012-04-17 11:04 1749
		break;
c53e6443 sago007 2012-04-17 11:04 1750
	case 5:
ecef5838 sago007 2015-11-24 20:01 1751
		if (!firstLineCreated) {
c53e6443 sago007 2012-04-17 11:04 1752
			PushLine();
c53e6443 sago007 2012-04-17 11:04 1753
			firstLineCreated = true;
c53e6443 sago007 2012-04-17 11:04 1754
		}
ecef5838 sago007 2015-11-24 20:01 1755
		else {
c53e6443 sago007 2012-04-17 11:04 1756
			PushLine();
c53e6443 sago007 2012-04-17 11:04 1757
			AIstatus = 0;
c53e6443 sago007 2012-04-17 11:04 1758
		}
c53e6443 sago007 2012-04-17 11:04 1759
		break;
c53e6443 sago007 2012-04-17 11:04 1760
	case 6:
c53e6443 sago007 2012-04-17 11:04 1761
		PushLine();
c53e6443 sago007 2012-04-17 11:04 1762
		AIstatus = 0;
c53e6443 sago007 2012-04-17 11:04 1763
		break;
c53e6443 sago007 2012-04-17 11:04 1764
	default:
ecef5838 sago007 2015-11-24 20:01 1765
		if (TowerHeight<6) {
ecef5838 sago007 2015-11-24 20:01 1766
			AIstatus = 1;
ecef5838 sago007 2015-11-24 20:01 1767
		}
ecef5838 sago007 2015-11-24 20:01 1768
		else if (horiClearPossible()) {
ecef5838 sago007 2015-11-24 20:01 1769
			AIstatus = 3;
ecef5838 sago007 2015-11-24 20:01 1770
		}
ecef5838 sago007 2015-11-24 20:01 1771
		else if (veriClearPossible()) {
ecef5838 sago007 2015-11-24 20:01 1772
			AIstatus = 4;
ecef5838 sago007 2015-11-24 20:01 1773
		}
ecef5838 sago007 2015-11-24 20:01 1774
		else if (ThereIsATower()) {
ecef5838 sago007 2015-11-24 20:01 1775
			AIstatus = 2;
ecef5838 sago007 2015-11-24 20:01 1776
		}
ecef5838 sago007 2015-11-24 20:01 1777
		else {
c53e6443 sago007 2012-04-17 11:04 1778
			AIstatus = 5;
ecef5838 sago007 2015-11-24 20:01 1779
		}
c53e6443 sago007 2012-04-17 11:04 1780
		break;
c53e6443 sago007 2012-04-17 11:04 1781
	}
c53e6443 sago007 2012-04-17 11:04 1782
}
17916a2e sago007 2010-11-07 11:26 1783
17916a2e sago007 2010-11-07 11:26 1784
//////////////////////////////////////////////////////////////////////////
17916a2e sago007 2010-11-07 11:26 1785
///////////////////////////// AI ends here! //////////////////////////////
17916a2e sago007 2010-11-07 11:26 1786
//////////////////////////////////////////////////////////////////////////
17916a2e sago007 2010-11-07 11:26 1787
17916a2e sago007 2010-11-07 11:26 1788
c53e6443 sago007 2012-04-17 11:04 1789
//Updates evrything, if not called nothing happends
ecef5838 sago007 2015-11-24 20:01 1790
void BlockGame::Update() {
63c773dd sago007 2016-01-24 11:47 1791
	unsigned int nowTime = ticks; //We remember the time, so it doesn't change during this call
b69f7fad sago007 2016-08-27 12:35 1792
	capMaxStops(stop, nowTime, gameStartedAt);
c53e6443 sago007 2012-04-17 11:04 1793
	{
c53e6443 sago007 2012-04-17 11:04 1794
		FindTowerHeight();
ca486238 sago007 2015-08-23 15:12 1795
		if ((linesCleared-TowerHeight>stageClearLimit) && (stageClear) && (!bGameOver)) {
ae5d6381 sago007 2015-12-29 13:26 1796
			StageClearSetClear(Level, score, nowTime-gameStartedAt);
c53e6443 sago007 2012-04-17 11:04 1797
			setPlayerWon();
c53e6443 sago007 2012-04-17 11:04 1798
			stageButtonStatus = SBstageClear;
c53e6443 sago007 2012-04-17 11:04 1799
		}
ecef5838 sago007 2015-11-24 20:01 1800
		if ((TowerHeight>12)&&(prevTowerHeight<13)&&(!puzzleMode)) {
c53e6443 sago007 2012-04-17 11:04 1801
			stop+=1000;
c53e6443 sago007 2012-04-17 11:04 1802
		}
c53e6443 sago007 2012-04-17 11:04 1803
63c773dd sago007 2016-01-24 11:47 1804
		while ( nowTime> nrStops*40+gameStartedAt) { //Increase stops, till we reach nowTime
ecef5838 sago007 2015-11-24 20:01 1805
			if (stop>0) {
c53e6443 sago007 2012-04-17 11:04 1806
				stop = stop-20;
ecef5838 sago007 2015-11-24 20:01 1807
				if (stop<=0) {
ecef5838 sago007 2015-11-24 20:01 1808
					nrPushedPixel=(int)((nowTime-gameStartedAt)/(1000.0*speed));
ecef5838 sago007 2015-11-24 20:01 1809
				}
c53e6443 sago007 2012-04-17 11:04 1810
			}
ecef5838 sago007 2015-11-24 20:01 1811
			if (stop<0) {
c53e6443 sago007 2012-04-17 11:04 1812
				stop = 0;
ecef5838 sago007 2015-11-24 20:01 1813
			}
c53e6443 sago007 2012-04-17 11:04 1814
			nrStops++;
c53e6443 sago007 2012-04-17 11:04 1815
		}
c53e6443 sago007 2012-04-17 11:04 1816
		//If we have static content, we don't raise at all!
055218be sago007 2015-08-22 18:44 1817
		if (hasStaticContent()) {
c53e6443 sago007 2012-04-17 11:04 1818
			stop++;
055218be sago007 2015-08-22 18:44 1819
		}
055218be sago007 2015-08-22 18:44 1820
		if ((puzzleMode)&&(!bGameOver)&&BoardEmpty()) {
a1072daf sago007 2016-02-20 12:47 1821
			if (!this->singlePuzzle) {
055218be sago007 2015-08-22 18:44 1822
				PuzzleSetClear(Level);
c53e6443 sago007 2012-04-17 11:04 1823
				stageButtonStatus = SBpuzzleMode;
c53e6443 sago007 2012-04-17 11:04 1824
			}
c53e6443 sago007 2012-04-17 11:04 1825
			setPlayerWon();
c53e6443 sago007 2012-04-17 11:04 1826
		}
c53e6443 sago007 2012-04-17 11:04 1827
c53e6443 sago007 2012-04-17 11:04 1828
		//increse speed:
ecef5838 sago007 2015-11-24 20:01 1829
		if ((nowTime>gameStartedAt+20000*speedLevel)&&(speedLevel <99)&&(!bGameOver)) {
38fbf4d7 sago007 2019-02-09 18:10 1830
			speed = (baseSpeed*0.9)/((double)speedLevel*0.8);
c53e6443 sago007 2012-04-17 11:04 1831
			speedLevel++;
c53e6443 sago007 2012-04-17 11:04 1832
			nrPushedPixel=(int)((double)(nowTime-gameStartedAt)/(1000.0*speed));
c53e6443 sago007 2012-04-17 11:04 1833
		}
c53e6443 sago007 2012-04-17 11:04 1834
c53e6443 sago007 2012-04-17 11:04 1835
c53e6443 sago007 2012-04-17 11:04 1836
		//To prevent the stack from raising a lot then we stop a chain (doesn't work anymore)
ecef5838 sago007 2015-11-24 20:01 1837
		if (chain>0) {
c53e6443 sago007 2012-04-17 11:04 1838
			stop+=1;
ecef5838 sago007 2015-11-24 20:01 1839
		}
c53e6443 sago007 2012-04-17 11:04 1840
		//Raises the stack
c53e6443 sago007 2012-04-17 11:04 1841
		if ((nowTime>gameStartedAt+nrPushedPixel*1000*speed) && (!bGameOver)&&(!stop))
ecef5838 sago007 2015-11-24 20:01 1842
			while ((nowTime>gameStartedAt+nrPushedPixel*1000*speed)&&(!(puzzleMode))) {
c53e6443 sago007 2012-04-17 11:04 1843
				PushPixels();
ecef5838 sago007 2015-11-24 20:01 1844
			}
ecef5838 sago007 2015-11-24 20:01 1845
		if (!bGameOver) {
ecef5838 sago007 2015-11-24 20:01 1846
			ClearBlocks();
ecef5838 sago007 2015-11-24 20:01 1847
		}
c53e6443 sago007 2012-04-17 11:04 1848
c53e6443 sago007 2012-04-17 11:04 1849
		/*************************************************************
c53e6443 sago007 2012-04-17 11:04 1850
		Ai stuff
c53e6443 sago007 2012-04-17 11:04 1851
		 **************************************************************/
ecef5838 sago007 2015-11-24 20:01 1852
		if (bGameOver) {
c53e6443 sago007 2012-04-17 11:04 1853
			AIstatus = 0;       //Enusres that AI is resetted
c53e6443 sago007 2012-04-17 11:04 1854
		}
b539639c sago007 2015-12-29 11:51 1855
		else if (AI_Enabled) {
ecef5838 sago007 2015-11-24 20:01 1856
			if (lastAImove+AI_MoveSpeed<ticks) {
c53e6443 sago007 2012-04-17 11:04 1857
				AI_Move();
c53e6443 sago007 2012-04-17 11:04 1858
				lastAImove=ticks;
c53e6443 sago007 2012-04-17 11:04 1859
			}
b539639c sago007 2015-12-29 11:51 1860
		}
c53e6443 sago007 2012-04-17 11:04 1861
c53e6443 sago007 2012-04-17 11:04 1862
		/*************************************************************
c53e6443 sago007 2012-04-17 11:04 1863
		Ai stuff ended
c53e6443 sago007 2012-04-17 11:04 1864
		 **************************************************************/
ecef5838 sago007 2015-11-24 20:01 1865
		if ((nowTime>gameStartedAt+nrFellDown*140) && (!bGameOver)) {
ecef5838 sago007 2015-11-24 20:01 1866
			FallDown();
ecef5838 sago007 2015-11-24 20:01 1867
		}
ecef5838 sago007 2015-11-24 20:01 1868
		if ((nowTime<gameStartedAt)&&(puzzleMode)) {
c53e6443 sago007 2012-04-17 11:04 1869
			FallDown();
c53e6443 sago007 2012-04-17 11:04 1870
			nrFellDown--;
c53e6443 sago007 2012-04-17 11:04 1871
		}
c53e6443 sago007 2012-04-17 11:04 1872
		ReduceStuff();
ecef5838 sago007 2015-11-24 20:01 1873
		if ((timetrial) && (!bGameOver) && (nowTime>gameStartedAt+2*60*1000)) {
c53e6443 sago007 2012-04-17 11:04 1874
			SetGameOver();
313ecd1b sago007 2015-08-22 20:38 1875
			TimeTrialEndEvent();
c53e6443 sago007 2012-04-17 11:04 1876
		}
c53e6443 sago007 2012-04-17 11:04 1877
	}
c53e6443 sago007 2012-04-17 11:04 1878
}
c53e6443 sago007 2012-04-17 11:04 1879
6b5b6bf4 sago007 2016-02-21 15:30 1880
bool BlockGame::IsNearDeath() const {
ecef5838 sago007 2015-11-24 20:01 1881
	if ((TowerHeight>12)&&(!puzzleMode)&&(!bGameOver)) {
80b830cd sago007 2012-08-19 17:51 1882
		return true;
ecef5838 sago007 2015-11-24 20:01 1883
	}
ecef5838 sago007 2015-11-24 20:01 1884
	else {
80b830cd sago007 2012-08-19 17:51 1885
		return false;
ecef5838 sago007 2015-11-24 20:01 1886
	}
18055aa0 sago007 2012-06-05 19:43 1887
}
18055aa0 sago007 2012-06-05 19:43 1888
ecef5838 sago007 2015-11-24 20:01 1889
void BlockGame::UpdateInternal(unsigned int newtick) {
71ea5b7f sago007 2017-03-02 18:43 1890
	while (newtick >= ticks+10) {
71ea5b7f sago007 2017-03-02 18:43 1891
		ticks+=10;
d12916ab sago007 2012-04-19 23:30 1892
		Update();
d12916ab sago007 2012-04-19 23:30 1893
	}
d12916ab sago007 2012-04-19 23:30 1894
}
d12916ab sago007 2012-04-19 23:30 1895
4fb2e351 sago007 2016-05-19 19:27 1896
void BlockGame::DoAction (const BlockGameAction& action) {
71ea5b7f sago007 2017-03-02 18:43 1897
	if (action.action == BlockGameAction::Action::UPDATE && action.tick < ticks+10) {
76514d10 sago007 2016-06-05 20:25 1898
		return;  //Ignore if this is an update and not high enough
76514d10 sago007 2016-06-05 20:25 1899
	}
76514d10 sago007 2016-06-05 20:25 1900
	if (action.action == BlockGameAction::Action::UPDATE && replayInfo.actions.size() > 0 && replayInfo.actions.back().action == action.action) {
76514d10 sago007 2016-06-05 20:25 1901
		replayInfo.actions.back() = action;
092bdebe sago007 2017-03-19 14:39 1902
	}
76514d10 sago007 2016-06-05 20:25 1903
	else {
76514d10 sago007 2016-06-05 20:25 1904
		replayInfo.actions.push_back(action);
76514d10 sago007 2016-06-05 20:25 1905
	}
62b3f619 sago007 2016-05-20 07:01 1906
	if (action.action == BlockGameAction::Action::UPDATE) {
4fb2e351 sago007 2016-05-19 19:27 1907
		UpdateInternal(action.tick);
4fb2e351 sago007 2016-05-19 19:27 1908
	}
62b3f619 sago007 2016-05-20 07:01 1909
	if (action.action == BlockGameAction::Action::SET_DRAW) {
07f5b3f3 sago007 2016-05-19 19:37 1910
		setDraw();
07f5b3f3 sago007 2016-05-19 19:37 1911
	}
62b3f619 sago007 2016-05-20 07:01 1912
	if (action.action == BlockGameAction::Action::SET_WON) {
07f5b3f3 sago007 2016-05-19 19:37 1913
		setPlayerWon();
07f5b3f3 sago007 2016-05-19 19:37 1914
	}
b58caa17 sago007 2016-06-04 10:32 1915
	if (action.action == BlockGameAction::Action::SET_GAME_OVER) {
b58caa17 sago007 2016-06-04 10:32 1916
		SetGameOver();
b58caa17 sago007 2016-06-04 10:32 1917
	}
c9226e8d sago007 2016-06-04 10:17 1918
	if (action.action == BlockGameAction::Action::PUSH) {
c9226e8d sago007 2016-06-04 10:17 1919
		PushLine();
c9226e8d sago007 2016-06-04 10:17 1920
	}
b58caa17 sago007 2016-06-04 10:32 1921
	if (action.action == BlockGameAction::Action::MOVE) {
e5a23912 sago007 2016-06-04 10:52 1922
		char direction = action.way;
b58caa17 sago007 2016-06-04 10:32 1923
		MoveCursor(direction);
b58caa17 sago007 2016-06-04 10:32 1924
	}
b58caa17 sago007 2016-06-04 10:32 1925
	if (action.action == BlockGameAction::Action::SWITCH) {
b58caa17 sago007 2016-06-04 10:32 1926
		SwitchAtCursor();
b58caa17 sago007 2016-06-04 10:32 1927
	}
8d5e5953 sago007 2016-06-04 13:15 1928
	if (action.action == BlockGameAction::Action::PUSH_GARBAGE) {
8d5e5953 sago007 2016-06-04 13:15 1929
		for (const GarbageStruct& i : action.garbage) {
8d5e5953 sago007 2016-06-04 13:15 1930
			if (i.greyGarbage) {
8d5e5953 sago007 2016-06-04 13:15 1931
				CreateGreyGarbage();
8d5e5953 sago007 2016-06-04 13:15 1932
			}
8d5e5953 sago007 2016-06-04 13:15 1933
			else {
8d5e5953 sago007 2016-06-04 13:15 1934
				CreateGarbage(i.width, i.height);
8d5e5953 sago007 2016-06-04 13:15 1935
			}
8d5e5953 sago007 2016-06-04 13:15 1936
		}
8d5e5953 sago007 2016-06-04 13:15 1937
	}
167c2a1d sago007 2016-06-05 12:45 1938
	if (action.action == BlockGameAction::Action::MOUSE_DOWN) {
167c2a1d sago007 2016-06-05 12:45 1939
		MouseDown(action.x, action.y);
167c2a1d sago007 2016-06-05 12:45 1940
	}
167c2a1d sago007 2016-06-05 12:45 1941
	if (action.action == BlockGameAction::Action::MOUSE_UP) {
167c2a1d sago007 2016-06-05 12:45 1942
		MouseUp();
167c2a1d sago007 2016-06-05 12:45 1943
	}
167c2a1d sago007 2016-06-05 12:45 1944
	if (action.action == BlockGameAction::Action::MOUSE_MOVE) {
167c2a1d sago007 2016-06-05 12:45 1945
		MouseMove(action.x);
167c2a1d sago007 2016-06-05 12:45 1946
	}
50258544 sago007 2012-05-10 19:11 1947
}
50258544 sago007 2012-05-10 19:11 1948
a1072daf sago007 2016-02-20 12:47 1949
bool BlockGame::isSinglePuzzle() const {
a1072daf sago007 2016-02-20 12:47 1950
	return singlePuzzle;
a1072daf sago007 2016-02-20 12:47 1951
}
fde1f2dd sago007 2016-02-21 15:24 1952
fde1f2dd sago007 2016-02-21 15:24 1953
int BlockGame::getLevel() const {
fde1f2dd sago007 2016-02-21 15:24 1954
	return Level;
fde1f2dd sago007 2016-02-21 15:24 1955
}
fde1f2dd sago007 2016-02-21 15:24 1956
3d12f4a8 sago007 2016-03-21 18:40 1957
void BlockGame::PopSendGarbage(std::vector<GarbageStruct>& poppedData) {
3d12f4a8 sago007 2016-03-21 18:40 1958
	for (const GarbageStruct& g : this->garbageSendQueue) {
3d12f4a8 sago007 2016-03-21 18:40 1959
		poppedData.push_back(g);
3d12f4a8 sago007 2016-03-21 18:40 1960
	}
3d12f4a8 sago007 2016-03-21 18:40 1961
	this->garbageSendQueue.clear();
3d12f4a8 sago007 2016-03-21 18:40 1962
}
3d12f4a8 sago007 2016-03-21 18:40 1963
092bdebe sago007 2017-03-19 14:39 1964
void BlockGame::GetMouseCursor(bool& pressed, int& x, int& y) const {
d0c62e33 sago007 2016-04-02 15:18 1965
	if (mouse_cursorx < 0 || mouse_cursory < 0 || mouse_cursorx >=6 || mouse_cursory > 13) {
d0c62e33 sago007 2016-04-02 15:18 1966
		pressed = false;
d0c62e33 sago007 2016-04-02 15:18 1967
		x = 0;
d0c62e33 sago007 2016-04-02 15:18 1968
		y = 0;
d0c62e33 sago007 2016-04-02 15:18 1969
		return;
d0c62e33 sago007 2016-04-02 15:18 1970
	}
d0c62e33 sago007 2016-04-02 15:18 1971
	pressed = true;
d0c62e33 sago007 2016-04-02 15:18 1972
	x = mouse_cursorx;
d0c62e33 sago007 2016-04-02 15:18 1973
	y = mouse_cursory;
d0c62e33 sago007 2016-04-02 15:18 1974
}
d0c62e33 sago007 2016-04-02 15:18 1975
d0c62e33 sago007 2016-04-02 15:18 1976
void BlockGame::MouseDown(int x, int y) {
d0c62e33 sago007 2016-04-02 15:18 1977
	if (AI_Enabled) {
d0c62e33 sago007 2016-04-02 15:18 1978
		//AI may not use mouse move. It must use the controller
d0c62e33 sago007 2016-04-02 15:18 1979
		return;
d0c62e33 sago007 2016-04-02 15:18 1980
	}
d0c62e33 sago007 2016-04-02 15:18 1981
	mouse_cursorx = x;
d0c62e33 sago007 2016-04-02 15:18 1982
	mouse_cursory = y;
092bdebe sago007 2017-03-19 14:39 1983
}
d0c62e33 sago007 2016-04-02 15:18 1984
d0c62e33 sago007 2016-04-02 15:18 1985
void BlockGame::MouseMove(int x) {
d0c62e33 sago007 2016-04-02 15:18 1986
	if (AI_Enabled) {
d0c62e33 sago007 2016-04-02 15:18 1987
		//AI may not use mouse move. It must use the controller
d0c62e33 sago007 2016-04-02 15:18 1988
		return;
d0c62e33 sago007 2016-04-02 15:18 1989
	}
d0c62e33 sago007 2016-04-02 15:18 1990
	if (mouse_cursorx < 0) {
d0c62e33 sago007 2016-04-02 15:18 1991
		return;
d0c62e33 sago007 2016-04-02 15:18 1992
	}
d0c62e33 sago007 2016-04-02 15:18 1993
	if (x < 0 || x >= 6) {
d0c62e33 sago007 2016-04-02 15:18 1994
		return;
d0c62e33 sago007 2016-04-02 15:18 1995
	}
d0c62e33 sago007 2016-04-02 15:18 1996
	if (x > mouse_cursorx) {
d0c62e33 sago007 2016-04-02 15:18 1997
		MoveCursorTo(mouse_cursorx, mouse_cursory);
d0c62e33 sago007 2016-04-02 15:18 1998
		++mouse_cursorx;
d0c62e33 sago007 2016-04-02 15:18 1999
		SwitchAtCursor();
d0c62e33 sago007 2016-04-02 15:18 2000
	}
d0c62e33 sago007 2016-04-02 15:18 2001
	if (x < mouse_cursorx) {
d0c62e33 sago007 2016-04-02 15:18 2002
		--mouse_cursorx;
d0c62e33 sago007 2016-04-02 15:18 2003
		MoveCursorTo(mouse_cursorx, mouse_cursory);
d0c62e33 sago007 2016-04-02 15:18 2004
		SwitchAtCursor();
d0c62e33 sago007 2016-04-02 15:18 2005
	}
d0c62e33 sago007 2016-04-02 15:18 2006
}
d0c62e33 sago007 2016-04-02 15:18 2007
d0c62e33 sago007 2016-04-02 15:18 2008
void BlockGame::MouseUp() {
d0c62e33 sago007 2016-04-02 15:18 2009
	mouse_cursorx = -1;
d0c62e33 sago007 2016-04-02 15:18 2010
	mouse_cursory = -1;
d0c62e33 sago007 2016-04-02 15:18 2011
}
c1785ec5 sago007 2016-02-21 16:07 2012
//Play the next level
c1785ec5 sago007 2016-02-21 16:07 2013
void nextLevel(BlockGame& g, unsigned int ticks) {
b256fda5 sago007 2016-02-21 16:21 2014
	BlockGameStartInfo s;
b256fda5 sago007 2016-02-21 16:21 2015
	s.ticks = ticks;
b256fda5 sago007 2016-02-21 16:21 2016
	s.level = g.getLevel()+1;
c1785ec5 sago007 2016-02-21 16:07 2017
	if (g.isPuzzleMode()) {
c1785ec5 sago007 2016-02-21 16:07 2018
		if (g.getLevel()<PuzzleGetNumberOfPuzzles()-1) {
b256fda5 sago007 2016-02-21 16:21 2019
			s.puzzleMode = true;
b256fda5 sago007 2016-02-21 16:21 2020
			g.NewGame(s);
c1785ec5 sago007 2016-02-21 16:07 2021
		}
c1785ec5 sago007 2016-02-21 16:07 2022
	}
c1785ec5 sago007 2016-02-21 16:07 2023
	else if (g.isStageClear()) {
c1785ec5 sago007 2016-02-21 16:07 2024
		if (g.getLevel() < 50-1) {
c1785ec5 sago007 2016-02-21 16:07 2025
			s.stageClear = true;
c1785ec5 sago007 2016-02-21 16:07 2026
			g.NewGame(s);
c1785ec5 sago007 2016-02-21 16:07 2027
		}
c1785ec5 sago007 2016-02-21 16:07 2028
	}
c1785ec5 sago007 2016-02-21 16:07 2029
}
fde1f2dd sago007 2016-02-21 15:24 2030
fde1f2dd sago007 2016-02-21 15:24 2031
void retryLevel(BlockGame& g, unsigned int ticks) {
b1fe2ae5 sago007 2016-02-21 16:01 2032
	BlockGameStartInfo s;
b1fe2ae5 sago007 2016-02-21 16:01 2033
	s.ticks = ticks;
b256fda5 sago007 2016-02-21 16:21 2034
	s.level = g.getLevel();
fde1f2dd sago007 2016-02-21 15:24 2035
	if (g.isPuzzleMode()) {
b256fda5 sago007 2016-02-21 16:21 2036
		s.puzzleMode = true;
b256fda5 sago007 2016-02-21 16:21 2037
		g.NewGame(s);
fde1f2dd sago007 2016-02-21 15:24 2038
	}
fde1f2dd sago007 2016-02-21 15:24 2039
	else if (g.isStageClear()) {
b1fe2ae5 sago007 2016-02-21 16:01 2040
		s.stageClear = true;
b1fe2ae5 sago007 2016-02-21 16:01 2041
		g.NewGame(s);
fde1f2dd sago007 2016-02-21 15:24 2042
	}
b256fda5 sago007 2016-02-21 16:21 2043
}
1970-01-01 00:00 2044