SurpriseMeGameButton in the Lobby
Posted: 06 Oct 2007, 16:20
Just a button, you hit it, and the Lobby autojoins in the Background a open Game you have Map&Mod for, out places, teams you up and takes you in there once the shows starts...
Open Source Realtime Strategy Game Engine
https://springrts.com/phpbb/
Code: Select all
if there are any open battles then
pick a battle
else
tell the user off
end if
Code: Select all
new "list" randomBattleList
for each battle: {
if (battleOpen AND !locked AND haveMap AND haveMod) {
add battle to randomBattleList
}
}
if sizeof(randomBattleList) != 0 {
pick a random battle from the "list" and join it
//optional: pick a team based on some algorithm: todo later
}else{
print("error. no suitable battles found")
}
Code: Select all
//optional: pick a team based on some algorithm: todo later
Code: Select all
ChooseAlly(void) {
if battle has startboxes {
int playersPerTeam[number of startboxes]
for each player that is not me{
if ((ally number of player) <=
(number of startboxes)) {
playersPerTeam[number of player]++
}
}
int allyToJoin = 1
for i, i < number of startboxes, i++ {
if playersPerTeam[allyToJoin] >
playersPerTeam[i] {
allyToJoin = i
}
}
join allyToJoin
}else{
// default battle join behavior is fine; do nothing
}
}
run ChooseAlly upon joining and when the startboxes change
lurker wrote:Code: Select all
ChooseAlly(void) { if battle has startboxes { int playersPerTeam[number of startboxes] for each player that is not me{ if ((ally number of player) <= (number of startboxes)) { playersPerTeam[number of player]++ } } int allyToJoin = 1 for i, i < number of startboxes, i++ { if playersPerTeam[allyToJoin] > playersPerTeam[i] { allyToJoin = i } } join allyToJoin }else{ // default battle join behavior is fine; do nothing } } [/quote] Maybee add a Timer : if GamewaitingTime is >3 Mins add CurrentBattle to NeverGoingtoStart.list set randomBattlelist = 0. (Loop ?) Sorry if this hurts some Coders feelings - has been years since i tryied to work with C++
Code: Select all
private void SurpriseMeButtonActionPerformed(java.awt.event.ActionEvent evt) {
ArrayList<CBattleInfo> randomBattleList = new ArrayList<CBattleInfo>();
ArrayList<CBattleInfo> battles = jbm.battles;
for (CBattleInfo i : battles) {
if (!i.IsIngame() && !i.locked && !i.IsPassworded() && !i.isladdergame()) {// AND i.haveMap AND haveMod) {
randomBattleList.add(i);
}
}
if (!randomBattleList.isEmpty()) {
//pick a random battle from the "list" and join it
Random r = new Random();
r.setSeed(randomBattleList.size());
int i = r.nextInt(randomBattleList.size());
JoinBattle(randomBattleList.get(i));
} else {
LM.Toasts.AddMessage("No suitable battles found");
}
}