]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_singleplayer.c
Merge branch 'master' into mand1nga/bot-fixes-II
[xonotic/xonotic-data.pk3dir.git] / qcsrc / menu / xonotic / dialog_singleplayer.c
1 #ifdef INTERFACE
2 CLASS(XonoticSingleplayerDialog) EXTENDS(XonoticDialog)
3         METHOD(XonoticSingleplayerDialog, fill, void(entity))
4         ATTRIB(XonoticSingleplayerDialog, title, string, _("Singleplayer"))
5         ATTRIB(XonoticSingleplayerDialog, color, vector, SKINCOLOR_DIALOG_SINGLEPLAYER)
6         ATTRIB(XonoticSingleplayerDialog, intendedWidth, float, 0.80)
7         ATTRIB(XonoticSingleplayerDialog, rows, float, 24)
8         ATTRIB(XonoticSingleplayerDialog, columns, float, 5)
9         ATTRIB(XonoticSingleplayerDialog, campaignBox, entity, NULL)
10 ENDCLASS(XonoticSingleplayerDialog)
11 #endif
12
13 #ifdef IMPLEMENTATION
14
15 void InstantAction_LoadMap(entity btn, entity dummy)
16 {
17         float pmin, pmax, pstep;
18
19         cvar_set("timelimit_override", "10");
20         cvar_set("g_lms_lives_override", "9");
21
22         if(random() < 0.4) // 40% are DM
23         {
24                 MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH);
25                 pmin = 2;
26                 pmax = 8;
27                 pstep = 1;
28         }
29         else if(random() < 0.5) // half of the remaining 60%, i.e. 30%, are CTF
30         {
31                 MapInfo_SwitchGameType(MAPINFO_TYPE_CTF);
32                 pmin = 4;
33                 pmax = 12;
34                 pstep = 2;
35         }
36         else if(random() < 0.5) // half of the remaining 30%, i.e. 15%, are TDM
37         {
38                 MapInfo_SwitchGameType(MAPINFO_TYPE_TEAM_DEATHMATCH);
39                 pmin = 4;
40                 pmax = 8;
41                 pstep = 2;
42         }
43         else if(random() < 0.666) // 2/3 of the remaining 15%, i.e. 10%, are KH
44         {
45                 MapInfo_SwitchGameType(MAPINFO_TYPE_KEYHUNT);
46                 pmin = 6;
47                 pmax = 6;
48                 pstep = 6; // works both for 2 and 3 teams
49                 // TODO find team count of map, set pstep=2 or 3, and use 2v2(v2) games at least
50         }
51         else // somehow distribute the remaining 5%
52         {
53                 float r;
54                 r = floor(random() * 5);
55                 switch(r)
56                 {
57                         default:
58                         case 0:
59                                 MapInfo_SwitchGameType(MAPINFO_TYPE_LMS);
60                                 pmin = 2;
61                                 pmax = 6;
62                                 pstep = 1;
63                                 cvar_set("timelimit_override", "-1");
64                                 break;
65                         case 1:
66                                 MapInfo_SwitchGameType(MAPINFO_TYPE_CA);
67                                 pmin = 2;
68                                 pmax = 8;
69                                 pstep = 2;
70                                 break;
71                         case 2:
72                                 MapInfo_SwitchGameType(MAPINFO_TYPE_DOMINATION);
73                                 pmin = 2;
74                                 pmax = 8;
75                                 pstep = 2;
76                                 break;
77                         case 3:
78                                 MapInfo_SwitchGameType(MAPINFO_TYPE_ONSLAUGHT);
79                                 pmin = 6;
80                                 pmax = 16;
81                                 pstep = 2;
82                                 break;
83                         case 4:
84                                 MapInfo_SwitchGameType(MAPINFO_TYPE_FREEZETAG);
85                                 pmin = 4;
86                                 pmax = 10;
87                                 pstep = 2;
88                                 break;
89                         case 5:
90                                 MapInfo_SwitchGameType(MAPINFO_TYPE_ASSAULT);
91                                 pmin = 4;
92                                 pmax = 16;
93                                 pstep = 2;
94                                 break;
95                 }
96         }
97
98         // find random map
99         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
100         string s;
101         do
102         {
103                 float m;
104                 m = floor(random() * MapInfo_count);
105                 s = MapInfo_BSPName_ByID(m);
106         }
107         while(!fexists(sprintf("maps/%s.waypoints", s)));
108         MapInfo_LoadMap(s);
109
110         // configure bots
111         float p;
112         pmin = pstep * ceil(pmin / pstep);
113         pmax = pstep * floor(pmax / pstep);
114         p = pmin + pstep * floor(random() * ((pmax - pmin) / pstep + 1));
115         cvar_set("bot_number", ftos(p - 1));
116
117         // make sure we go back to menu
118         cvar_set("lastlevel", "1");
119 }
120
121 void XonoticSingleplayerDialog_fill(entity me)
122 {
123         entity e, btnPrev, btnNext, lblTitle;
124
125         me.TR(me);
126                 me.TDempty(me, (me.columns - 3) / 2);
127                 me.TD(me, 2, 3, e = makeXonoticBigButton(_("Instant action! (random map with bots)"), '0 0 0'));
128                         e.onClick = InstantAction_LoadMap;
129                         e.onClickEntity = NULL;
130         me.TR(me);
131         me.TR(me);
132         me.TR(me);
133                 me.TD(me, 1, 1, btnPrev = makeXonoticButton("<<", '0 0 0'));
134                 me.TD(me, 1, me.columns - 2, lblTitle = makeXonoticTextLabel(0.5, _("???")));
135                 me.TD(me, 1, 1, btnNext = makeXonoticButton(">>", '0 0 0'));
136         me.TR(me);
137                 me.TD(me, me.rows - 5, me.columns, me.campaignBox = makeXonoticCampaignList());
138                         btnPrev.onClick = MultiCampaign_Prev;
139                         btnPrev.onClickEntity = me.campaignBox;
140                         btnNext.onClick = MultiCampaign_Next;
141                         btnNext.onClickEntity = me.campaignBox;
142                         me.campaignBox.buttonNext = btnNext;
143                         me.campaignBox.buttonPrev = btnPrev;
144                         me.campaignBox.labelTitle = lblTitle;
145                         me.campaignBox.campaignGo(me.campaignBox, 0);
146
147         me.gotoRC(me, me.rows - 1, 0);
148                 me.TD(me, 1, me.columns, e = makeXonoticButton(_("Start Singleplayer!"), '0 0 0'));
149                         e.onClick = CampaignList_LoadMap;
150                         e.onClickEntity = me.campaignBox;
151 }
152 #endif