Announcement

Collapse
No announcement yet.

DEBUG: BureauBert's Crash GetMinPrerequisites@Advances

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

  • DEBUG: BureauBert's Crash GetMinPrerequisites@Advances

    Bureaubert's crash http://www.apolyton.net/forums/showt...93#post4346793

    Code:
      0x0047ffa3  [?GetMinPrerequisites@Advances@@QBEJJJ@Z + 0x6]
      0x00480049  [?GetMinPrerequisites@Advances@@QBEJJJ@Z + 0xac]
      0x004ce35a  [?ChooseType@GoodyHut@@AAE?AW4GOODY@@ABJ@Z + 0x177]
      0x004ce5f8  [?OpenGoody@GoodyHut@@QAEXABJABVMapPoint@@@Z + 0x33]
      0x00492eb2  [?CheckTerrainEvents@ArmyData@@QAEXXZ + 0x60]
    Code:
    //----------------------------------------------------------------------------
    //
    // Name       : Advances::GetMinPrerequisites
    //
    // Description: Get the number of missing steps to get to an advance
    //
    // Parameters : adv     : the advance to get to
    //              limit   : when to stop counting and report it as too advanced
    //
    // Globals    : g_theAdvanceDB
    //
    // Returns    : sint32  : the number of missing prerequisite steps
    //
    // Remark(s)  : - When you already have the advance, the returned value is 0.
    //              - When you have all prerequisites for the advance, but do not
    //                have the advance itself, the returned value is 1.
    //              - When you are missing prerequisites for the advance, the 
    //                returned value is the sum of the recursive application of 
    //                this function to the missing prerequisites.
    //              - When the limit is reached, the returned value is unspecified,
    //                but always larger than the limit.
    //
    //----------------------------------------------------------------------------
    sint32 Advances::GetMinPrerequisites(sint32 adv, sint32 limit) const
    {
    	if (m_hasAdvance[adv])
        {
    		return 0;
        }
    
    	AdvanceRecord const *   rec         = g_theAdvanceDB->Get(adv);
    	sint32                  totalneeded = 0;
    
    	for (sint32 prereq = 0; prereq < rec->GetNumPrerequisites(); ++prereq)
        {
    		if ((rec->GetIndex() != rec->GetPrerequisitesIndex(prereq)) &&
                !m_hasAdvance[rec->GetPrerequisitesIndex(prereq)]
               ) 
            {
    			totalneeded += 
                    GetMinPrerequisites(rec->GetPrerequisitesIndex(prereq), limit - 1);
    
                if (totalneeded > limit)
                {
                    return totalneeded;
                }
    		}
    	}
    
    	return totalneeded + 1; 
    }
    Code:
        case GOODY_ADVANCE:
            {
                Advances const *    advances     = g_player[owner]->m_advances;
    		    AdvanceType *       possible     = 
                    new AdvanceType[g_theAdvanceDB->NumRecords()];
    		    size_t              nextPossible = 0;
                sint32 const        maxNovelty   = risk.GetMaxAdvanceLeap();
    
    		    for (AdvanceType i = 0; i < g_theAdvanceDB->NumRecords(); ++i) 
                {
                    if (advances->HasAdvance(i)) 
    					continue;   // known
    
    				if (g_theAdvanceDB->Get(i)->GetGoodyHutExcluded())
    				    continue;   // EMOD new flag to prevent some unts from appearing
    
    				if ((g_theAdvanceDB->Get(i)->GetNumPrerequisites() > 0) &&
    			        (g_theAdvanceDB->Get(i)->GetPrerequisitesIndex(0) == i)
                       )
                        continue;   // undiscoverable
    
                    if (advances->GetMinPrerequisites(i, maxNovelty) <= maxNovelty)
                    {
                        possible[nextPossible++] = i;			    
                    // else: too advanced
    		    }
    
    		    if (nextPossible) 
                {
    		        m_value = possible[(nextPossible * m_value) / k_VALUE_RANGE];
    		    }
                else
                {
                    result  = GOODY_BOGUS;
                }
    
    		    delete [] possible;
    	    }
            break;
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

  • #2
    well tweaking risk.txt and my advances.txt appeared to do the rick i even reloaded your game BB and it finished the turn. So my next update will be out soon.
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • #3
      well tweaking risk.txt and my advances.txt appeared to do the rick i even reloaded your game BB and it finished the turn. So my next update will be out soon.
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • #4


        Great, so I can continue the game and don't need to crash a new one.
        Congratulations!!!

        Today, one of these maniac moments, I thought of starting to re-build my MoT-Mod based upon the playtest files. Well, I think I'd better wait a little ...
        The modding knowledgebase: CTP2 Bureau (with CTP2 AE Modding Wiki). Modern Times Mod (work in progress): MoT-Mod for CTP2.

        Comment


        • #5
          Originally posted by E
          well tweaking risk.txt and my advances.txt appeared to do the rick i even reloaded your game BB and it finished the turn. So my next update will be out soon.
          And what were your changes?

          -Martin
          Civ2 military advisor: "No complaints, Sir!"

          Comment


          • #6
            i closed the gap between techs. I think an issue was that the AI would go way down to the path of say gunpowder but bypass ironworking (or something) and the number of tech gaps were huge which I think affect the mintechprereqs in risk.txt.

            So I made it that techs of a new ge required the all of the 'last' techs of the previous age, and then i increased the risk.txt values to 10. i did take a hut in a test game and got a nearby tech so it didnt grab so 10 tachs down the road one so it seems to have done the trick.


            eventually i think it would be nice to have a EitherPreRequisite code for advances to get the fluid tree of Civ4. I think using my NeedsCityGood code with either good avail would be kindof what I need. but thats for later.
            Formerly known as "E" on Apolyton

            See me at Civfanatics.com

            Comment


            • #7
              The point here is that the input from your textfiles is valid and it shouldn't make fail the ctp2.exe. Therefore this should fixed.

              -Martin
              Civ2 military advisor: "No complaints, Sir!"

              Comment


              • #8
                How many unit types and advances did you have in your mod, E?

                There is a cut-and-paste error in the GOODY_UNIT case of GoodyHut::ChooseType (not shown in your code dump). The reserved space for the "possible" array in the GOODY_UNIT case is incorrect. It is now set to the number of advances, but this should be the number of unit types.

                In the normal game this is not a problem, because the number of advances is larger than the number of units.

                Comment


                • #9
                  Ahhh,

                  then that is the problem. I have 99 units but 84 techs. I'll make an attempt to correct it and post it here to make sure i got in right.

                  I did see that (of course not understanding that was the problem) but I assumed that the advance reference was used to identify what unit was available

                  for reference i believe your talking about this code
                  Code:
                      case GOODY_UNIT:
                          {
                              Advances const *    advances     = g_player[owner]->m_advances;
                  		    sint32 *            possible     = new sint32[g_theAdvanceDB->NumRecords()];
                  		    size_t              nextPossible = 0;
                              sint32 const        maxNovelty   = risk.GetMaxUnitAdvanceLeap();
                  
                  		    for (sint32 i = 0; i < g_theUnitDB->NumRecords(); ++i) 
                              {
                  			    UnitRecord const * rec = g_theUnitDB->Get(i);
                  
                  			    if (!rec->GetMovementTypeLand())
                  				    continue;   // would die immediately here
                  			    if (rec->GetAttack() < 1)               
                  				    continue;   // defenseless?
                  			    if (rec->GetGoodyHutExcluded())
                  				    continue;   // EMOD new flag to prevent some unts from appearing
                  			    if (rec->GetHasPopAndCanBuild())
                  				    continue;   // settler, handled separately
                  			    if (g_exclusions->IsUnitExcluded(i))    
                  				    continue;   // excluded (MP, mod)
                  			    if (rec->GetNumGovernmentType() > 0) 
                  				    continue;   // government specific?
                  
                  			    if (advances->GetMinPrerequisites
                                          (rec->GetEnableAdvanceIndex(), maxNovelty) 
                                      <= maxNovelty)  {
                  				   possible[nextPossible++] = i;
                  			    } else {
                  				continue; //EMOD to prevent Bureaubert crash
                  				}
                  				// else : too advanced
                  		    }
                  
                  		    if (nextPossible)
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • #10
                    Playtesting my mod this crash has returned

                    I did add a few more units and a few more techs. But based on Fromafar's change which I implemented it should not have crashed.

                    Is it because the code (posted above) still address next possible with advances? Should we just change it to a player->canbuildunit check?
                    Formerly known as "E" on Apolyton

                    See me at Civfanatics.com

                    Comment


                    • #11
                      I still get the feeling that because the GOODY_UNIT calls the advances with the possible stuff it causes a crash. So I'm thinking of just checking available units:

                      Code:
                          case GOODY_UNIT:
                              {
                                  Advances const *    advances     = g_player[owner]->m_advances;
                      		    sint32 *            possible     = new sint32[g_theUnitDB->NumRecords()]; //EMOD changed from AdvancesDB recomended by Fromafar 4-12-2006
                      		    size_t              nextPossible = 0;
                                  sint32 const        maxNovelty   = risk.GetMaxUnitAdvanceLeap();
                      
                      		    for (sint32 i = 0; i < g_theUnitDB->NumRecords(); ++i) 
                                  {
                      			    UnitRecord const * rec = g_theUnitDB->Get(i);
                      
                      			    if (!rec->GetMovementTypeLand())
                      				    continue;   // would die immediately here
                      			    if (rec->GetAttack() < 1)               
                      				    continue;   // defenseless?
                      			    if (rec->GetGoodyHutExcluded())
                      				    continue;   // EMOD new flag to prevent some unts from appearing
                      			    if (rec->GetHasPopAndCanBuild())
                      				    continue;   // settler, handled separately
                      			    if (g_exclusions->IsUnitExcluded(i))    
                      				    continue;   // excluded (MP, mod)
                      			    if (rec->GetNumGovernmentType() > 0) 
                      				    continue;   // government specific?
                      /////////////////ORIGINAL
                      //			    if (advances->GetMinPrerequisites
                      //                        (rec->GetEnableAdvanceIndex(), maxNovelty) 
                      //                    <= maxNovelty
                      //                  )
                      //               {
                      //				    possible[nextPossible++] = i;
                      //			    }
                                      // else : too advanced
                      ///////////////////////
                      //EMOD
                      				sint32 p;
                      				for(p = 0; p < k_MAX_PLAYERS; p++) {
                      					if(g_player[p] && g_player[p]->m_advances->HasAdvance(rec->GetEnableAdvanceIndex())){
                      						m_value = i;
                      					}
                      				}
                      //EMOD
                      			}
                      /////////////////ORIGINAL
                      //		    if (nextPossible) 
                      //           {
                      //		        m_value = possible[(nextPossible * m_value) / k_VALUE_RANGE];
                      //		    }
                      //          else
                      //          {
                                      result  = GOODY_BOGUS;
                      //          }
                      //
                      //		    delete [] possible;
                      ///////////////////////
                      	    }
                              break;

                      Can anyone see something wrong with the code?
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • #12
                        Code:
                          0x00480067  [?GetMinPrerequisites@Advances@@QBEJJJ@Z + 0x6]
                          0x0048010d  [?GetMinPrerequisites@Advances@@QBEJJJ@Z + 0xac]
                          0x004d249a  [?ChooseType@GoodyHut@@AAE?AW4GOODY@@ABJ@Z + 0x177]
                          0x004d2729  [?OpenGoody@GoodyHut@@QAEXABJABVMapPoint@@@Z + 0x33]
                          0x00493d4f  [?CheckTerrainEvents@ArmyData@@QAEXXZ + 0x60]
                        this time I changed the code in the Unit part getting rid of the getminprereq part so that means the crash is in the advances part. But again this is with my civ3mod and not the normal game so it appears the code has a problem with pathing.
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • #13
                          Pave told me that its still there. I fixed some pathing (I thought). But I'm thinking of just adding this code to Goodyhuts:

                          Code:
                          			sint32 i = g_player[owner]->m_advances->GetResearching();
                          			if(!g_theAdvanceDB->Get(i)->GetGoodyHutExcluded()){
                          				m_value	= g_player[owner]->m_advances->GetResearching(); //added by E 8-15-2006 for minPreReqCrash
                          			}
                          			else
                          			{
                          				result  = GOODY_BOGUS;
                          			}

                          No need for all that premin advance checking you just get whatever you are researching, and if if what you are researching isnt available in a goody hut you get nada. This is all I can think of unless someone can think of a way to fix this.
                          Formerly known as "E" on Apolyton

                          See me at Civfanatics.com

                          Comment


                          • #14
                            No E that is stupid. And actually it would be a little bit suspicious if you get always what are currently researching. There are no native people with some occult psycic abilities that makes them know your current research project.

                            -Martin
                            Civ2 military advisor: "No complaints, Sir!"

                            Comment


                            • #15
                              OK, Then what do you think the problem is? it looks like it cant handle the integers.
                              Formerly known as "E" on Apolyton

                              See me at Civfanatics.com

                              Comment

                              Working...
                              X