]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
rewrite instant action
authorRudolf Polzer <divverent@xonotic.org>
Sun, 21 Aug 2011 18:23:11 +0000 (20:23 +0200)
committerRudolf Polzer <divverent@xonotic.org>
Sun, 21 Aug 2011 18:23:11 +0000 (20:23 +0200)
now uses a truly random map, no longer .instantaction files

qcsrc/menu/xonotic/dialog_singleplayer.c

index 81eb68e39232bd09e078bcf9d9bb7d1990be6290..7364e24524b5523f3e2f3d558340f46f900a056e 100644 (file)
@@ -14,40 +14,108 @@ ENDCLASS(XonoticSingleplayerDialog)
 
 void InstantAction_LoadMap(entity btn, entity dummy)
 {
-       float glob, i, n, fh;
-       string s;
-       glob = search_begin("maps/*.instantaction", TRUE, TRUE);
-       if(glob < 0)
-               return;
-       i = ceil(random() * search_getsize(glob)) - 1;
-       fh = fopen(search_getfilename(glob, i), FILE_READ);
-       search_end(glob);
-       if(fh < 0)
-               return;
-       while((s = fgets(fh)))
+       float pmin, pmax, pstep;
+
+       cvar_set("timelimit_override", "10");
+       cvar_set("g_lms_lives_override", "9");
+
+       if(random() < 0.4) // 40% are DM
+       {
+               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
+       {
+               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
+       {
+               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
        {
-               if(substring(s, 0, 4) == "set ")
-                       s = substring(s, 4, strlen(s) - 4);
-               n = tokenize_console(s);
-               if(argv(0) == "bot_number")
-                       cvar_set("bot_number", argv(1));
-               else if(argv(0) == "skill")
-                       cvar_set("skill", argv(1));
-               else if(argv(0) == "timelimit")
-                       cvar_set("timelimit_override", argv(1));
-               else if(argv(0) == "fraglimit")
-                       cvar_set("fraglimit_override", argv(1));
-               else if(argv(0) == "changelevel")
+               MapInfo_SwitchGameType(MAPINFO_TYPE_KEYHUNT);
+               pmin = 6;
+               pmax = 6;
+               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%
+       {
+               float r;
+               r = floor(random() * 5);
+               switch(r)
                {
-                       fclose(fh);
-                       localcmd("\nmenu_loadmap_prepare\n");
-                       MapInfo_SwitchGameType(MAPINFO_TYPE_DEATHMATCH);
-                       MapInfo_LoadMap(argv(1));
-                       cvar_set("lastlevel", "1");
-                       return;
+                       default:
+                       case 0:
+                               MapInfo_SwitchGameType(MAPINFO_TYPE_LMS);
+                               pmin = 2;
+                               pmax = 6;
+                               pstep = 1;
+                               cvar_set("timelimit_override", "-1");
+                               break;
+                       case 1:
+                               MapInfo_SwitchGameType(MAPINFO_TYPE_CA);
+                               pmin = 2;
+                               pmax = 8;
+                               pstep = 2;
+                               break;
+                       case 2:
+                               MapInfo_SwitchGameType(MAPINFO_TYPE_DOMINATION);
+                               pmin = 2;
+                               pmax = 8;
+                               pstep = 2;
+                               break;
+                       case 3:
+                               MapInfo_SwitchGameType(MAPINFO_TYPE_ONSLAUGHT);
+                               pmin = 6;
+                               pmax = 16;
+                               pstep = 2;
+                               break;
+                       case 4:
+                               MapInfo_SwitchGameType(MAPINFO_TYPE_FREEZETAG);
+                               pmin = 4;
+                               pmax = 10;
+                               pstep = 2;
+                               break;
+                       case 5:
+                               MapInfo_SwitchGameType(MAPINFO_TYPE_ASSAULT);
+                               pmin = 4;
+                               pmax = 16;
+                               pstep = 2;
+                               break;
                }
        }
-       fclose(fh);
+
+       // find random map
+       MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
+       string s;
+       do
+       {
+               float m;
+               m = floor(random() * MapInfo_count);
+               s = MapInfo_BSPName_ByID(m);
+       }
+       while(!fexists(sprintf("maps/%s.waypoints", s)));
+       MapInfo_LoadMap(s);
+
+       // configure bots
+       float p;
+       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));
+
+       // make sure we go back to menu
+       cvar_set("lastlevel", "1");
 }
 
 void XonoticSingleplayerDialog_fill(entity me)