X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fmenu%2Fxonotic%2Fdialog_singleplayer.qc;h=686c0bfcb8b71aea686bc7fe45242064d44d620d;hb=803bb1f7a6849bd8b662d2f968c1297beb46ffce;hp=aa00d8fe8e5d56eab97a5ed16c6246b7f9d289de;hpb=a16bfaa11ae87fe6fdab9e6c4504e2c5528ea595;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/menu/xonotic/dialog_singleplayer.qc b/qcsrc/menu/xonotic/dialog_singleplayer.qc index aa00d8fe8..686c0bfcb 100644 --- a/qcsrc/menu/xonotic/dialog_singleplayer.qc +++ b/qcsrc/menu/xonotic/dialog_singleplayer.qc @@ -1,48 +1,62 @@ -#ifndef DIALOG_SINGLEPLAYER_H -#define DIALOG_SINGLEPLAYER_H -#include "dialog.qc" -CLASS(XonoticSingleplayerDialog, XonoticDialog) - METHOD(XonoticSingleplayerDialog, fill, void(entity)) - ATTRIB(XonoticSingleplayerDialog, title, string, _("Singleplayer")) - ATTRIB(XonoticSingleplayerDialog, color, vector, SKINCOLOR_DIALOG_SINGLEPLAYER) - ATTRIB(XonoticSingleplayerDialog, intendedWidth, float, 0.80) - ATTRIB(XonoticSingleplayerDialog, rows, float, 24) - ATTRIB(XonoticSingleplayerDialog, columns, float, 5) - ATTRIB(XonoticSingleplayerDialog, campaignBox, entity, NULL) -ENDCLASS(XonoticSingleplayerDialog) -#endif - -#ifdef IMPLEMENTATION +#include "dialog_singleplayer.qh" + +#include +#include "bigbutton.qh" +#include "commandbutton.qh" +#include "leavematchbutton.qh" +#include "radiobutton.qh" +#include "textlabel.qh" +#include "campaign.qh" void InstantAction_LoadMap(entity btn, entity dummy) { float pmin = 2, pmax = 16, pstep = 1; cvar_set("timelimit_override", "10"); - cvar_set("g_lms_lives_override", "9"); - if(random() < 0.4) // 40% are DM + bool check_probability_distribution = true; + float r = 1; + + LABEL(doit); + if (!check_probability_distribution) + r = random(); + + if((r -= 0.30) < 0) { MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH); pmin = 2; pmax = 8; pstep = 1; } - else if(random() < 0.5) // half of the remaining 60%, i.e. 30%, are CTF + else if((r -= 0.25) < 0) { MapInfo_SwitchGameType(MAPINFO_TYPE_CTF); pmin = 4; pmax = 12; pstep = 2; } - else if(random() < 0.5) // half of the remaining 30%, i.e. 15%, are TDM + else if((r -= 0.15) < 0) { MapInfo_SwitchGameType(MAPINFO_TYPE_TEAM_DEATHMATCH); pmin = 4; pmax = 8; pstep = 2; } - else if(random() < 0.666) // 2/3 of the remaining 15%, i.e. 10%, are KH + else if((r -= 0.10) < 0) + { + MapInfo_SwitchGameType(MAPINFO_TYPE_CA); + pmin = 4; + pmax = 8; + pstep = 2; + } + else if((r -= 0.10) < 0) + { + MapInfo_SwitchGameType(MAPINFO_TYPE_FREEZETAG); + pmin = 4; + pmax = 8; + pstep = 2; + } + else if((r -= 0.05) < 0) { MapInfo_SwitchGameType(MAPINFO_TYPE_KEYHUNT); pmin = 6; @@ -50,9 +64,16 @@ void InstantAction_LoadMap(entity btn, entity dummy) pstep = 6; // works both for 2 and 3 teams // TODO find team count of map, set pstep=2 or 3, and use 2v2(v2) games at least } - else // somehow distribute the remaining 5% + else { - float r; + r -= 0.05; + if (check_probability_distribution) + { + if(fabs(r) > 0.001) + error("Incorrect probability distribution."); + check_probability_distribution = false; + goto doit; + } r = floor(random() * 4); switch(r) { @@ -82,7 +103,6 @@ void InstantAction_LoadMap(entity btn, entity dummy) pmax = 16; pstep = 2; break; - // CA, Freezetag: bot AI does not work, add them once it does } } @@ -96,6 +116,14 @@ void InstantAction_LoadMap(entity btn, entity dummy) s = MapInfo_BSPName_ByID(m); } while(!fexists(sprintf("maps/%s.waypoints", s))); + + // these commands are also executed when starting a map from Multiplayer / Create + // in the menu_loadmap_prepare alias + localcmd("disconnect\n"); + localcmd("g_campaign 0\n"); + + makeServerSingleplayer(); + MapInfo_LoadMap(s, 1); // configure bots @@ -103,12 +131,17 @@ void InstantAction_LoadMap(entity btn, entity dummy) pmin = pstep * ceil(pmin / pstep); pmax = pstep * floor(pmax / pstep); p = pmin + pstep * floor(random() * ((pmax - pmin) / pstep + 1)); - cvar_set("bot_number", ftos(p - 1)); + + // cvar_set doesn't always work starting an InstantAction game while playing the campaign + //cvar_set("bot_number", ftos(p - 1)); + localcmd(strcat("bot_number ", ftos(p - 1), "\n")); // make sure we go back to menu cvar_set("lastlevel", "1"); } +.entity leaveMatchButton; + void XonoticSingleplayerDialog_fill(entity me) { entity e, btnPrev, btnNext, lblTitle; @@ -137,11 +170,13 @@ void XonoticSingleplayerDialog_fill(entity me) me.gotoRC(me, me.rows - 2, 0); me.TD(me, 1, 2, e = makeXonoticTextLabel(0.5, _("Campaign Difficulty:"))); me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "-2", ZCTX(_("CSKL^Easy")))); - me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "-1", ZCTX(_("CSKL^Medium")))); - me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "0", ZCTX(_("CSKL^Hard")))); - me.TR(me); - me.TD(me, 1, me.columns, e = makeXonoticButton(_("Start Singleplayer!"), '0 0 0')); + me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "0", ZCTX(_("CSKL^Medium")))); + me.TD(me, 1, 1, e = makeXonoticRadioButton(1, "g_campaign_skill", "2", ZCTX(_("CSKL^Hard")))); + me.TR(me); + me.TDempty(me, me.columns * 1/13); + me.TD(me, 1, me.columns * 5/13, me.leaveMatchButton = makeXonoticLeaveMatchButton('0 0 0', 0)); + me.TDempty(me, me.columns * 1/13); + me.TD(me, 1, me.columns * 5/13, e = makeXonoticButton(_("Play campaign!"), '0 0 0')); e.onClick = CampaignList_LoadMap; e.onClickEntity = me.campaignBox; } -#endif