Announcement

Collapse
No announcement yet.

PROJECT: ShowOnMap

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

  • #46
    I'm just not good with arrays so I havent figured really how to get the it.pos to store

    but I was thinking that would it be wise instead to do a check if (g_player->m_allimprovements) to see if the improvement already exists?

    create improvement inserts the improvement into the m_allimps array. So i'm thinking that first it checks if it already exists. if it doesn't than it checks the position.

    Of course this is based on an assumption that the for loop with it.pos repeats each time and thats why i got multiple wonders instead of it.pos being all the positions at once.

    well i'll give it a try unless you guys see a flaw in my logic and stop me (I dont have access to the game and my compiler at work)
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • #47
      Originally posted by E
      I'm just not good with arrays so I havent figured really how to get the it.pos to store
      Who needs to use arrays? Just go through all the positions, if you find a position store it, and if you find a better position than before, replace the old position with the new. And so on and so fort. You just have to store one position.

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

      Comment


      • #48
        sorry, i'm getting confused on 'store' and positions.

        storing i thought was only with an aray thing. whats an example of storing?

        Are you saying that instead of the iterator I shoulduse somethinglike World->IsNextToWater where I go through North and check, then northeat east etc until it is true somewhere?


        by the way, i did this
        Code:
        BOOL CityData::HasTileImpInRadius(sint32 tileimp) const
        {
        	MapPoint cityPos(m_home_city.RetPos());
        	CityInfluenceIterator it(cityPos, m_sizeIndex);
        
        	for(it.Start(); !it.End(); it.Next()) {
        	Cell *cell = g_theWorld->GetCell(it.Pos());
        	
        	return cell->GetDBImprovement(tileimp) > 0;
        	}
        }
        i think i did it right but it didnt help
        Last edited by Ekmek; April 8, 2006, 13:28.
        Formerly known as "E" on Apolyton

        See me at Civfanatics.com

        Comment


        • #49
          ahhhhh, i think i'm getting close...

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

          See me at Civfanatics.com

          Comment


          • #50
            Originally posted by E
            sorry, i'm getting confused on 'store' and positions.

            storing i thought was only with an aray thing. whats an example of storing?
            Well, to answer the question yourself you could use a monolingual dictionary like Cambridge online dictionaries. About 'to store' it says:

            to put or keep things in a special place for use in the future:
            The data is stored on a hard disk and backed up on a floppy disk.
            I stored my possessions in my mother's house while I was living in Spain.
            I've stored my thick sweaters and jackets (away) until next winter.
            Squirrels store (up) nuts for the winter.


            So our things to put or keep are certain positions on the CTP2 map that's a MapPoint. And the special place is a place in our computer memory represented by a variable or a pointer on a variable and of course such a pointer can also point on an array. To store something it doesn't matter where you store it, it just matters that you can use it later.

            Originally posted by E
            ahhhhh, i think i'm getting close...
            Indeed you are getting closer, but you aren't at the finish line, yet.

            For now you go through all the tiles that a city owns. And the last tile that allows to build the special improvement is taken. So far there is no check whether the tile found before is better or worse than the current tile.

            For instance if the current tile is empty then it is a better compared to a tile that has improvments and all these improvements are removed by your wonder improvement.

            And another point is what you want to do if the tiles are equal good, keep the old tile or use the new tile.

            And of course the most important question is whether you have already found a tile before.

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

            Comment


            • #51
              really there is no method to determine best for this, so i'm just going with the first available since i think it'll be easier for now.

              this was my next best guess:

              Code:
              //EMOD add visible wonder 4-9-2006
                  MapPoint n, ne, nw, so, sw, se, w, e;
              	MapPoint SpotFound;
              	sint32 s;
              	for(s = 0; s < rec->GetNumShowOnMap(); s++) {
              	const TerrainImprovementRecord *trec = g_theTerrainImprovementDB->Get(s);
                     
              		if(m_point.GetNeighborPosition(NORTH, n) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, n)) {  
              			SpotFound = n;
              		} 
              		if(m_point.GetNeighborPosition(NORTHWEST, nw) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, nw)) {  
              			SpotFound = nw;
              		} 
              		
              		if(m_point.GetNeighborPosition(NORTHEAST, ne) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, ne)) {  
              			SpotFound = ne;
              		}
              		
              		if(m_point.GetNeighborPosition(SOUTH, so) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, so)) {  
              			SpotFound = so;
              		} 
              		
              		if(m_point.GetNeighborPosition(SOUTHWEST, sw) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, sw)) { 
              			SpotFound = sw;
              		}
              		
              		if(m_point.GetNeighborPosition(SOUTHEAST, se) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, se)) {  
              			SpotFound = se;
              		} 
              		if(m_point.GetNeighborPosition(WEST, w) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, w)) {  
              			SpotFound = w;
              		}
              		if(m_point.GetNeighborPosition(EAST, e) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, e)) {  
              			SpotFound = e;
              		} 
              		g_player[m_owner]->CreateSpecialImprovement(rec->GetShowOnMapIndex(s), SpotFound, 0);
              	}
              i figured the iterator wasn't checking sequentially so i took it out in order. it seemed to work for a few tries and then not.

              am i closer? what am i'm missing. i think i show that spotfound should be replaced with the next mappoint but it didnt seem to work out like that
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • #52
                Originally posted by E
                really there is no method to determine best for this, so i'm just going with the first available since i think it'll be easier for now.

                this was my next best guess:

                Code:
                //EMOD add visible wonder 4-9-2006
                    MapPoint n, ne, nw, so, sw, se, w, e;
                	MapPoint SpotFound;
                	sint32 s;
                	for(s = 0; s < rec->GetNumShowOnMap(); s++) {
                	const TerrainImprovementRecord *trec = g_theTerrainImprovementDB->Get(s);
                       
                		if(m_point.GetNeighborPosition(NORTH, n) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, n)) {  
                			SpotFound = n;
                		} 
                		if(m_point.GetNeighborPosition(NORTHWEST, nw) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, nw)) {  
                			SpotFound = nw;
                		} 
                		
                		if(m_point.GetNeighborPosition(NORTHEAST, ne) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, ne)) {  
                			SpotFound = ne;
                		}
                		
                		if(m_point.GetNeighborPosition(SOUTH, so) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, so)) {  
                			SpotFound = so;
                		} 
                		
                		if(m_point.GetNeighborPosition(SOUTHWEST, sw) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, sw)) { 
                			SpotFound = sw;
                		}
                		
                		if(m_point.GetNeighborPosition(SOUTHEAST, se) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, se)) {  
                			SpotFound = se;
                		} 
                		if(m_point.GetNeighborPosition(WEST, w) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, w)) {  
                			SpotFound = w;
                		}
                		if(m_point.GetNeighborPosition(EAST, e) && terrainutil_CanPlayerSpecialBuildAt(trec, m_owner, e)) {  
                			SpotFound = e;
                		} 
                		g_player[m_owner]->CreateSpecialImprovement(rec->GetShowOnMapIndex(s), SpotFound, 0);
                	}
                i figured the iterator wasn't checking sequentially so i took it out in order. it seemed to work for a few tries and then not.
                And what is this code supposed to do? It doesn't matter whether if the iterator checks the city radius sequentialy. The important part is that it checks all the tiles in the city radius.

                Originally posted by E
                am i closer? what am i'm missing. i think i show that spotfound should be replaced with the next mappoint but it didnt seem to work out like that
                No, in fact you are further away than you were before. And your code just finds a neighbour spot of some position which I don't know. But the code is supposed to find a spot withing the whole city radius and that does the code you made before. It just lacks the way to figure out if the current tile is better than the tile before and I gave you three criteria to determine this: First has been already found a spot before? Second is the new spot empty. Third if the current spot isn't empty does the wonder improvement remove all the tiles there.

                With this you should be able to determine if the new spot is better than the old one. And if the new spot is better than the old one replace the old one with the new one.

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

                Comment


                • #53
                  Originally posted by Martin Gühmann
                  It just lacks the way to figure out if the current tile is better than the tile before and I gave you three criteria to determine this:


                  First has been already found a spot before?
                  ok, this is probably do to my lack of understanding about the iterator. I've used it.Pos can I just use pos? I thought that only gave me the center position not only one position in the iteration. I haven't see any code that grabs one cell out of the iteration of many.

                  my assumption is that when it does the iteration it stores all the point based on the radius. And then applies the test. not sure how to grab one point.


                  Second is the new spot empty.
                  thats what I tried with my terrainutil_CanPlayerSpecialBuildAtshould i use a cell->getnumdbimps then. I don't think its necessary because the terrainutil_CanPlayerSpecialBuildAt checks the terrain and the excludes stuff.

                  Third if the current spot isn't empty does the wonder improvement remove all the tiles there.
                  similar issue but i don't think it needs to cutimprovements just go onto the next tile and if no tile I was thinking of sticking it in the city square, like citywalls looks like.

                  With this you should be able to determine if the new spot is better than the old one. And if the new spot is better than the old one replace the old one with the new one.

                  -Martin
                  how do I compare "better"? use score? number of tileimps? not sure why we should compare. I think its easier to stick it in the first available.
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • #54
                    Originally posted by E
                    how do I compare "better"? use score? number of tileimps?
                    Number of tileimps seems like a good start, yes.
                    not sure why we should compare. I think its easier to stick it in the first available.
                    Easier, but more annoying for players.

                    Comment


                    • #55
                      Thanks J,

                      I did find ths code:
                      Code:
                      void CityData:: DoLocalPollution()
                      {
                      	if(!g_theGameSettings->GetPollution())
                      		return;
                      
                      	if(m_total_pollution < g_theConstDB->LocalPollutionLevel())
                      		return;
                      
                      	double diff = double(m_total_pollution) - g_theConstDB->LocalPollutionLevel();
                      	double chance = diff * g_theConstDB->LocalPollutionChance();
                      
                      	
                      	if ((chance > 0.10) &&
                      		(g_slicEngine->GetSegment("080CityPollutionWarning")->TestLastShown(m_owner, 10))) {
                      		SlicObject *so = new SlicObject("080CityPollutionWarning");
                      		so->AddCity(m_home_city);
                      		so->AddRecipient(m_owner);
                      		so->AddCivilisation(m_owner);
                      		g_slicEngine->Execute(so);
                      	}
                      
                      	if(g_rand->Next(1000) < chance * 1000) {
                      		SlicObject *so = new SlicObject("040GrossPolluter");
                      		so->AddCity(m_home_city);
                      		so->AddRecipient(m_owner);
                      		g_slicEngine->Execute(so);
                      
                      		sint32 totalTiles=0;
                      		MapPoint cpos;
                      		m_home_city.GetPos(cpos);
                      		CityInfluenceIterator it(cpos, m_sizeIndex);
                      		for(it.Start(); !it.End(); it.Next()) 
                      		{
                      			totalTiles++;
                      		}
                      		
                      		m_whichtile = g_rand->Next(totalTiles);
                      		m_tilecount = 0;
                      		
                      		m_cityRadiusOp = RADIUS_OP_KILL_TILE;
                      		for(it.Start(); !it.End(); it.Next())
                      		{
                      			CityRadiusFunc(it.Pos());
                      		}
                      	}
                      }
                      but nothing that places pollution in it from what I can tell but i think it gives me a start.

                      i'm assuming I have to create another For loop and return a value (some hall) and return that tile's pos. then add that pos. But easier said than pseudo coded for me.
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • #56
                        ok I'm lost. can i get another hint.
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • #57
                          Originally posted by E
                          ok I'm lost. can i get another hint.
                          What's so difficuilt to do something like this :

                          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
                          Now you just have to figure out how this works:

                          if current tile is better than found tile do

                          What about 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
                          Well that should it be.

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

                          Comment


                          • #58
                            the problem I'm having is with 'tile.' using it.pos does it for every tile in the radius. For something like IsNewTileBetter my input would be it.pos and what for the old and new? if its both it.pos and it.pos I think it will cancel itself out.

                            i tried something similar with asTileImp in radius but instead of only building once it would not build any.

                            How do I get only one pos from it.pos?
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • #59
                              Originally posted by E
                              the problem I'm having is with 'tile.' using it.pos does it for every tile in the radius. For something like IsNewTileBetter my input would be it.pos and what for the old and new? if its both it.pos and it.pos I think it will cancel itself out.
                              The old tile is the tile you have found before and was saved in the pseudo in the variable foundTile. And that is the good tile that has been found before.

                              Originally posted by E
                              How do I get only one pos from it.pos?
                              It is just one position.

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

                              Comment


                              • #60
                                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);
                                	}

                                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;
                                	}
                                }
                                Formerly known as "E" on Apolyton

                                See me at Civfanatics.com

                                Comment

                                Working...
                                X