Announcement

Collapse
No announcement yet.

AE Scenario Conversion: Cradle

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Code:
    HandleEvent(KillCity) 'CRA_MilitiaCityDestroyed' pre {
    unit_t    tmpUnit;
    city_t    tmpCity;
    int_t    i;
    int_t    tmpPlayer;
        
        if(DisbandCityCheck == 0) {
            tmpPlayer = player[0];
            for(i = GetUnitsAtLocation(city[0].location)-1; i >= 0; i = i - 1) {
                GetUnitByIndex(tmpPlayer, i, tmpUnit);
                if (CRA_IsMilitia(tmpUnit.type)) {
                    KillUnit(tmpUnit);
                }
            }
        }
        else { DisbandCityCheck = 0; }
    }
    I had to add this check in case the player disbands a city. There is another event for that. the invalid player error is still occurring, as well as the GetUnitByIndex out of bounds error.
    "

    Comment


    • #32
      Maybe change it to:

      Code:
      if (GetUnitByIndex(tmpPlayer, i, tmpUnit)) {

      And what is the disband check for? Don't the militia units get destroyed if a player disbands a city too?
      Call to Power 2: Apolyton Edition - download the latest version (12th June 2011)
      CtP2 AE Wiki & Modding Reference
      One way to compile the CtP2 Source Code.

      Comment


      • #33
        Originally posted by Maquiladora View Post
        Maybe change it to:

        Code:
        if (GetUnitByIndex(tmpPlayer, i, tmpUnit)) {
        And what is the disband check for? Don't the militia units get destroyed if a player disbands a city too?
        They do, but CRA_MilitiaCityDestroyed triggers too and causes the GetUnitByIndex error.
        "

        Comment


        • #34
          if (GetUnitByIndex(tmpPlayer, i, tmpUnit))
          Testing this now, no crashes so far.
          "

          Comment


          • #35
            Code:
            HandleEvent(BeginTurn) 'CRA_MilitiaCity' pre { 
            int_t     TEMP_PLAYER_COUNT;  
            int_t        i;
            int_t        j;
            location_t    tmpLoc;
            city_t    tmpCity;
            
                if(IsHumanPlayer(player[0])) {
                    TEMP_PLAYER_COUNT= preference("NumPlayers");
                    for (i=0; i < TEMP_PLAYER_COUNT; i = i + 1){
                        if (IsPlayerAlive(i)){ 
                            if(!IsHumanPlayer(i)) {
                                player[1] = i;
                                for (j = 0; j < player[1].cities; j = j + 1) {                // cycle through all cities
                                    GetCityByIndex(i, j, tmpCity);
                                    tmpLoc = tmpCity.location;
                                    if(UnitsInCell(tmpLoc) == 0){
                                        CRA_CreateMilitia(1, i, tmpLoc); // create 1 Militia
                                    }
                                } [B]<- line 260[/B]
                            }
                        }
                    }
                }
            }
            Still says there is an error on line 260: Array index 1 out of bounds
            "

            Comment


            • #36
              Originally posted by EPW View Post
              Code:
              HandleEvent(BeginTurn) 'CRA_MilitiaCity' pre { 
              int_t     TEMP_PLAYER_COUNT;  
              int_t        i;
              int_t        j;
              location_t    tmpLoc;
              city_t    tmpCity;
              
                  if(IsHumanPlayer(player[0])) {
                      TEMP_PLAYER_COUNT= preference("NumPlayers");
                      for (i=0; i < TEMP_PLAYER_COUNT; i = i + 1){
                          if (IsPlayerAlive(i)){ 
                              if(!IsHumanPlayer(i)) {
                                  player[1] = i;
                                  for (j = 0; j < player[1].cities; j = j + 1) {                // cycle through all cities
                                      GetCityByIndex(i, j, tmpCity);
                                      tmpLoc = tmpCity.location;
                                      if(UnitsInCell(tmpLoc) == 0){
                                          CRA_CreateMilitia(1, i, tmpLoc); // create 1 Militia
                                      }
                                  } [B]<- line 260[/B]
                              }
                          }
                      }
                  }
              }
              Still says there is an error on line 260: Array index 1 out of bounds
              So NumPlayers is wrong. I guess either a civ was removed from the game, or numplayers was changed in userprofile.txt, since the game began.

              Try using one of the new variables to find the current number of players: http://www.ctp2.info/database/slic/v...s/currentgame/
              Call to Power 2: Apolyton Edition - download the latest version (12th June 2011)
              CtP2 AE Wiki & Modding Reference
              One way to compile the CtP2 Source Code.

              Comment


              • #37
                Originally posted by Maquiladora View Post
                So NumPlayers is wrong. I guess either a civ was removed from the game, or numplayers was changed in userprofile.txt, since the game began.

                Try using one of the new variables to find the current number of players: http://www.ctp2.info/database/slic/v...s/currentgame/

                I'll try it.

                if (GetUnitByIndex(tmpPlayer, i, tmpUnit))
                This didn't work, same error.
                "

                Comment


                • #38
                  I'll try it.
                  Same error, using g.num_of_players.
                  "

                  Comment


                  • #39
                    Maq is right, g.last_player would be the variable of choice here.

                    These index out of bounds errors often occur when using the internal arrays like in this function player[1].cities - this can be avoided by using the Cities() function here.

                    As a general method of avoiding possible trouble , I'd suggest to strictly use int-functions in a conditional way, which means replacing

                    Code:
                    GetCityByIndex(i, j, tmpCity);
                    by

                    Code:
                    if(GetCityByIndex(i, j, tmpCity)) {
                    ... etc ...
                    }
                    So I'd suggest to try the following:

                    Code:
                    HandleEvent(BeginTurn) 'CRA_MilitiaCity' pre {  
                    int_t        i;
                    int_t        j;
                    location_t    tmpLoc;
                    city_t    tmpCity;
                    
                        if(IsHumanPlayer(player[0])) {
                            for(i = 0; i <= g.last_player; i = i + 1) {
                                if(IsPlayerAlive(i)) { 
                                    if(!IsHumanPlayer(i)) {
                                        for(j = 0; j < Cities(i); j = j + 1) {
                                            if(GetCityByIndex(i, j, tmpCity)) {
                                                tmpLoc = tmpCity.location;
                                                if(UnitsInCell(tmpLoc) == 0){
                                                    CRA_CreateMilitia(1, i, tmpLoc); // create 1 Militia
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    The modding knowledgebase: CTP2 Bureau (with CTP2 AE Modding Wiki). Modern Times Mod (work in progress): MoT-Mod for CTP2.

                    Comment


                    • #40
                      Okay, i'll try g.last_player and your other changes. Any ideas why CRA_MilitiaCityDestroyed is still causing errors?
                      "

                      Comment


                      • #41
                        Oops, sorry, I didn't notice this one.

                        In this case you need the GetUnitFromCell function instead of GetUnitByIndex, because if there are 10 units at the location you don't need the 1st-10th of the player's total units in tmpUnit, but the 1st-10th units in the cell:

                        Code:
                        HandleEvent(KillCity) 'CRA_MilitiaCityDestroyed' pre {
                        unit_t    tmpUnit;
                        city_t    tmpCity;
                        int_t    i;
                            
                            tmpCity = city[0];
                            if(DisbandCityCheck == 0) {
                                for(i = GetUnitsAtLocation(tmpCity.location) - 1; i >= 0; i = i - 1) {
                                    if(GetUnitFromCell(tmpCity.location, i, tmpUnit)) {
                                        if(CRA_IsMilitia(tmpUnit.type)) {
                                            KillUnit(tmpUnit);
                                        }
                                    }
                                }
                            }
                            else { DisbandCityCheck = 0; }
                        }
                        The modding knowledgebase: CTP2 Bureau (with CTP2 AE Modding Wiki). Modern Times Mod (work in progress): MoT-Mod for CTP2.

                        Comment


                        • #42
                          Originally posted by Maquiladora View Post
                          Untested so may not work as advertised..
                          I did post a disclaimer
                          Call to Power 2: Apolyton Edition - download the latest version (12th June 2011)
                          CtP2 AE Wiki & Modding Reference
                          One way to compile the CtP2 Source Code.

                          Comment


                          • #43
                            Originally posted by BureauBert View Post
                            Oops, sorry, I didn't notice this one.

                            In this case you need the GetUnitFromCell function instead of GetUnitByIndex, because if there are 10 units at the location you don't need the 1st-10th of the player's total units in tmpUnit, but the 1st-10th units in the cell:

                            Code:
                            HandleEvent(KillCity) 'CRA_MilitiaCityDestroyed' pre {
                            unit_t    tmpUnit;
                            city_t    tmpCity;
                            int_t    i;
                                
                                tmpCity = city[0];
                                if(DisbandCityCheck == 0) {
                                    for(i = GetUnitsAtLocation(tmpCity.location) - 1; i >= 0; i = i - 1) {
                                        if(GetUnitFromCell(tmpCity.location, i, tmpUnit)) {
                                            if(CRA_IsMilitia(tmpUnit.type)) {
                                                KillUnit(tmpUnit);
                                            }
                                        }
                                    }
                                }
                                else { DisbandCityCheck = 0; }
                            }
                            That makes sense, hopefully this is the final fix.
                            "

                            Comment


                            • #44
                              Eh, I'm getting -1 is not a valid player index for'CRA_MilitiaCityDestroyed'. It doesn't make any sense since no player is referred to in that function...
                              "

                              Comment


                              • #45
                                I assume you started a new game? Other than that I dunno. Is it trying to kill a unit that it can't? Put a tmpUnit.valid check in there.
                                Call to Power 2: Apolyton Edition - download the latest version (12th June 2011)
                                CtP2 AE Wiki & Modding Reference
                                One way to compile the CtP2 Source Code.

                                Comment

                                Working...
                                X