]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/menu/xonotic/dialog_singleplayer.c
Merge remote-tracking branch 'origin/terencehill/reload_binds', closes #1360
[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 = 2, pmax = 16, pstep = 1;
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() * 4);
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_DOMINATION);
67                                 pmin = 2;
68                                 pmax = 8;
69                                 pstep = 2;
70                                 break;
71                         case 2:
72                                 MapInfo_SwitchGameType(MAPINFO_TYPE_ONSLAUGHT);
73                                 pmin = 6;
74                                 pmax = 16;
75                                 pstep = 2;
76                                 break;
77                         case 3:
78                                 MapInfo_SwitchGameType(MAPINFO_TYPE_ASSAULT);
79                                 pmin = 4;
80                                 pmax = 16;
81                                 pstep = 2;
82                                 break;
83                         // CA, Freezetag: bot AI does not work, add them once it does
84                 }
85         }
86
87         // find random map
88         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
89         string s;
90         do
91         {
92                 float m;
93                 m = floor(random() * MapInfo_count);
94                 s = MapInfo_BSPName_ByID(m);
95         }
96         while(!fexists(sprintf("maps/%s.waypoints", s)));
97         MapInfo_LoadMap(s, 1);
98
99         // configure bots
100         float p;
101         pmin = pstep * ceil(pmin / pstep);
102         pmax = pstep * floor(pmax / pstep);
103         p = pmin + pstep * floor(random() * ((pmax - pmin) / pstep + 1));
104         cvar_set("bot_number", ftos(p - 1));
105
106         // make sure we go back to menu
107         cvar_set("lastlevel", "1");
108 }
109
110 void XonoticSingleplayerDialog_fill(entity me)
111 {
112         entity e, btnPrev, btnNext, lblTitle;
113
114         me.TR(me);
115                 me.TDempty(me, (me.columns - 3) / 2);
116                 me.TD(me, 2, 3, e = makeXonoticBigButton(_("Instant action! (random map with bots)"), '0 0 0'));
117                         e.onClick = InstantAction_LoadMap;
118                         e.onClickEntity = NULL;
119         me.TR(me);
120         me.TR(me);
121         me.TR(me);
122                 me.TD(me, 1, 1, btnPrev = makeXonoticButton("<<", '0 0 0'));
123                 me.TD(me, 1, me.columns - 2, lblTitle = makeXonoticTextLabel(0.5, _("???")));
124                 me.TD(me, 1, 1, btnNext = makeXonoticButton(">>", '0 0 0'));
125         me.TR(me);
126                 me.TD(me, me.rows - 6, me.columns, me.campaignBox = makeXonoticCampaignList());
127                         btnPrev.onClick = MultiCampaign_Prev;
128                         btnPrev.onClickEntity = me.campaignBox;
129                         btnNext.onClick = MultiCampaign_Next;
130                         btnNext.onClickEntity = me.campaignBox;
131                         me.campaignBox.buttonNext = btnNext;
132                         me.campaignBox.buttonPrev = btnPrev;
133                         me.campaignBox.labelTitle = lblTitle;
134                         me.campaignBox.campaignGo(me.campaignBox, 0);
135
136         me.gotoRC(me, me.rows - 2, 0);
137                 me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Campaign Difficulty:")));
138                 me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "-2", ZCTX(_("CSKL^Easy"))));
139                 me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "-1", ZCTX(_("CSKL^Medium"))));
140                 me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "0", ZCTX(_("CSKL^Hard"))));
141                 me.TR(me);
142                 me.TD(me, 1, me.columns, e = makeXonoticButton(_("Start Singleplayer!"), '0 0 0'));
143                         e.onClick = CampaignList_LoadMap;
144                         e.onClickEntity = me.campaignBox;
145 }
146 #endif