Announcement

Collapse
No announcement yet.

Limiting City placement/terrain specific cities

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

  • #46
    OK, here is the final version:

    Code:
    BOOL UDUnitTypeCanSettle(sint32 unit_type, const MapPoint &pos) 
    {
    #if defined(ACTIVISION_ORIGINAL)
    	sint32 searching = TRUE;    
    	const UnitRecord *rec = g_theUnitDB->Get(unit_type);   
      	sint32 t = rec->GetSettleCityTypeIndex();
    
    	if (t < 0) {
    		return FALSE; 
    	}
    
    	if (g_theUnitDB->Get(t)->GetHasPopAndCanBuild() == FALSE) {
    		return FALSE; 
    	}
    
    	if (g_theWorld->HasCity(pos)) 
    		return FALSE; 
    
    	if (rec->GetSettleLand() && g_theWorld->IsLand(pos))
    		searching = FALSE; 
    	else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos))
    		searching = FALSE; 
    	else if (rec->GetSettleWater() && g_theWorld->IsWater(pos))
    		searching = FALSE; 
    	else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos))
    		searching = FALSE; 
         
    	if (searching) 
    		return FALSE; 
    
    	return TRUE; 
    #else
    	sint32 i;
    	const UnitRecord *rec = g_theUnitDB->Get(unit_type);   
    	sint32 t = rec->GetSettleCityTypeIndex();
    	if (t < 0) {
    		return FALSE;      
    	}
    	if (g_theUnitDB->Get(t)->GetHasPopAndCanBuild() == [b]FALSE[/b]) {
    		return FALSE;                               
    	}
    	if (g_theWorld->HasCity(pos)) 
    		return FALSE;
    
    	for(i = 0; i < rec->GetNumCanSettleOn(); i++) {
    		if(rec->GetCanSettleOnIndex(i) == [b]g_theWorld->GetCell(pos)->GetTerrain()[/b]) {
    			return TRUE;
    		}
    	}
    
    	if (rec->GetSettleLand() && g_theWorld->IsLand(pos))
    		return TRUE; 
    	else if (rec->GetSettleMountain() && g_theWorld->IsMountain(pos))
    		return TRUE; 
    	else if (rec->GetSettleWater() && g_theWorld->IsWater(pos))
    		return TRUE; 
    	else if (rec->GetSettleSpace() && g_theWorld->IsSpace(pos))
    		return TRUE;
    	
    	return FALSE;
    #endif
    }
    In bolt the changes. The first change is a change that replaces a TRUE by a FALSE, and restores the original code at that place.

    The consequence of this non-original code was that all the units with the flag HasPopAndCanBuild can't settle a city even if they meet all the other criteria. unfortunatly all and only all settle units have this flag. The consequence is that no settler was able to settle.

    The other change is a chnge to make the code compile, in this function there is no pointer on a Cell object defined with the name cell. To get such a pointer you can use g_theWorld->GetCell(pos) if pos is a valid MapPint object.

    Since I was modifying this file anyway I corrected the comments a little bit.

    In unit.cdb I replaced

    Int UnitUpkeep by
    Bit(Int) GoldHunger

    The name GoldHunger makes it coherent with the other hunger flags, ShieldHunger and FoodHunger, and the Bit makes it optional so that you don't have to add it, to unit.txt so that CTP2 doesn't complain about it if it is missing.

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

    Comment


    • #47
      Thanks Martin! And GoldHunger is something I need to get back on and just a initial look its going to affect a lot of files and I think there should be a modification to the display so that you can know your unit cost...
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • #48
        concerning the Bug that the game uses urban planners as the starting unit and not settlers, I think it has something to do with CanSettle and the game looks to see if a unit has a Settle: (terrain) flag and identifies that as a settler and my CansettleOn flag is excluded. as a possibility should we make a reference here:

        Code:
         armydata.cpp
        BOOL ArmyData::CanSettle(const MapPoint &pos) const
        {
            sint32 i; 
            
            for (i=0; iIsValid(m_array[i]));
                if( g_theUnitPool->IsValid(m_array[i]) && g_theUnitDB->Get(m_array[i].GetType())->GetSettle() &&
        			m_array[i].CanPerformSpecialAction())
                    return TRUE;
            }
            return FALSE;
        }
        or here:
        Code:
         unit.cpp
        BOOL Unit::CanSettle(const MapPoint &pos) const
        {
            return GetData()->CanSettle(pos); 
        }
        or do you think it could be elsewhere or defined differently?
        Formerly known as "E" on Apolyton

        See me at Civfanatics.com

        Comment


        • #49
          I think you have to do something with the first code fragment and for the second one you need to have a deeper look at the CanSettle function there, if it is one of UnitData. But actual there is a third place that might be valuable to investigate.

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

          Comment


          • #50
            I think it might be worthwhile to allow the unit(s) given at game start to be specified elsewhere (Probably in DiffDB.txt), so that modders can avoid worrying about this sort of problem, and only fall back on the existing system if that specification is absent.

            This would also allow "deathmatch" style scenarios to be more easily designed where the players used only military units and not settlers. I'm sure there are other applications too.

            Comment


            • #51
              J, good point, I'll check out DiffDB when I can.
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • #52
                So E, is your compiler up and running so that we can fix this?

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

                Comment


                • #53
                  Unfortunately No. I haven't devted enough time yet. I did look at my program and a little confused on how to compile since I haven't done it before (well along time ago with Turbo Pascal doesn't count).

                  I was looking for a main.cpp to use to compile, most stuff in my book are only 3 or 4 file programs. Any hints on what I need to do? Do I have load all files into the project (it does one at a time I think) or is there a main file somewhere that rund what to include and know what directories to go to?
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • #54
                    Originally posted by E
                    I was looking for a main.cpp to use to compile, most stuff in my book are only 3 or 4 file programs. Any hints on what I need to do? Do I have load all files into the project (it does one at a time I think) or is there a main file somewhere that rund what to include and know what directories to go to?
                    No need for a main.cpp. If you have have installed some "demo" version of MS VC++ (and not VBasic as you told me) then you just need to double click on the file civctp.dsw and the Visual Studio opens this project file. And then you can use the IDE to edit the files and of course to compile and link the files.

                    Of course to compile and link the files you need DirectX installed.

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

                    Comment


                    • #55
                      Martin,
                      The program I'm using is Dev C++ 4.9.8.0 It did open up the civctp.dsw so hopefully this weekend I'll get time to mess around with compiling.
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • #56
                        Originally posted by E
                        Martin,
                        The program I'm using is Dev C++ 4.9.8.0 It did open up the civctp.dsw so hopefully this weekend I'll get time to mess around with compiling.
                        That will be a hard piece of work. So far we were only be able to compile the source code on VC++ 6 and 7. As the compiler used by DevC++ is a gcc windows port we can expect some problems as the Linux guys have as well.

                        Well you should open then a thread about compiling with DevC++ in the source code forum.

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

                        Comment


                        • #57
                          hmmm I'll try to scrounge a copy ov VC++ then...

                          but I wil give DevC++ a shotthis weekend.
                          Formerly known as "E" on Apolyton

                          See me at Civfanatics.com

                          Comment


                          • #58
                            Well actual our goal is to make the game to compile on as many compilers as possible, so we need this as well. But one problem I see are the differences between intel and AT&T assembler code. Probably not a problem that can't be solved, but actual I prefere a system independent solution for these assempler pieces.

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

                            Comment


                            • #59
                              Well this is a VERY old thread but since my can settle on code also appears to be affected I notice that the Ai just sits settlers in places it cant build if you simply remove original activision stuff like settle:mountain. So its an AI bug. I tried to mess with scores but it still doesnt solve it because the scores just calculate the whole area and not the center the square SO I havent compiled or tested this yet but taking stuff from above I'm thinking of doing this:


                              Code:
                              double SettleMap::ComputeSettleValue(const MapPoint & pos) const
                              {
                              	sint32 score = 0;
                              	RadiusIterator it(pos, k_minimum_settle_city_size);
                              
                              	for (it.Start(); !it.End(); it.Next()) 
                              	{
                              		const Cell * cell = 
                              
                              g_theWorld->GetCell(it.Pos());
                              		score += cell->GetScore();
                              	}
                              //EMOD to allow for AI notto settle some places
                              //	If Unit Get SettleType 
                              //		GetCell(pos) != settletype
                              //		score = 0;
                              //EMOD
                                sint32 i;
                              	const UnitRecord *rec = g_theUnitDB->Get(unit_type); 
                              	for(i = 0; i < rec->GetNumCanSettleOn(); i++) {
                              		if(!rec->GetCanSettleOnIndex(i) == 
                              
                              g_theWorld->GetCell(pos)->GetTerrain()) {
                              			score = 0;
                              		}
                              	}
                              // end EMOD
                              
                              	if !(rec->GetSettleLand() && g_theWorld->IsLand(pos))
                              		score = 0; 
                              	else if (rec->GetSettleMountain() && 
                              
                              g_theWorld->IsMountain(pos))
                              		score = 0; 
                              	else if (rec->GetSettleWater() && 
                              
                              g_theWorld->IsWater(pos))
                              		score = 0; 
                              	else if (rec->GetSettleSpace() && 
                              
                              g_theWorld->IsSpace(pos))
                              		score = 0;
                              //end EMOD
                              	return score;
                              }
                              of course the settlemap.cpp doesnt take unis into affect so I think I might have to connect the dots on that.
                              Formerly known as "E" on Apolyton

                              See me at Civfanatics.com

                              Comment


                              • #60
                                Originally posted by E
                                Code:
                                //EMOD to allow for AI notto settle some places
                                //	If Unit Get SettleType 
                                //		GetCell(pos) != settletype
                                //		score = 0;
                                //EMOD
                                  sint32 i;
                                	const UnitRecord *rec = g_theUnitDB->Get(unit_type); 
                                	for(i = 0; i < rec->GetNumCanSettleOn(); i++) {
                                		if(!rec->GetCanSettleOnIndex(i) == 
                                
                                g_theWorld->GetCell(pos)->GetTerrain()) {
                                			score = 0;
                                		}
                                	}
                                // end EMOD
                                That looks wrong. From visual inspection, the only way the score can avoid being reset to 0 is if the current terrain type is the only terrain type upon which the settler can settle. That's not what you want.

                                Comment

                                Working...
                                X