Announcement

Collapse
No announcement yet.

E's Source Code attempts

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

  • I left out 'index'

    well I tried it and it works!, and well in the editor mode too...but the question of course, is it optimized?

    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->GetNeedsCityGoodAnyCityIndex(g))) 
    						goodavail = true;
    						break;
    					
    				}
    			}
    			if(!goodavail)
    			return FALSE;
    	}

    the other stuff I want to do is :
    HiddenNationality
    Inreasehappiness etc with goods, I think I have something now...

    and then the plant good tile improvements

    I guess later we can look at pillaging goods, capturing good tiles, and maybe a way of giving a city a good if it built a certain building???
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • Originally posted by E
      but the question of course, is it optimized?
      No, and actually it doesn't quite do what you want so here is a precision and an optimization:

      Code:
      good available := false
      
      for all cities do
          for all goods [b]in the needed list[/b] do
              if city has good do
                  good available := true
                  break (leave) loop
              end if
          end for
          [b]if good is available do
               break (leave) loop
          end if[/b]
      end for
      
      if good is not vaialble do
          return false
      end if
      In the original code I didn't add the break loop thing, because this is an implementation detail, and actually not needed for the algorithm.

      For the precisioning the "needed list" is of course NeedsCityGoodAnyCity. So your code just checks whether there is a city that has a good and then you can build the unit, but you are rather behind a good that you find in the NeedsCityGoodAnyCity list.

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

      Comment


      • ok here it is martin:

        Code:
        	if(rec->GetNumNeedsCityGoodAnyCity()) {
        		
        		sint32 i, g;
        		bool goodavail = false;
        
        			for(i = 0; i < m_all_cities->Num(); i++) {
        				for(g = 0; g < rec->GetNumNeedsCityGoodAnyCity(); g++) {
        					if(m_all_cities->Access(i).AccessData()->GetCityData()->HasEitherGood(rec->GetNeedsCityGoodAnyCityIndex(g))){ 
        						goodavail = true;
        						break;
        					}
        				}
        				if(goodavail){
        				break;
        				}
        			}
        			if(!goodavail)
        			return FALSE;
        	}
        Now not to waste time I ran accross this back in my old friend citydata.cpp

        Code:
        void CityData::CollectResources() 
        {
        ...code...code...
        
        // Add if city has building GetEnablesGood>0
        
        	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);
        		}
        
        //add tiles that enable goods here (by E oct 2005)
        		}
        
        
        ....more code... more code...
        I'm looking to add two bits of code here and I think I know the code bits but your "handwritten code" last time helped a lot to get the logic flow so I want to run this by you first

        my intent essentially is if a player builds a building with the enable good flag than it gives that city that good, not placing it in the terrain because I think we can have goods that don't show up in terrain but are in the goods.txt this will allow for "commodity" goods like electronics that you can only get if you build a building that enables it later.

        so the logic part I think is this
        Code:
        if effectivebuilding do
               if effectivebuilding->getenablesgood >0
                        for enablesgood
                               add resource
                        end for
                end if
        end if
        AND I'm trying to have the iterator look at improvements. I added a flag enablesGood that would put a resource in there. So if the city has the tileimp that enablesgood (say corn) than it would add that resource to the collecting resources array even though there is no good on the terrain, this will allow it to be traded.

        I see that there is no GetImprovement in the wrld.h. So how do I get the improvement from a cell, I made some attempts finding some references here and there and tried this code but its not compiling...

        Code:
        		sint32 i,g;
        		const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(i);
        			if(g_theWorld->GetCell(pos)->(cell->GetNumDBImprovements() > 0)){
        				for(i = 0; i < g_theTerrainImprovementDB->NumRecords(); i++) {
        					if (rec->GetNumEnablesGood() > 0){
        						for(g = 0; g < rec->GetNumEnablesGood(); g++) {
        							m_collectingResources.AddResource(g);
        						}
        					}
        				}
        			}

        thanks...
        Last edited by Ekmek; October 27, 2005, 00:52.
        Formerly known as "E" on Apolyton

        See me at Civfanatics.com

        Comment


        • Originally posted by E
          ok here it is martin:

          Code:
          	if(rec->GetNumNeedsCityGoodAnyCity()) {
          		
          		sint32 i, g;
          		bool goodavail = false;
          
          			for(i = 0; i < m_all_cities->Num(); i++) {
          				for(g = 0; g < rec->GetNumNeedsCityGoodAnyCity(); g++) {
          					if(m_all_cities->Access(i).AccessData()->GetCityData()->HasEitherGood(rec->GetNeedsCityGoodAnyCityIndex(g))){ 
          						goodavail = true;
          						break;
          					}
          				}
          				if(goodavail){
          				break;
          				}
          			}
          			if(!goodavail)
          			return FALSE;
          	}
          Well that looks fine. Except that the indention isn't correct. A language like Python isn't so forgiving by the way.

          Originally posted by E
          Now not to waste time I ran accross this back in my old friend citydata.cpp

          Code:
          void CityData::CollectResources() 
          {
          ...code...code...
          
          // Add if city has building GetEnablesGood>0
          
          	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);
          		}
          
          //add tiles that enable goods here (by E oct 2005)
          		}
          
          
          ....more code... more code...
          I'm looking to add two bits of code here and I think I know the code bits but your "handwritten code" last time helped a lot to get the logic flow so I want to run this by you first

          my intent essentially is if a player builds a building with the enable good flag than it gives that city that good, not placing it in the terrain because I think we can have goods that don't show up in terrain but are in the goods.txt this will allow for "commodity" goods like electronics that you can only get if you build a building that enables it later.

          so the logic part I think is this
          Code:
          if effectivebuilding do
                 if effectivebuilding->getenablesgood >0
                          for enablesgood
                                 add resource
                          end for
                  end if
          end if
          AND I'm trying to have the iterator look at improvements. I added a flag enablesGood that would put a resource in there. So if the city has the tileimp that enablesgood (say corn) than it would add that resource to the collecting resources array even though there is no good on the terrain, this will allow it to be traded.

          I see that there is no GetImprovement in the wrld.h. So how do I get the improvement from a cell, I made some attempts finding some references here and there and tried this code but its not compiling...

          Code:
          		sint32 i,g;
          		const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(i);
          			if(g_theWorld->GetCell(pos)->(cell->GetNumDBImprovements() > 0)){
          				for(i = 0; i < g_theTerrainImprovementDB->NumRecords(); i++) {
          					if (rec->GetNumEnablesGood() > 0){
          						for(g = 0; g < rec->GetNumEnablesGood(); g++) {
          							m_collectingResources.AddResource(g);
          						}
          					}
          				}
          			}

          thanks...
          Actually you want to do something like this:

          Code:
          for all tiles in the city radius do
              add tile food to city food
              add tile prod to city prod
              add tile gold to city gold
              if tile has good do
                  add tile good to city's goods list
              end if
              if tile has improvement that give goods do
                  add goods from tile improvements to city's goods list
              end if
          end for
          for all buildings do
              if building gives goods
                  add goods to city's goods list
              end if
          end if
          So now get the code into that structure, maybay you have to add some for loops or remove one, to archieve this. And by the way this is called pseudo code, statements written in a code like way, but of course this is only human readible.

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

          Comment


          • SWEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEET

            I got the tileimprovement enables good working!

            Code:
            		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));
            						}
            					}
            		}
            I'm sure optimization is in order but I'm finally feeling some progress on my coding skills, just in time to abandon it for civ4

            well ctp2 now has city only goods, civwidegoods, either or goods, planting of goods, next will be buildings and then I'll go back to exporting good bonuses. So resources are better than civ3 offers, i guess the hard part will be trying to port this stuff to civ4

            Im off to try the buildings next,
            Formerly known as "E" on Apolyton

            See me at Civfanatics.com

            Comment


            • Two things before you submit it to the respository:

              The first thing is to get the indention right. In the code above after the line with the for the next line starts on the same indention level like the for.

              And the if inside the loop has one indention to much.

              And then in the revsion thread I posted detailed instructions how to use to use TortoiseSVN to attach to the revsion a revision report:

              3. Commiting your changes

              Sending the changes you made to your working copy is known as committing the changes. But before you commit you have to make sure that your working copy is up to date. You can either make an Update directly. Or you can Check for Modifications first, to see which files have changed locally or on the server.

              If your working copy is up to date and there are no conflicts, you are ready to commit your changes. Select any file and/or folders you want to commit and select Commit... from the context menu.

              The commit dialog will show you every changed file, including added, deleted and unversioned files. If you don't want a changed file to be committed, just uncheck that file. If you want to include an unversioned file, just check that file to add it to the commit.

              The commit dialog has two fields one text field at the top for the Revision comment. And a file list in the middle for the files you have added/modified/deleted.

              To fill the revision message you can use the button Paste Changed file names first. This pastes the changed file names into the revision message. Now you can add your descriptions to into that box. Make sure that the first line of your message contains something descriptive as a title of your whole revision or at least the description of your first modification you mention there.

              Never leave this first line empty or fill it with a file path, because TortoiseSVN uses the first line of the message as title in the log messages window.

              Once this is done you can press the OK button to commit your changes.

              If you copy your log message before you press OK you can post it here easily. If you forget this you can still copy it from the Log Messages window.
              Note that the revision thread is there to let those know of our work who don't have access to the respository. And it isn't meant as a replacement as those revision messages. It is always a nuisance to look up the necassary bits of information in that revision thread.

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

              Comment


              • enablesgoods works for buildings now! the advatage to this code is that say with gunpowder you can build the weapons factory it provides the good armaments which you can trade with a lesser power to give them weapons before they have the tech (provided you set up the units and building text files right)


                Code:
                    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());
                			if (rec->GetNumEnablesGood() > 0){
                				for(good = 0; good < rec->GetNumEnablesGood(); good++) {
                  						m_collectingResources.AddResource(rec->GetEnablesGoodIndex(good));
                				}
                			}
                		}
                	}

                i fixed most of my indentation butthe repository is down so I'll updated once kaan fixes it again
                Formerly known as "E" on Apolyton

                See me at Civfanatics.com

                Comment


                • The sint32 good; and the for are on the same level, that has to be fixed. And the innerst of the inner for loop has one tab to much.

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

                  Comment


                  • Martin I got my export a good bonus code working...

                    Code:
                    void CityData::ProcessFood(double &foodLostToCrime, double &producedFood, double &grossFood, bool considerOnlyFromTerrain) const{
                    
                    [i]...some code ...[/i]
                    
                    	sint32 g;
                    	for(g = 0; g < g_theResourceDB->NumRecords(); g++) {
                    		if((m_buyingResources[g] + m_collectingResources[g]) > 0){
                    						grossFood += ceil(grossFood * (g_theResourceDB->Get(g))->GetFoodPercent());		
                    		}
                    	}
                    BUT I want it so that the unit is selling thegood loses the bonus. As it stands now if it collecting and then sells, both cities get the bonus. Granted this code is useful so I'll make it a different flag. BUt how do I get it to not give the bonus if it sells the good?
                    Formerly known as "E" on Apolyton

                    See me at Civfanatics.com

                    Comment


                    • First thing: Fix the indention.

                      Originally posted by E
                      BUT I want it so that the unit is selling thegood loses the bonus. As it stands now if it collecting and then sells, both cities get the bonus. Granted this code is useful so I'll make it a different flag. BUt how do I get it to not give the bonus if it sells the good?
                      In that case you have to remove the number of sold goods from the sum of collected and bought goods. And if the resulting number is still biger than zero you grand the effect.

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

                      Comment


                      • Martin,

                        I think I got in the code but I have yet to test it (waiting on Fromafar to finish his updates)

                        but is there anychance you can provide some pseudocode on how to evaluate a road connection between twopoints? I dont think there is something like that in the code (if there is please point the direction)

                        essentially I want tosee if point A (a city) is connected to another city (or imp) by a road (or other tile imp). any recommendations?
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • E, where are your revision reports? I use the Log Message tool of TortoiseSVN and to your revisions no reports are attched. I know you use TortoiseSVN, and I posted at the start of the Revision Report thread detailed instructions to do them with TortoiseSVN, at least in my opinion they are detailed enough and I reposted in this thread these instructions extra for you, so that you do it this time right. So next time I see the box with the question marks filled. The Revision Report thread is not there for additional information, its only purpose is to show those unlucky guys without access to the repository. I don't want to browse that thread for some additional pieces of infomation. Basically everything you find in the revision report thread, must be available in the repository.

                          but is there anychance you can provide some pseudocode on how to evaluate a road connection between twopoints? I dont think there is something like that in the code (if there is please point the direction)

                          essentially I want tosee if point A (a city) is connected to another city (or imp) by a road (or other tile imp). any recommendations?
                          I think you have now enough to think about. So not right now.

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

                          Comment


                          • AH that revision reports you were talking about. I'll check it out tonight.
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • Originally posted by E
                              AH that revision reports you were talking about. I'll check it out tonight.
                              What about asking next time. However you aren't able to add or modify revision reports afterwards you have submitted the revision only Klaus is able to do so. So for the next time.

                              Originally posted by E
                              but is there anychance you can provide some pseudocode on how to evaluate a road connection between twopoints? I dont think there is something like that in the code (if there is please point the direction)

                              essentially I want tosee if point A (a city) is connected to another city (or imp) by a road (or other tile imp). any recommendations?
                              Now I can answer this. I don't thing there is something like a road connectivity routine in. But what you can do is to add an road checker astar algorithm, it is basicly the same like one for the trade routes, but it has cost of 0 if there is a road and infinity if there is no road. In that case it is up to you to dig up the astar algorithm.

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

                              Comment


                              • Originally posted by Martin Gühmann
                                Now I can answer this. I don't thing there is something like a road connectivity routine in. But what you can do is to add an road checker astar algorithm, it is basicly the same like one for the trade routes, but it has cost of 0 if there is a road and infinity if there is no road. In that case it is up to you to dig up the astar algorithm.
                                I don't know anything about A* in particular, but I can imagine some algorithms would work better if you used a small positive finite cost for the road tiles, rather than a 0 cost.

                                Comment

                                Working...
                                X