Completed
Pull Request — master (#242)
by Marek
02:10
created

IAIMutantPlayer.processINITPhase()   A

Complexity

Conditions 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nop 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
#
2
#  Copyright 2001 - 2016 Ludek Smid [http://www.ospace.net/]
3
#
4
#  This file is part of Outer Space.
5
#
6
#  Outer Space is free software; you can redistribute it and/or modify
7
#  it under the terms of the GNU General Public License as published by
8
#  the Free Software Foundation; either version 2 of the License, or
9
#  (at your option) any later version.
10
#
11
#  Outer Space is distributed in the hope that it will be useful,
12
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
#  GNU General Public License for more details.
15
#
16
#  You should have received a copy of the GNU General Public License
17
#  along with Outer Space; if not, write to the Free Software
18
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
#
20
import time
21
22
import Rules
23
import ShipUtils
24
import Utils
25
26
import Const
27
from ige import log
28
from IPlayer import IPlayer
29
from ige.IObject import public
30
from ige.IDataHolder import IDataHolder
31
32
class IAIMutantPlayer(IPlayer):
33
34
    typeID = Const.T_AIMUTPLAYER
35
    forums = {"INBOX": 56, "OUTBOX": 56, "EVENTS": 0}
36
37
    def init(self, obj):
38
        IPlayer.init(self, obj)
39
        #
40
        obj.name = u'Mutant'
41
        obj.race = "m"
42
        obj.login = '*'
43
44 View Code Duplication
    def register(self, tran, obj, galaxyID):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
45
        log.debug("Registering player", obj.oid)
46
        counter = 1
47
        while 1:
48
            obj.name = u'Mutant faction %d' % counter
49
            obj.login = '*AIP*mutant%d' % counter
50
            if galaxyID in tran.gameMngr.accountGalaxies(obj.login):
51
                counter += 1
52
                continue
53
            tran.gameMngr.registerPlayer(obj.login, obj, obj.oid)
54
            tran.db[Const.OID_UNIVERSE].players.append(obj.oid)
55
            tran.gameMngr.clientMngr.createAIAccount(obj.login, obj.name, 'ais_mutant')
56
            break
57
        # grant techs and so on
58
        self.cmd(obj).update(tran, obj)
59
60
    @staticmethod
61
    def setStartingPlanet(tran, planet):
62
        planet.plSlots = max(planet.plSlots, 9)
63
        planet.plMaxSlots = max(planet.plMaxSlots, 9)
64
        planet.plDiameter = max(planet.plDiameter, 9000)
65
        planet.slots.append(Utils.newStructure(tran, Rules.Tech.MUTANTBASE, planet.owner, Const.STRUCT_STATUS_ON, Rules.structNewPlayerHpRatio))
66
        planet.storPop = 3000
67
68
    @staticmethod
69
    def setStartingTechnologies(obj):
70
        obj.techLevel = 3
71
        # grant technologies
72
        starting_techs = [Rules.Tech.SMALLHULL0,
73
                          Rules.Tech.MEDIUMHULL0,
74
                          Rules.Tech.SCOCKPIT0,
75
                          Rules.Tech.SBRIDGE0,
76
                          Rules.Tech.CANNON0,
77
                          Rules.Tech.CONBOMB0,
78
                          Rules.Tech.TORPEDO0,
79
                          Rules.Tech.SSROCKET0,
80
                          Rules.Tech.FTLENG0,
81
                          Rules.Tech.SCANNERMOD0,
82
                          # technologies for ship design creation
83
                          Rules.Tech.SMALLHULL1,
84
                          Rules.Tech.SCOCKPIT1,
85
                          Rules.Tech.SCANNERMOD1,
86
                          Rules.Tech.CONBOMB1,
87
                          Rules.Tech.EMCANNON,
88
                          Rules.Tech.STLENG1,
89
                          Rules.Tech.FTLENG1,
90
                          Rules.Tech.MUTANTPOD,
91
                          # structures
92
                          Rules.Tech.MUTANTBASE,
93
                          Rules.Tech.MUTANTBASE2,
94
                          Rules.Tech.MUTANTBASE3,
95
                          Rules.Tech.MUTANTBASE4,
96
                          Rules.Tech.MUTANTPP1,
97
                          Rules.Tech.MUTANTPP2,
98
                          Rules.Tech.MUTANTFACT1,
99
                          Rules.Tech.MUTANTFACT2,
100
                          Rules.Tech.MUTANTMINES,
101
                          ]
102
        for tech in starting_techs:
103
            if tech in obj.techs: continue
104
            obj.techs[tech] = 1
105
106
    @staticmethod
107
    def setStartingShipDesigns(obj):
108
        obj.shipDesigns[1] = ShipUtils.makeShipMinSpec(obj, 'Swarmer', Rules.Tech.SMALLHULL1,
109
                {Rules.Tech.SCOCKPIT1:1, Rules.Tech.EMCANNON:2, Rules.Tech.STLENG1:1, Rules.Tech.FTLENG1:2}, [])
110
        obj.shipDesigns[2] = ShipUtils.makeShipMinSpec(obj, 'Seeder', Rules.Tech.MEDIUMHULL2,
111
                {Rules.Tech.SCOCKPIT1:1, Rules.Tech.MUTANTPOD:1, Rules.Tech.FTLENG1:4}, [])
112
        obj.shipDesigns[3] = ShipUtils.makeShipMinSpec(obj, 'Seeker', Rules.Tech.SMALLHULL1,
113
                {Rules.Tech.SCOCKPIT1:1, Rules.Tech.SCANNERMOD1:1, Rules.Tech.FTLENG1:2}, [])
114
        obj.shipDesigns[4] = ShipUtils.makeShipMinSpec(obj, 'Sower', Rules.Tech.SMALLHULL1,
115
                {Rules.Tech.SCOCKPIT1:1, Rules.Tech.CONBOMB1:1, Rules.Tech.STLENG1:1, Rules.Tech.FTLENG1:2}, [])
116
117
    def processINITPhase(self, tran, obj, data):
118
        IPlayer.processINITPhase(self, tran, obj, data)
119
        obj.lastLogin = time.time()
120
        # delete itself if there are no fleets and planets
121
        # delete the account as well
122
        # unregister it from the AI system
123
        if not obj.fleets and not obj.planets:
124
            self.cmd(obj).delete(tran, obj)
125
126
    def update(self, tran, obj):
127
        self.setStartingTechnologies(obj)
128
        self.setStartingShipDesigns(obj)
129
        # create two basic designs [they use modules not available to the
130
        # player otherwise so it has to be done this way]
131
        # call super method
132
        IPlayer.update(self, tran, obj)
133
134
    def processFINALPhase(self, tran, obj, data):
135
        IPlayer.processFINALPhase(self, tran, obj, data)
136
        # fix goverment power
137
        obj.govPwrCtrlRange = 10000
138
139