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