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