[BUG?] Ships with apparently no associated design
Posted: Mon Dec 28, 2015 7:28 pm
To follow up on the issue that came up when testing this PR where I ran several test games for ~100 turns with the default quickstart settings and got quite a lot error messages in the AI logs about ships with apparently no valid design (see line comments and discussions in that PR).
I investigated a bit further and it looks like we might actually not dealing with a bug here. Additional info I added to the log messages indicate that those ships had no name, no owner, no design, all stats zero, no nothing. Looking at the code of Ship::Copy......reveals that if an empire has only basic visibility of an unknown/enemy ship it does not know the ship design (design id isn't copied). According to the additional info I logged, although there are quite a lot of these error messages, they only refer to very few ships, it's just that the same few ships trigger that error over and over again. It also appears only in some AI logs, so all in all this seems to be a rare case.
But apparently now and then it does happen that an empire can "see" a ship with only basic visibility, so it basically only knows that it's there, but that's it - no stats, no info about the owner or the design, nothing. Causing errors whenever the AI code tries to access the design of such a ship of course. As far as I can tell this currently happens in two places, the one in AIstate.py Morlic fixed in the PR mentioned above, and the other one in GetEffectsAndTargets, which apparently gets called when the AI client runs meter estimates:The question now is, is that intended behavior (ships empires have only basic visibility of), or is something amiss here? In the former case we should stop throwing errors if a ship without design is encountered, as this is a case that actually can happen and must be accounted for in the respective code sections (both Python and C++).
I investigated a bit further and it looks like we might actually not dealing with a bug here. Additional info I added to the log messages indicate that those ships had no name, no owner, no design, all stats zero, no nothing. Looking at the code of Ship::Copy...
Code: Select all
if (vis >= VIS_BASIC_VISIBILITY) {
if (this->m_fleet_id != copied_ship->m_fleet_id) {
// as with other containers, removal from the old container is triggered by the contained Object; removal from System is handled by UniverseObject::Copy
if (TemporaryPtr<Fleet> oldFleet = GetFleet(this->m_fleet_id))
oldFleet->RemoveShip(this->ID());
this->m_fleet_id = copied_ship->m_fleet_id; // as with other containers (Systems), actual insertion into fleet ships set is handled by the fleet
}
if (vis >= VIS_PARTIAL_VISIBILITY) {
if (this->Unowned())
this->m_name = copied_ship->m_name;
this->m_design_id = copied_ship->m_design_id;
But apparently now and then it does happen that an empire can "see" a ship with only basic visibility, so it basically only knows that it's there, but that's it - no stats, no info about the owner or the design, nothing. Causing errors whenever the AI code tries to access the design of such a ship of course. As far as I can tell this currently happens in two places, the one in AIstate.py Morlic fixed in the PR mentioned above, and the other one in GetEffectsAndTargets, which apparently gets called when the AI client runs meter estimates:
Code: Select all
2015-12-28 18:24:29.868592 [debug] AI : Universe::InitMeterEstimatesAndDiscrepancies
2015-12-28 18:24:29.868618 [debug] AI : IMEAD: updating meter estimates
2015-12-28 18:24:29.877236 [error] AI : Universe.cpp:2092 : GetEffectsAndTargets couldn't get ShipDesign
2015-12-28 18:24:29.877289 [error] AI : Universe.cpp:2093 : OBJ_SHIP 1122: at: Hewish γ owner: (Unowned) created on turn: 65 specials: Meters: Target Industry: Cur: 0 Init: 0 Target Research: Cur: 0 Init: 0 Target Trade: Cur: 0 Init: 0 Max Fuel: Cur: 0 Init: 0 Max Shield: Cur: 0 Init: 0 Max Structure: Cur: 0 Init: 0 Industry: Cur: 0 Init: 0 Research: Cur: 0 Init: 0 Trade: Cur: 0 Init: 0 Fuel: Cur: 0 Init: 0 Shield: Cur: 0 Init: 0 Structure: Cur: 0 Init: 0 Stealth: Cur: 0 Init: 65536 Detection Range: Cur: 0 Init: 0 Speed: Cur: 0 Init: 0 design id: -1 fleet id: 1123 species name: produced by empire id: -1 fighters: part meters: