Announcement

Collapse
No announcement yet.

E's Source Code attempts

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

  • Originally posted by E
    Any recommendations on how to make this optional? The difficulty db doesnt look the same as the other and I'm hesitant to make it a flag there or in Const.cdb since it might further complicate backwards compatibility. I guess I could make it a "AIDeficitSpending' flag for a building...
    It goes into the difficulty database, but not into the current CTP1 one. However I already have replaced it with the new one in my working copy, but first I would like to do some playtesting.

    Originally posted by E
    Are you sure about this? Looking at player it does assign the wonder to the city but not the same way addimprovement does for a biulding in citydata.

    My add borders code doesn't activate without [C]ity[D]ata::[A]dd[W]onder called in the cityevent. Thats how I got it to work with my buildings and not it doesn't work. So i think I wasn'tthat off unless you think it should go into player (I doubt it because it doesn't address generate borders) and putting it in cityevent.cpp also I had problems with.
    As far as I was able to see it CityData::AddWonder is called in Player::AddWonder, therefore it shouldn't be a problem. Of course I should have a look at it again.

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

    Comment


    • Originally posted by Martin Gühmann
      It goes into the difficulty database, but not into the current CTP1 one. However I already have replaced it with the new one in my working copy, but first I would like to do some playtesting.
      Great! I'll wait until you get it going. I think I need to add one with shields too. I have that in readiness and it maybe causing BureauBerts latest Governor/readiness crash

      Originally posted by Martin Gühmann

      As far as I was able to see it CityData::AddWonder is called in Player::AddWonder, therefore it shouldn't be a problem. Of course I should have a look at it again.

      I don't see it there...should we add it there or back into cityevent?

      Code:
      void Player::AddWonder(sint32 wonder, Unit &city)
      {
      	DPRINTF(k_DBG_GAMESTATE, ("Player %d built wonder %d\n", m_owner, wonder));
      	m_builtWonders |= ((uint64)1 << wonder);
      	
      
      	if(wonderutil_Get(wonder)->GetPollutersToParks()) {
      
      		
      		
      		
      		if(!g_network.IsClient() || g_network.IsLocalPlayer(m_owner)) {
      			
      			sint32 polluters;
      			wonderutil_Get(wonder)->GetPollutersToParks(polluters);
      			Unit *ua = new Unit[polluters];
      			for(sint32 i = 0; i < polluters; i++) {
      				ua[i].m_id = (0);
      			}
      			
      			sint32 pl, c, po, mv;
      			
      			for(pl = 0; pl < k_MAX_PLAYERS; pl++) {
      				if(!g_player[pl]) continue;
      				int numCities=g_player[pl]->m_all_cities->Num() ;
      				for(c = 0; c m_all_cities->Access(c));
      
      					
      					if(city.AccessData()->GetCityData()->GetBuiltWonders() & (uint64(1) << wonder))
      						continue;
      
      					
      					if(city.GetPollution() < 1)
      						continue;
      
      					for(po = 0; po < polluters; po++) {
      						if(ua[po].m_id == (0)) {
      							ua[po] = city;
      							break;
      						} else if(city.GetPollution() > ua[po].GetPollution()) {
      							for(mv = polluters - 1; mv > po; mv--) {
      								ua[mv] = ua[mv -1];
      							}
      							ua[po] = city;
      							break;
      						}
      					}
      				}
      			}
      
      			for(po = 0; po < polluters; po++) {
      				if(ua[po].m_id != (0)) {
      					ua[po].CityToPark(m_owner);
      				}
      			}
      			delete [] ua;
      		}
      	}
      
      	if(wonderutil_GetFreeSlaves((uint64)1 << wonder)) {
      		sint32 i, n = m_all_cities->Num();
      		for(i = 0; i < n; i++) {
      			m_all_cities->Access(i).FreeSlaves();
      		}
      
      		for(i = m_all_units->Num() - 1; i >= 0; i--) {
      			const UnitRecord *rec = m_all_units->Access(i).GetDBRec();
      			if(rec->GetSlaveRaids() || rec->GetSettlerSlaveRaids() ||
      			   rec->GetSlaveUprising()) {
      				m_all_units->Access(i).Kill(CAUSE_REMOVE_ARMY_EMANCIPATION, -1);
      			}
      		}
      			
      		for(i = 0; i < k_MAX_PLAYERS; i++) {
      			if(g_player[i] && i != m_owner) {
      				g_player[i]->Emancipate();
      			}
      		}
      	}
      
      	sint32 hpBonus = wonderutil_GetIncreaseHP((uint64)1 << wonder);
      	if(hpBonus > 0) {
      		sint32 i, n = m_all_units->Num();
      		for(i = 0; i < n; i++) {
      			m_all_units->Access(i).AddWonderHPBonus(hpBonus);
      		}
      	}
      
      	sint32 fullHappinessTurns = wonderutil_GetTemporaryFullHappiness(
      		((uint64)1 << wonder));
      	if(fullHappinessTurns > 0) {
      		sint32 i, n = m_all_cities->Num();
      		for(i = 0; i < n; i++) {
      			m_all_cities->Access(i).SetFullHappinessTurns(fullHappinessTurns);
      		}
      	}
      
      	
      	
      	
      	
      	sint32 readinessReduction = wonderutil_GetReadinessCostReduction((uint64)1 << wonder);
      	if(readinessReduction > 0) {
      		m_readiness->RecalcCost();
      	}
      		
      	if(wonderutil_GetNukesEliminated((uint64) 1 << wonder)) {
      		sint32 i, p;
      		SlicObject *so = new SlicObject("251NaniteDefuseEliminatesNukes");
      		so->AddWonder(wonder);
      		so->AddCivilisation(m_owner);
      		for(p = 0; p < k_MAX_PLAYERS; p++) {
      			if(g_player[p]) {
      				so->AddRecipient(p);
      				
      				for(i = 0; i < g_player[p]->m_all_cities->Num(); i++) {
      					g_player[p]->m_all_cities->Access(i).AccessData()->GetCityData()->EliminateNukes();
      				}
      				
      				for(i = g_player[p]->m_all_units->Num() - 1; i >= 0; i--) {
      					if(g_player[p]->m_all_units->Access(i).GetDBRec()->GetNuclearAttack()) {
      						g_player[p]->m_all_units->Access(i).Kill(CAUSE_REMOVE_ARMY_NUKES_ELIMINATED, m_owner);
      					}
      				}
      			}
      		}
      		g_slicEngine->Execute(so);
      	}
      
      	if(wonderutil_GetCloseEmbassies((uint64)1 << wonder)) {
      		sint32 p;
      		for(p = 0; p < k_MAX_PLAYERS; p++) {
      			if(g_player[p]) {
      				g_player[p]->CloseEmbassy(m_owner);
      				g_player[p]->SetDiplomaticState(m_owner, DIPLOMATIC_STATE_NEUTRAL);
      				SetDiplomaticState(p, DIPLOMATIC_STATE_NEUTRAL);
      			}
      		}
      	}
      
      	if(wonderutil_GetEmbassiesEverywhereEvenAtWar((uint64)1 << wonder)) {
      		sint32 p;
      		for(p = 0; p < k_MAX_PLAYERS; p++) {
      			if(g_player[p]) {
      				g_player[p]->SetDiplomaticState(m_owner, DIPLOMATIC_STATE_NEUTRAL);
      				SetDiplomaticState(p, DIPLOMATIC_STATE_NEUTRAL);
      			}
      		}
      	}
      
      	if(wonderutil_Get(wonder)->GetPreventConversion()) {
      		sint32 i;
      		for(i = 0; i < m_all_cities->Num(); i++) {
      			m_all_cities->Access(i).GetData()->GetCityData()->Unconvert(FALSE);
      		}
      	}
      
      	
      	if(wonderutil_Get(wonder)->GetGlobalRadar()) {
      		m_hasGlobalRadar = TRUE;
      		g_theWonderTracker->SetGlobeSatFlags(g_theWonderTracker->GlobeSatFlags() | (1 << m_owner));
      
      		
      		sint32 p;
      		for(p = 0; p < k_MAX_PLAYERS; p++) {
      			sint32 u;
      			if(!g_player[p] || m_owner == p)
      				continue;
      
      			
      			
      			ContactMade(p);
      
      			for(u = 0; u < g_player[p]->m_all_units->Num(); u++) {
      				if(g_player[p]->m_all_units->Access(u).GetDBRec()->GetVisionClassStandard()) {
      					g_player[p]->m_all_units->Access(u).SetVisible(m_owner);
      				}
      			}
      
      			sint32 c;
      			for(c = 0; c < g_player[p]->m_all_cities->Num(); c++) {
      				g_player[p]->m_all_cities->Access(c).SetVisible(m_owner);
      			}
      		}
      
      		
      		
      		m_vision->SetTheWholeWorldExplored();
      		m_vision->ClearUnseen();
      
      		if(m_owner == g_selected_item->GetVisiblePlayer()) {
      			
      			
      			
      			g_director->AddCopyVision();
      		}
      	}
      
      	sint32 i;
      	for(i = 0; i < m_all_cities->Num(); i++) {
      		m_all_cities->Access(i).GetData()->GetCityData()->GetBuildQueue()->RemoveIllegalItems();
      	}
      
      	
      	
      	sint32 pl, c;
      	for(pl = 0; pl < k_MAX_PLAYERS; pl++) {
      		if(pl == m_owner || 
      		   !g_player[pl]) {
      			continue;
      		}
      		int numCities=g_player[pl]->m_all_cities->Num() ;
      		for(c = 0; c m_all_cities->Access(c).GetData()->GetCityData()->GetBuildQueue()->
      				RemoveIllegalItems(TRUE);
      		}
      	}
      
      	const WonderRecord *wrec = g_theWonderDB->Get(wonder);
      	sint32 buildingIndex;
      	if(wrec->GetBuildingEverywhereIndex(buildingIndex)) {
      		m_wonderBuildings |= ((uint64)1 << buildingIndex);
      	}
      		
      }

      I don't see it there...should we add it there or back into cityevent?
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • Originally posted by E
        Great! I'll wait until you get it going. I think I need to add one with shields too. I have that in readiness and it maybe causing BureauBerts latest Governor/readiness crash
        What do you mean by this, and what does it has to do with your Governor related crash?

        Originally posted by E
        I don't see it there...should we add it there or back into cityevent?
        Well maybe I look closer at the call again. I just outcommented it.

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

        Comment


        • Originally posted by Martin Gühmann


          What do you mean by this, and what does it has to do with your Governor related crash?
          I also have a 'If Player is Robot' in readiness where if the AI has more units than shields can support it does not disband the extra units like it does for the human player. It allows the AI a lot of extra units. So, like the Gold cheat I added I'm sure you'd prefer that to be an option in the difficulty db instead of just being there.

          it may relate to the crash because m_cost is featured in the shield cost calculation and may affect how the governor is calculating that cost.


          re: AddWonder
          Well maybe I look closer at the call again. I just outcommented it.
          ok
          Formerly known as "E" on Apolyton

          See me at Civfanatics.com

          Comment


          • Martin (and others),
            I had two problems when compiling and they stem from accessing player.h from ArmyData

            it was this code (outcommented) in ArmyData::BeginTurn()

            g_player[m_owner]->m_materialPool->AddMaterials(shields);

            AND

            in Armydata:isband

            g_player[m_owner]->CreateSpecialImprovement(rec->GetSettleImprovementIndex(imp), m_pos, 0)

            in the first it was saying the declaration of MaterialPool was wrong and the second it was that Terrain Improvement was wrong. Even odder if i don't out comment the material pool part the terrainimp one doesn't shown as an error, but it pops up if materialpool is outcommented. not sure why it does that, they aren't linked.

            I was thinking it has something to do with public and private declarations in player.h but didn't see anything like that. Is there something I'm missing?

            thanks



            g_player[m_owner]->m_materialPool->AddMaterials(
            Formerly known as "E" on Apolyton

            See me at Civfanatics.com

            Comment


            • Originally posted by E
              I was thinking it has something to do with public and private declarations in player.h but didn't see anything like that.
              No E, all the stuff you use is declared public. Maybe it would be more helpful if you post the error messages here.

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

              Comment


              • Martin,

                I was able to get this stuff working, it appears that Materials.h wasn't included

                but I still can't get around this code I'm trying in player.cpp:

                Code:
                			sint32 good;
                			if ((rec->GetCanExportGood()) && (g_theWorld->GetGood(inst.RetPos(), good))){
                				for (sint32 c=0; c < n; c++) {
                					CityData *cd = m_all_cities->Access(i).CD();
                					//CityData *cd = m_all_cities->Access(c).GetData()->GetCityData();
                					if(!cd->IsLocalResource (good)) {
                						//cd->GetCollectingResources()->AddResource(good);
                						cd->m_collectingResources.AddResource(good); //GetCollectingResources()->AddResource(good);
                						//cd->AddGoodToCity(good);
                						//break;  may have to add a break like sneakattack because only one city should receive it
                					}
                				}
                			}
                My out commented stuff was other attempts I had at trying to access this. But, now it looks like its a private problem...

                Code:
                ...trunk\ctp2_code\gs\gameobj\Player.cpp(2138) : error C2248: 'm_collectingResources' : cannot access private member declared in class 'CityData'
                 ... \trunk\ctp2_code\gs\gameobj\citydata.h(253) : see declaration of 'm_collectingResources'
                what do I have to do to access it? My code intent is to search all cities to see if they are collecting the good that this imp has. if its not it will add to that city and only that city.
                Formerly known as "E" on Apolyton

                See me at Civfanatics.com

                Comment


                • m_collectingResources is private and should be private: The best is if you encapsulate the stuff you want to do from the if including the if in a method of CityData.

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

                  Comment


                  • I tried this
                    Code:
                    void CityData::AddGoodToCity(sint32 good) const
                    {
                    	 m_collectingResources.AddResource(good);
                    }
                    but got this

                    Code:
                    trunk\ctp2_code\gs\gameobj\CityData.cpp(5299) : error C2662: 'AddResource' : cannot convert 'this' pointer from 'const class Resources' to 'class Resources &'
                            Conversion loses qualifiers
                    why cant it load this sint32 good when it does it usually?
                    Formerly known as "E" on Apolyton

                    See me at Civfanatics.com

                    Comment


                    • Originally posted by E
                      I tried this
                      Code:
                      void CityData::AddGoodToCity(sint32 good) [b]const[/b]
                      You declared the method const, so it cannot modify the object *this, but you are trying to make it do so. You may be able to simply remove the const, but OTOH that may lead to other problems. I would say it looks like it should not be const.

                      Comment


                      • Thanks J!

                        That was exactly the problem. It works now!
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • Originally posted by E
                          I thought restoring this line
                          Code:
                          Assert(foreignerId < m_diplomacy.size() );
                          to
                          Code:
                          sint32 Diplomat::GetNewProposalPriority(const PLAYER_INDEX foreignerId, const PROPOSAL_TYPE proposalType ) const
                          would fix the new CTD
                          Adding or removing Assert statements will do nothing to prevent CTDs in the final version. Those are active only in the debug version and report expected unexpected situations. In this case, the Assert is quite useless - even in the debug version. The foreigner Id is used as index in the line before the Assert, so when using a wrong index, it could have crashed before reaching the Assert.

                          Because the reported crash is attributed to the GetProposal() call, you have already passed the Assert statements. Are you running the debug version? Set a breakpoint (or run until you get the automatic breakpoint when the crash occurs) at the line
                          Code:
                          const DiplomacyProposalRecord * rec = elem->GetProposal();
                          and examine the value of elem. It could be NULL, which would definitely cause a CTD.

                          Comment


                          • BUt the code was there before, but now it doesn't work the same.

                            I tried removing that part
                            Code:
                            sint32 Diplomat::GetNewProposalPriority(const PLAYER_INDEX foreignerId, 
                            							  const PROPOSAL_TYPE proposalType ) const
                            {
                            	Assert(s_proposalTypeToElemIndex[proposalType] < m_diplomacy[foreignerId].GetNumProposalElement());
                            	
                            	const DiplomacyRecord::ProposalElement * elem =
                            		m_diplomacy[foreignerId].GetProposalElement(s_proposalTypeToElemIndex[proposalType]);
                            
                            	
                            //	const DiplomacyProposalRecord * rec = elem->GetProposal();
                            //	if (InvalidNewProposal(foreignerId, rec))
                            //		return -1;
                            
                            	sint32 priority = -1;
                            	(void) elem->GetSendPriority(priority);
                            	return priority;
                            }
                            and still got the crash.
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • That does not invalidate the hypothesis.
                              Code:
                              (void) elem->GetSendPriority(priority);
                              will cause the same kind of crash when elem is NULL.

                              Comment


                              • Code:
                                sint32 Diplomat::GetNewProposalPriority(const PLAYER_INDEX foreignerId, 
                                							  const PROPOSAL_TYPE proposalType ) const
                                {
                                	Assert(s_proposalTypeToElemIndex[proposalType] < m_diplomacy[foreignerId].GetNumProposalElement());
                                	
                                	const DiplomacyRecord::ProposalElement * elem =
                                		m_diplomacy[foreignerId].GetProposalElement(s_proposalTypeToElemIndex[proposalType]);
                                
                                	
                                	const DiplomacyProposalRecord * rec = elem->GetProposal();
                                	if (InvalidNewProposal(foreignerId, rec))
                                		return -1;
                                [b]
                                	if (rec == NULL)
                                		return -1;
                                [/b]
                                	sint32 priority = -1;
                                	(void) elem->GetSendPriority(priority);
                                	return priority;
                                }
                                I tried this for the null but still got a crash. What I dont get is why did the original code not crash before but now it does?
                                Formerly known as "E" on Apolyton

                                See me at Civfanatics.com

                                Comment

                                Working...
                                X