Announcement

Collapse
No announcement yet.

PROJECT: ShowOnMap

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

  • #61
    Originally posted by E
    just drafted this. I'm sure I'll have to tweak it


    Code:
    	MapPoint SpotFound;
    	CityInfluenceIterator it(m_point, m_sizeIndex); 
    	
    	sint32 s;
    	for(s = 0; s < rec->GetNumShowOnMap(); s++) {
    	const TerrainImprovementRecord *trec = g_theTerrainImprovementDB->Get(s);
    
    
    		for(it.Start(); !it.End(); it.Next()) {
    			Cell *cell = g_theWorld->GetCell(it.Pos());
    			if(m_point == it.Pos())
    				continue;
    
    			if(terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, it.Pos)) {
    				SpotFound = it.Pos(); 
    			}
    			else { 
    				SpotFound = it.Pos(); 
    			}
    		}
    		g_player[m_owner]->CreateSpecialImprovement(rec->GetShowOnMapIndex(s), SpotFound, 0);
    	}
    This is not that:

    Code:
    for all tiles in the city radius do
        if a good tile has been found do
             if current tile is better than found tile do
                 foundTile := currentTile
             end
        else
             foundTile := currentTile;
        end
    end
    
    place wonder improvement on foundTile
    You rather did something like this:

    Code:
    for all tiles in the city radius do
        if current tile is better than found tile do
             foundTile := currentTile
        else
             foundTile := currentTile;
        end
    end
    
    place wonder improvement on foundTile
    Of course this is stupid, if you are at the first tile you have nothing to compare with, thus the game will crash. And the if else statement is rediculous as well: If the condition is false let's do the stuff we wanted to do anyway.


    Originally posted by E
    I got this drafted but didn't see where I needed tothe tileimp. I guess basie off the excludes of a tile imp. So far this just compares if one tile has more improvements than another one.

    Code:
    	
    
    void CityData::IsNewTileBetter(const MapPoint &npos, MapPoint &opos, sint32 &wonderimp )
    {
    	Cell *ncell = g_theWorld->GetCell(&npos);
    	Cell *ocell = g_theWorld->GetCell(&opos);
        // Of course preferable is that wonderImp does't remove any tileimps 
    	    //if wonderImp removes less Imps at newTile than at oldTile do
    	if(ocell->GetNumImprovements() > ncell->GetNumImprovements() ) 
    		return true;
    	} else {
    		return false;
    	}
    }
    And again this is not this:

    Code:
    IsNewTileBetter(Tile newTile, Tile oldTile, Imp wonderImp)
        // Of course preferable is that wonderImp does't remove any tileimps 
        if wonderImp removes less Imps at newTile than at oldTile do
            return true;
        else
            // Of course if the better check is be just simple than we can do without an own function 
            return false;
        end
    end
    It is rather this:

    Code:
    IsNewTileBetter(Tile newTile, Tile oldTile, Imp wonderImp)
        // Of course preferable is that wonderImp does't remove any tileimps 
        [b]if at newTile are less Imps than at  at oldTile do[/b]
            return true;
        else
            // Of course if the better check is be just simple than we can do without an own function 
            return false;
        end
    end
    Of course for this you do not need wonderImp, but than you can stick to your old code and drive the player mad.

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

    Comment


    • #62
      ok, I see I'll try to think of something for wonderimp, I figure looking at th excludes stuff in terrainutil is where I'll start
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • #63
        Originally posted by E
        ok, I see I'll try to think of something for wonderimp, I figure looking at th excludes stuff in terrainutil is where I'll start
        Yes something like this, and that holds for the wonder improvement and for the improvements that you find at the new tile and of course you find at the old tile as well.

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

        Comment


        • #64
          would you recommend using something like governor::GetBestTerraformImprovement?
          Formerly known as "E" on Apolyton

          See me at Civfanatics.com

          Comment


          • #65
            Originally posted by E
            would you recommend using something like governor::GetBestTerraformImprovement?
            No, it is something simpler. First you have to determine which tile improvements your wonder tileimp removes, than you have to count the tile imprvements on the give tile that your wonder improvement removes. Than the better tile is that loses less improvements.

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

            Comment


            • #66
              Martin I was trying this
              Code:
              	MapPoint SpotFound;
              	CityInfluenceIterator it(m_point, m_sizeIndex); 
              	
              	sint32 s;
              	for(s = 0; s < rec->GetNumShowOnMap(); s++) {
              	const TerrainImprovementRecord *trec = g_theTerrainImprovementDB->Get(s);
              	
              
              		for(it.Start(); !it.End(); it.Next()) {
              			Cell *cell = g_theWorld->GetCell(it.Pos());
              			Cell *ncell = g_theWorld->GetCell(it.Pos());
              			Cell *ocell = g_theWorld->GetCell(SpotFound);
              			if(m_point == it.Pos())
              				continue;
              
              			if(terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, it.Pos())) {
              				if(ncell->GetGoldFromTerrain() > ocell->GetGoldFromTerrain()) {
              					SpotFound = it.Pos(); 
              				}
              			} else { 
              					SpotFound = it.Pos(); 
              			}
              
              		}
              		g_player[m_owner]->CreateSpecialImprovement(rec->GetShowOnMapIndex(s), SpotFound, 0);
              	}

              basically I was just trying to see if tile gold value as a discriminatory would work. We can make it more detailed later but for now I was trying to get the iterator part to work, and it didn't.
              It created the imp in one spot. then I tried again but in a situation where there were two cells that were perfectly the same (blank plains) it should of picked one but it picked neither.

              Am I doing something wrong with the SpotFound part? or the ncell>ocell part? it appppeared that the code was behaving the same as my previous code, only checking the North (or in some cases the east) cell but if they were unavailable it wouldn't check the rest.
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • #67
                One problem is that my pseudo code doesn't cover all possibilities:

                Code:
                for all tiles in the city radius do
                    if current tile is better than found tile do
                         foundTile := currentTile
                    else
                         foundTile := currentTile;
                    end
                end
                
                place wonder improvement on foundTile
                This code asumes that you can build the tile improvement at every location, but if you can't built it at a certain location, and that location has the best value, then the game tries to build it there and fails of course.

                So here is the improved pseudo code:

                Code:
                for all tiles in the city radius do
                    if current tile allows building of wonder imp do
                        if current tile is better than found tile do
                            foundTile := currentTile
                        else
                            foundTile := currentTile;
                        end
                    end
                end
                
                place wonder improvement on foundTile
                And we may have a look at the initialization of SpotFound, it might be initialized with a valid position on the map and that isn't a good idea if we don't find a spot.

                By the way what is the use of the pointer cell in your code?

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

                Comment


                • #68
                  ok, thanks, wow that extra 'end' makes a big difference

                  as for
                  Code:
                  Cell *cell = g_theWorld->GetCell(it.Pos());
                  thats kind of a residual cell i had left over, it'll probably go away but I was leaving it in there for now in case I put in the IsNewTileBetter function (in which case ocell or ncell would go). I'll out comment it for now.
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • #69
                    Code:
                    	MapPoint SpotFound;
                    	CityInfluenceIterator it(point, m_sizeIndex); 
                    	
                    	sint32 s;
                    	for(s = 0; s < rec->GetNumShowOnMap(); s++) {
                    	const TerrainImprovementRecord *trec = g_theTerrainImprovementDB->Get(s);
                    	
                    
                    		for(it.Start(); !it.End(); it.Next()) {
                    			//Cell *cell = g_theWorld->GetCell(it.Pos());
                    			Cell *ncell = g_theWorld->GetCell(it.Pos());
                    			Cell *ocell = g_theWorld->GetCell(SpotFound);
                    			if(point == it.Pos())
                    				continue;
                    
                    			if(terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, it.Pos())) {
                    				if(ncell->GetGoldFromTerrain() > ocell->GetGoldFromTerrain()) {
                    					SpotFound = it.Pos(); 
                    				} else { 
                    					SpotFound = it.Pos(); 
                    				}
                    			}
                    		}
                    		g_player[m_owner]->CreateSpecialImprovement(rec->GetShowOnMapIndex(s), SpotFound, 0);
                    	}

                    I think there is an initialization issue. It seems that it operates as an either or. In this case it was either the East position of the South East, if either one was not available then it would not create the wonderimp. (at other times it has been North or NorthEast, don't know why it switches).
                    Formerly known as "E" on Apolyton

                    See me at Civfanatics.com

                    Comment


                    • #70
                      Originally posted by E
                      Code:
                      if(ncell->GetGoldFromTerrain() > ocell->GetGoldFromTerrain()) {
                      	SpotFound = it.Pos(); 
                      } else { 
                      	SpotFound = it.Pos(); 
                      }
                      What is the purpose of this if statement? Whatever it is, I'm fairly sure it's not doing what you want - it makes no sense at all. It's equivalent to just:

                      Code:
                      SpotFound = it.Pos();

                      Comment


                      • #71
                        the if statement was trying to compare the gold value in either the current found cell or a previous one. the comparison was to allow for some differation and then move to the next tile or keep the current one.
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • #72
                          Obviously I copied the wrong pseudocode, well this should now be the right one:

                          Code:
                          for all tiles in the city radius do
                              if current tile allows building of wonder imp do
                                  if no good tile has been found yet
                                  or current tile is better than found tile do
                                      foundTile := currentTile
                                  end
                              end
                          end
                          
                          place wonder improvement on foundTile
                          -Martin
                          Civ2 military advisor: "No complaints, Sir!"

                          Comment


                          • #73
                            the
                            'if no good tile has been found yet'

                            is a little unclear to me. I put in my bold my best guess. But not sure if checking that twice is what constitutes a 'good tile' what should a 'good tile' be?

                            PS bold through my spacing off

                            Code:
                            	MapPoint SpotFound;
                            	CityInfluenceIterator it(point, m_sizeIndex); 
                            	
                            	sint32 s;
                            	for(s = 0; s < rec->GetNumShowOnMap(); s++) {
                            	const TerrainImprovementRecord *trec = g_theTerrainImprovementDB->Get(s);
                            	
                            
                            		for(it.Start(); !it.End(); it.Next()) {
                            			//Cell *cell = g_theWorld->GetCell(it.Pos());
                            			Cell *ncell = g_theWorld->GetCell(it.Pos());
                            			Cell *ocell = g_theWorld->GetCell(SpotFound);
                            			if(point == it.Pos())
                            				continue;
                            
                            			if(terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, it.Pos())) {
                            				[b]if(!terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, SpotFound)) || [/b]
                            				(ncell->GetGoldFromTerrain() > ocell->GetGoldFromTerrain()) {
                            					SpotFound = it.Pos(); 
                            				}
                            			}
                            		}
                            		g_player[m_owner]->CreateSpecialImprovement(rec->GetShowOnMapIndex(s), SpotFound, 0);
                            	}
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • #74
                              Originally posted by E
                              the
                              'if no good tile has been found yet'

                              is a little unclear to me. I put in my bold my best guess. But not sure if checking that twice is what constitutes a 'good tile' what should a 'good tile' be?
                              It is a tile that is good, for instance for placing a wonder improvement. That's it.


                              Originally posted by E
                              PS bold through my spacing off

                              Code:
                              	MapPoint SpotFound;
                              	CityInfluenceIterator it(point, m_sizeIndex); 
                              	
                              	sint32 s;
                              	for(s = 0; s < rec->GetNumShowOnMap(); s++) {
                              	const TerrainImprovementRecord *trec = g_theTerrainImprovementDB->Get(s);
                              	
                              
                              		for(it.Start(); !it.End(); it.Next()) {
                              			//Cell *cell = g_theWorld->GetCell(it.Pos());
                              			Cell *ncell = g_theWorld->GetCell(it.Pos());
                              			Cell *ocell = g_theWorld->GetCell(SpotFound);
                              			if(point == it.Pos())
                              				continue;
                              
                              			if(terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, it.Pos())) {
                              				[b]if(!terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, SpotFound)) || [/b]
                              				(ncell->GetGoldFromTerrain() > ocell->GetGoldFromTerrain()) {
                              					SpotFound = it.Pos(); 
                              				}
                              			}
                              		}
                              		g_player[m_owner]->CreateSpecialImprovement(rec->GetShowOnMapIndex(s), SpotFound, 0);
                              	}
                              So why do you test a tile that hasn't been found yet? Actually you are supposed to test whether SpotFound is a valid position on the map.

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

                              Comment


                              • #75
                                would SpotFound is a valid position be tested by if( SpotFound == 0) or just if(!SpotFound)? I thought MapPoint doesnt work like a sint32?
                                Formerly known as "E" on Apolyton

                                See me at Civfanatics.com

                                Comment

                                Working...
                                X