project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/LocalRoomStateManager.java
author Wuzzy <Wuzzy2@mail.ru>
Fri, 12 Oct 2018 03:40:21 +0200
changeset 13881 99b265e0d1d0
parent 10017 de822cd3df3a
permissions -rw-r--r--
Drop internal PhysFS, bump PhysFS requirement to 3.0.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7584
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     1
/*
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     2
 * Hedgewars for Android. An Android port of Hedgewars, a free turn based strategy game
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     3
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     4
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     5
 * This program is free software; you can redistribute it and/or
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     6
 * modify it under the terms of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     8
 * of the License, or (at your option) any later version.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
     9
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    13
 * GNU General Public License for more details.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    14
 *
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    15
 * You should have received a copy of the GNU General Public License
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    16
 * along with this program; if not, write to the Free Software
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    18
 */
7831c84cc644 License change: With the agreement of Xeli, I changed the Hedgeroid license to
Medo <smaxein@googlemail.com>
parents: 7582
diff changeset
    19
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
package org.hedgewars.hedgeroid;
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
import org.hedgewars.hedgeroid.Datastructures.GameConfig;
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
import org.hedgewars.hedgeroid.Datastructures.Scheme;
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
import org.hedgewars.hedgeroid.Datastructures.Team;
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    26
import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    27
import org.hedgewars.hedgeroid.Datastructures.TeamIngameAttributes;
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    28
import org.hedgewars.hedgeroid.Datastructures.Weaponset;
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    29
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    30
import android.util.Log;
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    31
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    32
/**
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    33
 * This RoomStateManager is responsible for keeping/changing the roomstate in local play.
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    34
 * That is very straightforward, just react to every request by immediately changing the
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    35
 * state.
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    36
 */
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    37
public class LocalRoomStateManager extends BasicRoomState {
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    38
    private static final String TAG = LocalRoomStateManager.class.getSimpleName();
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    39
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    40
    public LocalRoomStateManager(Scheme defaultScheme, Weaponset defaultWeaponset) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    41
        setChief(true);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    42
        setGameStyle(GameConfig.DEFAULT_STYLE);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    43
        setMapRecipe(MapRecipe.makeRandomMap(0, MapRecipe.makeRandomSeed(), GameConfig.DEFAULT_THEME));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    44
        setScheme(defaultScheme);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    45
        setWeaponset(defaultWeaponset);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    46
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    48
    public void changeMapRecipe(MapRecipe map) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    49
        setMapRecipe(map);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    50
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    51
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    52
    public void changeMapTheme(String theme) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    53
        setMapRecipe(getMapRecipe().withTheme(theme));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    54
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    56
    public void changeMapNameAndGenerator(String mapName) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    57
        int newGenerator = MapRecipe.generatorForMapname(mapName);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    58
        setMapRecipe(getMapRecipe().withName(mapName).withMapgen(newGenerator));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    59
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    61
    public void changeMapTemplate(int template) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    62
        setMapRecipe(getMapRecipe().withTemplateFilter(template));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    63
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    64
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    65
    public void changeMazeSize(int mazeSize) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    66
        setMapRecipe(getMapRecipe().withMazeSize(mazeSize));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    67
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    69
    public void changeMapSeed(String seed) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    70
        setMapRecipe(getMapRecipe().withSeed(seed));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    71
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    72
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    73
    public void changeMapDrawdata(byte[] drawdata) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    74
        setMapRecipe(getMapRecipe().withDrawData(drawdata));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    75
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    76
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    77
    public void changeScheme(Scheme scheme) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    78
        setScheme(scheme);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    79
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    80
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    81
    public void changeGameStyle(String style) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    82
        setGameStyle(style);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    83
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    84
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    85
    public void changeWeaponset(Weaponset weaponset) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    86
        setWeaponset(weaponset);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    87
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    88
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    89
    public void requestAddTeam(Team team, int colorIndex) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    90
        putTeam(new TeamInGame(team, new TeamIngameAttributes("Player", colorIndex, TeamIngameAttributes.DEFAULT_HOG_COUNT, false)));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    91
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    92
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    93
    public void requestRemoveTeam(String teamname) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    94
        removeTeam(teamname);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    95
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
    96
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    97
    public void changeTeamColorIndex(String teamname, int colorIndex) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    98
        TeamInGame oldTeam = getTeams().get(teamname);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
    99
        if(oldTeam != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   100
            putTeam(oldTeam.withAttribs(oldTeam.ingameAttribs.withColorIndex(colorIndex)));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   101
        } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   102
            Log.e(TAG, "Requested color change for unknown team "+ teamname);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   103
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   104
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   105
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   106
    public void changeTeamHogCount(String teamname, int hogcount) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   107
        TeamInGame oldTeam = getTeams().get(teamname);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   108
        if(oldTeam != null) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   109
            putTeam(oldTeam.withAttribs(oldTeam.ingameAttribs.withHogCount(hogcount)));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   110
        } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   111
            Log.e(TAG, "Requested hog count change for unknown team "+ teamname);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   112
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 7584
diff changeset
   113
    }
7582
714310efad8f Hedgeroid: Final sprint to the deadline
Medo <smaxein@googlemail.com>
parents:
diff changeset
   114
}