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
|
|
|
|
21
|
|
|
import time |
22
|
|
|
|
23
|
|
|
import Const |
24
|
|
|
import Rules |
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 IAIEDENPlayer(IPlayer): |
33
|
|
|
|
34
|
|
|
typeID = Const.T_AIEDENPLAYER |
35
|
|
|
|
36
|
|
|
def init(self, obj): |
37
|
|
|
IPlayer.init(self, obj) |
38
|
|
|
# |
39
|
|
|
obj.name = u'E.D.E.N.' |
40
|
|
|
obj.race = "e" |
41
|
|
|
obj.login = '*' |
42
|
|
|
|
43
|
|
View Code Duplication |
def register(self, tran, obj, galaxyID): |
|
|
|
|
44
|
|
|
log.debug("Registering player", obj.oid) |
45
|
|
|
counter = 1 |
46
|
|
|
while 1: |
47
|
|
|
obj.name = u'E.D.E.N. %d' % counter |
48
|
|
|
obj.login = '*AIP*eden%d' % counter |
49
|
|
|
if galaxyID in tran.gameMngr.accountGalaxies(obj.login): |
50
|
|
|
counter += 1 |
51
|
|
|
continue |
52
|
|
|
tran.gameMngr.registerPlayer(obj.login, obj, obj.oid) |
53
|
|
|
tran.db[Const.OID_UNIVERSE].players.append(obj.oid) |
54
|
|
|
tran.gameMngr.clientMngr.createAIAccount(obj.login, obj.name, 'ais_eden') |
55
|
|
|
break |
56
|
|
|
# grant techs and so on |
57
|
|
|
self.cmd(obj).update(tran, obj) |
58
|
|
|
|
59
|
|
|
def update(self, tran, obj): |
60
|
|
|
self.setStartingTechnologies(obj) |
61
|
|
|
self.setStartingShipDesigns(obj) |
62
|
|
|
IPlayer.update(self, tran, obj) |
63
|
|
|
|
64
|
|
|
@staticmethod |
65
|
|
|
def setStartingPlanet(tran, planet): |
66
|
|
|
planet.plSlots = max(planet.plSlots, 2) |
67
|
|
|
planet.plMaxSlots = max(planet.plMaxSlots, 2) |
68
|
|
|
planet.plDiameter = max(planet.plDiameter, 2000) |
69
|
|
|
planet.slots.append(Utils.newStructure(tran, Rules.Tech.EDENBASE, planet.owner, Const.STRUCT_STATUS_ON, Rules.structNewPlayerHpRatio)) |
70
|
|
|
planet.slots.append(Utils.newStructure(tran, Rules.Tech.EDENSTATION, planet.owner, Const.STRUCT_STATUS_ON, Rules.structNewPlayerHpRatio)) |
71
|
|
|
planet.storPop = 3000 |
72
|
|
|
|
73
|
|
|
@staticmethod |
74
|
|
|
def setStartingTechnologies(obj): |
75
|
|
|
obj.techLevel = 7 |
76
|
|
|
obj.techs[Rules.Tech.LASCANNONTUR3] = Rules.techMaxImprovement |
77
|
|
|
obj.techs[Rules.Tech.SSROCKET2] = Rules.techMaxImprovement |
78
|
|
|
obj.techs[Rules.Tech.TORPEDO] = Rules.techMaxImprovement |
79
|
|
|
obj.techs[Rules.Tech.EDENCANNON] = Rules.techMaxImprovement |
80
|
|
|
obj.techs[Rules.Tech.EDENMISSILE] = Rules.techMaxImprovement |
81
|
|
|
obj.techs[Rules.Tech.EDENTORP] = Rules.techMaxImprovement |
82
|
|
|
obj.techs[Rules.Tech.EDENBOMB] = Rules.techMaxImprovement |
83
|
|
|
obj.techs[Rules.Tech.EDENSTATION] = Rules.techMaxImprovement |
84
|
|
|
|
85
|
|
|
@staticmethod |
86
|
|
|
def setStartingShipDesigns(obj): |
87
|
|
|
pass |
88
|
|
|
|
89
|
|
|
@public(Const.AL_ADMIN) |
90
|
|
|
def processINITPhase(self, tran, obj, data): |
91
|
|
|
IPlayer.processINITPhase(self, tran, obj, data) |
92
|
|
|
obj.lastLogin = time.time() |
93
|
|
|
# delete itself if there are no fleets and planets |
94
|
|
|
# delete the account as well |
95
|
|
|
# unregister it from the AI system |
96
|
|
|
if not obj.fleets and not obj.planets: |
97
|
|
|
self.cmd(obj).delete(tran, obj) |
98
|
|
|
|
99
|
|
|
def getDiplomacyWith(self, tran, obj, playerID): |
100
|
|
|
if obj.oid == playerID: |
101
|
|
|
return Const.REL_UNITY |
102
|
|
|
player = tran.db.get(playerID, None) |
103
|
|
|
if player.type in (Const.T_AIPIRPLAYER, Const.T_PIRPLAYER): |
104
|
|
|
dipl = obj.diplomacyRels.get(playerID, None) |
105
|
|
View Code Duplication |
if not dipl: |
|
|
|
|
106
|
|
|
# make default |
107
|
|
|
dipl = IDataHolder() |
108
|
|
|
dipl.type = Const.T_DIPLREL |
109
|
|
|
dipl.pacts = { |
110
|
|
|
Const.PACT_ALLOW_CIVILIAN_SHIPS: [Const.PACT_ACTIVE, Const.PACT_ALLOW_CIVILIAN_SHIPS], |
111
|
|
|
Const.PACT_ALLOW_MILITARY_SHIPS: [Const.PACT_ACTIVE, Const.PACT_ALLOW_MILITARY_SHIPS] |
112
|
|
|
} |
113
|
|
|
dipl.relation = Const.REL_FRIENDLY |
114
|
|
|
dipl.relChng = 0 |
115
|
|
|
dipl.lastContact = tran.db[Const.OID_UNIVERSE].turn |
116
|
|
|
dipl.contactType = Const.CONTACT_NONE |
117
|
|
|
dipl.stats = None |
118
|
|
|
if playerID != obj.oid: |
119
|
|
|
obj.diplomacyRels[playerID] = dipl |
120
|
|
|
else: |
121
|
|
|
log.debug("getDiplomacyWith myself", obj.oid) |
122
|
|
|
return dipl |
123
|
|
|
# this AI battles with overyone |
124
|
|
|
# make default |
125
|
|
|
dipl = IDataHolder() |
126
|
|
|
dipl.type = Const.T_DIPLREL |
127
|
|
|
dipl.pacts = {} |
128
|
|
|
dipl.relation = Const.REL_ENEMY |
129
|
|
|
dipl.relChng = 0 |
130
|
|
|
dipl.lastContact = tran.db[Const.OID_UNIVERSE].turn |
131
|
|
|
dipl.contactType = Const.CONTACT_NONE |
132
|
|
|
dipl.stats = None |
133
|
|
|
return dipl |
134
|
|
|
|
135
|
|
|
def isPactActive(self, tran, obj, partnerID, pactID): |
136
|
|
|
if partnerID == Const.OID_NONE: |
137
|
|
|
return 0 |
138
|
|
|
partner = tran.db.get(partnerID, None) |
139
|
|
|
if partner.type in (Const.T_AIPIRPLAYER, Const.T_PIRPLAYER): |
140
|
|
|
# force the peace! |
141
|
|
|
if pactID in (Const.PACT_ALLOW_CIVILIAN_SHIPS, Const.PACT_ALLOW_MILITARY_SHIPS): |
142
|
|
|
return Const.PACT_ACTIVE |
143
|
|
|
return 0 |
144
|
|
|
|