Announcement

Collapse
No announcement yet.

Project: Unit Upgrading

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

  • Project: Unit Upgrading

    I'm hoping that Upgrading units becomes part of the code (I'm sure many do)

    I figure it will involve a lot of code, and I'm hoping others may be interested. I've done some initial digging and see that we'll have to add a button (like I've done under the expel boot):




    Then I think we'll have to add the upgrade flag of course (I already added it to the cdb)

    A CanUpgrade function that will entail if the unit is at a city, if an advance is available and (possibly) if a building is available.

    Next the cost. The slic is pre-set but I think if we calculate the shield cost of the unit minus the cost of the upgrading unit times a number of Gold (is there somewhere that gives a gold to shield ratio? I didn't see it in DiffDB and thought infrastructure or capitalization would have it)

    Then the upgrade paths. this may be hardest for me since I'm not sure how to get it to check if you've missed a few upgrades (say a warrior to infrantry but you didn't upgrade to pikemen)

    Finally, AI. Should we make it free for the AI like the SLIC or try to teach it. I notice Civ3 isn't good at this and I tend toward giving the AI free, automatic upgrades (for the challenge factor if anything).

    Please post comments and I hope some are willing to contribute (because I have to finish show on map first).
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

  • #2
    love the button idea, can it go dark if it cannot be used? like how some attacks go dark when inside a city

    and if we have a button, do we want that they need to be in a city?

    Comment


    • #3
      Units can only be upgraded within a city, a fortification or perhaps when grouped with a "supply" unit?

      As for the AI, it should at least be tried to use it properly without giving it a cheat of free upgrades first. /Martin G.
      Call to Power 2: Apolyton Edition - download the latest version (12th June 2011)
      CtP2 AE Wiki & Modding Reference
      One way to compile the CtP2 Source Code.

      Comment


      • #4
        fortification and supply unit hmmm I guess it would just require addind an additional flag for imps and units and then a check at the position of the unit...

        Yeah I'd like the AI to "think" about it to, but as my code attempts show I think AI is out of my league for now.
        Last edited by Ekmek; March 27, 2005, 23:34.
        Formerly known as "E" on Apolyton

        See me at Civfanatics.com

        Comment


        • #5
          Just a little research as I fix (again) my code. I think the CDB may have to have something like:

          Code:
          	Struct UpgradeTo {
          		Record Unit Unit
          		Int Cost
          }
          Formerly known as "E" on Apolyton

          See me at Civfanatics.com

          Comment


          • #6
            Originally posted by E
            fortification and supply unit hmmm I guess it would just require addind an additional flag for imps and units and then a check at the position of the unit...

            Yeah I'd like the AI to "think" about it to, but as my code attempts show I think AI is out of my league for now.
            The easiest solution to this is, to check on the BeginTurnUnit event whether the unit can be upgraded and if it can upgrade it. Of course this has nothing to do with strategic planing but is better than nothing.

            Originally posted by Maquiladora
            Units can only be upgraded within a city, a fortification or perhaps when grouped with a "supply" unit?
            Why so restrictive? It should be up to the modder how it works, whether the unit needs to be in a city or can be upgraded on high sea.

            -Martin
            Last edited by Martin Gühmann; March 28, 2005, 14:08.
            Civ2 military advisor: "No complaints, Sir!"

            Comment


            • #7
              Well that was my point Martin, that it should be possible with a unit (called "supply unit" as an example) with a flag present on the same tile as the unit wanting to be upgraded, a certain city improvement present in the city, a flag for tile improvements capable of it, whatever, so its all possible.
              Call to Power 2: Apolyton Edition - download the latest version (12th June 2011)
              CtP2 AE Wiki & Modding Reference
              One way to compile the CtP2 Source Code.

              Comment


              • #8
                In the case of naval units, assuming they're being considered, I don't think that upgrading should be possible. Ships cannot be modified to the extent of the Tech leaps in CtP2. You can't really convert a Ship-of-the-Line into an Ironclad! The only item to carry over would be the crews.

                Also, once Tech reaches a certain level, some upgrades won't be possible in the field, ie, Cavalry to Tank, as they are equipment specific.

                Comment


                • #9
                  actually you CAN "convert a Ship-of-the-Line into an Ironclad", but not into anything after ironclads...

                  but what if upgrade had different cost depending on situation? fort cost more than city (forts dont make extra stuff for soldiers) and then quite a jump for when grouped w/ some supply or hero unit? possible?

                  Comment


                  • #10
                    I should say that the struct describing the upgrade should add any other requirement. e.g. the struct could also have RequiredBuilding if a building is required, etc...

                    On the other hand, it would really be nice to have arbitrary logical combinations of requirements, and the only way to do this is to hand off to SLIC - perhaps some simple text-file based method like requiring a building, and then hand off to SLIC (via a new mod_ function or an appropriate event) to allow modders to do anything more complicated that they want (like supply units, etc.).

                    Comment


                    • #11
                      J,
                      are you recommending something like a SLICflag that in the SLIC code you could have the SLIC see if a unit has that flag and then have an operation with it. OR create a SLIC flag that you specify the slic file and if you have the unit at the start of the turn it runs the slic file?
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • #12
                        Nothing to get excited about just a draft of my code (still need to finish ShowOnMap)

                        This is just based on my success with gifting units. It came to me that the disbanding and creating a unit would be similar to upgrading units but with a few different checks.

                        However, this should be a separate order than disband so I have to figure out how to add new orders. and the a check for city building, tileimp, and a unit with a upgrading property. then what to do with the AI. Civ3 is no guide because I didn't see the AI do much upgrading. My inclination is to have some units upgrade every age or number of turns and NOT cost the AI gold because the AI spends his gold too fast to store enough for upgrading.

                        This is all down the road, just getting it documented.


                        Anyways my Upgrade code is in there but I'm sure I'll have to do some tweaking tonight so I'll see if the basic mechanics work.

                        Code:
                        //Disband an army. Recover 1/2 it's ShieldCost if it's in a city.
                        void ArmyData:: Disband()
                        {
                        
                        	Cell *cell = g_theWorld->GetCell(m_pos);
                        	sint32 CellOwner = cell->GetOwner();
                        	Diplomat & cell_diplomat = Diplomat::GetDiplomat(CellOwner);
                        
                        	if(g_player[m_owner]->m_all_armies->Num() < 2 &&
                        	   g_player[m_owner]->m_all_cities->Num() < 1)
                        		return;
                        
                        	sint32 i;
                        	Unit city = g_theWorld->GetCity(m_pos);
                        	for(i = m_nElements - 1; i >= 0; i--) {
                        		
                        		if(city.m_id != (0)) {
                        //Initial Upgrade code (before I know how to create new orders) by E 4-17-2006
                        			if(m_array[i].GetDBRec()->GetUpgradeTo()){
                        				sint32 newunit = m_array[i].GetDBRec()->GetNumUpgradeTo();
                        				sint32 newshields = g_theUnitDB->Get(m_array[i].GetDBRec()->GetNumUpgradeTo(), g_player[m_owner]->GetGovernmentType())->GetShieldCost();
                        				sint32 oldschield = m_array[i].GetDBRec()->GetShieldCost();
                        				sint32 rushmod = g_theGovernmentDB->Get(g_player[m_owner]->m_government_type)->GetUnitRushModifier();
                        				sint32 goldcost = (newshields - oldshields) * rushmod;
                        
                        				if((g_player[m_owner]->GetPlayerType() != PLAYER_TYPE_ROBOT) && (g_player[m_owner]->m_gold->GetLevel() > goldcost)  && (city.AccessData()->GetCityData()->CanBuildUnit(newunit))) {
                        					m_array[i].Kill(CAUSE_REMOVE_ARMY_DISBANDED, -1);
                        					g_player[m_owner]->CreateUnit(newunit, m_pos, Unit(), FALSE, CAUSE_NEW_ARMY_INITIAL);
                        					g_player[m_owner]->m_gold->SubGold(goldcost);
                        				} else {
                        					city.AccessData()->GetCityData()->AddShields(m_array[i].GetDBRec()->GetShieldCost() / 2);
                        				}
                        			} else {
                        			city.AccessData()->GetCityData()->AddShields(m_array[i].GetDBRec()->GetShieldCost() / 2);
                        			}
                        		}
                        //		m_array[i].Kill(CAUSE_REMOVE_ARMY_DISBANDED, -1);
                        //	}
                        
                        //EMOD Gift Units for Human Player 4-12-2006
                        		if (!AgreementMatrix::s_agreements.HasAgreement(CellOwner, m_owner, PROPOSAL_TREATY_DECLARE_WAR)){
                        			if(m_array[i].GetDBRec()->GetCanBeGifted()){
                        				sint32 newunit = m_array[i].GetType();
                        				sint32 regardcost = (m_array[i].GetDBRec()->GetAttack()) / 5;
                        				if((g_player[m_owner]->GetPlayerType() != PLAYER_TYPE_ROBOT) && (CellOwner > 0)) {
                        					StringId strId;
                        					g_theStringDB->GetStringID("REGARD_EVENT_UNITS_GIFTED", strId);
                        					m_array[i].Kill(CAUSE_REMOVE_ARMY_DISBANDED, -1);
                        					g_player[CellOwner]->CreateUnit(newunit, m_pos, Unit(), FALSE, CAUSE_NEW_ARMY_INITIAL);
                        					cell_diplomat.LogRegardEvent(m_owner, regardcost, REGARD_EVENT_GOLD, strId);
                        				} else {
                        					m_array[i].Kill(CAUSE_REMOVE_ARMY_DISBANDED, -1);
                        				}
                        			} else {
                        				m_array[i].Kill(CAUSE_REMOVE_ARMY_DISBANDED, -1);
                        			}
                        		} else {
                        			m_array[i].Kill(CAUSE_REMOVE_ARMY_DISBANDED, -1);
                        		}
                        	}
                        ///
                        
                        	
                        	if ( g_selected_item->GetSelectedCity(city) ) {
                        		
                        	}
                        }
                        Formerly known as "E" on Apolyton

                        See me at Civfanatics.com

                        Comment


                        • #13
                          You put the stuff into ArmyData:isband(), are mad? You should use for it an own method.

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

                          Comment


                          • #14
                            I know and it will be its own method (eventually) but for now I just wanted to check if the disband and creating works as well as the gold and shield cost checks. then I'll move it to an upgrade function and map it to an order
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • #15
                              Originally posted by E
                              disband and creating
                              Must it really be disband and create? Why not just change the unit owner?

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

                              Comment

                              Working...
                              X