Latest Posts

Topic: AI hints cause the game to crash. -> fixing code

MarkMcWire
Avatar
Topic Opener
Joined: 2017-02-08, 21:06
Posts: 321
Ranking
Tribe Member
Location: Eisenach, Germany
Posted at: 2020-12-02, 10:34

If several buildings have the hint "supports_production_of = {" log "}," or "collects_ware_from_map =" log "," the game crashes. I noticed that because I built two extensions for all building types, including for the foresters and lumberjacks. If I also give this AI Hint to the expanded buildings, I can no longer start the game.

The same applies to fisher houses, hunting houses and wells. Strangely enough, that doesn't happen to mines, fish breeders houses or gamekeepers houses.

Edit, I found the code in the defaultai.cc, that throws these exceptions.

// We must verify that some buildings has been identified
	// Also note that the AI assumes that some buildings are unique, if you want to
	// create e.g. two barracks or bakeries, the impact on the AI must be considered
	if (count_buildings_with_attribute(BuildingAttribute::kBarracks) != 1) {
		throw wexception("The AI needs the tribe '%s' to define 1 type of barracks building. "
		                 "This is the building that produces the tribe's 'soldier' worker.",
		                 tribe_->name().c_str());
	}
	if (count_buildings_with_attribute(BuildingAttribute::kRanger) != 1) {
		throw wexception(
		   "The AI needs the tribe '%s' to define 1 type of ranger's building. "
		   "This is the building that has 'supports_production_of = { \"log\" }' in its AI hints.",
		   tribe_->name().c_str());
	}
	if (count_buildings_with_attribute(BuildingAttribute::kWell) != 1) {
		throw wexception(
		   "The AI needs the tribe '%s' to define 1 type of well. "
		   "This is the building that has 'collects_ware_from_map = \"water\"' in its AI hints.",
		   tribe_->name().c_str());
	}
	if (count_buildings_with_attribute(BuildingAttribute::kLumberjack) != 1) {
		throw wexception(
		   "The AI needs the tribe '%s' to define 1 type of lumberjack's building. "
		   "This is the building that has 'collects_ware_from_map = \"log\"' in its AI hints.",
		   tribe_->name().c_str());
	}

	if (count_buildings_with_attribute(BuildingAttribute::kHunter) != 0 &&
	    count_buildings_with_attribute(BuildingAttribute::kHunter) != 1) {
		throw wexception(
		   "The AI needs the tribe '%s' to define 1 type of hunter's building at the most. "
		   "Hunters are buildings that have 'collects_ware_from_map = \"meat\"' in their AI hints.",
		   tribe_->name().c_str());
	}

	if (count_buildings_with_attribute(BuildingAttribute::kFisher) != 1) {
		throw wexception(
		   "The AI needs the tribe '%s' to define 1 type of fisher's building. "
		   "This is the building that has 'collects_ware_from_map = \"fish\"' in its AI hints "
		   "and doesn't have any ware inputs.",
		   tribe_->name().c_str());
	}

I suggest not checking for exactly 1 here but specifying a range. For example 1 to 3 buildings, if there are extensions.
Edited: 2020-12-02, 10:41

My widelands project: https://github.com/widelands/wl_addons_server/tree/master/addons/europeans_tribe.wad

Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-12-02, 12:14

Hi, this will be fixed / gone with the following PR merged.

https://github.com/widelands/widelands/pull/4465


Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-12-02, 14:04

The historical reason for this was that AI decides to have (for example) 5 wood cutters, 2 hunters, 4 wells - and it is simpler if there is only one type of cutter, one type of well and so on. If we allow multiple buildings of the same type - I dont know how ready AI is for it.


Top Quote
MarkMcWire
Avatar
Topic Opener
Joined: 2017-02-08, 21:06
Posts: 321
Ranking
Tribe Member
Location: Eisenach, Germany
Posted at: 2020-12-02, 14:10

My temporary solution / workarround is, only the basic building get the AI hint, the extensions not. So there should be no problem at the moment.


My widelands project: https://github.com/widelands/wl_addons_server/tree/master/addons/europeans_tribe.wad

Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-12-02, 20:40

But some assertions fail....


Top Quote
MarkMcWire
Avatar
Topic Opener
Joined: 2017-02-08, 21:06
Posts: 321
Ranking
Tribe Member
Location: Eisenach, Germany
Posted at: 2020-12-03, 13:25

Tibor wrote:

But some assertions fail....

Can you please explain

BTW: I know what an assertion is.


My widelands project: https://github.com/widelands/wl_addons_server/tree/master/addons/europeans_tribe.wad

Top Quote
Tibor

Joined: 2009-03-23, 23:24
Posts: 1377
Ranking
One Elder of Players
Location: Slovakia
Posted at: 2020-12-04, 16:49

I mean they have some reason to be there. The fact that game does not crash after removing some of them does not mean that no harm was done.


Top Quote
hessenfarmer
Avatar
Joined: 2014-12-11, 23:16
Posts: 2646
Ranking
One Elder of Players
Location: Bavaria
Posted at: 2020-12-04, 17:10

Well,
I believe the Solution from MarkMcWire for his tribe will not crash in trunk However the AI might not handle the buildings properly in terms of starting stopping them (especially the rangers) this might get better with the new design in the PR from GunChleoc but still might have flaws with the rangers.
However I think deducing properties rather then declaring them is the way to go and if some changes are needed to reinstate proper AI handling of them I definitly will contribute in doing so.

It is extremely probable that the AI could benefit from more generalized handling of buildings which might result from this exercise.


Top Quote