Announcement

Collapse
No announcement yet.

E's Source Code attempts

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

  • I think i fixed the stack problem I had to make it -1 1 not +1

    Code:
    for (i = m_nElements - 1; 0 <= i; i--) {
    Last edited by Ekmek; February 28, 2006, 11:56.
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • I PM'd Fromafar for help but if any one else can I'd appreciate it. I was trying to do a piece of code that would give the player PW or Gold for a terrain improvement any where in its territory (right now its only in city radius). I tried this in Player.cpp

      Code:
      void Player::BeginTurnImprovements()
      
      ...some code...
      
      	for(i = 0; i < m_terrainImprovements->Num(); i++) {
      		const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(i);
      		const TerrainImprovementRecord::Effect *effect = rec->GetTerrainEffect(i);
      			if (effect->GetColony()) {
      m_materialPool->AddMaterials(effect->GetBonusProductionExport());
      		}
      	}
      it compiled but nothing happened so since it didnt rash it put me at a dead end
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • Originally posted by E
        Code:
        void Player::BeginTurnImprovements()
        
        ...some code...
        
        	for(i = 0; i < m_terrainImprovements->Num(); i++) {
        		const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(i);
        		const TerrainImprovementRecord::Effect *effect = rec->GetTerrainEffect(i);
        			if (effect->GetColony()) {
        m_materialPool->AddMaterials(effect->GetBonusProductionExport());
        		}
        	}
        it compiled but nothing happened so since it didnt [c]rash it put me at a dead end
        In fact E your code can crash: Namely if the player has more terrain improvements than there are terrain improvement records in the database. Of course if the Get method of the DBs does not handle it, at least it should give you an assert in debug mode.

        However you have to figure out how you can retrieve an object pointer by an index access from m_terrainImprovements. And you have to figure out if m_terrainImprovements really contains what you are looking for. At least if I remember correctly it should contain the endgame objects.

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

        Comment


        • thanks Martin, good to see you are still around. I tried m_installations before which I believe utilizes the forts and stuff so I may try that again to avoid the crash.

          I did try the installations before and it didwork. I think the BeginTurnImprovement is used because thats where it builds from. I'll keep poking.

          Hopefully I'll get something working that can eventually be used so it saves a lot of time in mods that would slow the game but scanning the map.
          Formerly known as "E" on Apolyton

          See me at Civfanatics.com

          Comment


          • Originally posted by E
            thanks Martin, good to see you are still around. I tried m_installations before which I believe utilizes the forts and stuff so I may try that again to avoid the crash.
            That's not really the problem:

            Your maximum i is dependent on m_terrainImprovements->Num() and not on the number of terrain improvement records. But you use your i to access a record from the terrain improvement database: g_theTerrainImprovementDB->Get(i)

            And then you use the same i to access the terrain effect struct: rec->GetTerrainEffect(i)

            You mix up three different things. So you shouldn't wonder why your code doesn't work.

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

            Comment


            • Martin,
              Thanks for the help I'm still working it though. but while still testing I found something interesting with my EnablesGood code.

              The city will collect the good (I know because I can build needsgood units) but I cant trade the good. For buildings I havent seen them pop up, but for tileimps it gets real weird. the tile imp has to be built on a terrain that has the good listed as a resource and the good must have a probability greater than 0.0

              ow if nonne of those apply the city will collect the good but you wont have the good in the trade window (so you cant trade it).

              The nice part is that I think I found a way to make non-tradeable goods that bad part is that I cant trade it.

              But I think this is where the problem is...

              Code:
              sint32 TradePool::GetGoldValue(sint32 resource, sint32 n)
              {
              	return ((n * (n+1)) / 2) * g_theResourceDB->Get(resource)->GetGold();
              
              #if 0
              	sint32 terrain = resource % k_BASE_TERRAIN_TYPES;
               	sint32 good = resource / k_BASE_TERRAIN_TYPES;
               	sint32 gold = (n+1) * 
              		g_theTerrainDB->Get(terrain)->GetGood(good)->GetGoodGoldValue();
              	return gold;
              #endif
              }
              I think the multiplying the g_theTerrainDB->Get(terrain)->GetGood(good)->GetGoodGoldValue(); is the part and that because its not coming from the terrain but a bldg or a tileimp its getting a 0 value so its not listing. BUT according to this code this is only for previous builds and shouldnt be the current one.

              Do I have that right or am I off? thanks
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • Originally posted by E
                The city will collect the good (I know because I can build needsgood units) but I cant trade the good. For buildings I havent seen them pop up, but for tileimps it gets real weird. the tile imp has to be built on a terrain that has the good listed as a resource and the good must have a probability greater than 0.0
                If you don't show your code here, then I can't help you.

                Originally posted by E
                The nice part is that I think I found a way to make non-tradeable goods that bad part is that I cant trade it.
                Maybe you should rephrase this sentence, I have no idea which word the final it referes to.

                Originally posted by E
                But I think this is where the problem is...

                Code:
                sint32 TradePool::GetGoldValue(sint32 resource, sint32 n)
                {
                	return ((n * (n+1)) / 2) * g_theResourceDB->Get(resource)->GetGold();
                
                #if 0
                	sint32 terrain = resource % k_BASE_TERRAIN_TYPES;
                 	sint32 good = resource / k_BASE_TERRAIN_TYPES;
                 	sint32 gold = (n+1) * 
                		g_theTerrainDB->Get(terrain)->GetGood(good)->GetGoodGoldValue();
                	return gold;
                #endif
                }
                I think the multiplying the g_theTerrainDB->Get(terrain)->GetGood(good)->GetGoodGoldValue(); is the part and that because its not coming from the terrain but a bldg or a tileimp its getting a 0 value so its not listing. BUT according to this code this is only for previous builds and shouldnt be the current one.
                Actually you have to ignore everything that is inside this #if 0 body. This is a leftover from CTP1. The only interesting stuff here is the first line of the function body. And it accesses the ressource database. So there is no problems with goods from terrain or not from terrain.

                I thing this is a method to evaluate the price of a good and that is determined by the good terrain bonus and is determined by n, probably this is a distance. And the value has a quadratic dependence of n.

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

                Comment


                • Martin's here's the enablesgood code. I swear that when I did it before it had no problems but anyways it does now.

                  Code:
                  CityData::CollectResources
                  ...some code...
                  
                  // Add if city has building GetEnablesGood >0 then that good will be added to the city for trade
                  
                  	sint32 good; 
                  	for(sint32 b = 0; b < g_theBuildingDB->NumRecords(); b++) {
                  		if(m_built_improvements & ((uint64)1 << b)) {
                  		const BuildingRecord *rec = g_theBuildingDB->Get(b, g_player[m_owner]->GetGovernmentType());
                  	//  Check If needsGood for the building a make bonuses dependent on having that good for further bonus
                  			if (rec->GetNumEnablesGood() > 0){
                  				for(good = 0; good < rec->GetNumEnablesGood(); good++) {
                  					m_collectingResources.AddResource(rec->GetEnablesGoodIndex(good));
                  				}
                  			}
                  		}
                  	}
                  
                  // end building enables good
                  
                  // Add if city has wonder GetEnablesGood >0 then that good will be dded to the city for trade
                      //sint32 wgood; 
                  	for(sint32 w = 0; w < g_theWonderDB->NumRecords(); w++) {
                  		if(m_builtWonders & ((uint64)1 << w)) {
                  			const WonderRecord *wrec = wonderutil_Get(w);
                  //      Check If needsGood for the building a make bonuses dependent on having that good for further bonus
                  			if (wrec->GetNumEnablesGood() > 0){
                  				for(good = 0; good < wrec->GetNumEnablesGood(); good++) {
                    					m_collectingResources.AddResource(wrec->GetEnablesGoodIndex(good));
                  				}
                  			}
                  		}
                  	}
                  
                  
                  	CityInfluenceIterator it(cityPos, m_sizeIndex);
                  	for(it.Start(); !it.End(); it.Next()) {
                  		Cell *cell = g_theWorld->GetCell(it.Pos());
                  		sint32 ring = GetRing(it.Pos());
                  		m_ringFood[ring] += cell->GetFoodProduced();
                  		m_ringProd[ring] += cell->GetShieldsProduced();
                  		m_ringGold[ring] += cell->GetGoldProduced();
                  		m_ringSizes[ring]++;
                  		sint32 good;
                  		if(g_theWorld->GetGood(it.Pos(), good)
                  #if !defined(NEW_RESOURCE_PROCESS)
                  		&& MapPoint::GetSquaredDistance(cityPos, it.Pos()) <= partSquaredRadius
                  #endif
                  		){
                  			m_collectingResources.AddResource(good);
                  		}
                  		// Added by E (10-29-2005) - If a tileimp has enablegood then give to city
                  		for(sint32 i = 0; i < cell->GetNumDBImprovements(); i++) {
                  		sint32 imp = cell->GetDBImprovement(i);
                  		const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(imp);
                  			if (rec->GetNumEnablesGood() > 0){
                  				for(good = 0; good < rec->GetNumEnablesGood(); good++) {
                    					m_collectingResources.AddResource(rec->GetEnablesGoodIndex(good));
                  				}
                  			}
                  		}
                  	}
                  as for:
                  The nice part is that I think I found a way to make non-tradeable goods that bad part is that I cant trade it.


                  Maybe you should rephrase this sentence, I have no idea which word the final it referes to.
                  sorry that was an aside, i'm looking to do a cant trade code someday. but in the mean time I want to have the goods that are enabled here tradeable.

                  Actually you have to ignore everything that is inside this #if 0 body. This is a leftover from CTP1. The only interesting stuff here is the first line of the function body. And it accesses the ressource database. So there is no problems with goods from terrain or not from terrain.

                  I thing this is a method to evaluate the price of a good and that is determined by the good terrain bonus and is determined by n, probably this is a distance. And the value has a quadratic dependence of n.
                  thats what i though but I was guessing that for some reason it was using the ctp1 trade which calls the terrain and i was thinking thats why it only appeared in the trade window if it was on the right terrain. So I guess the problem is elsewhere.

                  thanks.
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • Originally posted by E So I guess the problem is elsewhere.
                    Indeed the problem seems to be elsewhere and I don't see any problems in your code. But of course you could check the content of the m_collectingResources object, so that you know that it contains the right number of goods.

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

                    Comment


                    • I think I isolated the problem to some game dynamic as to what a city wants.

                      I made enablesgood a terrain effect and got it working so the same imp on different terains enabled different goods. It got frustrating because sometimes the good would be enabled on one terrain but a different terrain it wasnt. adding A LOT more cities all of a sudden one became available. Also I added one of my buildings with a good and it became available although the other good for another building wasnt. so i guess it comes to some game dynamic.

                      I'm strongly leaning towards all goods wanted sometime somewhere but i have to dig around to see how to implement it.

                      thnkas for the help.
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • Originally posted by Martin Gühmann


                        In fact E your code can crash: Namely if the player has more terrain improvements than there are terrain improvement records in the database. Of course if the Get method of the DBs does not handle it, at least it should give you an assert in debug mode.

                        However you have to figure out how you can retrieve an object pointer by an index access from m_terrainImprovements. And you have to figure out if m_terrainImprovements really contains what you are looking for. At least if I remember correctly it should contain the endgame objects.

                        -Martin

                        Well, I tried this and it compiles but crashes at start up, throwing a fit about GetColony, if i outcomment that then it goes for the export line. I think it might be unit64 whch I took from GetEffectiveBuildings. I admit I dont fully understand what that line means though i've used it alot (for effective buildings).
                        If that line is the source of the problem how do I add 'DBRec' to access? I found in terrimprove.cpp that stuff is and copied how dbrec is used elesewhere but it wouldnt compile.


                        anyways here's the code:

                        Code:
                        void Player::BeginTurnImprovements()
                        {
                        	int i, n;
                        	
                        	n = m_terrainImprovements->Num();
                        	
                        	
                        	for(i = 0; i < n; i++) {
                        		if(!m_terrainImprovements->Access(i).IsBuilding()) {
                        			if(m_materialPool->GetMaterials() >= m_terrainImprovements->Access(i).GetMaterialCost())
                        				m_terrainImprovements->Access(i).StartBuilding();
                        			else
                        				break;
                        		}
                        	}
                        
                        	
                        	for(i=0; i < n; i++) {
                        		g_gevManager->AddEvent(GEV_INSERT_Tail,
                        							   GEV_ImprovementAddTurn,
                        							   GEA_Improvement, m_terrainImprovements->Access(i),
                        							   GEA_End);
                        
                        		
                        	}
                        
                        	//EMOD - Get production for TradeProduction Tile Imps  move to beginturnimps?
                        
                        	MapPoint pos;
                        	for(sint32 b = 0; b < g_theTerrainImprovementDB->NumRecords(); b++) {
                        		if(m_terrainImprovements && ((uint64)1 << b)) {
                        		const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(b);
                        		const TerrainImprovementRecord::Effect *effect = terrainutil_GetTerrainEffect(rec, pos);
                        			if (effect->GetColony()) {
                        				m_materialPool->AddMaterials(rec->GetBonusProductionExport());
                        			}
                        		}
                        	}
                        ///
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • Originally posted by E
                          Well, I tried this and it compiles but crashes at start up, throwing a fit about GetColony, if i outcomment that then it goes for the export line. I think it might be unit64 whch I took from GetEffectiveBuildings. I admit I dont fully understand what that line means though i've used it alot (for effective buildings).
                          If that line is the source of the problem how do I add 'DBRec' to access? I found in terrimprove.cpp that stuff is and copied how dbrec is used elesewhere but it wouldnt compile.
                          The problem here is indeed that line you mention. They used a uint64 to store the buildings of a city and therefore you need to figure out whether the city has the building in question as they do it.

                          However m_terrainImprovements is an array so you have to access its elements by other means.

                          However, you should do something else anyway: Since you turned colony into an installation, you find them now in the m_allInstallations. This array contains much less elements than m_terrainImprovements.

                          Retrieve from m_allInstallations an installation and than use the GetDBRec() method to retrieve a tile improvement record from an Installation object.

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

                          Comment


                          • Thanks Martin, I'm going to give this a try to night:
                            Code:
                            	MapPoint pos;
                            	for(sint32 b = 0; b < m_allInstallations->Num(); b++) {
                            	Installation inst = m_allInstallations->Access(b);
                            	const TerrainImprovementRecord *rec = inst.GetDBRec();
                            	const TerrainImprovementRecord::Effect *effect = terrainutil_GetTerrainEffect(rec, pos);
                            		if (effect->GetColony()) {
                            			m_materialPool->AddMaterials(rec->GetBonusProductionExport());
                            		}
                            	}





                            In the mean time this one bugs me, I think its a defect because I've NEVER seen these SLIC messages called:

                            Code:
                            BOOL ArmyData::VerifyAttack(UNIT_ORDER_TYPE order, const MapPoint &pos,
                            							sint32 defense_owner)
                            {
                            	if(IsEnemy(defense_owner) &&
                            	   !g_player[m_owner]->WillViolateCeaseFire(defense_owner) &&
                            	   !g_player[m_owner]->WillViolatePact(defense_owner))
                            // EMOD
                            		{
                            			SlicObject *so = new SlicObject("110bCantAttackHaveTreaty") ;
                            			so->AddRecipient(player->m_owner) ;
                            			so->AddCity(*unit) ;
                            			g_slicEngine->Execute(so) ;
                            			return(FALSE); 
                            		}
                            // end EMOD
                            		return TRUE;
                            	   
                            	SlicObject *so;
                            	if(g_network.IsActive() && g_network.TeamsEnabled() &&
                            	   g_player[m_owner]->m_networkGroup == g_player[defense_owner]->m_networkGroup) {
                            		so = new SlicObject("110aCantAttackTeammates");
                            	} else if(!IsEnemy(defense_owner)) {
                            		so = new SlicObject("110CantAttackAllies");
                            	} else {
                            		so = new SlicObject("110bCantAttackHaveTreaty");
                            	}
                            
                            	so->AddRecipient(m_owner);
                            	so->AddCivilisation(defense_owner);
                            	so->AddUnit(m_array[0]);
                            	so->AddLocation(pos);
                            	so->AddOrder(order);
                            	g_slicEngine->Execute(so);
                            	g_selected_item->ForceDirectorSelect(Army(m_id));
                            	return FALSE;
                            }
                            am I missing something? I think this SHOULD be implemented and ad the EMOd part suggests I think we should have a pop up to the player warning that an attack may declare war. Am I looking in the right spot?
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • well this code compiled:
                              Code:
                              	MapPoint pos;
                              	for(sint32 b = 0; b < m_allInstallations->Num(); b++) {
                              	Installation inst = m_allInstallations->Access(b);
                              	const TerrainImprovementRecord *rec = inst.GetDBRec();
                              	const TerrainImprovementRecord::Effect *effect = terrainutil_GetTerrainEffect(rec, pos);
                              		if (effect->GetColony()) {
                              			if (effect->GetBonusProductionExport() > 0){
                              				m_materialPool->AddMaterials(effect->GetBonusProductionExport());
                              			}
                              		}
                              	}
                              and it crashed...
                              0x0089aa8a [?GetDefault@BuildListSequenceElement@StrategyRecor d@@QBE_NXZ + 0xa]
                              0x004dd168 [?BeginTurnImprovements@Player@@QAEXXZ + 0x154]
                              0x004f0ad5 [?GEVHookCallback@BeginTurnImprovementsEvent@@EAE?A W4GAME_EVENT_HOOK_DISPOSITION@@W4GAME_EVENT@@PAVGa meEventArgList@@@Z + 0x30]
                              0x005bcc0f [?Run@GameEventHook@@AAE?AW4GAME_EVENT_ERR@@AAViter ator@?$list@UNode@GameEventHook@@V?$allocator@UNod e@GameEventHook@@@std@@@std@@PAVGameEventArgList@@ AAJ@Z + 0x63]

                              and I also tried this code:
                              Code:
                              sint32 buildingutil_GetTotalUpkeep(const uint64 built_improvements,
                              										   sint32 wonderLevel)
                              {
                                  sint32 owner = 0;
                              	sint32 upkeep = 0;
                              	for(sint32 i = 0; i < g_theBuildingDB->NumRecords(); i++) {
                              		if(built_improvements & shiftbit(i)) {
                              			if(g_theBuildingDB->Get(i)->GetUpkeep() > wonderLevel) {
                              				upkeep += g_theBuildingDB->Get(i)->GetUpkeep();
                              
                              //EMOD added new Upkeep calculations (3-13-2006) it might be better for the AI to handle thn using negative "goldper"
                              
                              				upkeep += g_theBuildingDB->Get(i)->GetUpkeepPerUnitWagesReadiness * g_player[owner]->GetNumUnits() * g_player[owner]->m_readiness->GetSupportModifier(g_player[owner]->GetGovernmentType()) * g_player[owner]->GetWagesPerPerson();
                              
                              				upkeep += g_theBuildingDB->Get(i)->GetUpkeepPerCity * g_player[owner]->GetNumCities();
                              
                              
                              				upkeep += g_theBuildingDB->Get(i)->GetUpkeepPerCitySq * g_player[owner]->GetNumCities() *  g_player[owner]->GetNumCities();
                              
                              
                              				upkeep += g_theBuildingDB->Get(i)->GetUpkeepPerUnit * g_player[owner]->GetNumUnits();
                              
                              
                              //end EMOD
                              			}
                              		}
                              	}
                              		return upkeep;
                              }
                              and it didnt work. Especially the owner part when ever I tried to add it as a sint32 in sint32 buildingutil_GetTotalUpkeep(const uint64 built_improvements, sint32 wonderLevel, sint32 owner)


                              CityData.obj : error LNK2001: unresolved external symbol "long __cdecl buildingutil_GetTotalUpkeep(unsigned __int64,long)" (?buildingutil_GetTotalUpkeep@@YAJ_KJ@Z)
                              Player.obj : error LNK2001: unresolved external symbol "long __cdecl buildingutil_GetTotalUpkeep(unsigned __int64,long)" (?buildingutil_GetTotalUpkeep@@YAJ_KJ@Z)
                              CauseAndEffectTab.obj : error LNK2001: unresolved external symbol "long __cdecl buildingutil_GetTotalUpkeep(unsigned __int64,long)" (?buildingutil_GetTotalUpkeep@@YAJ_KJ@Z)
                              ctp2.exe : fatal error LNK1120: 1 unresolved externals
                              Error executing link.exe.
                              never saw that one before.
                              Last edited by Ekmek; March 15, 2006, 00:24.
                              Formerly known as "E" on Apolyton

                              See me at Civfanatics.com

                              Comment


                              • Originally posted by E
                                and it crashed...
                                According to the crash.txt the crash is caused by something that is called by the BeginTurnImprovements method. Maybe you should recompile again or even better you should use the debug version of the executable.

                                Originally posted by E
                                never saw that one before.
                                If you add a parameter to the parameter list of a function and you don't add the parameter in question everywhere it is used you get linker errors as you got.

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

                                Comment

                                Working...
                                X