Announcement

Collapse
No announcement yet.

E's Source Code attempts

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

  • #91
    well I attempted these two. They are spliced from the GetSlaves in CanBuildUnit and bool addcityreferencetoplayer (it had the clearest expression of GetCityData, though I saw "CD" used also which might be the same

    Code:
    		if(rec->GetNumNeedsCityGoodAnyCity()) {
    		
    		sint32 i, g, n = m_all_cities->Num();
    		for(i = 0; i < n; i++) {
    			if((m_all_cities->Access(i).AccessData()->GetCityData()->HasResource[rec->GetNeedsCityGoodAnyCityIndex(g)] + m_all_cities->Access(i).AccessData()->GetCityData()->IsLocalResource[rec->GetNeedsCityGoodAnyCityIndex(g)]) == 0)
    				return FALSE;
    		}
    	}
    and

    Code:
    	if(rec->GetNumNeedsCityGoodAnyCity()) {
    		
    		sint32 i, g, n = m_all_cities->Num();
    		for(i = 0; i < n; i++) {
    			if((m_all_cities->Access(i).AccessData()->GetCityData()->m_buyingResources[rec->GetNeedsCityGoodAnyCityIndex(g)] + m_all_cities->Access(i).AccessData()->GetCityData()->m_collectingResources[rec->GetNeedsCityGoodAnyCityIndex(g)]) == 0)
    				return FALSE;
    		}
    	}
    the problem I ran into was how to get into the city's resources because I got this (on the first one which is actually the second I did), but the error messages were similar:
    Code:
    F:\SVN-Code\trunk\ctp2_code\gs\gameobj\Player.cpp(10147) : error C2109: subscript requires array or pointer type
    F:\SVN-Code\trunk\ctp2_code\gs\gameobj\Player.cpp(10147) : error C2109: subscript requires array or pointer type
    F:\SVN-Code\trunk\ctp2_code\gs\gameobj\Player.cpp(10147) : error C2296: '+' : illegal, left operand has type 'int (__thiscall CityData::*)(long) const'
    F:\SVN-Code\trunk\ctp2_code\gs\gameobj\Player.cpp(10147) : error C2297: '+' : illegal, right operand has type 'int (__thiscall CityData::*)(long) const'
    i think I got pretty close but how do i access the m_buyingresources etc in the citydata?
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • #92
      There are two problems with your code:

      First you don't cycle through all the entries in the NeedsCityGoodAnyCity array. There is only a loop that cycles through all your cities. And g is not initialized. If you are lucky it is something in the range of the NeedsCityGoodAnyCity array, if not GetNeedsCityGoodAnyCityIndex returns 0.

      Then I told you that the Resource objects are private members of CityData, so you can't access them from outside and I also told you to create a new method that encapsules the functionality you need.

      So you need to modify citydata.h and CityData.cpp first.

      The thing I wonder about is why the compiler does not complain about the fact that m_collectingResources and m_buyingResources are private.

      By the way all members of a class are private by default and all members of a struct are public by default. Other than that there is no difference between struct and class in C++.

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

      Comment


      • #93
        Originally posted by Martin Gühmann
        There are two problems with your code:

        First you don't cycle through all the entries in the
        NeedsCityGoodAnyCity array. There is only a loop that
        cycles through all your cities. And g is not initialized. If
        you are lucky it is something in the range of the
        NeedsCityGoodAnyCity array, if not
        GetNeedsCityGoodAnyCityIndex returns 0.
        Then I told you that the Resource objects are private
        members of CityData, so you can't access them from
        outside and I also told you to create a new method that
        encapsules the functionality you need.

        So you need to modify citydata.h and CityData.cpp first.

        ok, could you recommend an example because
        HasREsource and IsLocalResource didnt work.



        The thing I wonder about is why the compiler does not
        complain about the fact that m_collectingResources and
        m_buyingResources are private.

        By the way all members of a class are private by default
        and all members of a struct are public by default. Other
        than that there is no difference between struct and
        class in C++.

        -Martin
        should i just change them to a struct then? my next
        question would be how or better is there an example
        somewhere in the code, and how do I know what the
        differnce looks like, is it more than just struct and class
        in the text?
        Formerly known as "E" on Apolyton

        See me at Civfanatics.com

        Comment


        • #94
          Originally posted by E
          ok, could you recommend an example because
          HasREsource and IsLocalResource didnt work.
          The source code is full of examples of methods. In fact HasResource and IsLocalResource are examples as well. If you don't mix them up with arrays and objects that have a bracket operator, it would at least compile, but probably it the code does something else than you want.

          Actual to generate an extra method is to copy the code of the HasResource method in source and header file, yeah the *.cpp and *.h file respectively, and rename the copy to something like HasNeededGood and replace the returned condition there by the condition you wanted to use in your last code.

          Originally posted by E
          should i just change them to a struct then?
          No the two Resource objects are private and that's good like that.

          Originally posted by E
          my next
          question would be how or better is there an example
          somewhere in the code, and how do I know what the
          differnce looks like, is it more than just struct and class
          in the text?
          Simple read the header file. There you will find the keyword class declaring a class, every member from the start of the class definition is private until you reach the keyword public from there everything is public until you get the private keyword. And with a struct it is the otherway around.

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

          Comment


          • #95
            Ok I gave it a shot and had stuff compiling but not working.

            In citydata.cpp and h I added
            Code:
            BOOL CityData::HasNeededGood(sint32 resource) const
            {
            	return m_buyingResources[resource] + m_collectingResources[resource] == 0;
            }
            which seems to be working fine

            but...
            Code:
            	if(rec->GetNumNeedsCityGoodAnyCity()) {
            		
            		sint32 i, g, n = m_all_cities->Num();
            		for(i = 0; i < n; i++) {
            			for(g = 0; g < rec->GetNumNeedsCityGoodAnyCity(); g++) {
            				if(m_all_cities->Access(i).AccessData()->GetCityData()->HasNeededGood(rec->GetNeedsCityGoodAnyCityIndex(g)))
            			return FALSE;
            			}
            		}
            	}
            I put in player.cpp. it compiles then in the cheat mode i add tobacco which is needed to make the abolitionist (I gave it the same tech as warrior so its immediately available, its my test units.txt) and its not available. but also no tobacco in the trade window. then i place a new city near a different resource, and for that new city the build manager, appearing once built, says the abolitionist is available. tobacco and the other good is now available in the trade window, but when i check other build ques, the abolitionist is no longer available. is it my code?
            Formerly known as "E" on Apolyton

            See me at Civfanatics.com

            Comment


            • #96
              Originally posted by E
              Ok I gave it a shot and had stuff compiling but not working.

              Originally posted by E
              In citydata.cpp and h I added
              Code:
              BOOL CityData::HasNeededGood(sint32 resource) const
              {
              	return m_buyingResources[resource] + m_collectingResources[resource] == 0;
              }
              which seems to be working fine
              I hope you just added that code above to CityData.cpp and only the declaration to citydata.h. However this should work, even if I prefer in a c++ file bool as return type instead of BOOL.



              but...
              Code:
              	if(rec->GetNumNeedsCityGoodAnyCity()) {
              		
              		sint32 i, g, n = m_all_cities->Num();
              		for(i = 0; i < n; i++) {
              			for(g = 0; g < rec->GetNumNeedsCityGoodAnyCity(); g++) {
              				if(m_all_cities->Access(i).AccessData()->GetCityData()->HasNeededGood(rec->GetNeedsCityGoodAnyCityIndex(g)))
              			return FALSE;
              			}
              		}
              	}
              I put in player.cpp. it compiles then in the cheat mode i add tobacco which is needed to make the abolitionist (I gave it the same tech as warrior so its immediately available, its my test units.txt) and its not available. but also no tobacco in the trade window. then i place a new city near a different resource, and for that new city the build manager, appearing once built, says the abolitionist is available. tobacco and the other good is now available in the trade window, but when i check other build ques, the abolitionist is no longer available. is it my code?
              The city has to recollect the resources, so that the good appears in the trade manager, and it doesn't recollect them if you just use the cheat manager. Maybe the optimize slider button could help or playing around with the specialist disrtibution or pressing end turn.

              The other problem seems to be a little bit trickier. Unfortunately I don't have enough time this week, therefore the best would be to go to Case2 at first. However I can't promise that it might work.

              One think you have to do is probably to switch the loops. But that is now a trial and error thing for your.

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

              Comment


              • #97
                thanks martin,

                actually if you mean the loops as the for statements, i did have them reversed before and maybe reversing is what undid it. i'll give case2 a try too. but i guess that means my code is generally correct.

                i know your busy, but i appreciate your help. when you are available again, i have a question about adding this same attribute to advances. I guess i have to create something for m_all_cities to make it accessible in the advances.cpp so that I can make advances that requires goods (whih would be cooler than civ3).

                I'll give the happyinc with goods attempt anothertry on my own if i get this working.

                And I think my final good addition would be to create that tile imp we talked about earlier that plants goods, to allow players to plant cotton or raise horses once they have the advance and the initial resource.
                Formerly known as "E" on Apolyton

                See me at Civfanatics.com

                Comment


                • #98
                  Originally posted by E
                  but i guess that means my code is generally correct.
                  I thought this as well on a first look, but after a closer look there is something wrong with the logic, that's everything I can tell you, today. One thing you could do is to go through the code by hand or better test it by hand: Assume you have two or three cities one of them has the requiredgood and you have in your list one good. Write the stuff that the program does according to the code on paper and maybe you see what goes wrong.

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

                  Comment


                  • #99
                    Ok I did this code:
                    Code:
                    	if(rec->GetNumNeedsCityGoodAnyCity()) {
                    		
                    		sint32 i, g, n = m_all_cities->Num();
                    		for(g = 0; g < rec->GetNumNeedsCityGoodAnyCity(); g++) {
                    			for(i = 0; i < n; i++) {
                    				if(m_all_cities->Access(i).AccessData()->GetCityData()->HasNeededGood(rec->GetNeedsCityGoodAnyCityIndex(g)))
                    			return FALSE;
                    			}
                    		}
                    	}
                    but the cheat is screwy. when I add a resource to the capitol then its available, but to the second city its not. I think my code because of the "i" sint32 it only checks the first city which is the capitol. I'm going to try fixing it but I guess I can make this code as a NeedsCityGoodCapitol
                    Formerly known as "E" on Apolyton

                    See me at Civfanatics.com

                    Comment


                    • Martin,

                      i know lately you've been busy but I have gotten this C++ from CyberDreyk for his civ3 FLC editor program. By your estimate is there enough here to make it worth it to have Civ3 FLCs usable in Ctp2? Ideally it would be nice to just Id the folder and ini file of a civ3 unit in the units.txt (if no sprite present etc) and then use this code to allow it to display. I think we'd have tomatch up pallettes to player colors also. but hopefully there is somthing here.


                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • Martin,

                        not sure how much time you have but I took a break on the other code and tried to do something simple. Adding a feature that shows the Army's Name similar to how debugai works. I did most of the changes but get this error. I tried getting rid of the const and changing it to a MBCHAR. Not sure what to do next.

                        Code:
                        TiledMap.cpp
                        F:\SVN-Code\trunk\ctp2_code\gfx\tilesys\TiledMap.cpp(2887) : error C2440: 'initializing' : cannot convert from 'const char *' to 'char *'
                                Conversion loses qualifiers
                        gfx_options.cpp
                        F:\SVN-Code\trunk\ctp2_code\gfx\gfx_utils\gfx_options.cpp(102) : error C2440: 'initializing' : cannot convert from 'const char *' to 'char *'
                                Conversion loses qualifiers
                        Code:
                        bool GraphicsOptions::AddNameToArmy(const Army &army, const MBCHAR *name, const uint8 &colorMagnitude) 
                        {
                        	
                        	if (!g_theArmyPool->IsValid(army)) 
                        		return FALSE;
                        
                        	ResetArmyName(army);
                        
                        	if (name == NULL)
                        		return FALSE;
                        
                        	MBCHAR *myString = new MBCHAR [strlen(name) + 1];
                        	memset(myString, 0, strlen(name) + 1);
                        	strcpy(myString, name);
                        
                        	army.AccessData()->SetName(myString);
                        	army.AccessData()->SetDebugStringColor(colorMagnitude);
                        
                        	return TRUE;
                        }
                        Attached Files
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • OK E here is an attemp in pseudocode for the good any thing in Case2, so not quite what you tried but for the start this is easier and maybe you igure out how Case3 works:

                          Code:
                          good available := false
                          
                          for all cities do
                              for all goods do
                                  if city has good do
                                      good available := true
                                  end if
                              end for
                          end for
                          
                          if good is not vaialble do
                              return false
                          end if
                          Now it is up to you to translate this into C++ code.

                          And for the other thing you should post some more details.

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

                          Comment


                          • Thanks Martin, I'm still messing with it but got side tracked with the previous post and another bit of code, I thought I could handle on my own but ran into a glitch.

                            First, the ArmyName code is that I copied the ArmyTExt command that lets people that tpe in the chat box /debugai that shows the strategy on the screen (remember we made a playtest accidentally that displayed it but later Peter Triggs add the option). I wanted to do something showing the name of the army, but I think the problem is that the strategies uses a regular char that finds a few predefined text strategies, where as the army name is a string and I'm not sure how to get that to display.


                            Second. The talk of Civ4 has invigorated me to try to get something of the stuff I like implemented soon before the "release" of the AE patch. So I tried to implement the hidden nationality. A unit flag that if a unit attacks or is attacked than it won't register with the other player (it will alow for new special units like guerrillas etc). I found this in player.cpp

                            Code:
                            void Player::ThisMeansWAR(PLAYER_INDEX defense_owner)
                            {
                            	Assert(0 <= defense_owner); 
                                Assert(defense_owner < k_MAX_PLAYERS);
                                Assert(m_owner != defense_owner); 
                                Assert(g_player[m_owner]); 
                                Assert(g_player[defense_owner]); 
                            
                                PLAYER_INDEX attack_owner = m_owner;
                            
                            //  Assert(unit.GetOwner() == m_owner);
                            //  
                            //	sint32 type;
                            //	const UnitRecord *rec = g_theUnitDB->Get(type);
                            //	if (rec->GetHiddenNationality() == 0) {
                            
                            	if ((attack_owner != 0) && (defense_owner != 0) && 
                            		!AgreementMatrix::s_agreements.HasAgreement(attack_owner, defense_owner, PROPOSAL_TREATY_DECLARE_WAR)) { 
                            //
                            //	if (unit.GetDBRec()->GetHiddenNationality() == 0)	{
                            //add hidden nationality flag here g_theUnitDB->Get(t)->GetHiddenNAtionality;
                            		
                            		SlicObject *so = new SlicObject("128CivStartedWar");
                                    so->AddCivilisation(attack_owner);
                                    so->AddCivilisation(defense_owner);
                                    so->AddAllRecipientsBut(attack_owner);
                                    g_slicEngine->Execute(so);
                                }        
                            
                            //	}
                            	sint32 oldBrokenAlliances = m_broken_alliances_and_cease_fires;
                            	
                            	Diplomat::GetDiplomat(m_owner).DeclareWar(defense_owner);
                            
                                g_player[m_owner]->RegisterAttack(defense_owner);
                                g_player[defense_owner]->RegisterAttack(m_owner);
                            
                            }
                            as you can see with the out-commented stuff I tried different approaches but cant seem to find how to acces a specific unit first before registering the attack, this function appears to affect any unit with predefined "attacks." Thismeanswar doesnt get called anywhere else so i figured this was the best place to do the check. but when i tried to call one of the units the type needed to be defined (from my cut and paste) and i cant think if a way around it so far.

                            thanks.
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • Originally posted by E
                              as you can see with the out-commented stuff I tried different approaches but cant seem to find how to acces a specific unit first before registering the attack, this function appears to affect any unit with predefined "attacks." Thismeanswar doesnt get called anywhere else so i figured this was the best place to do the check. but when i tried to call one of the units the type needed to be defined (from my cut and paste) and i cant think if a way around it so far.
                              Well, maybe you should look at the code that call the ThisMeansWAR method, maybe there you find the offending army. And of course I would say that all units in the army need the hidden nationality flag so that the ThisMeansWAR method isn't called.

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

                              Comment


                              • Martin for the Good code I got this error:
                                Code:
                                F:\SVN-Code\trunk\ctp2_code\gs\gameobj\Player.cpp(10133) : error C2664: 'HasEitherGood' : cannot convert parameter 1 from 'const class ResourceRecord *' to 'long'
                                        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
                                Error executing cl.exe.
                                when I did this:

                                Code:
                                	if(rec->GetNumNeedsCityGoodAnyCity()) {
                                		
                                		sint32 i, g;
                                		bool goodavail = false;
                                
                                			for(i = 0; i < m_all_cities->Num(); i++) {
                                				for(g = 0; g < g_theResourceDB->NumRecords(); g++) {
                                					if(m_all_cities->Access(i).AccessData()->GetCityData()->HasEitherGood(rec->GetNeedsCityGoodAnyCity(g))) {
                                						goodavail = true;
                                						break;
                                					}
                                				}
                                			}
                                			if(!goodavail)
                                			return FALSE;
                                	}
                                Did I miss something? I made either good with this in citydata.cpp
                                Code:
                                BOOL CityData::HasEitherGood(sint32 resource) const
                                {
                                	return m_buyingResources[resource] + m_collectingResources[resource] > 0;
                                }

                                AS FOR MEANSWAR stuff. I didn't see it called anywhere, except in Armydata but there is an out comment above it that says //not used

                                I think the player.cpp code is a way to track all actions. I go through and check the units later.

                                thanks.
                                Formerly known as "E" on Apolyton

                                See me at Civfanatics.com

                                Comment

                                Working...
                                X