Announcement

Collapse
No announcement yet.

PROJECT: ShowOnMap

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

  • #31
    E, don't you have ideas that are simpler to code first than this?

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

    Comment


    • #32
      Yeah I have a few on my list. Allow this would be nice to add, I guess I can get by on the SLIC.

      Are you proposing that I start working on the Unit Upgrading stuff?
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • #33
        Originally posted by E
        Yeah I have a few on my list. Allow this would be nice to add, I guess I can get by on the SLIC.

        Are you proposing that I start working on the Unit Upgrading stuff?
        Actual I am proposing to finish the good stuff first.

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

        Comment


        • #34
          Visible Wonder Code

          Based on my experience of having buildings increase the border radius. I found that the AddWonder function n CityData is better than the event, But ran into a problem (first my code)

          note: the outcommented parts are functions I found in the code that I figured I needed

          Code:
          void CityData::AddWonder(sint32 type)
          {
          
          	const WonderRecord* wrec = wonderutil_Get(type); //added by E
          	MapPoint cityPos = m_home_city.RetPos(); //EMOD 
          	MapPoint Pos; 
          
          	m_builtWonders |= (uint64(1) << type);
          
          //EMOD Visible Wonders should go here like the radius for AddImprovement 3-27-2006
          if (wrec->GetNumShowOnMap() > 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());
          		sint32 s;
          		for(s = 0; s < wrec->GetNumShowOnMap(); s++) {
          		const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(s);
          		//if terrainutil_CanPlayerBuildAt(const TerrainImprovementRecord *rec, sint32 pl, const MapPoint &pos)
          			if(terrainutil_CanPlayerBuildAt(rec, m_owner, Pos)) {
          			//CreateImprovement(sint32 dbIndex, MapPoint &point, sint32 extraData)
          				//g_player[m_owner]->CreateImprovement(wrec->GetShowOnMapIndex(s), Pos, 0);
          				
          			}
          		}
          	}
          }


          I keep getting this error:
          error C2027: use of undefined type 'TerrainImprovement'
          and I know its the wrec->GetShowOnMapIndex(s) doing it. I've tried just making it rec, s, Index etc.

          the function says it takes a sint32 dbIndex. and searches in the code have it taking sint32's just like my 's' but its not working. What am I doing wrong.


          I'm going to try these next, but I think it will throw up the same error.

          Code:
          	//g_player[m_owner]->CreateImprovement(rec->GetIndex(),  Pos, 0);
          OR

          Code:
          				g_gevManager->AddEvent(GEV_INSERT_Tail,
          			                       GEV_CreateImprovement,
          			                       GEA_Player,      m_owner,
          			                       GEA_MapPoint,    Pos,
          			                       GEA_Int,         s, //type,
          			                       GEA_Int,         0,
          			                       GEA_End);
          Am I missing something?
          Formerly known as "E" on Apolyton

          See me at Civfanatics.com

          Comment


          • #35
            Re: Visible Wonder Code

            Originally posted by E
            I keep getting this error:

            error C2027: use of undefined type 'TerrainImprovement'
            That error suggests that you have not #included whatever header defines the TerrainImprovement class in the source file where you are using it.

            Comment


            • #36
              ahhhhhh,

              Thanks J. I'll give it a shot.

              I tried the event stuff, it compiled, but nothing happened when I tested it. i have better luck with functions than calling events so hopefully this helps. Thanks!

              PS does the code seem optimized though?
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • #37
                J or Martin

                I got it to compile and I found that addwonder isnt called in cityevent which i added with no problem (I found this when my borders code from addbuilding wouldnt work in addwonder)

                BUT my code still doesnt work in AddBuilding or AddWonder. It builds the wonder fine, i even added PW in case that was the limiting factor but still it doesn't create the tile_imp (I was using farms as the test model)

                Why isn't it creating the tile imp?


                Code:
                //EMOD Visible Wonders should go here like the radius for AddImprovement 3-27-2006
                if (wrec->GetNumShowOnMap() > 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());
                		sint32 s;
                		for(s = 0; s < wrec->GetNumShowOnMap(); s++) {
                		const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(s);
                		//if terrainutil_CanPlayerBuildAt(const TerrainImprovementRecord *rec, sint32 pl, const MapPoint &pos)
                			if(terrainutil_CanPlayerBuildAt(rec, m_owner, Pos)) {
                			//CreateImprovement(sint32 dbIndex, MapPoint &point, sint32 extraData)
                				g_player[m_owner]->CreateImprovement(wrec->GetShowOnMapIndex(s), Pos, 0);
                				
                			}
                		}
                	}
                }
                instead of "wrec->GetShowOnMapIndex(s)" I tried 'rec' and 's' am i putting something wrong in there? and i changed the 0 in the extradata spot to 1 and still nothing. having it not do anything is worse than crash
                Formerly known as "E" on Apolyton

                See me at Civfanatics.com

                Comment


                • #38
                  GOOD NEWS: Its works (sort of)

                  BAD NEWS: It builds as many imps as you have PW for. It also requires that you have the tech etc.

                  MORE GOOD NEWS: I think I know what I have to do to fix it

                  So now you won't need slic to have visible wonders (or buildings) on a map. You just add ShowOnMap in the appropriate txt file and then follow it with the imp name.

                  TODO: Removing that imp after a wonder is destroyed or a building is sold/destroyed.




                  Code:
                  void CityData::AddWonder(sint32 type)  //not used? cityevent did not call it now it does 3-26-2006 EMOD
                  {
                  
                  	const WonderRecord* wrec = wonderutil_Get(type); //added by E
                  	MapPoint cityPos(m_home_city.RetPos());
                  	MapPoint Pos; 
                  
                  	m_builtWonders |= (uint64(1) << type);
                  
                  //EMOD wonders add borders too
                  	sint32 intRad;
                      	sint32 sqRad;
                  	//EMOD increases city borders
                  	if (wrec->GetIntBorderRadius(intRad) && wrec->GetSquaredBorderRadius(sqRad)) {
                  		GenerateBorders(cityPos, m_owner, intRad, sqRad);
                  	}
                  	//end Emod
                  
                  //EMOD Visible Wonders should go here like the radius for AddImprovement 3-27-2006
                  	CityInfluenceIterator it(cityPos, m_sizeIndex);
                  	for(it.Start(); !it.End(); it.Next()) {
                  		Cell *cell = g_theWorld->GetCell(it.Pos());
                  		if(cityPos == it.Pos())
                  				continue;
                  		sint32 s;
                  		for(s = 0; s < wrec->GetNumShowOnMap(); s++) {
                  		const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(s);
                  			if(terrainutil_CanPlayerBuildAt(rec, m_owner, it.Pos())) {
                  				g_player[m_owner]->CreateImprovement(rec->GetIndex(), it.Pos(), 0);
                  				break;
                  		}
                  	}
                  }
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • #39
                    I need help

                    Ok I got it working so that it doesn't look for advances etc

                    How do I get it to place just once?

                    Currently it puts it all around the city until you run out of PW, but in the case of wonders PW cost is zero. How do I get the iterator to stop after the first time it builds?

                    Martin, J, Fromafar, anyone?


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

                    See me at Civfanatics.com

                    Comment


                    • #40
                      Well, first you correct your indentation, and then you figure out how to break out of the outer for loop when you've placed the improvement.

                      Comment


                      • #41
                        Thanks J,

                        I knew it requireda break but couldn't get it working. Finally I did this:

                        Code:
                        //EMOD Visible Wonders 4-1-2006
                        	CityInfluenceIterator it(cityPos, m_sizeIndex); 
                        	for(it.Start(); !it.End(); it.Next()) {
                        		Cell *cell = g_theWorld->GetCell(it.Pos());
                        		if(cityPos == it.Pos())
                        				continue;
                        			sint32 s;
                        			bool SpotFound = true;
                        			for(s = 0; s < wrec->GetNumShowOnMap(); s++) {
                        				const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(s);
                        				if(!terrainutil_CanPlayerSpecialBuildAt(rec, m_owner, it.Pos())) {
                        					SpotFound = false;
                        					break;
                        				}
                        				if(!SpotFound){
                        					continue;
                        				} else {
                        					g_player[m_owner]->CreateSpecialImprovement(wrec->GetShowOnMapIndex(s), it.Pos(), 0);
                        					return;
                        				}
                        			}
                        	}
                        So finally it works. For now, I'm not going to have the imp removed if the wonder is destroyed (I guess they can serve as ruins for now)

                        the other code is useful for a future city expansion code though

                        thanks for the help
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • #42
                          D'oh

                          Ok it DOES NOT WORK

                          It just checks only one spot now and doesn't try to check anymore. I need it to keep checking like last time but only build one. how am i messing up this iterator?
                          Formerly known as "E" on Apolyton

                          See me at Civfanatics.com

                          Comment


                          • #43
                            First E, as John remarked get the indentation right. And than you have to do something like this:

                            For each tile check whether it is suitable for the tileimp in question. If the tile is good then store it. If there is already a tile stored and your current tile is better replace the old one wirth the new one.

                            Finally once you evaluated all the tiles, construct the improvement at the best position you have found.

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

                            Comment


                            • #44
                              Thanks Martin,

                              I guess thats how the slic handled it. Any chance the source code did this somewhere?
                              Formerly known as "E" on Apolyton

                              See me at Civfanatics.com

                              Comment


                              • #45
                                Originally posted by E
                                I guess thats how the slic handled it. Any chance the source code did this somewhere?
                                No chance, you have to do it on your own. However this isn't too difficuilt if you convert my words from my last post into pseudocode.

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

                                Comment

                                Working...
                                X