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