As it stands now, the AI system interface is the most inconvient thing
i have ever created. The following is the required code to order an
inn to be constructed, using the constraints provided on the page:

//The main order for the building
AIEcho::Construction::BuildingOrder bo(IntBuildingType::FOOD_BUILDING, 2);

//Constraints arround the location of wheat
AIEcho::Gradients::GradientInfo gi_wheat;
gi_wheat.add_source(new AIEcho::Gradients::Entities::Ressource(CORN));
//You want to be close to wheat
bo.add_constraint(new AIEcho::Construction::MinimizedDistance(gi_wheat, 4));
//You can't be farther than 10 units from wheat
bo.add_constraint(new AIEcho::Construction::MaximumDistance(gi_wheat, 10));

//Constraints arround nearby settlement
AIEcho::Gradients::GradientInfo gi_building;
gi_building.add_source(new
AIEcho::Gradients::Entities::AnyTeamBuilding(team->team_id));
gi_building.add_obstacle(new AIEcho::Gradients::Entities::AnyRessource));
//You want to be close to other buildings, but wheat is more important
bo.add_constraint(new AIEcho::Construction::MinimizedDistance(gi_building, 2));

//Constraints arround the location of fruit
AIEcho::Gradients::GradientInfo gi_fruit;
gi_fruit.add_source(new AIEcho::Gradients::Entities::Ressource(CHERRY));
gi_fruit.add_source(new AIEcho::Gradients::Entities::Ressource(ORANGE));
gi_fruit.add_source(new AIEcho::Gradients::Entities::Ressource(PRUNE));
//You want to be reasnobly close to fruit, closer if possible
bo.add_constraint(new AIEcho::Construction::MinimizedDistance(gi_fruit, 1));

//Copnstraints arround the location of the enemy
AIEcho::Gradients::GradientInfo gi_enemy;
gi_enemy.add_source(new
AIEcho::Gradients::Entities::AnyTeamBuilding(team->enemy_id));
gi_enemy.add_obstacle(new AIEcho::Gradients::Entities::AnyRessource));
//You want to be far from the enemy, so they can't attack your inns easily
bo.add_constraint(new AIEcho::Construction::MaximizedDistance(gi_enemy, 1));

//Add the building order to the list of orders
ai.add_building_order(bo);




The above code is verbose, long, much more than what feels nesseccarry
for the construction of an Inn. I really want to discuss the interface
with some people, hopefully to work it down to size.

I've enclosed the header for this interface. Be alert that none of
this is complete yet.
/*
  Copyright (C) 2006 Bradley Arsenault

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#ifndef AIEcho_h
#define AIEcho_h


#include <Map.h>

namespace AIEcho
{
	struct position
	{
		position(int x, int y);
		int x;
		int y;
	};


	namespace Gradients
	{
		namespace Entities
		{
			class Entity
			{
			public:
				virtual bool operator()(Map* map, int posx, int posy);
			};

			class Building : public Entity
			{
			public:
				Building(int building_type, int team);
				bool operator()(Map* map, int posx, int posy);
			};

			class AnyTeamBuilding : public Entity
			{
			public:
				AnyTeamBuilding(int team);
				bool operator()(Map* map, int posx, int posy);
			};

			class AnyBuilding : public Entity
			{
			public:
				AnyBuilding();
				bool operator()(Map* map, int posx, int posy);
			};

			class Ressource : public Entity
			{
			public:
				Ressource(int ressource_type);
				bool operator()(Map* map, int posx, int posy);
			};

			class AnyRessource : public Entity
			{
			public:
				AnyRessource();
				bool operator()(Map* map, int posx, int posy);
			};

			class Water : public Entity
			{
			public:
				Water();
				bool operator()(Map* map, int posx, int posy);
			};
		};

		class GradientInfo
		{
		public:
			GradientInfo();
			void add_source(Entities::Entity* source);
			void add_obstacle(Entities::Entity* obstacle);
		};

		class Gradient
		{
		public:
			Gradient(const GradientInfo& gi);
			void recalculate(Map* map);
			int get_height(int posx, int posy);
		};

		class GradientManager
		{
		public:
			GradientManager();
			Gradient& get_gradient(const GradientInfo& gi);
			void update();
		};
	};

	namespace Construction
	{
		class Constraint
		{
		public:
			Constraint();
		};

		class MinimumDistance : public Constraint
		{
		public:
			MinimumDistance(const GradientInfo& gi, int distance);
		};

		class MaximumDistance: public Constraint
		{
		public:
			MaximumDistance(const GradientInfo& gi, int distance);
		};

		class MinimizedDistance : public Constraint
		{
		public:
			MinimizedDistance(const GradientInfo& gi, int weight);
		};

		class MaximizedDistance : public Constraint
		{
		public:
			MaximizedDistance(const GradientInfo& gi, int weight);
		};

		class BuildingOrder
		{
		public:
			BuildingOrder(int building_type, int number_of_workers);
			void add_constraint(const Constraint& constraint);
			position find_location(GradientManager& manager);
		};
	};

	class Echo
	{
	public:
		Echo();
		void add_building_order(BuildingOrder& bo);
	};
};


#endif


_______________________________________________
glob2-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/glob2-devel

Reply via email to