Announcement

Collapse
No announcement yet.

PROJECT: ShowOnMap

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

  • #16
    Martin this code kept popping up in governor.cpp

    Code:
    MapAnalysis & the_map =  MapAnalysis::GetMapAnalysis();
    not sure if this what you were talking about, but I also found this..

    Code:
    Governor::PlaceTileImprovements()
    {
    
    			for(it.Start(); !it.End(); it.Next()) 
    				{
    					
    					if (unit.RetPos() == it.Pos())
    						continue;
    
    					cell = g_theWorld->GetCell(it.Pos());
    
    					
    					if (!(cell->GetCityOwner() == unit))
    						continue;
    
    					
    					if (cell->GetNumImprovements() > 0)
    						continue;
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • #17
      It is the second one, that's an iterator. This iterator contains all the locations within a certain radius. Therefore they check whether the current locations isn't the center or doesn't even belong to the city influence area, and finally they check whether the locations has a tile improvement.

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

      Comment


      • #18
        Great! I thought I'd have to look more. But the problem is that the iterator is part of a code. Should I make a free standing search function (for later coders too?)
        Formerly known as "E" on Apolyton

        See me at Civfanatics.com

        Comment


        • #19
          Originally posted by E
          Great! I thought I'd have to look more. But the problem is that the iterator is part of a code. Should I make a free standing search function (for later coders too?)
          No it is an iterator, a pointer on the first element, a pointer on the last element and a way to get from one element to the next element. And actual this is all you need. You have to get the iterator, well you omitted that piece of code and the for loop, that goes through all the elements, and that is your search function, you wouldn't do much different stuff with your search function.

          And of course everyone may have to do something else in that for-loop. But I think that you need the three checks you posted here as well.

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

          Comment


          • #20
            Okay this isnt a real attempt at the code (yet) but I'm trying to gather exactly what I'll need to do.
            1) it has to go in the citywonderevent, no prob.
            2) first it has to check the radius for terrain andimprovements
            3) then it has to get the wonder imp properties Cantbuildon and excludes
            4) it has to check if the wonder can be built on terrain or the improvements
            5) then it has to build the wonder

            I know I'm going to need help on the iterator, havent done anything like that before, but I think I found something similar in the jumble of code I pasted there. Questions though:
            1) do I have to copy the checks that createtile (like Cantbuildon etc) or is there some whay I can just do Get terrainutil_CanPlayerBuildAt?

            2)How do I tell it to create the tile?

            3) should I make it do a check n the build ques to see if the wonder can be shown on the map so it doesn't cause a problem afterwards?

            thanks




            Code:
            ////
            	sint32 w;
            	const WonderRecord *rec = g_theWonderDB->Get(wonder_type);   
            	sint32 t = rec->GetTerrutilIndex();
            	sint32 wonderimp = rec->GetShowOnMapIndex();		
            	if (t < 0) {
            		return FALSE; 
            	for(i = 0; i < rec->GetNumCanSettleOn(); i++) {
            		if(rec->GetCanSettleOnIndex(i) == cell->GetTerrain()) {
            			return TRUE;
            		}
            	}
            	if(cell->GetOwner() == -1) {
            		if(rec->GetIntBorderRadius()) {
            			if(!g_player[pl]->IsVisible(pos)) {
            				
            				return false;
            			}
            		} else {
            			return false;
            		}
            	}
            		for(i = 0; i < rec->GetNumCantBuildOn(); i++) {
            			if(rec->GetCantBuildOnIndex(i) == cell->GetTerrain()) {
            				return FALSE;
            			}
            		}
            	}
            
            	
            						g_gevManager->AddEvent(GEV_INSERT_Tail, 
            									   GEV_CreateImprovement,
            									   GEA_Player,		m_playerId,
            									   GEA_MapPoint,	iter->pos,
            									   GEA_Int,			iter->type,
            									   GEA_Int,			0, 
            									   GEA_End);
            Formerly known as "E" on Apolyton

            See me at Civfanatics.com

            Comment


            • #21
              I realize its going to be a multi change process. Mainly since I don't want the program to run the iterator ONCE the wonder has already been built, first I have to do the radius search to the ShowOn Map here first:

              Code:
              BOOL CityData::CanBuildWonder(sint32 type) const
              {
              	if(g_exclusions->IsWonderExcluded(type))
              		return FALSE;
              
              	if(!wonderutil_IsAvailable(type, m_owner))
              		return FALSE;
              
              	return g_slicEngine->CallMod(mod_CanCityBuildWonder, TRUE, m_home_city.m_id, type);
              }
              then once they build it then the build event will just run the iterator (again?) to find the best spot and then place the improvement. Still working....
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • #22
                Originally posted by E
                I realize its going to be a multi change process.
                Nice that you have got this in the mean time.

                Originally posted by E
                Mainly since I don't want the program to run the iterator ONCE the wonder has already been built, first I have to do the radius search to the ShowOn Map here first:
                Why that? That's the time when it should be done and the slic file does it like that.

                Originally posted by E
                Code:
                BOOL CityData::CanBuildWonder(sint32 type) const
                {
                	if(g_exclusions->IsWonderExcluded(type))
                		return FALSE;
                
                	if(!wonderutil_IsAvailable(type, m_owner))
                		return FALSE;
                
                	return g_slicEngine->CallMod(mod_CanCityBuildWonder, TRUE, m_home_city.m_id, type);
                }
                then once they build it then the build event will just run the iterator (again?) to find the best spot and then place the improvement. Still working....
                Why do you want to modify this? It just determines whether your city can build the according wonder.

                Originally posted by E
                I realize its going to be a multi change process.
                Back to this. You have to modify tileimp.txt. You have to extend the Excludes set, so that we don't have to worry about removing the other tileimp from the given tile, but of course it would be nice to find a free tile.

                Then tileimp.txt needs an unpillageble flag. Maybe also a flag that doesn't allow to build other tileimps on it.

                You have to change the AI so that it doesn't go for goals that pillages this tile if it only contains the wonder improvement. You have to modify wonders.txt, for the flag that specifies the tileimprovement.

                And of course you have to find a good spot to place the tileimp.

                And maybe some other things I have forgotten.

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

                Comment


                • #23
                  The tile imp stuff I havent gotten to yet and I'll probably take the stuff from IW's visible wonders mod (graphics and tileimp.txt info).

                  I'll have to see how the slic handles the building after the city has already built it, mainly because I'm thinking about what happens if the wonder has a CantBuildOn flag and the city is on a single square island. Does the slic just place it in the water? I was thinking of doing the iteration (like building sea units only in coast cities) so that land wonders can only be built in cities that have a land tile adjacent to it.

                  The cant pillage I'll look into once I get the iterator and stuff down.
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • #24
                    Originally posted by E
                    I'll have to see how the slic handles the building after the city has already built it, mainly because I'm thinking about what happens if the wonder has a CantBuildOn flag and the city is on a single square island. Does the slic just place it in the water? I was thinking of doing the iteration (like building sea units only in coast cities) so that land wonders can only be built in cities that have a land tile adjacent to it.
                    In that case the solution is no visible wonder, but just the wonder inside the city. At least that would be the first step.

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

                    Comment


                    • #25
                      no wonder at all... i was taking the more difficult route and insisting that it must show. Ok I'll pursue that....
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • #26
                        Martin (or someone) could you walk me through how the iterator falls into the code, I'm getting use to if and == stuff but not sure how the iterator would kick in mainly since I only see it like this:

                        Code:
                        	sint16 num_cities = player_ptr->m_all_cities->Num();
                        	for (sint16 city_index = 0; city_index < num_cities; city_index++)
                        		{
                        			unit = player_ptr->m_all_cities->Get(city_index);
                        			Assert(unit->GetCityData());
                        			city = unit->GetCityData();
                        
                        			
                        			if (city->GetUseGovernor() == false)
                        				continue;
                        
                        			CityInfluenceIterator it(unit.RetPos(), city->GetSizeIndex());
                        
                        			bonusFood = 0;
                        			bonusProduction = 0;
                        			bonusCommerce = 0;
                        
                        			
                        			for(it.Start(); !it.End(); it.Next()) 
                        				{
                        					
                        					if (unit.RetPos() == it.Pos())
                        						continue;
                        
                        					cell = g_theWorld->GetCell(it.Pos());
                        
                        					
                        					if (!(cell->GetCityOwner() == unit))
                        						continue;
                        
                        					
                        					if (cell->GetNumImprovements() > 0)
                        						continue;
                        
                        					
                        					if ( FindBestTileImprovement(it.Pos(), ti_goal) )
                        I see Start and End of course but how do I limit to only the city radius or just a radius of one? And do I make it equal to the CantBuild for the result. Just need a little direction here. I think Can't Pillage is easy (except the AI part) but the iterator and "finding" the best spot is a little confusing.
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • #27
                          Originally posted by E
                          Martin (or someone) could you walk me through how the iterator falls into the code
                          I'll try. The important part is where the iterator is created, which I think is here:

                          Code:
                          CityInfluenceIterator it(unit.RetPos(), city->GetSizeIndex());
                          This part says that you want an iterator which is centred on the unit (the city), and of radius the city SizeIndex, which I presume means the city radius. Once the iterator is so initialized, the loop goes over all the squares specified.

                          Comment


                          • #28
                            John is right. One thing to add is that as far as I could figure it out the city iterator only visit tiles that are inside the city's influence radius. This means that actual this part of code is superflous:

                            Code:
                            		
                            					if (!(cell->GetCityOwner() == unit))
                            						continue;
                            -Martin
                            Civ2 military advisor: "No complaints, Sir!"

                            Comment


                            • #29
                              Thanks guys,
                              I found in the CityInfluenceIterator.cpp that there is also a Get CityRadius, might be a duplicate form of code. But I would like to limit it to the city radius (no sense having the wondering pop up four tiles away for an ancient wonder if it goes by influence).

                              I think I might know enough to be dangerous so I'll take a crack at the code soon...
                              Formerly known as "E" on Apolyton

                              See me at Civfanatics.com

                              Comment


                              • #30
                                Just some left over notes and stuff to clean up after I finish NeedsCityGood. the stuff in bold I'll need to walk through though...

                                Code:
                                STDEHANDLER(CreateWonderEvent)
                                {
                                	Unit c;
                                	sint32 wonder;
                                	if(!args->GetCity(0, c)) return GEV_HD_Continue;
                                	if(!args->GetInt(0, wonder)) return GEV_HD_Continue;
                                
                                	c.CD()->SetWonders(c.CD()->GetBuiltWonders() | ((uint64)1 << (uint64)wonder));
                                	wonderutil_AddBuilt(wonder);
                                	g_player[c->GetOwner()]->AddWonder(wonder, c);
                                	g_player[c->GetOwner()]->RegisterCreateWonder(c, wonder);
                                
                                	
                                	if (c->GetOwner() == g_selected_item->GetVisiblePlayer() &&
                                		!Player::IsThisPlayerARobot(c->GetOwner())) {
                                		
                                		if ( g_theProfileDB->IsWonderMovies() ) {
                                			if (g_director) {
                                				g_director->AddPlayWonderMovie(c.CD()->GetBuildQueue()->GetHead()->m_type);
                                			}
                                		}
                                		
                                	}
                                	if(g_network.IsHost()) {
                                		g_network.Block(c.GetOwner());
                                		g_network.Enqueue(new NetInfo(NET_INFO_CODE_WONDER_BUILT,
                                									  c.CD()->GetBuildQueue()->GetHead()->m_type, (uint32)c.m_id));
                                		g_network.Unblock(c.GetOwner());
                                	}
                                
                                	Unit u;
                                	c.CD()->GetBuildQueue()->FinishBuildFront(u);
                                	SlicObject *so;
                                	if(wonder == wonderutil_GetFobCityIndex()) {
                                		so = new SlicObject("911ForbiddenCityPeace");
                                		so->AddRecipient(c.GetOwner());
                                		so->AddCity(c);
                                		g_slicEngine->Execute(so);
                                	}
                                //begin E code from Governor.cpp PlaceTileImprovements
                                
                                	Player *player_ptr;
                                	CityData *city;
                                	Unit unit;
                                	Cell *cell;
                                	TiGoal ti_goal;
                                	MapPoint pos;
                                
                                
                                			CityInfluenceIterator it(unit.RetPos(), city->GetSizeIndex());
                                			
                                			for(it.Start(); !it.End(); it.Next()) 	{
                                					
                                		if (unit.RetPos() == it.Pos())
                                						continue;
                                
                                						cell = g_theWorld->GetCell(it.Pos());
                                		
                                					if (!(cell->GetCityOwner() == unit))
                                						continue;
                                		
                                					if (cell->GetNumImprovements() > 0)
                                						continue;
                                							if ( terrutil_PlayerCanBuildAt(it.Pos(), imp) )
                                			
                                					[b]g_gevManager->AddEvent(GEV_INSERT_Tail, GEV_CreateImprovement,
                                								   GEA_Player, m_playerId,
                                								   GEA_MapPoint, iter->pos,
                                								   GEA_Int, iter->type,
                                								   GEA_Int, 0, [/b]
                                	//end E code
                                
                                	if(wonder == wonderutil_GetGaiaIndex()) {
                                		// Notify the other players that they have to hurry to win.
                                		// Starting at 1: the Barbarians do not have to be notified.
                                		for (sint32 i = 1; i < k_MAX_PLAYERS; ++i)
                                		{
                                			if (g_player[i] && !g_player[i]->IsDead() && (i != c.GetOwner()))
                                			{
                                				SlicObject * so	= new SlicObject("GCMustDiscoverGaiaController");
                                				so->AddRecipient(i);
                                				so->AddPlayer(i);
                                				so->AddPlayer(c.GetOwner());
                                				g_slicEngine->Execute(so);	// will delete so after handling
                                			}
                                		}
                                	}
                                
                                	return GEV_HD_Continue;
                                }
                                Formerly known as "E" on Apolyton

                                See me at Civfanatics.com

                                Comment

                                Working...
                                X