Completed
Push — master ( b75f51...3da424 )
by Marek
16s queued 14s
created

ige.ospace.IAIRenegadePlayer.IAIRenegadePlayer.getDiplomacyWith()   A

Complexity

Conditions 2

Size

Total Lines 14
Code Lines 12

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nop 4
dl 14
loc 14
rs 9.8
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 Const
23
import Rules
24
import ShipUtils
25
import Utils
26
27
from ige import log
28
from ige.IDataHolder import IDataHolder
29
from ige.IObject import public
30
from IPlayer import IPlayer
31
32
class IAIRenegadePlayer(IPlayer):
33
34
    typeID = Const.T_AIRENPLAYER
35
    forums = {"INBOX": 56, "OUTBOX": 56, "EVENTS": 0}
36
37
    def init(self, obj):
38
        IPlayer.init(self, obj)
39
        #
40
        obj.name = u'Renegade'
41
        obj.race = "r"
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'Renegade faction %d' % counter
49
            obj.login = '*AIP*renegade%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_renegade')
56
            break
57
        # grant techs and so on
58
        self.cmd(obj).update(tran, obj)
59
60
    @public(Const.AL_ADMIN)
61
    def processINITPhase(self, tran, obj, data):
62
        IPlayer.processINITPhase(self, tran, obj, data)
63
64
        obj.lastLogin = time.time()
65
        # delete itself if there are no fleets and planets
66
        # delete the account as well
67
        # unregister it from the AI system
68
        if not obj.fleets and not obj.planets:
69
            self.cmd(obj).delete(tran, obj)
70
71
    @public(Const.AL_ADMIN)
72
    def processRSRCHPhase(self, tran, obj, data):
73
        # do not research anything
74
        return
75
76
    def update(self, tran, obj):
77
        self.setStartingTechnologies(obj)
78
        self.setStartingShipDesigns(obj)
79
        IPlayer.update(self, tran, obj)
80
81
    @staticmethod
82
    def setStartingPlanet(tran, planet):
83
        planet.slots.append(Utils.newStructure(tran, Rules.Tech.RENEGADEBASE, planet.owner, Const.STRUCT_STATUS_ON, Rules.structNewPlayerHpRatio))
84
        planet.storPop = 3000
85
86
    @staticmethod
87
    def setStartingTechnologies(obj):
88
        obj.techLevel = 2
89
        obj.techs[Rules.Tech.SMALLHULL1] = 3
90
        obj.techs[Rules.Tech.SCOCKPIT1] = 3
91
        obj.techs[Rules.Tech.MEDIUMHULL2] = 3
92
        obj.techs[Rules.Tech.SBRIDGE1] = 3
93
        obj.techs[Rules.Tech.CANNON1] = 3
94
        obj.techs[Rules.Tech.SSROCKET] = 3
95
        obj.techs[Rules.Tech.STLENG1] = Rules.techMaxImprovement
96
        obj.techs[Rules.Tech.NSTLENG2] = Rules.techMaxImprovement
97
        obj.techs[Rules.Tech.RENEGADETITANIUMMHULL] = Rules.techMaxImprovement
98
        obj.techs[Rules.Tech.RENEGADEBASE] = 3
99
        obj.techs[Rules.Tech.RENEGADEBASE2] = 3
100
        obj.techs[Rules.Tech.RENEGADEBASE2MINOR] = 3
101
        obj.techs[Rules.Tech.RENEGADEBASE3] = 3
102
        obj.techs[Rules.Tech.RENEGADEBASE3MINOR] = 3
103
        obj.techs[Rules.Tech.RENEGADECOSMODROME] = 3
104
105
    @staticmethod
106
    def setStartingShipDesigns(obj):
107
        obj.shipDesigns[1] = ShipUtils.makeShipMinSpec(obj, 'Fighter', Rules.Tech.SMALLHULL1,
108
            {Rules.Tech.SCOCKPIT1:1, Rules.Tech.CANNON1:1, Rules.Tech.STLENG1:2}, [])
109
        obj.shipDesigns[2] = ShipUtils.makeShipMinSpec(obj, 'Corvette', Rules.Tech.SMALLHULL1,
110
            {Rules.Tech.SCOCKPIT1:1, Rules.Tech.CANNON1:2, Rules.Tech.STLENG1:1, Rules.Tech.STEELARM2:1}, [])
111
        obj.shipDesigns[3] = ShipUtils.makeShipMinSpec(obj, 'Frigate', Rules.Tech.MEDIUMHULL2,
112
            {Rules.Tech.SBRIDGE1:1, Rules.Tech.CANNON1:2, Rules.Tech.SSROCKET:2, Rules.Tech.STLENG1:2}, [])
113
        obj.shipDesigns[4] = ShipUtils.makeShipMinSpec(obj, 'Destroyer', Rules.Tech.MEDIUMHULL2,
114
            {Rules.Tech.SBRIDGE1:1, Rules.Tech.CANNON1:4, Rules.Tech.SSROCKET:2, Rules.Tech.NSTLENG2:3}, [])
115
        obj.shipDesigns[5] = ShipUtils.makeShipMinSpec(obj, 'Armored Cruiser', Rules.Tech.RENEGADETITANIUMMHULL,
116
            {Rules.Tech.SBRIDGE1:1, Rules.Tech.CANNON1:5, Rules.Tech.SSROCKET:3, Rules.Tech.STLENG1:4}, [])
117
118