Announcement

Collapse
No announcement yet.

E's Source Code attempts

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

  • E's Source Code attempts

    Since Martin Helps me out a lot and there are a few things I'd like to do. AND instead of adding a bunch of threads for others to go through (since my struggle may help guide others) I'll just start one thread so Martin doesn't have to hop around. It could also serve as an addition to Martin's C++ Lecture.


    As a heads up, this is a loose list I have of things I may attempt at coding (hoping I don't give Martin a heart attack!). The * means they are done (mostly) and I have notes following them.
    They are in a loose priority list.

    Code completed
    *Increase Bombardment----see Peter Triggs rev 339
    *Terrain-specific Cities ------ CanSettleOn
    *Barbarian list? BarbarianOnly and SeaPirates- see tombom
    NoBarbarian
    *immobile ---- See Peter Triggs Rev 339
    *Good-Specific Imps ------- IsRestrictedToGood
    *CultureOnly --- Imps, buildings, wonders, units,
    *CityStyleOnly----same
    *GovtOnly----- added
    *Building Prerequiste for Units and Wonders
    *NeedsCityGood-in radius or if buying; Either good (iron or bronze etc) rev 465?
    *NeedsCityGoodAll (needs all goods listed)
    *Warning Box for declaring War &&
    *Good attrbutes (using building flags for goods to increase food, science or crime)
    *GoodFlags ----- CantTrade
    *BuildGood tile imp----(PlantGood Slic))
    *PillageGood tile imp----(RemoveGood
    *NeedsCivGood
    *NeedsCivGoodAll (any city must be collecting good)

    *Hidden Nationality (probably used in same in code area)

    *Settlers Can Join Cities -Rev540
    * CantPillage - rev540

    Civ specific traits - using wonders and buildings flags for goods to increase food, science or crime)

    GoldHunger --UnitUpkeep--see building upkeep and Readiness
    Building maintenance times population
    PopulationCost for Units
    UpgradeUnit ---EventAdvance? Flag?
    blitz -----Clearbattleflag slic.cpp
    CaptureTileImp when Pillaged (for forts and airbases?)
    DeniedToEnemy - Improvement Flag that removes bonus for RR if owner != Unit owner in mvmt?

    ExcludesUnit etc ---Switch PreRequisiteBuilding to exclude certain units and buildings to add Guns vs Butter choices.

    VanishAdv & ExcludesAdvance & GovtOnly Advance

    Kill City ----Event City Capture (Plunder, raze, give to, occupy), && creates Ruins with City Raze

    CaptureTile --- Use Pillage code?

    New Govt flags - Xenophobia (reduces pop), Feudal (cities
    more independent?), Centralized, federal, Rebellions
    (creates rebels), secessionist (chance of revolts)
    Other?

    Units SettleImprovement

    Code In Works

    ShowOnMap ---- CityData: BuildWonderEvent
    -------------------Player::RemoveWonder
    -------------------Can't Pillage & Remove Wonder & AI Pillage


    can't group ----- --- cantgroup slic in wokers?

    HasRoadConnection
    -----------function that uses the pathing and sees if the movepoint value is equal to road value thereby says its all roads?


    Religion Advance - only have unless switch (SLIC?)

    CraterTerrain ---- autopillage and create "dead tile" craters

    IsIrrigation ----- riverto build or adjacent to IsIrrigation
    More Improvements - science, happy, regard,
    minefields/damage, StopMove, Impassable,
    BuildGood, NeedsWater for imps, built on river OR
    adjacent is farm

    rebase air units----- Use Paradrop?

    Advances - NotTradeable, CantCaptureAdv, EnableGuerrillas

    Mercenary/Lease - (Good/Fast/Cheap Idea)
    Conscript/Cheap?

    NeedGoodPoint?
    Fuelpoints? -- make like PW? use readiness, maintenance etc
    Last edited by Ekmek; July 6, 2006, 15:41.
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

  • #2
    Done.

    Code:
    	if(irec->GetNumPrerequisiteBuilding() > 0) {
    		for(o = 0; o < irec->GetNumPrerequisiteBuilding(); o++) {
    			sint32 b = irec->GetPrerequisiteBuildingIndex(o);
    			if(!(GetEffectiveBuildings() & ((uint64)1 << (uint64)b)))
    				return FALSE;
    		}
    	}
    Last edited by Ekmek; May 6, 2005, 23:45.
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • #3
      Ok trying this NeedsCityGood
      HasResource is a function I found in citydata and unit.cpp and unitdata.cpp (the unit files reference m_city_data)
      I figure if I put the above code into the CanBuildUnit(building and wonder)
      it should compare the two to see if a unit can build. This is assuming that HasResource means what it says, and it looks like that is the same function to find if a city has a resource to trade.

      Code:
      if(irec->GetNumNeedsCityGood() > 0) {
      		sint32 s;
      		sint32 resource;
      		bool found = false;
      		for(s = 0; s < irec->GetNumNeedsCityGood(); s++) {
      			if(irec->GetNeedsCityGoodIndex(s) == HasResource(resource) {
      				found = true;
      				break;
      			}
      		}
      		if(!found)
      			return FALSE;
      	}
      When I tried to compile I got this:


      Code:
      F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4815) : error C2039: 'GetNumNeedsCityGood' : is not a member of 'UnitRecord'
              ..\gs\newdb\UnitRecord.h(351) : see declaration of 'UnitRecord'
      F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4819) : error C2039: 'GetNumNeedsCityGood' : is not a member of 'UnitRecord'
              ..\gs\newdb\UnitRecord.h(351) : see declaration of 'UnitRecord'
      F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4820) : error C2660: 'GetNeedsCityGoodIndex' : function does not take 1 parameters
      (edit: I fixed some of my own C2227 errors)

      I thought the error is because I didn't do anything in the cdb but I checked and I did put it in there before. Is there somewhere I can see the definition for a C2660 and C2039 error is?

      I checked the UnitRecord.h and its automatically generated so I'm not to change it.
      Finally, any tips on the does not take 1 parameters?




      (I know I also have to finish the other settler code too)
      Last edited by Ekmek; July 4, 2005, 21:04.
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • #4
        Originally posted by E
        I checked the UnitRecord.h and its automatically generated so I'm not to change it.
        If you've put it in the cdb file but it's not appeared in UnitRecord.h, then the IDE may have failed to regenerate UnitRecord.h. Try cleaning and then rebuilding.

        Finally, any tips on the does not take 1 parameters?


        Well, what's the definition of the 'GetNeedsCityGoodIndex' function that you're calling?

        Comment


        • #5
          Originally posted by J Bytheway
          If you've put it in the cdb file but it's not appeared in UnitRecord.h, then the IDE may have failed to regenerate UnitRecord.h. Try cleaning and then rebuilding.
          That's a little bit to much for just recompiling the unit.cdb, the best is to open it and while the window of the file is active to use the option of compiling the file in the active window. Ctrl + F7 should do the job.

          Originally posted by J Bytheway
          Well, what's the definition of the 'GetNeedsCityGoodIndex' function that you're calling?
          I guess it returns the database index of that good at i[i]th[/b] position in the NeedsCityGood array. Well and that's definatly something different than a BOOL that is returned by HasResource.

          So E what does represent the parameter of HasResource?

          Well that's the answer of a question you have to find on your own E. And it shouldn't be so difficuilt, since you already encountered a function that returns the needed input.

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

          Comment


          • #6
            Thanks J and Martin. I'll try the recompile for the cdb and unitrecord stuff. THe HasResource uses M_collectingResources so I'm guessing that I'll have to put that there. I'll give it a shot and hunt around the code a bit more.
            Formerly known as "E" on Apolyton

            See me at Civfanatics.com

            Comment


            • #7
              Originally posted by E
              THe HasResource uses M_collectingResources so I'm guessing that I'll have to put that there. I'll give it a shot and hunt around the code a bit more.
              At first it is called m_collectingResources, C++ is a case sensitive language. Second what do you want to do with this here? And third so far you didn't answer my question: What is the parameter of HasResource? What do you have to pass to HasRessource? First answer this question and you will get on with your problem.

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

              Comment


              • #8
                Based on the following code, the parameter is resource. Which based on the code looks like it stores the resource located near a city. So my code is an attempt to match the Units NeedsCityGood resource/good with that of the good/resource that a city is collectingin its radius.

                Code:
                //this city is collecting more sint32 resource than than it is selling
                BOOL CityData::HasResource(sint32 resource) const
                {
                	return m_collectingResources[resource] > m_sellingResources[resource];
                }
                I'll get back to that I think I'm on to something... As for the UnitRecord stuff I found this in UnitRecord.h
                Code:
                    sint32           GetNumCityStyleOnly() const { return m_numCityStyleOnly;}
                    sint32           GetSettleImprovementIndex() const { return m_SettleImprovement; }
                    const TerrainImprovementRecord *GetSettleImprovement() const;
                    sint32           GetNeedsCityGoodIndex() const { return m_NeedsCityGood; }
                    const ResourceRecord *GetNeedsCityGood() const;
                For some reason it was passing the NeedsCityGood without a Number which I think will make it hard to compare to the HasResource but I'll stil check. In the meantime I'll take the Num out.

                Edit: I changed the code to this (probably wrong but I'm learning still):
                Code:
                	if(rec->GetNeedsCityGood() > 0) {
                		sint32 r;
                		bool found = false;
                		for(r = 0; r < rec->GetNeedsCityGood(); r++) {
                			if(rec->GetNeedsCityGoodIndex() == m_collectingResources) {
                				found = true;
                				break;
                			}
                		}
                		if(!found)
                			return FALSE;
                	}
                so I solved the unitrecord.h problem and the parameters, but I see that the Num removed removes the comparison, I guess I have to change something in Unit.CDB so it knows that RecordResource is a numeric value? I'm going to compare other resource record stuff now. In the mean time the bottom two are new to me...

                Code:
                F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4818) : error C2446: '<' : no conversion from 'const class ResourceRecord *' to 'long'
                        This conversion requires a reinterpret_cast, a C-style cast or function-style cast
                F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4818) : error C2040: '<' : 'long' differs in levels of indirection from 'const class ResourceRecord *'
                F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4819) : error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'long' (or there is no acceptable conversion)
                Last edited by Ekmek; July 5, 2005, 18:25.
                Formerly known as "E" on Apolyton

                See me at Civfanatics.com

                Comment


                • #9
                  Originally posted by E
                  Based on the following code, the parameter is resource. Which based on the code looks like it stores the resource located near a city.

                  Code:
                  //this city is collecting more sint32 resource than than it is selling
                  BOOL CityData::HasResource(sint32 resource) const
                  {
                  	return m_collectingResources[resource] > m_sellingResources[resource];
                  }
                  Not quite, take a look again: What does represent the parameter resource? That's crucial to find out how the code must.

                  Originally posted by E
                  For some reason it was passing the NeedsCityGood without a Number which I think will make it hard to compare to the HasResource but I'll stil check. In the meantime I'll take the Num out.
                  What is the your design idea? Do you want to allow the modders only one good that is needed for an item, or do you want allow multiple item. I guess you made it so that the *.cdb file only allows one good as prerequisite.

                  And by the way it is hard to compare to the HasGood method anyway, if not to say impossible if you exspect to get something meaningfull.

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

                  Comment


                  • #10
                    Just to catch your edit E. The HasResource belongs into the if statement, but so far you haven't understood it.

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

                    Comment


                    • #11
                      Originally posted by Martin Gühmann


                      Not quite, take a look again: What does represent the parameter resource? That's crucial to find out how the code must.
                      hmmm...it looked straight forward to me, I'll have to dig into my book perhaps terminology is getting to me. Unless I'm miss understanding goods as resources? or are you saying that m_collectingResources doesn't store a good like I thought it does?


                      What is the your design idea? Do you want to allow the modders only one good that is needed for an item, or do you want allow multiple item. I guess you made it so that the *.cdb file only allows one good as prerequisite.
                      Yeah I just caught that...so I made it multiple...that was the Num problem I think.

                      And by the way it is hard to compare to the HasGood method anyway, if not to say impossible if you exspect to get something meaningfull.
                      -Martin
                      I gues I may have to create new functions then? But I thought the the game used this stuff so you knew what cities could trade stuff so thats stored somehow and then I though just matching similar to the way the receive or have a good to a value it ought to work. Where is my thinking messed up?

                      and I'm down tothis:
                      Code:
                      F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4819) : error C2660: 'GetNeedsCityGoodIndex' : function does not take 0 parameters
                      F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4819) : error C2065: 'resource' : undeclared identifier
                      after I put has resource back and updated the unit.cdb with "[]"
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • #12
                        Okay, my last guess whould to base it on HasAdvance and develop a code like:

                        Code:
                        	if(rec->GetNumNeedsCityGood() > 0) {
                        		sint32 r;
                        		bool found = false;
                        		for(r = 0; r < rec->GetNumNeedsCityGood(); r++) {
                        			if(HasResource(rec->GetNeedsCityGoodIndex() >= 0)  {
                        				found = true;
                        				break;
                        			{
                        		return FALSE;
                        	}
                        Thats my last hunch, but I do guess what is throwing me off is that HasResource is a BOOL witha ">" instead of just a regular return.
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • #13
                          Originally posted by E
                          Thats my last hunch, but I do guess what is throwing me off is that HasResource is a BOOL witha ">" instead of just a regular return.
                          It just checks wheather the city is collecting more units of a certain kind of good than it is selling. Maybe you need to reconsider what you wan't to check.

                          But currently I am more confused why you pass a bool or a BOOL to the HasResource function, even if it expects a sint32.

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

                          Comment


                          • #14
                            Originally posted by Martin Gühmann


                            It just checks wheather the city is collecting more units of a certain kind of good than it is selling. Maybe you need to reconsider what you wan't to check.
                            I started redigging into citydata.cpp. I'm looking for some array that stores whether a city has a good or not and I found this:
                            Code:
                            	
                            	
                            	sint32 good;
                            	if(g_theWorld->GetGood(center_point, good)) {
                            		m_collectingResources.AddResource(good);
                            so it adds it to m_collectingResource, but how do I get back to it. I think I need to create a function that GetsCityGood by looking into m_collectingResource. Am I right? I'm unclear on the use of "." any good examples (that I could recognize) on getting to the good stored with a city?


                            But currently I am more confused why you pass a bool or a BOOL to the HasResource function, even if it expects a sint32.

                            -Martin

                            I though since this is how we checked a citystyle a city may have it would be the same way to check a Unit NeedsCityGood versus the good a city has (if it does have one).

                            I've dug into the trade stuff to and I cant sem to find how they link a route to a city and to a specific good, is there a specific function that does this, its not readily apparent. my best guess is:
                            Code:
                            void TradeRouteData::GetSourceResource(ROUTE_TYPE &type, sint32 &resource) const
                            {
                            	type = m_sourceRouteType;
                            	resource = m_sourceResource;
                            }
                            but I don't think i can access m_sourceResource in citydata.cpp

                            so my next bet is:
                            Code:
                            CityData::GetResourceTradeRoute(sint32 resource, TradeRoute & route) const
                            {
                            	sint32 i;
                            	for(i = 0; i < m_tradeSourceList.Num(); i++) {
                            		ROUTE_TYPE type;
                            		sint32 rr;
                            		m_tradeSourceList[i].GetSourceResource(type, rr);
                            		if(type != ROUTE_TYPE_RESOURCE) continue;
                            		if(rr != resource) continue;
                            
                            		
                            		route = m_tradeSourceList[i];
                            		return true;
                            	}
                            
                            	
                            	return false;
                            }
                            
                            
                            bool CityData::IsSellingResourceTo(sint32 resource, Unit & destination) const
                            {
                            	sint32 i;
                            	for(i = 0; i < m_tradeSourceList.Num(); i++) {
                            		ROUTE_TYPE type;
                            		sint32 rr;
                            		m_tradeSourceList[i].GetSourceResource(type, rr);
                            		if(type != ROUTE_TYPE_RESOURCE) continue;
                            		if(rr != resource) continue;
                            
                            		
                            		destination.m_id = m_tradeSourceList[i].GetDestination().m_id;
                            		return true;
                            	}
                            
                            	
                            	destination.m_id = 0;
                            	return false;
                            }

                            So is m_tradeSourceList.Num() what I should be looking for? or maybe m_tradeSourceList[i].GetSourceResource(type, res)?
                            Last edited by Ekmek; July 7, 2005, 15:47.
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • #15
                              Originally posted by E
                              I though since this is how we checked a citystyle a city may have it would be the same way to check a Unit NeedsCityGood versus the good a city has (if it does have one).
                              I don't think we checked the city style this. At first the ckity style check was free of syntax errors. Your compiler should tell you that there are at least a closing parenthesis and a closing brace missing.

                              And regardless how you parenthesise this line it's still wrong:

                              if(HasResource(rec->GetNeedsCityGoodIndex()) >= 0) {

                              if(HasResource(rec->GetNeedsCityGoodIndex() >= 0)) {

                              In the first place HasResource returns a BOOL. As it is just a typedef of a long the only values the methods return are 0 or 1. After the application of >= 0 you get in every case TRUE or in other words 1.

                              In the second case the result is wrong as well. Since all the indeces of goods in the database are >= 0 you get always a TRUE or 1 for the function as argument. That means the hasResource method doesn't check whether the city has the good in question given by your list, but always the good with the database index 1.

                              Now think again how should the code look if you use the condition by the HasResource function. And write down the result here in this thread.

                              Now take again a look on the HasResource function, espeacilly on the two objetct that are part of the unequality in the return statement. You want to know the information that they store. And take again a look on the CityData class, it should have methods to access these objects.

                              And if you are looking for arrays then you should take a close look on the Resource class, then you will see that it wraps an array and adds some basic functionality.

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

                              Comment

                              Working...
                              X