Announcement

Collapse
No announcement yet.

Project: Unit Upgrading

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

  • #16
    Originally posted by Martin Gühmann


    Must it really be disband and create? Why not just change the unit owner?

    -Martin
    Oh, for Gifting. I'll check it out, so far it works though
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • #17
      Originally posted by E
      Oh, for Gifting. I'll check it out, so far it works though
      Well it depends where it is, whether it is in a city or in open field espeacilly whether it is in the land of the receiver.

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

      Comment


      • #18
        Originally posted by Martin Gühmann


        Well it depends where it is, whether it is in a city or in open field espeacilly whether it is in the land of the receiver.

        -Martin
        thats what i was going for, it just disbands everywhere else. once i make Gifting an order than I'll have a bool if the cell is valid for gifting.
        Formerly known as "E" on Apolyton

        See me at Civfanatics.com

        Comment


        • #19
          Originally posted by E
          thats what i was going for, it just disbands everywhere else. once i make Gifting an order than I'll have a bool if the cell is valid for gifting.
          So you want to do it like in Civ4, and not like in Civ2 where you send the units via diplomacy.

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

          Comment


          • #20
            yes, it seems more tedius but i'm not up for the task of doing it through diplomacy
            Formerly known as "E" on Apolyton

            See me at Civfanatics.com

            Comment


            • #21
              I decided to test Upgrading in Sleep (like the slic) instead of disband. Sleep does it work better because why would you sleep in a city instead of entrench and naval units probably wont be upgradeable (you got to build a new ship)

              anyways I tired a lot of times and eventually just outcommented it all. Here it is for history sake

              Code:
              // Put this army on sentinal duty.
              void ArmyData::Sleep()
              {
              //ORIGINAL
              //    sint32 i;
              //    for(i = 0; i < m_nElements; i++) {
              //
              //EMOD upgrade code 4-25-2006 outcommented
              
              	sint32 i;
              	sint32 s = 0;
              	Unit city = g_theWorld->GetCity(m_pos);
              	for(i = m_nElements - 1; i >= 0; i--) {
              	
              //		if((city.m_id != (0)) && (m_array[i].GetDBRec()->GetUpgradeToIndex(s)))  {  // add terrainutil_HasAirfield(m_pos) || terrainutil_HasFort(m_pos) || terrainutil_HasUpgrader(m_pos)
              //			for(s = 0; s < m_array[i].GetDBRec()->GetNumUpgradeTo(); s++) {
              //			sint32 s = m_array[i].GetDBRec()->GetNumUpgradeTo(); // s++) {  //m_array[i].GetDBRec()->GetUpgradeToIndex(s)
              //				if(city.AccessData()->GetCityData()->CanBuildUnit(m_array[i].GetDBRec()->GetUpgradeToIndex(s))){
              //					sint32 newunit = m_array[i].GetDBRec()->GetUpgradeToIndex(s);
              //					sint32 newshields = m_array[i].GetDBRec()->GetShieldCost() * 2;
              //					sint32 oldshields = m_array[i].GetDBRec()->GetShieldCost();
              //					sint32 rushmod = g_theGovernmentDB->Get(g_player[m_owner]->m_government_type)->GetUnitRushModifier();
              //					sint32 goldcost = (newshields - oldshields);// * rushmod;
              //
              //					if((city.AccessData()->GetCityData()->CanBuildUnit(m_array[i].GetDBRec()->GetUpgradeToIndex(s))) ){//&& (g_player[m_owner]->m_gold->GetLevel() > goldcost)) { //&& (g_player[m_owner]->GetPlayerType() != PLAYER_TYPE_ROBOT)
              //						m_array[i].Kill(CAUSE_REMOVE_ARMY_DISBANDED, -1);
              //						g_player[m_owner]->CreateUnit(s, m_pos, Unit(), FALSE, CAUSE_NEW_ARMY_INITIAL);
              //						g_player[m_owner]->m_gold->SubGold(goldcost);
              //					} else {
              //						g_gevManager->AddEvent(GEV_INSERT_AfterCurrent, GEV_SleepUnit,
              //                              GEA_Unit, m_array[i],
              //                            GEA_End);
              //					}
              //
              //			}
              //		} else {
              
              //end EMOD
                      g_gevManager->AddEvent(GEV_INSERT_AfterCurrent, GEV_SleepUnit,
                                             GEA_Unit, m_array[i],
                                             GEA_End);
              //		}
              
                  }
              }

              I should note that it was generating a crash when it tried to get the unit. GetDBRec and GetOwner were mentioned there too (I dont have the crash.txt with me right now). Cant figure out how to fix. I tried a debugslic but that getcontinent assert is still there. I'll try again with another playtest version I have.
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • #22
                E, why do you kill the unit and add a new one instead of simply replacing its type?

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

                Comment


                • #23
                  I don't think there is a ChangeType function. And I haven't seen an example of a unit changing its type. But also when you create a unit it adds it to the array and killing it removes it so this is the best way that i can keep those things in line. Atleast with my limited knowledge.
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • #24
                    Originally posted by E
                    I don't think there is a ChangeType function.
                    And what? Can't you make a SetType method? (SetType that is the standart name for such methods by the way)

                    Originally posted by E
                    And I haven't seen an example of a unit changing its type. But also when you create a unit it adds it to the array and killing it removes it so this is the best way that i can keep those things in line. Atleast with my limited knowledge.
                    And that keeps you from doing, instead of the plain simple way you chose a complicate way of killing the old unit causing a lot computed stuff and adding a new unit and again this means adding a lot of CPU load and memory usage and so on.

                    Making it more complicated than necessary asks for trouble, basicly it is just an asignement of a new value and maybe an additional graphic update and you are done.

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

                    Comment


                    • #25
                      Well I got it working with this bit of code

                      Code:
                      // Put this army on sentinal duty or upgrade it.
                      void ArmyData::Sleep()
                      {
                      	Cell *cell = g_theWorld->GetCell(m_pos);
                      	sint32 CellOwner = cell->GetOwner();
                      
                      	sint32 i;
                      	sint32 s;
                      
                      	//rec = g_theUnitDB->Get(m_array[i].GetType(), g_player[GetOwner()]->GetGovernmentType());
                      	Unit city = g_theWorld->GetCity(m_pos);
                      	for(i = m_nElements - 1; i >= 0; i--) {
                      		const UnitRecord *rec = m_array[i].GetDBRec();
                      		if((city.m_id != (0)) && (rec->GetNumUpgradeTo() > 0))  { 
                      			for(s = 0; s < rec->GetNumUpgradeTo(); s++) {
                      				sint32 oldshield = rec->GetShieldCost();
                      				sint32 newshield = g_theUnitDB->Get(rec->GetUpgradeToIndex(s))->GetShieldCost();
                      				sint32 rushmod = g_theGovernmentDB->Get(g_player[m_owner]->m_government_type)->GetUnitRushModifier();
                      				sint32 goldcost = (newshield - oldshield) * rushmod;
                      				sint32 newunit = rec->GetUpgradeToIndex(s);
                      				if(city.AccessData()->GetCityData()->CanBuildUnit(rec->GetUpgradeToIndex(s)) && (g_player[m_owner]->m_gold->GetLevel() > goldcost)){
                      					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 {
                      				    g_gevManager->AddEvent(GEV_INSERT_AfterCurrent, GEV_SleepUnit,
                                                 GEA_Unit, m_array[i],
                                                 GEA_End);
                      				}
                      			}
                      		} else {
                      			g_gevManager->AddEvent(GEV_INSERT_AfterCurrent, GEV_SleepUnit,
                                           GEA_Unit, m_array[i],
                                           GEA_End);
                      		}
                      	}
                      }
                      But upgrading from a warrior to a legion (in my civ3 mod) came to 2000 gold. So I'm thinking about reducing the rushmod
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • #26
                        And why do you still break a fly on the wheel by killing the old unit and creating a new unit instead of just changing the type of the unit?

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

                        Comment


                        • #27
                          Originally posted by Martin Gühmann
                          And why do you still break a fly on the wheel by killing the old unit and creating a new unit instead of just changing the type of the unit?

                          -Martin
                          that would entail creating a function that identifies the type of the unit (GetType()) and finding some way to change that sint32. Where I can understand what needs to be done, I still don't know how to do it. My best guess was that the SetType would be something like type = upgradetoIndex(s) kind of like how the gold = 0 stuff works. But still not sure how to call it.

                          So yes I'm lazy but I'm also not a programmer and so far this works. I'm open to change with more instruction but I think that should be explored once I learn more about how new orders are created so we don't use the sleep command.

                          But I am happy this works this was actually a lot less lines than i thought it would take and its easy for modders to implement with out doing a lot of changing to the slic files
                          Formerly known as "E" on Apolyton

                          See me at Civfanatics.com

                          Comment


                          • #28
                            Originally posted by E
                            that would entail creating a function that identifies the type of the unit (GetType()) and finding some way to change that sint32.
                            No it doesn't, because there is already a method called UnitData::GetType. All you need is to create a UnitData::SetType method. There are myrads of examples of Get and Set methods in the entire source code. So it shouldn't be a problem to copy and paste and modify one of them. If you don't at an input valid check then it is just one single little tiny additional line to UnitData.h.

                            Originally posted by E
                            Where I can understand what needs to be done, I still don't know how to do it. My best guess was that the SetType would be something like type = upgradetoIndex(s) kind of like how the gold = 0 stuff works. But still not sure how to call it.
                            It is something like this, the upgrade to index is the argument of the SetType method and you don't need to figure out its type, because the type is just an index into the unit database, and since you have the record you don't need this.

                            Originally posted by E
                            So yes I'm lazy but I'm also not a programmer and so far this works.
                            Maybe I should be lazzy too and just outcomment those pieces of inefficent, buggy or not working at all code.

                            Originally posted by E
                            I'm open to change with more instruction but I think that should be explored once I learn more about how new orders are created so we don't use the sleep command.
                            Well for the start I would be happy with a replacement of the unit killing and creation overhead by a simple type change. Maybe I should really outcomment those two lines in question in my next revision so that you can find them more easily.

                            The next step is to put the stuff into its own Unit::Upgrade method and than call this method by a UnitUpgrade event.

                            Originally posted by E
                            But I am happy this works this was actually a lot less lines than i thought it would take and its easy for modders to implement with out doing a lot of changing to the slic files
                            A change type slic function would be nice, but before we get this one we need such a method in the Unit class.

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

                            Comment


                            • #29
                              Looking here...

                              Code:
                              void UnitData::SetOwner(PLAYER_INDEX newo)
                              { 
                              	m_owner = newo; 
                              	ENQUEUE(); 
                              }
                              and based on this in unit.cpp

                              Code:
                              PLAYER_INDEX Unit::GetOwner() const
                              
                              {
                              	return g_theUnitPool->GetUnit(m_id)->GetOwner();
                              }
                              
                              sint32 Unit::GetType() const
                              {
                              	return g_theUnitPool->GetUnit(m_id)->GetType();
                              }
                              I realize I have to make a void function for set type and it will call a sint32 for the new type. But I'm guess m_type in unitdata.cpp I jus set to the type value?

                              I'll give it a shot
                              Formerly known as "E" on Apolyton

                              See me at Civfanatics.com

                              Comment


                              • #30
                                well I tried this and all it did was sleep the unit and take my gold

                                Code:
                                	for(i = m_nElements - 1; i >= 0; i--) {
                                		const UnitRecord *rec = m_array[i].GetDBRec();
                                		if((city.m_id != (0)) && (rec->GetNumUpgradeTo() > 0))  { 
                                			for(s = 0; s < rec->GetNumUpgradeTo(); s++) {
                                				sint32 oldshield = rec->GetShieldCost();
                                				sint32 newshield = g_theUnitDB->Get(rec->GetUpgradeToIndex(s))->GetShieldCost();
                                				sint32 rushmod = g_theGovernmentDB->Get(g_player[m_owner]->m_government_type)->GetUnitRushModifier();
                                				sint32 goldcost = (newshield - oldshield) * rushmod;
                                				sint32 newunit = rec->GetUpgradeToIndex(s);
                                				if(city.AccessData()->GetCityData()->CanBuildUnit(rec->GetUpgradeToIndex(s)) && (g_player[m_owner]->m_gold->GetLevel() > goldcost)){
                                					m_array[i].SetType(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 {
                                				    g_gevManager->AddEvent(GEV_INSERT_AfterCurrent, GEV_SleepUnit,
                                                           GEA_Unit, m_array[i],
                                                           GEA_End);
                                				}
                                			}
                                		} else {
                                Code:
                                
                                void Unit::SetType(const sint32 type)
                                
                                {
                                	AccessData()->SetType(type); 
                                }
                                
                                void UnitData::SetType(sint32 type)
                                { 
                                	m_type = type; 
                                	//ENQUEUE(); 
                                }

                                not seeing how type is accesed
                                Formerly known as "E" on Apolyton

                                See me at Civfanatics.com

                                Comment

                                Working...
                                X