00001 #include "prototypes.h"
00002 #include "defines.h"
00003 #include "globals.h"
00004
00005 bool canPlace(int player, cblock* cp)
00006 {
00007 cblock& p = !cp ? block[player] : *cp;
00008 cblockdesc& desc = blocks[p.blocknum];
00009
00010 int width = g_players[player].playfieldWidth;
00011 int height = g_players[player].playfieldHeight;
00012
00013 for (int y = 0; y < 4; y++)
00014 {
00015 for (int x = 0; x < 4; x++)
00016 {
00017
00018 if (desc.map[p.rot][x][y])
00019 {
00020
00021
00022 int calcx = p.xtile + x;
00023 int calcy = p.ytile + y;
00024
00025
00026
00027 if (calcx >= width)
00028 calcx -= width;
00029 else if (calcx < 0)
00030 calcx += width;
00031
00032
00033 if (calcy >= height)
00034 return false;
00035
00036
00037 if (calcy >= 0 && map[player][calcx][calcy] != 9)
00038 return false;
00039 }
00040 }
00041 }
00042
00043 return true;
00044 }
00045
00046 void rotate(int rot, int player)
00047 {
00048 cblock& p = block[player];
00049
00050 int oldRot = p.rot;
00051
00052 while(rot < 0)
00053 rot += 4;
00054
00055 while(rot > 3)
00056 rot -= 4;
00057
00058 p.rot = rot;
00059
00060 FillBlockInfo(p);
00061
00062
00063 if (!canPlace(player))
00064 {
00065 p.rot = oldRot;
00066 FillBlockInfo(p);
00067 }
00068 }