Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct servermap
- {
- const char *name;
- int minplayers, maxplayers, bestplayers;
- vector<int> modes;
- int lastplayedmillis;
- int lastmodesmillis[GMODE_NUM];
- int bestmode; // auto generated;
- servermap() : name(""), minplayers(0), maxplayers(0), bestplayers(0), lastplayedmillis(0), bestmode(-1)
- {
- loopi(GMODE_NUM) { modes[i] = 0; lastmodesmillis[i] = 0; }
- }
- };
- vector<servermap *>servermaps;
- // when the cfg file is read
- void smap_add(const char *map, ...)
- {
- servermap smap;
- smap.name = newstring(map);
- servermaps.add(smap);
- }
- // when a game starts
- void smap_update(const char *map, int gamemode)
- {
- if(gamemode < 0 || gamemode >= GMODE_NUM) return;
- loopv(servermaps) if(!strcmp(servermaps[i]->name, map))
- {
- servermaps[i]->lastmodesmillis[gamemode] = servermaps[i]->lastplayedmillis = servmillis;
- }
- }
- // can a specified map/mode be voted now ?
- bool fitsmap(char *map, int mode)
- {
- int players_count = numclients();
- loopv(servermaps) if(!strcmp(servermaps[i], map))
- {
- servermap *smap = sevrermaps[i];
- if(players_count < smap->minplayers || players_count > smap->maxplayers || !modes.find(mode)) return false;
- return true;
- }
- return false;
- }
- // get the ideal map to be played
- servermap *smap_best()
- {
- int bestsmapscore = 0, servermap *bestsmap = NULL;
- loopv(servermaps)
- {
- int smapscore = 0;
- serversmap *smap = servermaps[i];
- int players_count = numclients();
- if(players_count < smap->minplayers || players_count > smap->maxplayers) continue; // too many / not enough players
- if(!modes.length()) continue; // no game mode available
- smapscore += 100 - pow(abs(players_count-smap->bestplayers), 2); // diff = 0 : 100 pts, diff = 5 : 75 pts, diff = 10 : 0 pts and then minus points (max = 100 pts !)
- smapscore += sqrt(servmillis - smap->lastplayedmillis) / 10; // 1 hour = 3600 sec = 189 points, 15 minutes = 94 points
- smapscore += rnd(50);
- oldestmodemillis = 0;
- loopv(modes) if(smap->bestmode < 0 || oldestmodemillis < smap->lastmodesmillis[modes[i]])
- {
- smap->bestmode = modes[i];
- oldestmodemillis = smap->lastmodesmillis[modes[i]];
- }
- if(!bestsmap || bestsmapscore <= smapscore)
- {
- bestsmapscore = smapscore;
- bestmap = smap;
- }
- }
- return bestsmap;
- }
- // format : mapname:minplayers:maxplayers:bestplayers:"list of modes num":
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement