View Issue Details

IDProjectCategoryLast Update
0022362AI War 2Bug - OtherDec 13, 2019 5:41 pm
ReporterStarKelp Assigned To 
Status resolvedResolutionfixed 
Product VersionBETA 1.015 Testing The Outguard Waters 
Fixed in Version1.016 Back From Beta 
Summary0022362: BaseFaction.GetAIDefensePlacerForPlanet is seemingly always failing
Descriptionpublic virtual AIDefensePlacer GetAIDefensePlacerForPlanet( Faction faction, Planet planet, ArcenSimContext Context )
        {
            //note from Chris: this should be something that comes back for ANY planet, or else it's going to break. Non-AI planets also use this.
            if ( faction.Type != FactionType.AI )
                return AITypeDataTable.Instance.DefaultRow.Implementation.GetAIDefensePlacerForPlanet( faction, planet, Context );
            return faction.GetSentinelsExternal().AIType.Implementation.GetAIDefensePlacerForPlanet( faction, planet, Context );
        }

This appears to always fail to find a faction and default to the 'DefaultRow' on account of, for some reason, not having a proper faction. (I'm unclear exactly, as the code around that is pretty deep and confuses me.) In addition, this DefaultRow wouldn't even be the selected AI type, resulting in many planets not following its own ai's rules.
The following code fixed it to always use a custom DefencePlacer when one is specified, and is listed here for review.

public virtual AIDefensePlacer GetAIDefensePlacerForPlanet( Faction faction, Planet planet, ArcenSimContext Context )
        {
            //note from Chris: this should be something that comes back for ANY planet, or else it's going to break. Non-AI planets also use this.
            if ( faction.Type != FactionType.AI )
            {
                if ( planet.InitialOwningAIFactionIndex != -1 ) // Has been previous owned by an ai, so use that ai's information.
                    return World_AIW2.Instance.GetFactionByIndex( planet.InitialOwningAIFactionIndex ).GetSentinelsExternal().AIType.Implementation.GetAIDefensePlacerForPlanet( faction, planet, Context );
                else // Seemingly never owned by an ai, so use the primary ai's information.
                    return World_AIW2.Instance.AIFactions[0].GetSentinelsExternal().AIType.Implementation.GetAIDefensePlacerForPlanet( faction, planet, Context );
            }
            // If currently owned, nice. Just return data from it.
            return faction.GetSentinelsExternal().AIType.Implementation.GetAIDefensePlacerForPlanet( faction, planet, Context );
        }
TagsNo tags attached.

Activities

BadgerBadger

Dec 13, 2019 5:23 pm

manager   ~0054985

When/where are you trying to call this function? Sim code? Seeding code?

Chris_McElligottPark

Dec 13, 2019 5:25 pm

administrator   ~0054986

This is a good code change, I approve.

StarKelp

Dec 13, 2019 5:30 pm

developer   ~0054987

Thats the thing. I don't quite know. I never directly call it, but call an overrided version that that is meant to call? Its a bit on the complicated side for me I fear to properly explain.
The above code is inside of BaseFaction.cs.

The code of mine that is related is in AiType.cs, and put below.
public class AITypeController_TypeName : BaseAITypeImplementation
    {
        public override AIDefensePlacer GetAIDefensePlacerForPlanet( Faction faction, Planet planet, ArcenSimContext Context )
        {
            return AIDefensePlacerTable.Instance.GetRowByName( "TypeName", false, null );
        }
    }

Chris_McElligottPark

Dec 13, 2019 5:41 pm

administrator   ~0054988

It's called by both -- during the game, and during mapgen.

Issue History

Date Modified Username Field Change
Dec 13, 2019 5:20 pm StarKelp New Issue
Dec 13, 2019 5:23 pm BadgerBadger Note Added: 0054985
Dec 13, 2019 5:25 pm Chris_McElligottPark Note Added: 0054986
Dec 13, 2019 5:30 pm StarKelp Note Added: 0054987
Dec 13, 2019 5:41 pm Chris_McElligottPark Status new => resolved
Dec 13, 2019 5:41 pm Chris_McElligottPark Resolution open => fixed
Dec 13, 2019 5:41 pm Chris_McElligottPark Fixed in Version => 1.016 Back From Beta
Dec 13, 2019 5:41 pm Chris_McElligottPark Note Added: 0054988