Announcement

Collapse
No announcement yet.

E's Source Code attempts

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

  • #16
    Code:
    	if(rec->GetNumNeedsCityGood() > 0) {
    		sint32 s;
    		bool found = false;  //not needed?
    		for(s = 0; s < rec->GetNumNeedsCityGood(); s++) {
    			if(HasResource > 0) {
    			rec->GetNeedsCityGood(s) == m_collectingResources->HaveGoodOfType() { //from CityData::CityRadiusFunc and SlicContext::HaveGoodOfType
    				found = true;
    				break;
    			}
    		}
    	
    	}
    		if(!found) //not needed?
    			return FALSE;
    I didn't see anything in the resources.h class but did find the HaveGoodOfType. I just updated my svn so I havent put this in a code, and if you check it out I'd appreciate. But after doing a playtest I think resources should go down on my priority and I made a big effort to try and code how upgrade mght work which I'll post next.
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • #17
      UPGRADE UNITS

      Okay I made my best atempt and I probably took on more than I should of, but I hope there is a consensus in the community that this should be a standard part of the game. Also I made it for unitdata, but it might go in armydata, not too sure but I didn't put it in city because maq would like to have units and tiles, etc that upgrade. but as it stands now i set up to do cities. I know I could just add and compile it myself but I hope I could get a look over to minimize any syntax errors or anything else before I get into the big stuff.


      anyways (I hope it fits) here's what I tried:

      Code:
      //----------------------------------------------------------------------------
      //
      // Name       : UnitData::GetUpgradeCost
      //
      // Description: Checks whether if player has gold to upgrade a unit
      //
      // Parameters : 
      //
      // Globals    : g_player:     The list of players
      //              g_theUnitDB:  The unit database
      //              g_theGovernmentDB: The government database
      //
      // Returns    : upgradegold; the amount of gold it will cost to upgrade
      //
      // Remark(s)  : used to see if a player CanUpgrade and to subtract cost
      //
      //----------------------------------------------------------------------------
      sint32 UnitData::GetUpgradeCost() //from sint32 CityData::GetOvertimeCost() 
      {
      	const GovernmentRecord *grec = g_theGovernmentDB->Get(g_player[m_owner]->m_government_type); //can I use in a sint32?
      	const UnitRecord *rec = g_theUnitDB->Get(type);	
      	Player *  player = g_player[m_owner];  //from bool CityData::PayForBuyFront()
      
      sint32 oldunit = rec->GetShieldCost();
      sint32 upgradeunit = rec->upgradeto()->rec->GetShieldCost();
      sint32 upgradegold = upgradeunit - oldunit * grec->GetCapitalizationCoefficient();
       	if ((player->GetGold() < upgradegold)) //from CityData::PayForBuyFront  rushbuy function
      	{
      		return false;
      	}
      
      	if(upgradegold < 0)
      		upgradegold = 0;
      	return upgradegold;
      }
      
      //----------------------------------------------------------------------------
      //
      // Name       : UnitData::CanUpgrade
      //
      // Description: Checks whether a player can upgrade a unit in a city
      //
      // Parameters : type: The unit type for that is checked whether the city can 
      //              build it.
      //
      // Globals    : g_player:     The list of players
      //              g_theUnitDB:  The unit database
      //              g_theBuildingDB: The building database
      //              g_theWorld:   The world properties
      //
      // Returns    : Whether the player can upgrade the unit specified by type.
      //
      // Remark(s)  : attempted by E
      //
      //----------------------------------------------------------------------------
      
      BOOL UnitData::CanUpgrade (const UnitRecord *rec, sint32 type, const MapPoint &pos) // not sure I need this stuff in parentheses
      {
      	const UnitRecord *rec = g_theUnitDB->Get(type);	
      	const BuildingRecord* irec = g_theBuildingDB->Get(type);
      
      	MapPoint pos;
      	GetPos(pos);
      	Cell *cell = g_theWorld->GetCell(pos);
      
      //Checks if unit position is a city
      if(!g_theWorld->GetCity(pos).IsValid())
      		return FALSE;
      
      
      //checks if player can build the unit they want to upgrade to
      	Assert(m_city_data);  //not sure what assert does but I guess it calls citydata from the city the unit is in
      	if(rec->GetUpgradeTo() > 0) {
      		sint32 i
      		for(i = 0; i < rec->GetUpgradeTo(); i++) {
      			if(rec->GetUpgradeTo(i) == m_city_data->CanBuildUnit() {
      				if(m_city_data->GetEffectiveBuildings(irec->CanUpgradeUnits)>0)
      			} 
      		}  return FALSE
      	}
      
      
      //HasGold
      	Player *	player	= g_player[m_owner];  //from bool CityData::PayForBuyFront()
      	sint32 const	upgradegold  = GetUpgradeCost();
      	if ((player->GetGold() < upgradegold))
      	{
      		return FALSE;
      	}
      
      	return TRUE;
      }
      
      
      
      //----------------------------------------------------------------------------
      //
      // Name       : UnitData::PayForUpgrade
      //
      // Description: Subtracts upgrade cost from player gold
      //
      // Parameters : 
      //
      // Globals    : g_player:     The list of players
      //              g_theUnitDB:  The unit database
      //
      // Returns    : subtracts the amount of gold it will cost to upgrade
      //
      // Remark(s)  : 
      //
      //----------------------------------------------------------------------------
      
      
      bool UnitData::PayForUpgrade()
      {
      	Player *	player	= g_player[m_owner];  
      	sint32 const	upgradegold  = GetUpgradeCost();
      
      	if ((player->GetGold() < upgradegold))
      	{
      		return false;
      	}
      
      	player->SubGold(upgradegold); //from bool CityData::PayForBuyFront()
      	//player->m_gold->AddLostToRushBuy(upgradegold); //not needed
      
      	//m_paidForBuyFront = true;  //not needed??
      
      	return true;
      }
      }
      
      
      
      
      // the following code is mostly incomplete (more so than the above)
      BOOL Player::UpgradeUnit(sint32 type)
      {
      
      	const UnitRecord* rec = const UnitRecord *rec = g_theUnitDB->Get(m_array[i].GetType(), g_player[GetOwner()]->GetUpgradeTo(t) //fromPlyer::CreateUnit
      
      	sint32 t
      		
      	if(!CanUpgradeUnit(type) {
      		if(rec->upgradeto() > 0 ) {g_player[m_owner]->CreateUnit(const sint32 t, 
                             							 const MapPoint &pos, 
                              						const Unit hc,
                              						BOOL tempUnit, 
                             							 CAUSE_NEW_ARMY cause)
      		{
      		return FALSE;
      
      	if(g_network.IsClient() && g_network.IsLocalPlayer(m_owner)) { //I guess this is multiplayer?
      		g_network.SendAction(new NetAction(NET_ACTION_BUILD, type, m_home_city));
      	} else if(g_network.IsHost()) {
      		g_network.Block(m_owner);
      		g_network.Enqueue(new NetInfo(NET_INFO_CODE_BUILDING_UNIT,
      		                  type, (uint32)m_home_city));
      		g_network.Unblock(m_owner);
      	}
      
      		ArmyData::Disband() //I still need to figure how to remove the old unit but don't add shields... 
      {
      		PayForUpgrade();
      		return FALSE; 
      	}
      }
      
      
      
      // CityWindow this still needsto be coded
      
      // this still needs to be coded for unit control anel
      
      // how AI handles it. I think  BeginTurnEven->UpgradeAll AI Units for free will keep them competive or maybe just take as much gold as it can?
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • #18
        Originally posted by E
        But after doing a playtest I think resources should go down on my priority and I made a big effort to try and code how upgrade mght work which I'll post next.
        I disagree. This resource thing is easier than the update thing.

        Again some question that you have now to answer before you code anything or before I review anything:

        What does the CityData::HasResource method do?
        What type of is its parameter.
        What does represent this parameter? What does it mean?
        What does it return?
        What is the meaning of its return value?

        What does the ResourceRecord::GetNeedsCityGood method do?
        What type of is its parameter.
        What does represent this parameter? What does it mean?
        What does it return?
        What is the meaning of its return value?

        And what is your code supposed to do?

        Answer all these questions and then you should be able to use these functions.

        (I am sorry E. But I think I must now do the hard way otherwise you won't move a milimeter. )

        Originally posted by E
        I didn't see anything in the resources.h class but did find the HaveGoodOfType.
        You shouldn't mess around with this class.

        Originally posted by E
        I just updated my svn so I havent put this in a code, and if you check it out I'd appreciate.
        Who cares about whether you update your working copy or not, actual TortoiseSVN can merge your code into the latest revision without any problems and if not you can merge the files manually. You are asked whether this piece of code should be taken from your copy or from their copy.

        Originally posted by E
        I know I could just add and compile it myself but I hope I could get a look over to minimize any syntax errors or anything else before I get into the big stuff.
        E you have a compiler to fix all the missing braces, brackets and parentheses. So that's not my task.

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

        Comment


        • #19
          Originally posted by Martin Gühmann
          I disagree. This resource thing is easier than the update thing.

          Again some question that you have now to answer before you code anything or before I review anything:

          What does the CityData::HasResource method do?
          What type of is its parameter.
          What does represent this parameter? What does it mean?
          What does it return?
          What is the meaning of its return value?

          What does the ResourceRecord::GetNeedsCityGood method do?
          What type of is its parameter.
          What does represent this parameter? What does it mean?
          What does it return?
          What is the meaning of its return value?

          And what is your code supposed to do?

          Answer all these questions and then you should be able to use these functions.
          Thanks Martin I know most of the answers to the questions and I've basically gone to the breakit and try to fix it method to quoting, on my 6+ attempt to compile the NeedsCityGood code.

          The compiler kicks it back, i dig into the code for another way to answer, etc etc. the thing I keep bumping into is that most of citydata just looks for a good COUNT, like the HasResource function does.

          BUt thanks for the help, the compiler helps out alot though.

          I've tried a few things and most recent was this:
          Code:
          	// Added by E - Compares Unit NeedsGood to the City's resource
          	if(rec->GetNumNeedsCityGood() > 0) {
          		sint32 s;
          		sint32 good;
          		bool found = false;  //not needed?
          		for(s = 0; s < rec->GetNumNeedsCityGood(); s++) {
          			if(rec->GetNeedsCityGoodIndex(s) == GetGoodCountInRadius(good)) { 
          				found = true;
          				break;
          			}
          		}
          		if(!found) 
          			return FALSE;
          	}
          but I got this when compiling
          Code:
          F:\SVN-Code\trunk\ctp2_code\gs\gameobj\CityData.cpp(4839) : error C2662: 'GetGoodCountInRadius' : cannot convert 'this' pointer from 'const class CityData' to 'class CityData &'
                  Conversion loses qualifiers
          And know it has something to with:
          Code:
          sint32 CityData::GetGoodCountInRadius(sint32 good)
          {
          	m_cityRadiusOp = RADIUS_OP_COUNT_GOODS;
          	m_tempGood = good;
          	m_tempGoodCount = 0;
          	MapPoint pos;
          	m_home_city.GetPos(pos);
          	CityRadiusIterator(pos, this);
          	return m_tempGoodCount;
          }
          
          void CityData::AddGoods(SlicObject *obj)
          {
          	m_tempGoodAdder = obj;
          	m_cityRadiusOp = RADIUS_OP_ADD_GOODS;
          	MapPoint pos;
          	m_home_city.GetPos(pos);
          	CityRadiusIterator(pos, this);
          }
          where the GetGoodCountInRadius returns a count, the same problem with HasResource.

          Early I tried inserting a cityradius iterator to find goods then compare etc but that ended up causing a lot of problems. Since I cant get around the counting of goods thing, my next two approaches are to:
          a) try the city iterator approach again
          b) creeate a new function that just returns thegood and then call it to compare against

          if you are online stop me if you got a better suggestion...
          Last edited by Ekmek; July 30, 2005, 23:50.
          Formerly known as "E" on Apolyton

          See me at Civfanatics.com

          Comment


          • #20
            Originally posted by E
            Thanks Martin I know most of the answers to the questions
            The problem is that you don't know all the answers. And the other possible problem might be that you don't know the correct answers. Unfortunately I cannot check whether the answers you know are correct as long as you don't post them. So to write it out explicitly: Post the answers to the questions, so that I can correct you if you're wrong. Otherwise you'll never reach the finish line. Questioning your asumptions is a good debug strategy by the way. That's something you have always to do as a programmer.

            Apart from that the HasResource method should point you into the right direction. That's why I ask the questions what should your code do and what does the HasResource method do.

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

            Comment


            • #21
              Well the radius stuff has been working. the 'this' pinter is matching with class CityData. Ive tried a few other things with the iterator and its just not going. The closest I got was where it just said 'good' is not identified.

              I'm leaning towarda function that does the iterator and then having an array that stores the good and then compare the good.

              am I on the right path? Is there sme other functions I should be looking at that might call what I need?
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • #22
                1) What does the CityData::HasResource method do?
                The HasResource only returns a positive value if the city is collecting. It does not identify the resource from what I assume.

                2)What type of is its parameter.
                its a sint32

                3)What does represent this parameter? What does it mean?
                Its parameter is 'resource', which is the value of colecting resources. I don't think its stating the resource name only the quantity

                4)What does it return?
                By looking at the function it returns if the city is collecting more resources than it is selling

                5)What is the meaning of its return value?
                the return value appears to say that the city is collecting more than its selling


                6)What does the ResourceRecord::GetNeedsCityGood method do?
                I don't think ResourceRecord::GetNeedsCityGood exists (didnt see it in a search though it would be nice). But I'm assumingyou mean CityData:GetNeedsCityGood. It compares the good listed in the Unit.txt NeedsCityGood to the good that is located in a City'sradius, atleast thats what I want it to do.

                7)What type of is its parameter.
                Its a sint32. but NeedsCitygOod is in ::CanBuildUnit where it also has a sint32 'type'

                8)What does represent this parameter? What does it mean?
                the sint32 in NeedsCityGood is to represent the value of the good listed in the unit.txt. ::CanBUildUnit's sint32 type is for the type of unit.

                9)What does it return?
                The parameter should return the good name.
                What is the meaning of its return value?

                10) And what is your code supposed to do?
                The code should be a bool if the unit can be built or not if the city has a good in its radius (or is receiving it from trade ideally) and if that good matches the one listedin the unit.txt
                Formerly known as "E" on Apolyton

                See me at Civfanatics.com

                Comment


                • #23
                  Well I see why you don't make progress. Question 2 is correct. I can except answer 7 but of course you have to use your compiler to regenerate ResourceRecord.h and ResourceRecord.cpp so that it contains these functions. So your answer is only a guess but a correct one. Answer 5 is correct, answer 4 is the same is answer 5 but I was rather behind the return type of the function.

                  Fortunately you figured out that it should be GetNeedsCityGoodIndex instead of GetNeedsCityGood, so answer the questions 6 to 10 for this method again.

                  And don't confuse question 11 and 10 again, you forgot to answer question 10 and renamed question 11 to 10.

                  But anyway, answer 11 is correct. Of course you should know what you are trying to do. And that is the only question that allows some alternative answers, depending on what you want to do.

                  But these other questions need a better answer and as I want to make you to use your brain I ask you some more questions:

                  What is the consequence of answer 11 to the HasResource method. Can you use it?
                  What is a resource database index?
                  What does represent it?
                  How do you use it?
                  And of course rethink the answers to the other questions. And of course post these answers.

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

                  Comment


                  • #24
                    Originally posted by E
                    6)What does the ResourceRecord::GetNeedsCityGood method do?
                    I don't think ResourceRecord::GetNeedsCityGood exists (didnt see it in a search though it would be nice). But I'm assumingyou mean CityData:GetNeedsCityGood.
                    Well E, I am sorry you are right about the existence of the ResourceRecord::GetNeedsCityGood method it doesn't exist and it won't exist. The correct method should be UnitRecord::GetNeedsCityGoodIndex. But You can't expect that I still know every little detail after quite a month. Therefore I expect your answers within this day. Just to make sure that we will arrive the finish line. This task isn't so difficuilt.

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

                    Comment


                    • #25
                      I looked for the NeedsCityGoodIndex, but it still shows the UnitRecord as an array and not index so I guess I have to change the cdb.

                      I'm still digging through how the good index is called but I'll get the answers as soon as I can
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • #26
                        Originally posted by E
                        I looked for the NeedsCityGoodIndex, but it still shows the UnitRecord as an array and not index so I guess I have to change the cdb.

                        I'm still digging through how the good index is called but I'll get the answers as soon as I can
                        I see you decided just to allow the unit to require one single good. Well that changes of course the code. However is it what you want to make modders to pick one good and not all good of a certain lists or not one good from a certain list.

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

                        Comment


                        • #27
                          Well E, since I came to the conclusion that you need some pressure, here is my question :

                          Were are the answers.

                          Well to give you a little you should open the goods.txt and read the comments to each good, to get an idea what could be a resource database index. Well Actual I wanted to tell you to consider common sense of index, but unfortunately there are so many different common snses of it, that I would tell you the solution if I would try to give you the hint to select the correct one.

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

                          Comment


                          • #28
                            Originally posted by Martin Gühmann
                            Well E, since I came to the conclusion that you need some pressure, here is my question :

                            Were are the answers.

                            Well to give you a little you should open the goods.txt and read the comments to each good, to get an idea what could be a resource database index. Well Actual I wanted to tell you to consider common sense of index, but unfortunately there are so many different common snses of it, that I would tell you the solution if I would try to give you the hint to select the correct one.

                            -Martin

                            thanks Martin. I didnt need the pressuire though I was trying to do some research in my C++ book to give you good/better answers. The hard part is that I see resource is a sint32 and I was searching for a sint32 but I seem not able to call the good from the array, atleast from what I see. I did go through the ResourceRecord and UnitRecord. But notice that the index doesn't call the name/type of good, even though I called in my RestrictedToGood code.

                            The other thing is that the iterator has a "this" pointer that wouldnt match up to what I was calling. It is used to get a good in a radius but its not the same "this" thats called in the CanBuildUnit code. So I had problems knowing how to call the right one. So I'll dig a bit than give you something later tonight.
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • #29
                              Ok in digging to try to get good answers for you I figured that I should research betterhow the code already uses HasResource. Looking at I *think* that where as my oriiginal assumption was that hasresource simply returned if you are colecxting a resource, i *think* now that the HasREsource function checks if a city has a good. So it passes a good or "g" and returns true or false if the city has the resource in its radius or from trade.

                              so I think I have to incorporate code similar to that in governor.cpp and trademanager.cpp

                              Code:
                              	for(g = 0; g < g_theResourceDB->NumRecords(); g++) {
                              			if(city.CD()->IsLocalResource(g)) {
                              			
                              				
                              				if(city.CD()->HasResource(g) == FALSE &&	
                              					city.CD()->GetResourceTradeRoute(g, curDestRoute))
                              but I don't think its as simple as checking the unitrec after "&&" in order to build. So I'm looking more into your answers, but I hope I'm making progress
                              Formerly known as "E" on Apolyton

                              See me at Civfanatics.com

                              Comment


                              • #30
                                Well you are getting closer to the answer about what is a resource database index. Actual you already told me its function. But of course I want it a little bit more precisely. In your example you have seen that the g is passed to the HasResource function. And you have seen that this g represents a certain type of good.

                                So g represents a good but of what type is this g? It shouldn't be a problem to guess if you know what type the argument of HasResource is of.

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

                                Comment

                                Working...
                                X