Xonotic
dialog_singleplayer.qc
Go to the documentation of this file.
1 #include "dialog_singleplayer.qh"
2 
4 #include "bigbutton.qh"
5 #include "radiobutton.qh"
6 #include "textlabel.qh"
7 #include "campaign.qh"
8 
10 {
11  float pmin = 2, pmax = 16, pstep = 1;
12 
13  cvar_set("timelimit_override", "10");
14 
15  bool check_probability_distribution = true;
16  float r = 1;
17 
18  LABEL(doit);
19  if (!check_probability_distribution)
20  r = random();
21 
22  if((r -= 0.30) < 0)
23  {
24  MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH);
25  pmin = 2;
26  pmax = 8;
27  pstep = 1;
28  }
29  else if((r -= 0.25) < 0)
30  {
31  MapInfo_SwitchGameType(MAPINFO_TYPE_CTF);
32  pmin = 4;
33  pmax = 12;
34  pstep = 2;
35  }
36  else if((r -= 0.15) < 0)
37  {
38  MapInfo_SwitchGameType(MAPINFO_TYPE_TEAM_DEATHMATCH);
39  pmin = 4;
40  pmax = 8;
41  pstep = 2;
42  }
43  else if((r -= 0.10) < 0)
44  {
45  MapInfo_SwitchGameType(MAPINFO_TYPE_CA);
46  pmin = 4;
47  pmax = 8;
48  pstep = 2;
49  }
50  else if((r -= 0.10) < 0)
51  {
52  MapInfo_SwitchGameType(MAPINFO_TYPE_FREEZETAG);
53  pmin = 4;
54  pmax = 8;
55  pstep = 2;
56  }
57  else if((r -= 0.05) < 0)
58  {
59  MapInfo_SwitchGameType(MAPINFO_TYPE_KEYHUNT);
60  pmin = 6;
61  pmax = 6;
62  pstep = 6; // works both for 2 and 3 teams
63  // TODO find team count of map, set pstep=2 or 3, and use 2v2(v2) games at least
64  }
65  else
66  {
67  r -= 0.05;
68  if (check_probability_distribution)
69  {
70  if(fabs(r) > 0.001)
71  error("Incorrect probability distribution.");
72  check_probability_distribution = false;
73  goto doit;
74  }
75  r = floor(random() * 4);
76  switch(r)
77  {
78  default:
79  case 0:
80  MapInfo_SwitchGameType(MAPINFO_TYPE_LMS);
81  pmin = 2;
82  pmax = 6;
83  pstep = 1;
84  cvar_set("timelimit_override", "-1");
85  break;
86  case 1:
87  MapInfo_SwitchGameType(MAPINFO_TYPE_DOMINATION);
88  pmin = 2;
89  pmax = 8;
90  pstep = 2;
91  break;
92  case 2:
93  MapInfo_SwitchGameType(MAPINFO_TYPE_ONSLAUGHT);
94  pmin = 6;
95  pmax = 16;
96  pstep = 2;
97  break;
98  case 3:
99  MapInfo_SwitchGameType(MAPINFO_TYPE_ASSAULT);
100  pmin = 4;
101  pmax = 16;
102  pstep = 2;
103  break;
104  }
105  }
106 
107  // find random map
109  string s;
110  do
111  {
112  float m;
113  m = floor(random() * MapInfo_count);
114  s = MapInfo_BSPName_ByID(m);
115  }
116  while(!fexists(sprintf("maps/%s.waypoints", s)));
117 
118  // these commands are also executed when starting a map from Multiplayer / Create
119  // in the menu_loadmap_prepare alias
120  localcmd("disconnect\n");
121  localcmd("g_campaign 0\n");
122 
123  MapInfo_LoadMap(s, 1);
124 
125  // configure bots
126  float p;
127  pmin = pstep * ceil(pmin / pstep);
128  pmax = pstep * floor(pmax / pstep);
129  p = pmin + pstep * floor(random() * ((pmax - pmin) / pstep + 1));
130 
131  // cvar_set doesn't always work starting an InstantAction game while playing the campaign
132  //cvar_set("bot_number", ftos(p - 1));
133  localcmd(strcat("bot_number ", ftos(p - 1), "\n"));
134 
135  // make sure we go back to menu
136  cvar_set("lastlevel", "1");
137 }
138 
140 {
141  entity e, btnPrev, btnNext, lblTitle;
142 
143  me.TR(me);
144  me.TDempty(me, (me.columns - 3) / 2);
145  me.TD(me, 2, 3, e = makeXonoticBigButton(_("Instant action! (random map with bots)"), '0 0 0'));
146  e.onClick = InstantAction_LoadMap;
147  e.onClickEntity = NULL;
148  me.TR(me);
149  me.TR(me);
150  me.TR(me);
151  me.TD(me, 1, 1, btnPrev = makeXonoticButton("<<", '0 0 0'));
152  me.TD(me, 1, me.columns - 2, lblTitle = makeXonoticTextLabel(0.5, _("???")));
153  me.TD(me, 1, 1, btnNext = makeXonoticButton(">>", '0 0 0'));
154  me.TR(me);
155  me.TD(me, me.rows - 6, me.columns, me.campaignBox = makeXonoticCampaignList());
156  btnPrev.onClick = MultiCampaign_Prev;
157  btnPrev.onClickEntity = me.campaignBox;
158  btnNext.onClick = MultiCampaign_Next;
159  btnNext.onClickEntity = me.campaignBox;
160  me.campaignBox.buttonNext = btnNext;
161  me.campaignBox.buttonPrev = btnPrev;
162  me.campaignBox.labelTitle = lblTitle;
163 
164  me.gotoRC(me, me.rows - 2, 0);
165  me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Campaign Difficulty:")));
166  me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "-2", ZCTX(_("CSKL^Easy"))));
167  me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "0", ZCTX(_("CSKL^Medium"))));
168  me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "2", ZCTX(_("CSKL^Hard"))));
169  me.TR(me);
170  me.TD(me, 1, me.columns, e = makeXonoticButton(_("Start Singleplayer!"), '0 0 0'));
171  e.onClick = CampaignList_LoadMap;
172  e.onClickEntity = me.campaignBox;
173 }
int MapInfo_RequiredFlags()
Definition: mapinfo.qc:1339
entity makeXonoticBigButton(string theText, vector theColor)
Definition: bigbutton.qc:3
entity makeXonoticRadioButton(float theGroup, string theCvar, string theValue, string theText)
Definition: radiobutton.qc:10
entity() spawn
entity makeXonoticTextLabel(float theAlign, string theText)
Definition: textlabel.qc:3
int MapInfo_ForbiddenFlags()
Definition: mapinfo.qc:1324
float MapInfo_count
Definition: mapinfo.qh:144
Gametype MapInfo_CurrentGametype()
Definition: mapinfo.qc:1150
int MapInfo_CurrentFeatures()
Definition: mapinfo.qc:1140
#define ZCTX(s)
Definition: i18n.qh:68
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"))
#define NULL
Definition: post.qh:17
#define LABEL(id)
Definition: compiler.qh:36
void InstantAction_LoadMap(entity btn, entity dummy)
void MapInfo_LoadMap(string s, float reinit)
Definition: mapinfo.qc:1183
float MapInfo_FilterGametype(Gametype pGametype, int pFeatures, int pFlagsRequired, int pFlagsForbidden, bool pAbortOnGenerate)
Definition: mapinfo.qc:158
ERASEABLE bool fexists(string f)
Definition: file.qh:4
string MapInfo_BSPName_ByID(float i)
Definition: mapinfo.qc:231
void MapInfo_SwitchGameType(Gametype t)
Definition: mapinfo.qc:1178
void XonoticSingleplayerDialog_fill(entity me)