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

Go to the source code of this file.

Functions

entity pp_find_piece (entity minig, string tile)
 
void pp_move (entity minigame, entity player, string pos)
 
void pp_next_match (entity minigame, entity player)
 
void pp_setup_pieces (entity minigame)
 
bool pp_valid_move (entity minigame, string pos)
 
bool pp_valid_tile (string tile)
 
bool pp_winning_piece (entity piece)
 
 REGISTER_MINIGAME (pp, _("Push-Pull"))
 

Variables

int cnt
 
entity pp_curr_piece
 
const int PP_LET_CNT = 7
 
int pp_nexteam
 
const int PP_NUM_CNT = 7
 
const int PP_SPECTATOR_TEAM = 255
 
int pp_team1_score
 
int pp_team2_score
 
const int PP_TILE_SIZE = 7
 
const int PP_TURN_DRAW = 0x0400
 
const int PP_TURN_NEXT = 0x0800
 
const int PP_TURN_PLACE = 0x0100
 
const int PP_TURN_TEAM = 0x000f
 
const int PP_TURN_TEAM1 = 0x0001
 
const int PP_TURN_TEAM2 = 0x0002
 
const int PP_TURN_TYPE = 0x0f00
 
const int PP_TURN_WIN = 0x0200
 

Function Documentation

◆ pp_find_piece()

entity pp_find_piece ( entity  minig,
string  tile 
)

Definition at line 31 of file pp.qc.

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

Referenced by pp_move(), pp_valid_move(), and pp_winning_piece().

32 {
33  entity e = NULL;
34  while ( ( e = findentity(e,owner,minig) ) )
35  if ( e.classname == "minigame_board_piece" && e.netname == tile )
36  return e;
37  return NULL;
38 }
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:

◆ pp_move()

void pp_move ( entity  minigame,
entity  player,
string  pos 
)

Definition at line 98 of file pp.qc.

References entity(), MINIG_SF_ALL, MINIG_SF_UPDATE, minigame_next_team(), minigame_server_sendflags(), msle_spawn(), pp_find_piece(), PP_TURN_DRAW, pp_valid_move(), pp_winning_piece(), strfree, and strzone().

Referenced by pp_next_match().

99 {
100  if ( minigame.minigame_flags & PP_TURN_PLACE )
101  if ( pos && player.team == (minigame.minigame_flags & PP_TURN_TEAM) )
102  {
103  if ( pp_valid_move(minigame,pos))
104  {
105  entity existing = pp_find_piece(minigame,pos);
106 
107  if(existing && existing.team != 5)
108  {
109  if(existing.team == 1)
110  minigame.pp_team1_score++;
111  if(existing.team == 2)
112  minigame.pp_team2_score++;
113  }
114 
115  if(minigame.pp_curr_piece)
116  {
117  minigame.pp_curr_piece.cnt = 0;
118  minigame.pp_curr_piece.team = 5;
119  minigame_server_sendflags(minigame.pp_curr_piece,MINIG_SF_ALL);
120  }
121 
122  if(existing)
123  {
124  strfree(existing.netname);
125  delete(existing);
126  }
127 
128  entity piece = msle_spawn(minigame,new(minigame_board_piece));
129  piece.cnt = 1;
130  piece.team = player.team; // temporary
131  piece.netname = strzone(pos);
134  minigame.pp_nexteam = minigame_next_team(player.team,2);
135  minigame.pp_curr_piece = piece;
136  if ( pp_winning_piece(piece) )
137  {
138  if(minigame.pp_team1_score == minigame.pp_team2_score)
139  minigame.minigame_flags = PP_TURN_DRAW;
140  else
141  minigame.minigame_flags = PP_TURN_WIN | ((minigame.pp_team1_score > minigame.pp_team2_score) ? 1 : 2);
142  }
143  else
144  minigame.minigame_flags = PP_TURN_PLACE | minigame.pp_nexteam;
145  }
146  }
147 }
void minigame_server_sendflags(entity ent, int mgflags)
Definition: minigames.qc:78
const int MINIG_SF_ALL
Definition: minigames.qh:112
bool pp_winning_piece(entity piece)
Definition: pp.qc:51
entity msle_spawn(entity minigame_session, entity e)
Definition: minigames.qc:87
int minigame_next_team(int curr_team, int n_teams)
Definition: minigames.qc:65
entity() spawn
bool pp_valid_move(entity minigame, string pos)
Definition: pp.qc:70
const int MINIG_SF_UPDATE
Definition: minigames.qh:109
const int PP_TURN_WIN
Definition: pp.qc:5
const int PP_TURN_TEAM
Definition: pp.qc:12
entity pp_find_piece(entity minig, string tile)
Definition: pp.qc:31
#define strfree(this)
Definition: string.qh:56
const int PP_TURN_PLACE
Definition: pp.qc:4
const int PP_TURN_DRAW
Definition: pp.qc:6
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pp_next_match()

void pp_next_match ( entity  minigame,
entity  player 
)

Definition at line 172 of file pp.qc.

References active_minigame, argv(), DRAWFLAG_NORMAL, entity(), eY, findentity(), FOREACH_MINIGAME_ENTITY, ftos(), hud_fontsize, int, MINIG_SF_UPDATE, minigame_count_players(), minigame_drawcolorcodedstring_wrapped(), minigame_drawpic_centered(), minigame_hud_denormalize(), minigame_hud_denormalize_size(), minigame_hud_fitsqare, minigame_hud_simpleboard(), minigame_next_team(), minigame_self, minigame_server_sendflags(), minigame_texture(), minigame_tile_pos(), NULL, owner, panel_fg_alpha, pp_move(), pp_setup_pieces(), PP_SPECTATOR_TEAM, PP_TURN_TEAM1, pp_valid_move(), pp_valid_tile(), strcat(), strfree, string_null, vector(), and WriteByte().

173 {
174 #ifdef SVQC
175  // on multiplayer matches, wait for both players to agree
176  if ( minigame.minigame_flags & (PP_TURN_WIN|PP_TURN_DRAW) )
177  {
178  minigame.minigame_flags = PP_TURN_NEXT | player.team;
179  minigame.SendFlags |= MINIG_SF_UPDATE;
180  }
181  else if ( (minigame.minigame_flags & PP_TURN_NEXT) &&
182  !( minigame.minigame_flags & player.team ) )
183 #endif
184  {
185  minigame.minigame_flags = PP_TURN_PLACE | minigame.pp_nexteam;
187  entity e = NULL;
188  while ( ( e = findentity(e,owner,minigame) ) )
189  if ( e.classname == "minigame_board_piece" )
190  delete(e);
191  minigame.pp_team1_score = 0;
192  minigame.pp_team2_score = 0;
193 
194  pp_setup_pieces(minigame);
195  }
196 }
void minigame_server_sendflags(entity ent, int mgflags)
Definition: minigames.qc:78
entity() spawn
const int PP_TURN_NEXT
Definition: pp.qc:7
const int MINIG_SF_UPDATE
Definition: minigames.qh:109
entity owner
Definition: main.qh:73
const int PP_TURN_WIN
Definition: pp.qc:5
#define NULL
Definition: post.qh:17
void pp_setup_pieces(entity minigame)
Definition: pp.qc:149
const int PP_TURN_PLACE
Definition: pp.qc:4
const int PP_TURN_DRAW
Definition: pp.qc:6
+ Here is the call graph for this function:

◆ pp_setup_pieces()

void pp_setup_pieces ( entity  minigame)

Definition at line 149 of file pp.qc.

References entity(), MINIG_SF_ALL, MINIG_SF_UPDATE, minigame_server_sendflags(), minigame_tile_buildname(), msle_spawn(), NULL, PP_LET_CNT, PP_NUM_CNT, and strzone().

Referenced by pp_next_match().

150 {
151  int i, t; // letter, number
152  for(i = 0; i < PP_LET_CNT; ++i)
153  for(t = 0; t < PP_NUM_CNT; ++t)
154  {
155  bool t2_true = ((i == 0 || i == 6) && t > 0 && t < 6);
156  bool t1_true = (i > 0 && i < 6 && (t == 0 || t == 6));
157 
158  if(t1_true || t2_true)
159  {
160  entity piece = msle_spawn(minigame,new(minigame_board_piece));
161  piece.team = ((t1_true) ? 1 : 2);
162  piece.netname = strzone(minigame_tile_buildname(i,t));
165  }
166  }
167 
168  minigame.pp_curr_piece = NULL;
169 }
void minigame_server_sendflags(entity ent, int mgflags)
Definition: minigames.qc:78
const int MINIG_SF_ALL
Definition: minigames.qh:112
entity msle_spawn(entity minigame_session, entity e)
Definition: minigames.qc:87
entity() spawn
const int MINIG_SF_UPDATE
Definition: minigames.qh:109
#define NULL
Definition: post.qh:17
string minigame_tile_buildname(int letter, int number)
Definition: minigames.qc:34
const int PP_LET_CNT
Definition: pp.qc:16
const int PP_NUM_CNT
Definition: pp.qc:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pp_valid_move()

bool pp_valid_move ( entity  minigame,
string  pos 
)

Definition at line 70 of file pp.qc.

References entity(), minigame_tile_buildname(), minigame_tile_letter(), minigame_tile_number(), number, pp_find_piece(), pp_valid_tile(), and team.

Referenced by pp_move(), and pp_next_match().

71 {
72  if(!pp_valid_tile(pos))
73  return false;
74  if(pp_find_piece(minigame,pos).team == 5)
75  return false;
76 
77  entity current = minigame.pp_curr_piece;
78  if(!current)
79  return true; // no current piece? allow the move anywhere
80 
81  int number = minigame_tile_number(pos);
82  int letter = minigame_tile_letter(pos);
83 
84  if( (pp_find_piece(minigame,minigame_tile_buildname(letter-1,number)) == current)
85  || (pp_find_piece(minigame,minigame_tile_buildname(letter+1,number)) == current)
86  || (pp_find_piece(minigame,minigame_tile_buildname(letter,number-1)) == current)
87  || (pp_find_piece(minigame,minigame_tile_buildname(letter,number+1)) == current)
88  || (pp_find_piece(minigame,minigame_tile_buildname(letter+1,number+1)) == current)
89  || (pp_find_piece(minigame,minigame_tile_buildname(letter-1,number-1)) == current)
90  || (pp_find_piece(minigame,minigame_tile_buildname(letter+1,number-1)) == current)
91  || (pp_find_piece(minigame,minigame_tile_buildname(letter-1,number+1)) == current)
92  ) { return true; }
93 
94  return false;
95 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
int int number
Definition: impulse.qc:89
int team
Definition: main.qh:157
entity() spawn
int minigame_tile_letter(string id)
Definition: minigames.qc:12
string minigame_tile_buildname(int letter, int number)
Definition: minigames.qc:34
entity pp_find_piece(entity minig, string tile)
Definition: pp.qc:31
bool pp_valid_tile(string tile)
Definition: pp.qc:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pp_valid_tile()

bool pp_valid_tile ( string  tile)

Definition at line 41 of file pp.qc.

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

Referenced by pp_next_match(), pp_valid_move(), and pp_winning_piece().

42 {
43  if ( !tile )
44  return 0;
45  int number = minigame_tile_number(tile);
46  int letter = minigame_tile_letter(tile);
47  return 0 <= number && number < PP_NUM_CNT && 0 <= letter && letter < PP_LET_CNT;
48 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
int int number
Definition: impulse.qc:89
int minigame_tile_letter(string id)
Definition: minigames.qc:12
const int PP_LET_CNT
Definition: pp.qc:16
const int PP_NUM_CNT
Definition: pp.qc:17
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pp_winning_piece()

bool pp_winning_piece ( entity  piece)

Definition at line 51 of file pp.qc.

References minigame_tile_buildname(), minigame_tile_letter(), minigame_tile_number(), number, pp_find_piece(), pp_valid_tile(), and team.

Referenced by pp_move().

52 {
53  int number = minigame_tile_number(piece.netname);
54  int letter = minigame_tile_letter(piece.netname);
55 
56  // here goes
57  if(!pp_valid_tile(minigame_tile_buildname(letter-1,number)) || pp_find_piece(piece.owner,minigame_tile_buildname(letter-1,number)).team == 5)
58  if(!pp_valid_tile(minigame_tile_buildname(letter+1,number)) || pp_find_piece(piece.owner,minigame_tile_buildname(letter+1,number)).team == 5)
59  if(!pp_valid_tile(minigame_tile_buildname(letter,number-1)) || pp_find_piece(piece.owner,minigame_tile_buildname(letter,number-1)).team == 5)
60  if(!pp_valid_tile(minigame_tile_buildname(letter,number+1)) || pp_find_piece(piece.owner,minigame_tile_buildname(letter,number+1)).team == 5)
61  if(!pp_valid_tile(minigame_tile_buildname(letter+1,number+1)) || pp_find_piece(piece.owner,minigame_tile_buildname(letter+1,number+1)).team == 5)
62  if(!pp_valid_tile(minigame_tile_buildname(letter-1,number-1)) || pp_find_piece(piece.owner,minigame_tile_buildname(letter-1,number-1)).team == 5)
63  if(!pp_valid_tile(minigame_tile_buildname(letter+1,number-1)) || pp_find_piece(piece.owner,minigame_tile_buildname(letter+1,number-1)).team == 5)
64  if(!pp_valid_tile(minigame_tile_buildname(letter-1,number+1)) || pp_find_piece(piece.owner,minigame_tile_buildname(letter-1,number+1)).team == 5)
65  return true;
66 
67  return false;
68 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
int int number
Definition: impulse.qc:89
int team
Definition: main.qh:157
int minigame_tile_letter(string id)
Definition: minigames.qc:12
string minigame_tile_buildname(int letter, int number)
Definition: minigames.qc:34
entity pp_find_piece(entity minig, string tile)
Definition: pp.qc:31
bool pp_valid_tile(string tile)
Definition: pp.qc:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ REGISTER_MINIGAME()

REGISTER_MINIGAME ( pp  ,
_("Push-Pull")   
)

Variable Documentation

◆ cnt

int cnt

Definition at line 21 of file pp.qc.

◆ pp_curr_piece

entity pp_curr_piece

Definition at line 28 of file pp.qc.

◆ PP_LET_CNT

const int PP_LET_CNT = 7

Definition at line 16 of file pp.qc.

Referenced by pp_setup_pieces(), and pp_valid_tile().

◆ pp_nexteam

int pp_nexteam

Definition at line 26 of file pp.qc.

◆ PP_NUM_CNT

const int PP_NUM_CNT = 7

Definition at line 17 of file pp.qc.

Referenced by pp_setup_pieces().

◆ PP_SPECTATOR_TEAM

const int PP_SPECTATOR_TEAM = 255

Definition at line 14 of file pp.qc.

Referenced by pp_next_match().

◆ pp_team1_score

int pp_team1_score

Definition at line 23 of file pp.qc.

◆ pp_team2_score

int pp_team2_score

Definition at line 24 of file pp.qc.

◆ PP_TILE_SIZE

const int PP_TILE_SIZE = 7

Definition at line 19 of file pp.qc.

◆ PP_TURN_DRAW

const int PP_TURN_DRAW = 0x0400

Definition at line 6 of file pp.qc.

Referenced by pp_move().

◆ PP_TURN_NEXT

const int PP_TURN_NEXT = 0x0800

Definition at line 7 of file pp.qc.

◆ PP_TURN_PLACE

const int PP_TURN_PLACE = 0x0100

Definition at line 4 of file pp.qc.

◆ PP_TURN_TEAM

const int PP_TURN_TEAM = 0x000f

Definition at line 12 of file pp.qc.

◆ PP_TURN_TEAM1

const int PP_TURN_TEAM1 = 0x0001

Definition at line 10 of file pp.qc.

Referenced by pp_next_match().

◆ PP_TURN_TEAM2

const int PP_TURN_TEAM2 = 0x0002

Definition at line 11 of file pp.qc.

◆ PP_TURN_TYPE

const int PP_TURN_TYPE = 0x0f00

Definition at line 8 of file pp.qc.

◆ PP_TURN_WIN

const int PP_TURN_WIN = 0x0200

Definition at line 5 of file pp.qc.