-
Notifications
You must be signed in to change notification settings - Fork 0
/
boardpos.c
158 lines (133 loc) · 4.54 KB
/
boardpos.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* Copyright (C) 2003 Joern Thyssen <jth@gnubg.org>
* Copyright (C) 2003-2018 the AUTHORS
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* $Id: boardpos.c,v 1.20 2018/04/21 16:20:21 plm Exp $
*/
#include "config.h"
#include <glib.h>
#include <stdlib.h>
#include "boarddim.h"
#include "boardpos.h"
#include "common.h"
extern void
ChequerPosition(const int clockwise, const int point, const int chequer, int *px, int *py)
{
int c_chequer;
c_chequer = (!point || point == 25) ? 3 : 5;
if (c_chequer > chequer)
c_chequer = chequer;
*px = positions[clockwise][point][0];
*py = positions[clockwise][point][1] - (c_chequer - 1) * positions[clockwise][point][2];
}
extern void
PointArea(const int fClockwise, const int nSize, const int n, int *px, int *py, int *pcx, int *pcy)
{
/* max chequer in column */
int c_chequer = (n == 0 || n == 25) ? 3 : 5;
g_assert(n >= 0);
*px = positions[fClockwise][n][0] * nSize;
*py = positions[fClockwise][n][1] * nSize;
*pcx = CHEQUER_WIDTH * nSize;
*pcy = positions[fClockwise][n][2] * nSize;
if (*pcy > 0) {
*pcy = *pcy * (c_chequer - 1) + (CHEQUER_HEIGHT + DISPLAY_POINT_EXTRA) * nSize;
*py += CHEQUER_HEIGHT * nSize - *pcy;
} else
*pcy = -*pcy * (c_chequer - 1) + (CHEQUER_HEIGHT + DISPLAY_POINT_EXTRA) * nSize;
}
/* Determine the position and rotation of the cube; *px and *py return the
* position (in board units -- multiply by nSize to get
* pixels) and *porient returns the rotation (1 = facing the top, 0 = facing
* the side, -1 = facing the bottom). */
extern void
CubePosition(const int crawford_game, const int cube_use,
const int doubled, const int cube_owner, int fClockwise, int *px, int *py, int *porient)
{
if (crawford_game || !cube_use) {
/* no cube */
if (px)
*px = NO_CUBE;
if (py)
*py = NO_CUBE;
if (porient)
*porient = -1;
} else if (doubled) {
if (px)
*px = (doubled > 0) ? CUBE_RIGHT_X : CUBE_LEFT_X;
if (py)
*py = CUBE_CENTRE_Y;
if (porient)
*porient = doubled;
} else {
if (px) {
if (fClockwise)
*px = BOARD_WIDTH - (BEAROFF_INSIDE + CUBE_TRAY_X);
else
*px = CUBE_TRAY_X;
}
if (py)
*py = (cube_owner < 0) ? CUBE_OWN_1_Y : (cube_owner == 0) ? CUBE_CENTRE_Y : CUBE_OWN_0_Y;
if (porient)
*porient = cube_owner;
}
}
extern void
ResignPosition(const int resigned, int *px, int *py, int *porient)
{
if (resigned) {
if (px)
*px = (SGN(resigned) < 0) ? CUBE_RESIGN_LEFT_X : CUBE_RESIGN_RIGHT_X;
if (py)
*py = CUBE_CENTRE_Y;
if (porient)
*porient = -SGN(resigned);
} else {
/* no resignation */
if (px)
*px = NO_CUBE;
if (py)
*py = NO_CUBE;
if (porient)
*porient = -1;
}
}
extern void
ArrowPosition(const int clockwise, int turn, const int nSize, int *px, int *py)
{
/* calculate the position of the arrow to indicate
* player on turn and direction of play; *px and *py
* return the position of the upper left corner in pixels,
* NOT board units */
int Point_x, Point_y, Point_dx, Point_dy;
PointArea(clockwise, nSize, (turn == 1) ? 26 : 27, &Point_x, &Point_y, &Point_dx, &Point_dy);
if (px) {
if (clockwise)
*px = Point_x + (nSize * BEAROFF_INSIDE);
else
*px = Point_x - (nSize * BORDER_WIDTH);
/* Center arrow in border */
*px += (nSize * (BORDER_WIDTH - ARROW_WIDTH)) / 2;
}
if (py) {
if (turn == 1)
*py = Point_y + Point_dy;
else
*py = Point_y - (nSize * BORDER_WIDTH); /*- 2 * nSize * ARROW_HEIGHT; */
/* Center arrow in border */
*py += (nSize * (BORDER_WIDTH - ARROW_HEIGHT)) / 2;
}
}