Announcement

Collapse
No announcement yet.

E's Source Code attempts

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

  • Originally posted by Martin Gühmann
    Than I can assume this, too. However I looked into the source code and it seemed that there they are filled in prperly. It might be a general problem with location and unit arraies in the message boxes. But that is a little bit hard to figure out. However you could figure out whether putting an army into the slic context works.
    will do. But i'm beginning to wonder if maybe some thing was missed when the patch was reimplemented. Maybe thats why the arrays aren't working with SLIC?

    Yes, we still need translators. By the way did you try the robot translation on my German text bit? Have some fun with robot translation.
    not yet I was messing with cleaning up my civ3 stuff

    Not really a custom ResourceDB, however there is some kind of resource map that contains good prbabilities or prices or whatever. That might be recomputed.
    I think my best bet starts with WrlEnv.cpp. But is it a MAX_GOOD issue? I thought about doing a g_ResourceDB->Num() in my enablesgood code but it caused crashes, and I'm not sure that would have been the solution. If you get a chance look at the code below and let me know if anything sticks out. I best bet was on the SetRandomGood code as i think it set the goods on the map but not sure where or how to change it. Maybe load all the enablesgoodIndex stuff from the tileimps and buildings too?


    EDIT: I think this might be it, it gets all the resources from the terrainDB and not the resourceDB right? Should add all the tileImp enablesgood too or am I off? I left the other code below.
    Code:
    sint32 Cell::GetGoodsIndex(sint32 &val) const
    {
        val = (m_env & k_MASK_ENV_GOOD);
        if (val == 0) {
            return FALSE;
    	} else {
    		val >>= k_SHIFT_ENV_GOOD;
    		val--;
    		while(val >= 0 && 
    			  (g_theTerrainDB->Get(m_terrain_type)->GetNumResources() <= val)) {
    			val--;
    		}
    		if(val < 0)
    			return FALSE;
    		return TRUE;
        }
    }
    Code:
    WrlEnv.cpp
    
    //------------------------------------------------------------------------
    
    ----
    //
    // Name       : World::GetGood
    //
    // Description: Checks whether the given location has a good.
    //
    // Parameters : const MapPoint &pos: Map position which 
    
    should be checked, 
    //                                   whether it has a good.
    //              sint32 &good:        Filled with the good database index 
    //                                   of the good at the map position.
    //
    // Globals    : g_theTerrainDB: The terrain database.
    //
    // Returns    : Whether the given location has a good.
    //
    // Remark(s)  : -
    //
    //------------------------------------------------------------------------
    
    ----
    BOOL World::GetGood(const MapPoint &pos, sint32 &good) 
    
    const
    {
    
    	sint32 i;
    	Cell *c = GetCell(pos);
    
    	if (c->GetGoodsIndex(i)) {
    		good= 
    
    g_theTerrainDB->Get(c->m_terrain_type)->GetResourcesIndex(
    
    i);
    		return TRUE;
    	} else {
    		return FALSE;
    	}
    }
    
    //------------------------------------------------------------------------
    
    ----
    //
    // Name       : World::GetGood
    //
    // Description: Checks whether the given location has a good.
    //
    // Parameters : Cell *cell:   Pointer on the cell for which should 
    
    be checked,
    //                            whether it has a good.
    //              sint32 &good: Filled with the good database index of 
    
    the good
    //                            in the cell.
    //
    // Globals    : g_theTerrainDB: The terrain database.
    //
    // Returns    : Whether the given location has a good.
    //
    // Remark(s)  : -
    //
    //------------------------------------------------------------------------
    
    ----
    BOOL World::GetGood(const Cell *c, sint32 &good) const
    {
    
    	sint32 i;
    
    	if (c->GetGoodsIndex(i)) {
    		good= 
    
    g_theTerrainDB->Get(c->m_terrain_type)->GetResourcesIndex(
    
    i);
    		return TRUE;
    	} else {
    		return FALSE;
    	}
    }
    
    void World::ClearGoods(const sint32 x, const sint32 y)
    {
    	m_map[x][y]->m_env &= ~k_MASK_ENV_GOOD ;
    }
    
    
    void World::SetGood(const sint32 x, const sint32 y, const sint32 
    
    g)
    
    { 
    	Assert(0<= x); 
    	Assert(xAccess(m_map[x][y]->m_terrain_type)->Get
    
    NumResources() <= g -1)
    		return; 
    	
    	switch(g) { 
    	case 0:   m_map[x][y]->m_env &= 
    
    ~k_MASK_ENV_GOOD; break;
    	case 1:   m_map[x][y]->m_env = 
    
    (m_map[x][y]->m_env & ~k_MASK_ENV_GOOD) | 
    
    k_BIT_ENV_GOOD1; break; 
    	case 2:   m_map[x][y]->m_env = 
    
    (m_map[x][y]->m_env & ~k_MASK_ENV_GOOD) | 
    
    k_BIT_ENV_GOOD2; break; 
    	case 3:   m_map[x][y]->m_env = 
    
    (m_map[x][y]->m_env & ~k_MASK_ENV_GOOD) | 
    
    k_BIT_ENV_GOOD3; break; 
    	case 4:   m_map[x][y]->m_env = 
    
    (m_map[x][y]->m_env & ~k_MASK_ENV_GOOD) | 
    
    k_BIT_ENV_GOOD4; break; 
    	default:
    		Assert(0); 
    	}
    #ifdef _DEBUG
    	
    	
    #endif
    }
    
    void World::SetRandomGood(const sint32 x, const sint32 y)
    {
    	double totalProb = 0;
    	double 
    
    prob[k_MAX_GOODS_TYPES_PER_TERRAIN];
    
    	Cell *cell = m_map[x][y];
    
    	sint32 i;
    	for(i = 0; i < 
    
    k_MAX_GOODS_TYPES_PER_TERRAIN; i++) {
    		
    
    if(g_theTerrainDB->Get(cell->m_terrain_type)->GetNumResour
    
    ces() > i) {
    			prob[i] = 
    
    g_theTerrainDB->Get(cell->m_terrain_type)->GetResources(i)-
    
    >GetProbability();
    			totalProb += prob[i];
    		} else {
    			prob[i] = 0;
    		}
    	}
    
    	Assert(totalProb <= 1.0);
    	totalProb = 0;
    	sint32 val = g_rand->Next(1000);
    	for(i = 0; i < 
    
    k_MAX_GOODS_TYPES_PER_TERRAIN; i++) {
    		if(val < (totalProb + prob[i]) * 1000) {
    			SetGood(x,y,i+1);
    			return;
    		}
    		totalProb += prob[i];
    	}
    }
    Last edited by Ekmek; March 25, 2006, 23:47.
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • Martin,

      I got the AllTerrainAsImprovement stuff wokrking as MoveBonus (finally). but I cant figure this out, I posted it also in ShowOnMap

      -----------------------------

      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


      • Originally posted by E
        I got the AllTerrainAsImprovement stuff wokrking as MoveBonus (finally).
        Maybe you could tell me what this MoveBonus should do, I found it in the unit.cdb. And in the code it just seems to do some strange stuff:

        Code:
        sint32 UnitData::DeductMoveCost(const Unit &me, const double cost, BOOL &out_of_fuel) 
        {
        
        	const UnitRecord *rec = g_theUnitDB->Get(m_type);
        
        	if(!Flag(k_UDF_PACMAN)) {
        
        			m_movement_points -= cost;
        			m_movement_points = std::max(m_movement_points, 0.0);
        			ClearFlag(k_UDF_FIRST_MOVE);
        	}
        
        
        
        	out_of_fuel = FALSE; 
        	if (!rec->GetNoFuelThenCrash()){ 
        		return FALSE; 
        	} else {
        		m_fuel -= g_theConstDB->NonSpaceFuelCost();
        
        		if (m_fuel <= 0) {
        			CheckForRefuel();//refuel the unit if it's in a city, airbase, or being transported
        
        			if(m_fuel <= 0) { //refuelling failed, it's NoFuelThenCrash
        				out_of_fuel = TRUE;
        			
        				if(g_player[m_owner]->GetPlayerType() != PLAYER_TYPE_ROBOT ||
        				  (g_network.IsClient() && g_network.IsLocalPlayer(m_owner))) {
        					m_army.AddDeath(Unit(m_id), CAUSE_REMOVE_ARMY_OUTOFFUEL, -1);
        				}
        
        				m_movement_points = 0;
        				return TRUE; 
        			}
        		}
        	}
        [b]
        	sint32 bonus;
        	if(rec->GetMoveBonus(bonus)) {  //EMOD
        		m_movement_points -= bonus;
        	} else {
        		m_movement_points -= cost;
        	}
        	[/b]
        	return FALSE;
        }
        By the way I already fixed it a little bit but still it does not do much sense. The old version just deducted one move point now it deducts always the same amount of movepoints regardless of the terrain. Is that what you really want?

        Second problem:

        Code:
        bool CityData::HasTileImpInRadius(sint32 tileimp, MapPoint &cityPos) 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());
        	
        		if(cell->GetDBImprovement(tileimp) > 0)[b];[/b]
        			return true;
        	}
        	return false;
        }
        What is this you add an semicolon after an if statement and put nothing before it. So what does do this little piece of code?

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

        Comment


        • Originally posted by Martin Gühmann
          By the way I already fixed it a little bit but still it does not do much sense. The old version just deducted one move point now it deducts always the same amount of movepoints regardless of the terrain. Is that what you really want?
          Yes. the move bonus code is supposed to be like AllTerrainAsRoad in Civ2 and Civ3. If you recall, that flagwould only cost 1/3 no matter what terrain the unit moved on, like there is a road there. this movebonus is like that except instead of forcing it to only be roads, I figured having a value as a movebonus a modder could specify roads (by giving it 33 just like roads have) or 20 for rail roads or different values to differentiate.

          So yes thats what I want. Thanks for fixing it.




          Second problem:

          Code:
          bool CityData::HasTileImpInRadius(sint32 tileimp, MapPoint &cityPos) 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());
          	
          		if(cell->GetDBImprovement(tileimp) > 0)[b];[/b]
          			return true;
          	}
          	return false;
          }
          What is this you add an semicolon after an if statement and put nothing before it. So what does do this little piece of code?

          -Martin
          I might have slipped on the semi colon. This coed was an attempt to do a check of a city radius for any tileimp in there, kind of like looking for a good in a radius.

          This was going to be a check for showOnMap and I was thinking that it could later be used for stuff like nuclear weapons, where you have to have a weapons lab tileimp in order to build hem and the AI 9or you) may try to pillage or bomb it to prevent nukes.
          Formerly known as "E" on Apolyton

          See me at Civfanatics.com

          Comment


          • Actually I asked you what the code does with the semicolon in, not what it was supposed to do.

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

            Comment


            • it just returns true if the tileimp is in that cell (thereby its greater than zero). But I figure I can just leave it as a bool.
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • Originally posted by E
                it just returns true if the tileimp is in that cell (thereby its greater than zero). But I figure I can just leave it as a bool.
                No, that is what it is supposed to do, and would do without the semicolon, so what does the code with the semicolon at that place?

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

                Comment


                • i guess does nothing
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • Originally posted by E
                    i guess does nothing
                    No, it does something else. And I think you have to understand this. So what does it?

                    Oh and I found anther piece of code:

                    Code:
                    			sint32 pop;
                    			for (pop = 0; pop < u.GetDBRec()->GetPopCostsToBuild(); ++pop) {
                    				if(u.GetDBRec()->GetPopCostsToBuild(pop) > 0) {
                    					cd->SubtractAccumulatedFood(static_cast(g_theConstDB->CityGrowthCoefficient()));
                    					cd->ChangePopulation(-pop);
                    				}
                    			}
                    I took the freedom to turn it into something like this:

                    Code:
                    			sint32 pop;
                    			if(u.GetDBRec()->GetPopCostsToBuild(pop)) {
                    				cd->SubtractAccumulatedFood(static_cast(g_theConstDB->CityGrowthCoefficient()));
                    				cd->ChangePopulation(-pop);
                    			}
                    So what is the difference between those two pieces of code? By the way did you check whether building such a unit that costs 2 pops does not make the parent city disband?

                    -Martin

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

                    Comment


                    • with > I think it changes it from a simple false true bool to a 0 or 1 bool?


                      as foor popcost. I had that check in there, well I tried. but I got stuck on trying to get the pop-up message to trigger right. but with your code changes I'll try again because I think that was the reason why I wasnt able to trigger the pop-up

                      PS I'm glad to see you had some time to devote to CtP2
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • Originally posted by E
                        with > I think it changes it from a simple false true bool to a 0 or 1 bool?
                        Nope, the result is something else. Remember what I told you about ifs (well also about fors and whiles): An if only works on the following statement, you can combine statements by putting them into brackets. But you didn't do this here. And the second thing about statements is that they are closed by a semicolon.

                        So you have an if that works on the next statement and right there is a semicolon. So what happens.

                        Originally posted by E
                        as foor popcost. I had that check in there, well I tried. but I got stuck on trying to get the pop-up message to trigger right. but with your code changes I'll try again because I think that was the reason why I wasnt able to trigger the pop-up
                        I doubt that my code changes do the trick in fact I asked you about the differences of the two pieces of code. For instance we have the functionality of the code and we have the complexity of the code which I would like o messure in this case by the number of lines. As a hint there is only a difference in one of these two aspects.

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

                        Comment


                        • By the way E what does GetDBImprovement do?

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

                          Comment


                          • based on this

                            Code:
                            sint32 Cell::GetDBImprovement(sint32 index) const
                            {
                            	if(!m_objects)
                            		return -1;
                            
                            	sint32 i, c = 0;
                            	for(i = m_objects->Num() -1; i >= 0; i--) {
                            		if((m_objects->Access(i).m_id & k_ID_TYPE_MASK) == k_BIT_GAME_OBJ_TYPE_IMPROVEMENT_DB) {
                            			if(c == index) {
                            				return m_objects->Access(i).m_id & k_ID_KEY_MASK;
                            			}
                            			c++;
                            		}
                            	}
                            	return -1;
                            }
                            I thought it returns the tileimprovemnt in the cell

                            So you have an if that works on the next statement and right there is a semicolon. So what happens.
                            ok, not sure. I don't think it crashes so my next guess would be that it either ignores the following statement or it just goes on to the next statement whether its true or false.

                            I asked you about the differences of the two pieces of code
                            it was abpout populating the value of the sint32 and the for only adds value of one where as your second piece of code populates it with the db text file's value
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • Originally posted by E
                              I thought it returns the tileimprovemnt in the cell
                              Well I thought this as well but if I look on the code I am not so sure. However this is not the problem here. The real problem is what is the input. What does mean the input.

                              Originally posted by E
                              ok, not sure. I don't think it crashes so my next guess would be that it either ignores the following statement or it just goes on to the next statement whether its true or false.
                              So you have to decide, what happens if the following statement that is under the control of the if is empty. That is what basicly stands there. And imediately following semicolon that marks the end of an statement, that contains in this case nothing.

                              Originally posted by E
                              it was abpout populating the value of the sint32 and the for only adds value of one where as your second piece of code populates it with the db text file's value
                              Not quite. What does return GetPopCostsToBuild()? Maybe this brings you a little bit closer.

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

                              Comment


                              • Outcommented AI gold cheat. This should be an option for modmakers and nothing else. The AI has to hande the gold stuff properly and if it can't then it must be modified so that it can.
                                modified ctp2_code/gs/gameobj/CityData.cpp
                                Any recommendations on how to make this optional? The difficulty db doesnt look the same as the other and I'm hesitant to make it a flag there or in Const.cdb since it might further complicate backwards compatibility. I guess I could make it a "AIDeficitSpending' flag for a building...


                                Removed double call of CityData::AddWonder, this method is already called in Player::AddWonder:
                                modified ctp2_code/gs/gameobj/CityEvent.cpp
                                Are you sure about this? Looking at player it does assign the wonder to the city but not the same way addimprovement does for a biulding in citydata.

                                My add borders code doesn't activate without citydata::addwonder called in the cityevent. Thats how I got it to work with my buildings and not it doesn't work. So i think I wasn'tthat off unless you think it should go into player (I doubt it because it doesn't address generate borders) and putting it in cityevent.cpp also I had problems with.
                                Formerly known as "E" on Apolyton

                                See me at Civfanatics.com

                                Comment

                                Working...
                                X