Xonotic
ps.qc File Reference
#include "ps.qh"
+ Include dependency graph for ps.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool ps_draw (entity minigame)
 
entity ps_find_piece (entity minig, string tile)
 
void ps_move (entity minigame, entity player, string thepiece, string pos)
 
bool ps_move_piece (entity minigame, entity piece, string pos, int leti, int numb)
 
void ps_setup_pieces (entity minigame)
 
bool ps_tile_blacklisted (string tile)
 
bool ps_valid_tile (string tile)
 
bool ps_winning_piece (entity minigame)
 
 REGISTER_MINIGAME (ps, _("Peg Solitaire"))
 

Variables

const int PS_LET_CNT = 7
 
const int PS_NUM_CNT = 7
 
const int PS_SPECTATOR_TEAM = 255
 
const int PS_TILE_SIZE = 8
 
const float PS_TURN_DRAW = 0x0400
 
const float PS_TURN_MOVE = 0x0100
 
const float PS_TURN_TYPE = 0x0f00
 
const float PS_TURN_WIN = 0x0200
 

Function Documentation

◆ ps_draw()

bool ps_draw ( entity  minigame)

Definition at line 26 of file ps.qc.

References entity(), findentity(), NULL, and owner.

Referenced by ps_move().

27 {
28  entity e = NULL;
29  while( ( e = findentity(e,owner,minigame) ) )
30  if( e.classname == "minigame_board_piece" )
31  {
32  return true;
33  }
34 
35  return false;
36 }
entity() spawn
entity owner
Definition: main.qh:73
#define NULL
Definition: post.qh:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ps_find_piece()

entity ps_find_piece ( entity  minig,
string  tile 
)

Definition at line 17 of file ps.qc.

References entity(), findentity(), NULL, and owner.

Referenced by ps_move(), ps_move_piece(), and ps_winning_piece().

18 {
19  entity e = NULL;
20  while ( ( e = findentity(e,owner,minig) ) )
21  if ( e.classname == "minigame_board_piece" && e.netname == tile )
22  return e;
23  return NULL;
24 }
entity() spawn
entity owner
Definition: main.qh:73
#define NULL
Definition: post.qh:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ps_move()

void ps_move ( entity  minigame,
entity  player,
string  thepiece,
string  pos 
)

Definition at line 158 of file ps.qc.

References active_minigame, argv(), DRAWFLAG_ADDITIVE, DRAWFLAG_NORMAL, entity(), findentity(), FOREACH_MINIGAME_ENTITY, hud_fontsize, MINIG_SF_UPDATE, minigame_count_players(), minigame_drawpic_centered(), minigame_hud_denormalize(), minigame_hud_denormalize_size(), minigame_hud_fitsqare, minigame_hud_simpleboard(), minigame_server_sendflags(), minigame_texture(), minigame_tile_buildname(), minigame_tile_letter(), minigame_tile_number(), minigame_tile_pos(), NULL, number, owner, panel_fg_alpha, ps_draw(), ps_find_piece(), ps_move_piece(), ps_setup_pieces(), PS_SPECTATOR_TEAM, PS_TURN_DRAW, PS_TURN_MOVE, PS_TURN_WIN, ps_valid_tile(), ps_winning_piece(), strfree, string_null, and vector().

159 {
160  if ( (minigame.minigame_flags & PS_TURN_MOVE) )
161  if ( pos )
162  {
163  if ( ps_valid_tile(pos) )
164  if ( !ps_find_piece(minigame, pos) && ps_find_piece(minigame, thepiece) )
165  {
166  entity piece = ps_find_piece(minigame, thepiece);
167  int number = minigame_tile_number(thepiece);
168  int letter = minigame_tile_letter(thepiece);
169  bool done = false;
170  string try;
171 
172  try = minigame_tile_buildname(letter-1,number);
173  if(ps_find_piece(minigame,try))
174  {
175  try = minigame_tile_buildname(letter-2,number);
176  if(ps_valid_tile(try) && try == pos)
177  done = ps_move_piece(minigame, piece, pos, letter - 1, number);
178  }
179  try = minigame_tile_buildname(letter+1,number);
180  if(!done && ps_find_piece(minigame,try))
181  {
182  try = minigame_tile_buildname(letter+2,number);
183  if(ps_valid_tile(try) && try == pos)
184  done = ps_move_piece(minigame, piece, pos, letter + 1, number);
185  }
186  try = minigame_tile_buildname(letter,number-1);
187  if(!done && ps_find_piece(minigame,try))
188  {
189  try = minigame_tile_buildname(letter,number-2);
190  if(ps_valid_tile(try) && try == pos)
191  done = ps_move_piece(minigame, piece, pos, letter, number - 1);
192  }
193  try = minigame_tile_buildname(letter,number+1);
194  if(!done && ps_find_piece(minigame,try))
195  {
196  try = minigame_tile_buildname(letter,number+2);
197  if(ps_valid_tile(try) && try == pos)
198  done = ps_move_piece(minigame, piece, pos, letter, number + 1);
199  }
200 
201  if(!done)
202  return; // didn't make a move
203 
205 
206  if ( ps_winning_piece(minigame) )
207  {
208  if(ps_draw(minigame))
209  minigame.minigame_flags = PS_TURN_DRAW;
210  else
211  minigame.minigame_flags = PS_TURN_WIN;
212  }
213  else
214  minigame.minigame_flags = PS_TURN_MOVE;
215  }
216  }
217 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
void minigame_server_sendflags(entity ent, int mgflags)
Definition: minigames.qc:78
int int number
Definition: impulse.qc:89
entity() spawn
bool ps_draw(entity minigame)
Definition: ps.qc:26
bool ps_valid_tile(string tile)
Definition: ps.qc:61
const float PS_TURN_WIN
Definition: ps.qc:5
entity ps_find_piece(entity minig, string tile)
Definition: ps.qc:17
const int MINIG_SF_UPDATE
Definition: minigames.qh:109
const float PS_TURN_DRAW
Definition: ps.qc:6
bool ps_winning_piece(entity minigame)
Definition: ps.qc:73
bool ps_move_piece(entity minigame, entity piece, string pos, int leti, int numb)
Definition: ps.qc:137
int minigame_tile_letter(string id)
Definition: minigames.qc:12
string minigame_tile_buildname(int letter, int number)
Definition: minigames.qc:34
const float PS_TURN_MOVE
Definition: ps.qc:4
+ Here is the call graph for this function:

◆ ps_move_piece()

bool ps_move_piece ( entity  minigame,
entity  piece,
string  pos,
int  leti,
int  numb 
)

Definition at line 137 of file ps.qc.

References entity(), MINIG_SF_ALL, minigame_server_sendflags(), minigame_tile_buildname(), ps_find_piece(), strcpy, and strfree.

Referenced by ps_move().

138 {
139  if(!piece)
140  return false;
141  if(ps_find_piece(minigame, pos))
142  return false;
143  entity middle = ps_find_piece(minigame, minigame_tile_buildname(leti,numb));
144  if(!middle)
145  return false;
146 
147  strfree(middle.netname);
148  delete(middle);
149 
150  strcpy(piece.netname, pos);
151 
153 
154  return true;
155 }
void minigame_server_sendflags(entity ent, int mgflags)
Definition: minigames.qc:78
const int MINIG_SF_ALL
Definition: minigames.qh:112
entity() spawn
entity ps_find_piece(entity minig, string tile)
Definition: ps.qc:17
#define strcpy(this, s)
Definition: string.qh:49
string minigame_tile_buildname(int letter, int number)
Definition: minigames.qc:34
#define strfree(this)
Definition: string.qh:56
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ps_setup_pieces()

void ps_setup_pieces ( entity  minigame)

Definition at line 117 of file ps.qc.

References entity(), floor(), MINIG_SF_ALL, MINIG_SF_UPDATE, minigame_server_sendflags(), minigame_tile_buildname(), msle_spawn(), PS_LET_CNT, PS_NUM_CNT, ps_valid_tile(), and strzone().

Referenced by ps_move().

118 {
119  int i, t;
120  for(i = 0; i < PS_NUM_CNT; ++i)
121  for(t = 0; t < PS_LET_CNT; ++t)
122  {
123  string try = minigame_tile_buildname(i,t);
124  if(!ps_valid_tile(try))
125  continue;
126  if(i == floor(PS_NUM_CNT * 0.5) && t == floor(PS_LET_CNT * 0.5))
127  continue; // middle piece is empty
128  entity piece = msle_spawn(minigame,new(minigame_board_piece));
129  piece.team = 1; // init default team?
130  piece.netname = strzone(minigame_tile_buildname(t,i));
132  }
133 
135 }
void minigame_server_sendflags(entity ent, int mgflags)
Definition: minigames.qc:78
const int MINIG_SF_ALL
Definition: minigames.qh:112
const int PS_NUM_CNT
Definition: ps.qc:12
entity msle_spawn(entity minigame_session, entity e)
Definition: minigames.qc:87
entity() spawn
bool ps_valid_tile(string tile)
Definition: ps.qc:61
const int MINIG_SF_UPDATE
Definition: minigames.qh:109
string minigame_tile_buildname(int letter, int number)
Definition: minigames.qc:34
const int PS_LET_CNT
Definition: ps.qc:11
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ps_tile_blacklisted()

bool ps_tile_blacklisted ( string  tile)

Definition at line 38 of file ps.qc.

References minigame_tile_letter(), minigame_tile_number(), and number.

Referenced by ps_valid_tile().

39 {
40  int number = minigame_tile_number(tile);
41  int letter = minigame_tile_letter(tile);
42  if(letter < 2)
43  {
44  if(number < 2)
45  return true;
46  else if(number > PS_NUM_CNT - 3)
47  return true;
48  }
49  if(letter > PS_LET_CNT - 3)
50  {
51  if(number < 2)
52  return true;
53  else if(number > PS_NUM_CNT - 3)
54  return true;
55  }
56 
57  return false;
58 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
const int PS_NUM_CNT
Definition: ps.qc:12
int int number
Definition: impulse.qc:89
int minigame_tile_letter(string id)
Definition: minigames.qc:12
const int PS_LET_CNT
Definition: ps.qc:11
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ps_valid_tile()

bool ps_valid_tile ( string  tile)

Definition at line 61 of file ps.qc.

References minigame_tile_letter(), minigame_tile_number(), number, PS_LET_CNT, and ps_tile_blacklisted().

Referenced by ps_move(), ps_setup_pieces(), and ps_winning_piece().

62 {
63  if ( !tile )
64  return false;
65  if(ps_tile_blacklisted(tile))
66  return false;
67  float number = minigame_tile_number(tile);
68  float letter = minigame_tile_letter(tile);
69  return 0 <= number && number < PS_NUM_CNT && 0 <= letter && letter < PS_LET_CNT;
70 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
const int PS_NUM_CNT
Definition: ps.qc:12
int int number
Definition: impulse.qc:89
bool ps_tile_blacklisted(string tile)
Definition: ps.qc:38
int minigame_tile_letter(string id)
Definition: minigames.qc:12
const int PS_LET_CNT
Definition: ps.qc:11
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ps_winning_piece()

bool ps_winning_piece ( entity  minigame)

Definition at line 73 of file ps.qc.

References entity(), findentity(), minigame_tile_buildname(), minigame_tile_letter(), minigame_tile_number(), NULL, number, owner, ps_find_piece(), and ps_valid_tile().

Referenced by ps_move().

74 {
75  //int number = minigame_tile_number(piece.netname);
76  //int letter = minigame_tile_letter(piece.netname);
77 
78  entity e = NULL;
79  while ( ( e = findentity(e,owner,minigame) ) )
80  if ( e.classname == "minigame_board_piece" )
81  {
82  int number = minigame_tile_number(e.netname);
83  int letter = minigame_tile_letter(e.netname);
84  string try = minigame_tile_buildname(letter - 1, number);
85  if(ps_find_piece(minigame,try))
86  {
87  try = minigame_tile_buildname(letter - 2, number);
88  if(ps_valid_tile(try) && !ps_find_piece(minigame,try))
89  return false; // a move is valid, abort!
90  }
91  try = minigame_tile_buildname(letter + 1, number);
92  if(ps_find_piece(minigame,try))
93  {
94  try = minigame_tile_buildname(letter + 2, number);
95  if(ps_valid_tile(try) && !ps_find_piece(minigame,try))
96  return false; // a move is valid, abort!
97  }
98  try = minigame_tile_buildname(letter, number - 1);
99  if(ps_find_piece(minigame,try))
100  {
101  try = minigame_tile_buildname(letter, number - 2);
102  if(ps_valid_tile(try) && !ps_find_piece(minigame,try))
103  return false; // a move is valid, abort!
104  }
105  try = minigame_tile_buildname(letter, number + 1);
106  if(ps_find_piece(minigame,try))
107  {
108  try = minigame_tile_buildname(letter, number + 2);
109  if(ps_valid_tile(try) && !ps_find_piece(minigame,try))
110  return false; // a move is valid, abort!
111  }
112  }
113 
114  return true;
115 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
int int number
Definition: impulse.qc:89
entity() spawn
bool ps_valid_tile(string tile)
Definition: ps.qc:61
entity ps_find_piece(entity minig, string tile)
Definition: ps.qc:17
entity owner
Definition: main.qh:73
#define NULL
Definition: post.qh:17
int minigame_tile_letter(string id)
Definition: minigames.qc:12
string minigame_tile_buildname(int letter, int number)
Definition: minigames.qc:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ REGISTER_MINIGAME()

REGISTER_MINIGAME ( ps  ,
_("Peg Solitaire")   
)

Variable Documentation

◆ PS_LET_CNT

const int PS_LET_CNT = 7

Definition at line 11 of file ps.qc.

Referenced by ps_setup_pieces(), and ps_valid_tile().

◆ PS_NUM_CNT

const int PS_NUM_CNT = 7

Definition at line 12 of file ps.qc.

Referenced by ps_setup_pieces().

◆ PS_SPECTATOR_TEAM

const int PS_SPECTATOR_TEAM = 255

Definition at line 9 of file ps.qc.

Referenced by ps_move().

◆ PS_TILE_SIZE

const int PS_TILE_SIZE = 8

Definition at line 14 of file ps.qc.

◆ PS_TURN_DRAW

const float PS_TURN_DRAW = 0x0400

Definition at line 6 of file ps.qc.

Referenced by ps_move().

◆ PS_TURN_MOVE

const float PS_TURN_MOVE = 0x0100

Definition at line 4 of file ps.qc.

Referenced by ps_move().

◆ PS_TURN_TYPE

const float PS_TURN_TYPE = 0x0f00

Definition at line 7 of file ps.qc.

◆ PS_TURN_WIN

const float PS_TURN_WIN = 0x0200

Definition at line 5 of file ps.qc.

Referenced by ps_move().