[BUG?] Ships with apparently no associated design

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Post Reply
Message
Author
User avatar
Vezzra
Release Manager, Design
Posts: 4609
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

[BUG?] Ships with apparently no associated design

#1 Post by Vezzra » 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...

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;
...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:

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: 
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++).

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12248
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [BUG?] Ships with apparently no associated design

#2 Post by Geoff the Medio » Mon Dec 28, 2015 7:54 pm

I think you get basic visibility of otherwise-stealthy opponent ships that attack you in combat.

Don't know why this would be more or less prone to happening in a moderated game, though, as was reported.

User avatar
MatGB
Creative Contributor
Posts: 3310
Joined: Fri Jun 28, 2013 11:45 pm

Re: [BUG?] Ships with apparently no associated design

#3 Post by MatGB » Mon Dec 28, 2015 10:05 pm

Geoff the Medio wrote:I think you get basic visibility of otherwise-stealthy opponent ships that attack you in combat.
I believe this is correct and iis intended, IIRC Dilvish was the most recent to do some work in that area as there were some issues with the way it was working, we decided we wanted to have something visible to players to let them know/remind them of issues (specific example, very early game Asteroid Snails get marked as a white ship if they kill something).

I think it's good that we show something, and I'm not certain it's working reliably for empire owned vessels, thus it would be good if the AI can handle knowledge that something is there without knowing what.
Mat Bowles

Any code or patches in anything posted here is released under the CC and GPL licences in use for the FO project.

User avatar
Vezzra
Release Manager, Design
Posts: 4609
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: [BUG?] Ships with apparently no associated design

#4 Post by Vezzra » Wed Dec 30, 2015 4:01 pm

Geoff the Medio wrote:I think you get basic visibility of otherwise-stealthy opponent ships that attack you in combat.
Ah yes, that could be the cause for these "basic visible" ships.

Well, this means that having a ship without a design isn't an error, but a possible (albeit rare) case. Consequently it needs to be handled as such. From what I've seen, there are two code sections that currently log errors when encountering this case. First one is the fix Morlic provided for AIstate.py:

Code: Select all

                if not design:
                    print "ERROR: Ship appears to have no valid design..."
                    continue
                for partname in design.parts:
                    if partname and fo.getPartType(partname).partClass == fo.shipPartClass.shortRange:
                        damage = ship.currentPartMeterValue(fo.meterType.capacity, partname)
                        stats['attack'] += damage
                        stats['attacks'][damage] = stats['attacks'].get(damage, 0) + 1
@Morlic, I guess that error log message can go?

The second one is in Universe::GetEffectsAndTargets (line 2092 in Universe.cpp):

Code: Select all

    // 5) EffectsGroups from Ship Hull and Ship Parts
    if (GetOptionsDB().Get<bool>("verbose-logging"))
        DebugLogger() << "Universe::GetEffectsAndTargets for SHIPS hulls and parts";
    type_timer.restart();
    // determine ship hulls and parts of each type in a single pass
    // the same ship might be added multiple times if it contains the part multiple times
    // recomputing targets for the same ship and part is kind of silly here, but shouldn't hurt
    std::map<std::string, std::vector<TemporaryPtr<const UniverseObject> > > ships_by_hull_type;
    std::map<std::string, std::vector<TemporaryPtr<const UniverseObject> > > ships_by_part_type;
    ships = m_objects.FindObjects<Ship>();
    for (std::vector<TemporaryPtr<Ship> >::const_iterator ship_it = ships.begin(); ship_it != ships.end(); ++ship_it) {
        TemporaryPtr<const Ship> ship = *ship_it;
        if (m_destroyed_object_ids.find(ship->ID()) != m_destroyed_object_ids.end())
            continue;

        const ShipDesign* ship_design = ship->Design();
        if (!ship_design) {
            ErrorLogger() << "GetEffectsAndTargets couldn't get ShipDesign";
            continue;
        }
As that function apparently gets also called by the clients (only AI?) to run estimates, it too shouldn't log an error here. Maybe necessary to check if that happens in the server or a client process, as the server probably should log an error in this case? Geoff?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12248
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [BUG?] Ships with apparently no associated design

#5 Post by Geoff the Medio » Thu Dec 31, 2015 8:14 pm

Vezzra wrote:As that function apparently gets also called by the clients (only AI?)
Should be used everything, I think.
...to run estimates, it too shouldn't log an error here. Maybe necessary to check if that happens in the server or a client process, as the server probably should log an error in this case? Geoff?
It's problematic to make different things happen on clients vs. the server in this type of code because it's supposed to be all in the common module, which is compiled as neither client nor server code. Just removing the error message is probably fine, as it's occasionally expected behaviour.

User avatar
Vezzra
Release Manager, Design
Posts: 4609
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: [BUG?] Ships with apparently no associated design

#6 Post by Vezzra » Sat Jan 02, 2016 8:50 pm

Ok, removed both error messages. Commit 9a5b4b3.

mel_o
Space Floater
Posts: 26
Joined: Tue Mar 10, 2015 8:23 am

Re: [BUG?] Ships with apparently no associated design

#7 Post by mel_o » Thu Jan 07, 2016 3:19 pm

Would it be possible to create an "unknown" ship design so that the server can specifically tell a client that a ship exists but nothing is known about it? Simply removing the error messages would make it more difficult to diagnose actual errors in the future.
Unless stated otherwise, code and scripts provided by me are released under GNU GPL 2.0 (or later) and other content is released under CC BY-SA 3.0.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12248
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [BUG?] Ships with apparently no associated design

#8 Post by Geoff the Medio » Thu Jan 07, 2016 3:36 pm

mel_o wrote:Would it be possible to create an "unknown" ship design so that the server can specifically tell a client that a ship exists but nothing is known about it?
That's what a ship with design id = INVALID_DESIGN_ID means... its design is not known to the player.

User avatar
Vezzra
Release Manager, Design
Posts: 4609
Joined: Wed Nov 16, 2011 12:56 pm
Location: Sol III

Re: [BUG?] Ships with apparently no associated design

#9 Post by Vezzra » Thu Jan 07, 2016 5:10 pm

Geoff the Medio wrote:
mel_o wrote:Would it be possible to create an "unknown" ship design so that the server can specifically tell a client that a ship exists but nothing is known about it?
That's what a ship with design id = INVALID_DESIGN_ID means... its design is not known to the player.
Hm, shouldn't we then have another constant that specifies "does not have a design assigned" that the design id is set to on object construction? That way we could catch cases where due to whatever bug a ship didn't get a design assigned.

Just tossing a thought around, no idea if that's really reasonable.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12248
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: [BUG?] Ships with apparently no associated design

#10 Post by Geoff the Medio » Thu Jan 07, 2016 5:37 pm

Vezzra wrote:...another constant that specifies "does not have a design assigned" that the design id is set to on object construction?
Not necessary as far as I know, and a bunch of awkward-to-add extra tests / checks would be required.

Post Reply