Skip to content

Commit

Permalink
Fix loading of default teams, given non-default starting positions. F…
Browse files Browse the repository at this point in the history
…ixes the «Hide Behind Me» challenge.

Also, add default teams for Clover, Manhattan and MizaMaze.

Fixes ticket:4341.
  • Loading branch information
Cyp committed Jun 5, 2016
1 parent 4b33f69 commit d53404f
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 1 deletion.
40 changes: 40 additions & 0 deletions data/mp/multiplay/maps/8c-clover.json
@@ -0,0 +1,40 @@
{
"map": {
"file": "8c-clover",
"id": "map",
"maxPlayers": 8,
"name": "Clover"
},
"player_0": {
"id": "player_0",
"team": 0
},
"player_1": {
"id": "player_1",
"team": 1
},
"player_2": {
"id": "player_2",
"team": 0
},
"player_3": {
"id": "player_3",
"team": 1
},
"player_4": {
"id": "player_4",
"team": 0
},
"player_5": {
"id": "player_5",
"team": 0
},
"player_6": {
"id": "player_6",
"team": 1
},
"player_7": {
"id": "player_7",
"team": 1
}
}
40 changes: 40 additions & 0 deletions data/mp/multiplay/maps/8c-manhattan.json
@@ -0,0 +1,40 @@
{
"map": {
"file": "8c-manhattan",
"id": "map",
"maxPlayers": 8,
"name": "Manhattan"
},
"player_0": {
"id": "player_0",
"team": 0
},
"player_1": {
"id": "player_1",
"team": 1
},
"player_2": {
"id": "player_2",
"team": 0
},
"player_3": {
"id": "player_3",
"team": 1
},
"player_4": {
"id": "player_4",
"team": 0
},
"player_5": {
"id": "player_5",
"team": 2
},
"player_6": {
"id": "player_6",
"team": 1
},
"player_7": {
"id": "player_7",
"team": 2
}
}
40 changes: 40 additions & 0 deletions data/mp/multiplay/maps/8c-mizamaze.json
@@ -0,0 +1,40 @@
{
"map": {
"file": "8c-mizamaze",
"id": "map",
"maxPlayers": 8,
"name": "MizaMaze"
},
"player_0": {
"id": "player_0",
"team": 0
},
"player_1": {
"id": "player_1",
"team": 1
},
"player_2": {
"id": "player_2",
"team": 0
},
"player_3": {
"id": "player_3",
"team": 1
},
"player_4": {
"id": "player_4",
"team": 0
},
"player_5": {
"id": "player_5",
"team": 1
},
"player_6": {
"id": "player_6",
"team": 0
},
"player_7": {
"id": "player_7",
"team": 1
}
}
32 changes: 31 additions & 1 deletion src/multiint.cpp
Expand Up @@ -2832,9 +2832,10 @@ static void loadMapSettings2()
{
sstrcpy(nameOverrides[i], ini.value("name").toString().toUtf8().constData());
}
NetPlay.players[i].position = MAX_PLAYERS; // Invalid value, fix later.
if (ini.contains("position"))
{
changePosition(i, ini.value("position", NetPlay.players[i].position).toInt());
NetPlay.players[i].position = std::min(std::max(ini.value("position").toInt(), 0), MAX_PLAYERS);
}
if (ini.contains("difficulty"))
{
Expand All @@ -2850,6 +2851,35 @@ static void loadMapSettings2()
}
ini.endGroup();
}

// Fix duplicate or unset player positions.
PlayerMask havePosition = 0;
for (int i = 0; i < MAX_PLAYERS; ++i)
{
if (NetPlay.players[i].position < MAX_PLAYERS)
{
PlayerMask old = havePosition;
havePosition |= PlayerMask(1) << NetPlay.players[i].position;
if (havePosition == old)
{
ASSERT(false, "Duplicate position %d", NetPlay.players[i].position);
NetPlay.players[i].position = MAX_PLAYERS;
}
}
}
int pos = 0;
for (int i = 0; i < MAX_PLAYERS; ++i)
{
if (NetPlay.players[i].position >= MAX_PLAYERS)
{
while ((havePosition & (PlayerMask(1) << pos)) != 0)
{
++pos;
}
NetPlay.players[i].position = pos;
++pos;
}
}
}

/*
Expand Down

0 comments on commit d53404f

Please sign in to comment.