Skip to content

Instantly share code, notes, and snippets.

@stubb
Created July 13, 2014 20:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stubb/ca01f4b1e2b6880942dd to your computer and use it in GitHub Desktop.
Save stubb/ca01f4b1e2b6880942dd to your computer and use it in GitHub Desktop.
diff --git a/horizons/ai/aiplayer/__init__.py b/horizons/ai/aiplayer/__init__.py
index cdefcb8..f146222 100644
--- a/horizons/ai/aiplayer/__init__.py
+++ b/horizons/ai/aiplayer/__init__.py
@@ -29,6 +29,7 @@ from horizons.ai.aiplayer.strategy.strategymanager import StrategyManager
from horizons.component.stancecomponent import NoneStance
from horizons.world.units.fightingship import FightingShip
from horizons.world.units.weaponholder import MovingWeaponHolder
+from horizons.world.units.ship import FisherShip
from mission.foundsettlement import FoundSettlement
from mission.preparefoundationship import PrepareFoundationShip
@@ -84,6 +85,7 @@ from horizons.util.worldobject import WorldObject
from horizons.ext.enum import Enum
from horizons.ai.generic import GenericAI
from horizons.component.selectablecomponent import SelectableComponent
+from horizons.constants import AI
class AIPlayer(GenericAI):
"""This is the AI that builds settlements."""
@@ -366,7 +368,13 @@ class AIPlayer(GenericAI):
def request_ship(self):
self.log.info('%s received request for more ships', self)
- self.need_more_ships = True
+ # TODO. This is a hack to prevent the AI to build to much ships.
+ print len([ship for ship in self.world.ships \
+ if ship.owner == self and type(ship) is not FisherShip])
+ if len([ship for ship in self.world.ships \
+ if ship.owner == self and type(ship) is not FisherShip]) <= AI.AMOUNT_OF_TRADE_S
+ print "will built a ship"
+ self.need_more_ships = True
def request_combat_ship(self):
self.log.info('%s received request for combat ships', self)
diff --git a/horizons/constants.py b/horizons/constants.py
index 8aaeac8..86e118b 100644
--- a/horizons/constants.py
+++ b/horizons/constants.py
@@ -418,11 +418,13 @@ class MESSAGES:
CUSTOM_MSG_VISIBLE_FOR = 90 # after this time the msg gets removed from screen
LOGBOOK_DEFAULT_DELAY = 1 # delay between condition fulfilled and logbook popping up
-# AI values read from the command line; use the values below unless overridden by the CLI or the GUI
class AI:
+ # AI values read from the command line; use the values below unless overridden by the CLI or the
HIGHLIGHT_PLANS = False # whether to show the AI players' plans on the map
HIGHLIGHT_COMBAT = False # whether to show the AI players' combat ranges around each unit
HUMAN_AI = False # whether the human player is controlled by the AI
+
+ AMOUNT_OF_TRADE_SHIPS = 6 # max amount of trade ships which can be build by one AI
class TRADER: # check resource values: ./development/print_db_data.py res
PRICE_MODIFIER_BUY = 1.0 # buy for x times the resource value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment