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

Go to the source code of this file.

Functions

entity nmm_find_tile (entity minig, string id)
 
bool nmm_in_mill (entity tile)
 
bool nmm_in_mill_string (entity tile, string s)
 
void nmm_init_tiles (entity minig)
 
void nmm_kill_tiles (entity minig)
 
void nmm_spawn_tile (string id, entity minig, int distance)
 
void nmm_spawn_tile_square (entity minig, int offset, int skip)
 
bool nmm_tile_adjacent (entity tile1, entity tile2)
 
string nmm_tile_build_hmill (entity tile)
 
string nmm_tile_build_vmill (entity tile)
 
bool nmm_tile_canmove (entity tile)
 
 REGISTER_MINIGAME (nmm, _("Nine Men's Morris"))
 

Variables

const int NMM_PIECE_BOARD = 0x2
 
const int NMM_PIECE_DEAD = 0x0
 
const int NMM_PIECE_HOME = 0x1
 
const int NMM_SPECTATOR_TEAM = 255
 
int nmm_tile_distance
 
string nmm_tile_hmill
 
entity nmm_tile_piece
 
string nmm_tile_vmill
 
const int NMM_TURN_FLY = 0x0400
 
const int NMM_TURN_MOVE = 0x0200
 
const int NMM_TURN_PLACE = 0x0100
 
const int NMM_TURN_TAKE = 0x0800
 
const int NMM_TURN_TAKEANY =0x1000
 
const int NMM_TURN_TEAM = 0x00ff
 
const int NMM_TURN_TEAM1 = 0x0001
 
const int NMM_TURN_TEAM2 = 0x0002
 
const int NMM_TURN_TYPE = 0xff00
 
const int NMM_TURN_WIN = 0x2000
 

Function Documentation

◆ nmm_find_tile()

entity nmm_find_tile ( entity  minig,
string  id 
)

Definition at line 141 of file nmm.qc.

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

Referenced by nmm_in_mill(), and nmm_in_mill_string().

142 {
143  entity e = NULL;
144  while ( ( e = findentity(e,owner,minig) ) )
145  if ( e.classname == "minigame_nmm_tile" && e.netname == id )
146  return e;
147  return NULL;
148 }
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:

◆ nmm_in_mill()

bool nmm_in_mill ( entity  tile)

◆ nmm_in_mill_string()

bool nmm_in_mill_string ( entity  tile,
string  s 
)

Definition at line 175 of file nmm.qc.

References argv(), entity(), nmm_find_tile(), and tokenize().

Referenced by nmm_in_mill().

176 {
177  int argc = tokenize(s);
178  for ( int i = 0; i < argc; i++ )
179  {
180  entity e = nmm_find_tile(tile.owner,argv(i));
181  if ( !e || !e.nmm_tile_piece || e.nmm_tile_piece.team != tile.nmm_tile_piece.team )
182  return false;
183  }
184  return true;
185 }
entity() spawn
entity nmm_find_tile(entity minig, string id)
Definition: nmm.qc:141
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nmm_init_tiles()

void nmm_init_tiles ( entity  minig)

Definition at line 135 of file nmm.qc.

References nmm_spawn_tile_square().

Referenced by nmm_in_mill().

136 {
137  nmm_spawn_tile_square(minig,0,2);
138 }
void nmm_spawn_tile_square(entity minig, int offset, int skip)
Definition: nmm.qc:100
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nmm_kill_tiles()

void nmm_kill_tiles ( entity  minig)

Definition at line 121 of file nmm.qc.

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

Referenced by nmm_in_mill().

122 {
123  entity e = NULL;
124  while ( ( e = findentity(e,owner,minig) ) )
125  if ( e.classname == "minigame_nmm_tile" )
126  {
127  strfree(e.netname);
128  strfree(e.nmm_tile_hmill);
129  strfree(e.nmm_tile_vmill);
130  delete(e);
131  }
132 }
entity() spawn
entity owner
Definition: main.qh:73
#define NULL
Definition: post.qh:17
#define strfree(this)
Definition: string.qh:56
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nmm_spawn_tile()

void nmm_spawn_tile ( string  id,
entity  minig,
int  distance 
)

Definition at line 83 of file nmm.qc.

References entity(), minigame_tile_pos(), nmm_tile_build_hmill(), nmm_tile_build_vmill(), and strzone().

Referenced by nmm_spawn_tile_square().

84 {
85  // TODO global variable + list_next for simpler tile loops
86  entity e = new(minigame_nmm_tile);
87  e.origin = minigame_tile_pos(id,7,7);
88  e.netname = id;
89  e.owner = minig;
90  e.team = 0;
91  e.nmm_tile_distance = distance;
92  e.nmm_tile_hmill = strzone(nmm_tile_build_hmill(e));
93  e.nmm_tile_vmill = strzone(nmm_tile_build_vmill(e));
94 }
string nmm_tile_build_hmill(entity tile)
Definition: nmm.qc:28
entity() spawn
string nmm_tile_build_vmill(entity tile)
Definition: nmm.qc:54
vector minigame_tile_pos(string id, int rows, int columns)
Definition: minigames.qc:27
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nmm_spawn_tile_square()

void nmm_spawn_tile_square ( entity  minig,
int  offset,
int  skip 
)

Definition at line 100 of file nmm.qc.

References minigame_tile_buildname(), nmm_spawn_tile(), number, and strzone().

Referenced by nmm_init_tiles().

101 {
102  int letter = offset;
103  int number = offset;
104  for ( int i = 0; i < 3; i++ )
105  {
106  number = offset;
107  for ( int j = 0; j < 3; j++ )
108  {
109  if ( i != 1 || j != 1 )
110  nmm_spawn_tile(strzone(minigame_tile_buildname(letter,number)),minig, skip+1);
111  number += skip+1;
112  }
113  letter += skip+1;
114  }
115 
116  if ( skip > 0 )
117  nmm_spawn_tile_square(minig,offset+1,skip-1);
118 }
int int number
Definition: impulse.qc:89
void nmm_spawn_tile_square(entity minig, int offset, int skip)
Definition: nmm.qc:100
string minigame_tile_buildname(int letter, int number)
Definition: minigames.qc:34
void nmm_spawn_tile(string id, entity minig, int distance)
Definition: nmm.qc:83
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nmm_tile_adjacent()

bool nmm_tile_adjacent ( entity  tile1,
entity  tile2 
)

Definition at line 151 of file nmm.qc.

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

Referenced by nmm_in_mill(), and nmm_tile_canmove().

152 {
153 
154  int dnumber = fabs ( minigame_tile_number(tile1.netname) - minigame_tile_number(tile2.netname) );
155  int dletter = fabs ( minigame_tile_letter(tile1.netname) - minigame_tile_letter(tile2.netname) );
156 
157  return ( dnumber == 0 && ( dletter == 1 || dletter == tile1.nmm_tile_distance ) ) ||
158  ( dletter == 0 && ( dnumber == 1 || dnumber == tile1.nmm_tile_distance ) );
159 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
int minigame_tile_letter(string id)
Definition: minigames.qc:12
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ nmm_tile_build_hmill()

string nmm_tile_build_hmill ( entity  tile)

Definition at line 28 of file nmm.qc.

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

Referenced by nmm_spawn_tile().

29 {
30  int number = minigame_tile_number(tile.netname);
31  int letter = minigame_tile_letter(tile.netname);
32  if ( number == letter || number+letter == 6 )
33  {
34  int add = letter < 3 ? 1 : -1;
35  return strcat(tile.netname," ",
36  minigame_tile_buildname(letter+add*tile.nmm_tile_distance,number)," ",
37  minigame_tile_buildname(letter+add*2*tile.nmm_tile_distance,number) );
38  }
39  else if ( letter == 3 )
40  return strcat(minigame_tile_buildname(letter-tile.nmm_tile_distance,number)," ",
41  tile.netname," ",
42  minigame_tile_buildname(letter+tile.nmm_tile_distance,number) );
43  else if ( letter < 3 )
44  return strcat(minigame_tile_buildname(0,number)," ",
45  minigame_tile_buildname(1,number)," ",
46  minigame_tile_buildname(2,number) );
47  else
48  return strcat(minigame_tile_buildname(4,number)," ",
49  minigame_tile_buildname(5,number)," ",
50  minigame_tile_buildname(6,number) );
51 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
int int number
Definition: impulse.qc:89
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
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:

◆ nmm_tile_build_vmill()

string nmm_tile_build_vmill ( entity  tile)

Definition at line 54 of file nmm.qc.

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

Referenced by nmm_spawn_tile().

55 {
56  int letter = minigame_tile_letter(tile.netname);
57  int number = minigame_tile_number(tile.netname);
58  if ( letter == number || letter+number == 6 )
59  {
60  int add = number < 3 ? 1 : -1;
61  return strcat(tile.netname," ",
62  minigame_tile_buildname(letter,number+add*tile.nmm_tile_distance)," ",
63  minigame_tile_buildname(letter,number+add*2*tile.nmm_tile_distance) );
64  }
65  else if ( number == 3 )
66  return strcat(minigame_tile_buildname(letter,number-tile.nmm_tile_distance)," ",
67  tile.netname," ",
68  minigame_tile_buildname(letter,number+tile.nmm_tile_distance) );
69  else if ( number < 3 )
70  return strcat(minigame_tile_buildname(letter,0)," ",
71  minigame_tile_buildname(letter,1)," ",
72  minigame_tile_buildname(letter,2) );
73  else
74  return strcat(minigame_tile_buildname(letter,4)," ",
75  minigame_tile_buildname(letter,5)," ",
76  minigame_tile_buildname(letter,6) );
77 }
int minigame_tile_number(string id)
Definition: minigames.qc:21
int int number
Definition: impulse.qc:89
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
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:

◆ nmm_tile_canmove()

bool nmm_tile_canmove ( entity  tile)

Definition at line 162 of file nmm.qc.

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

Referenced by nmm_in_mill().

163 {
164  entity e = NULL;
165  while ( ( e = findentity(e,owner,tile.owner) ) )
166  if ( e.classname == "minigame_nmm_tile" && !e.nmm_tile_piece
167  && nmm_tile_adjacent(e,tile) )
168  {
169  return true;
170  }
171  return false;
172 }
entity() spawn
entity owner
Definition: main.qh:73
#define NULL
Definition: post.qh:17
bool nmm_tile_adjacent(entity tile1, entity tile2)
Definition: nmm.qc:151
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ REGISTER_MINIGAME()

REGISTER_MINIGAME ( nmm  ,
_("Nine Men's Morris")   
)

Variable Documentation

◆ NMM_PIECE_BOARD

const int NMM_PIECE_BOARD = 0x2

Definition at line 18 of file nmm.qc.

Referenced by nmm_in_mill().

◆ NMM_PIECE_DEAD

const int NMM_PIECE_DEAD = 0x0

Definition at line 16 of file nmm.qc.

Referenced by nmm_in_mill().

◆ NMM_PIECE_HOME

const int NMM_PIECE_HOME = 0x1

Definition at line 17 of file nmm.qc.

Referenced by nmm_in_mill().

◆ NMM_SPECTATOR_TEAM

const int NMM_SPECTATOR_TEAM = 255

Definition at line 20 of file nmm.qc.

Referenced by nmm_in_mill().

◆ nmm_tile_distance

int nmm_tile_distance

Definition at line 22 of file nmm.qc.

◆ nmm_tile_hmill

string nmm_tile_hmill

Definition at line 24 of file nmm.qc.

◆ nmm_tile_piece

entity nmm_tile_piece

Definition at line 23 of file nmm.qc.

◆ nmm_tile_vmill

string nmm_tile_vmill

Definition at line 25 of file nmm.qc.

◆ NMM_TURN_FLY

const int NMM_TURN_FLY = 0x0400

Definition at line 7 of file nmm.qc.

◆ NMM_TURN_MOVE

const int NMM_TURN_MOVE = 0x0200

Definition at line 6 of file nmm.qc.

◆ NMM_TURN_PLACE

const int NMM_TURN_PLACE = 0x0100

Definition at line 5 of file nmm.qc.

◆ NMM_TURN_TAKE

const int NMM_TURN_TAKE = 0x0800

Definition at line 8 of file nmm.qc.

◆ NMM_TURN_TAKEANY

const int NMM_TURN_TAKEANY =0x1000

Definition at line 9 of file nmm.qc.

Referenced by nmm_in_mill().

◆ NMM_TURN_TEAM

const int NMM_TURN_TEAM = 0x00ff

Definition at line 14 of file nmm.qc.

Referenced by nmm_in_mill().

◆ NMM_TURN_TEAM1

const int NMM_TURN_TEAM1 = 0x0001

Definition at line 12 of file nmm.qc.

Referenced by nmm_in_mill().

◆ NMM_TURN_TEAM2

const int NMM_TURN_TEAM2 = 0x0002

Definition at line 13 of file nmm.qc.

◆ NMM_TURN_TYPE

const int NMM_TURN_TYPE = 0xff00

Definition at line 11 of file nmm.qc.

◆ NMM_TURN_WIN

const int NMM_TURN_WIN = 0x2000

Definition at line 10 of file nmm.qc.