Announcement

Collapse
No announcement yet.

E's Source Code attempts

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

  • Originally posted by E
    its mainly that the game cant handle stacks. if its a hiddenNationality(HN) or non-HN it crashes or 2 or more non-HN, but a HN vs a non HN it works fine
    Maybe you should write code that handles the stack and not just the first unit of an army.

    So you have to do something like this:

    Code:
    for all units of army do
        if unit is not hidden
            mark stack as not hidden and break
        end if
    end do
    if stack is not do
        notify defender of attack
    end if
    An by the way...

    Originally posted by E
    Code:
    	if(!(ta.GetDBRec()->GetHiddenNationality() == true)) {
    you can code this better.

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

    Comment


    • Thanks Martin I'll try it on my complier tonight.

      Looking in diplomacywizard.cpp
      [code]
      void DipWizard::FillProposalLists()
      {

      sint32 pr;
      ctp2_ListBox *propList = NULL, *exchList = NULL;

      sint32 i;
      for(i = 0; i < DIP_WIZ_PROP_TAB_MAX; i++) {
      m_propList[i]->Clear();
      m_exchList[i]->Clear();
      m_propList[i]->SetActionFuncAndCookie(PropListCallback, (void *)i);
      m_exchList[i]->SetActionFuncAndCookie(ExchListCallback, (void *)i);
      }

      const Diplomat & diplomat =
      Diplomat::GetDiplomat(g_selected_item->GetVisiblePlayer());

      for(pr = 0; pr < g_theDiplomacyProposalDB->NumRecords(); pr++) {
      const DiplomacyProposalRecord *rec = g_theDiplomacyProposalDB->Get(pr);
      if(!rec) continue;


      if (diplomat.InvalidNewProposal(m_recipient, rec))
      continue;



      if(rec->GetArg1HisCity() && m_recipient >= 0 && m_recipient < k_MAX_PLAYERS && g_player[m_recipient]) {
      sint32 c;
      bool seenOne = false;
      for(c = 0; c < g_player[m_recipient]->m_all_cities->Num(); c++) {
      if(g_player[m_recipient]->m_all_cities->Access(c)->GetEverVisible() & (1 << g_selected_item->GetVisiblePlayer())) {
      seenOne = true;
      break;
      }
      }
      if(!seenOne)
      continue;
      }

      if(rec->GetCategoryRequest()) {
      propList = m_propList[DIP_WIZ_PROP_TAB_REQUEST];
      exchList = m_exchList[DIP_WIZ_PROP_TAB_REQUEST];
      }

      if(rec->GetCategoryGift()) {
      propList = m_propList[DIP_WIZ_PROP_TAB_OFFER];
      exchList = m_exchList[DIP_WIZ_PROP_TAB_OFFER];
      }

      if(rec->GetCategoryTreaty()) {
      propList = m_propList[DIP_WIZ_PROP_TAB_TREATY];
      exchList = m_exchList[DIP_WIZ_PROP_TAB_TREATY];
      }

      AddProposalItem(propList, rec);
      AddProposalItem(exchList, rec);
      }
      [code]

      how do I take the treaties out of the category and put into the other boxes? am I looking in the right function?

      and..

      Code:
      const MBCHAR *DipWizard::GetCategoryName(DIP_WIZ_PROP_TAB tab)
      {
      	switch(tab) {
      		case DIP_WIZ_PROP_TAB_REQUEST: return "Request";
      		case DIP_WIZ_PROP_TAB_OFFER: return "Offer";
      		case DIP_WIZ_PROP_TAB_TREATY: return "Treaty";
      		default: return "";
      	}
      }
      this "switch" i assume is here the tabs come from what do i change this into? list box. do I separate them? am I looking in the right place? thanks
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • The first thing is to rezize approximately everything so that there is enough space to add the new components. And of course you have to add the second list box.

        For the code I must say that I need more time zhan just a few minutes. So the start with the easy stuff.

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

        Comment


        • Martin, I tried this:

          Code:
          // EMOD - Hidden Nationality check added by E 18 Nov 2005 - if unit is not Hidden Nationality then Regard Event is Logged 
          //	if((ta.GetDBRec()->GetSneakAttack() == false)) {
          
          		Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
          		defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
          //	}
          
          //	Unit u;
          //	bool ArmyIsHidden;
          //	CellUnitList stack;
          //	g_theWorld->GetArmy(u.RetPos(), stack);
          //	if(!(u.GetDBRec()->GetSneakAttack() == true)) {
          //			ArmyIsHidden = false;
          //	}	
          	
          //	if(ArmyIsHidden = false) {
          
          		//original code
          //		Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
          //		defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
          //	}
          
          
          //end EMOD
          it still crashes so I knw I'm wrong. I took the cellunitlist code from the civilian check but not sure its working. anywhere to find code on hhow to get all units in an army?
          Formerly known as "E" on Apolyton

          See me at Civfanatics.com

          Comment


          • You still don't check each unit of the stack whether it has the required flag. It's still the first unit.

            Originally posted by E
            Code:
            //	if((ta.GetDBRec()->GetSneakAttack() == false)) {
            //	if(!(u.GetDBRec()->GetSneakAttack() == true)) {
            //	if(ArmyIsHidden = false) {
            And I realdy told you that you can code this better, and by the way the last statement is simply not what you want to do.

            In fact the code behind the if statement is executed if the expression in the statement is true, so no need to check this again. And for the false check use the negation with the exclamation mark.

            Originally posted by E
            it still crashes so I knw I'm wrong. I took the cellunitlist code from the civilian check but not sure its working. anywhere to find code on hhow to get all units in an army?
            In case of doubt you have to test each single line or use a debugger or use the DPRINTF statements to figure iut what goes wrong.

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

            Comment


            • ok I tried this since going through the stack reminded me of my needscitygood code

              Code:
              	Unit u;
              	CellUnitList stack;
              	bool found;
              	for(g_theWorld->GetArmy(u.RetPos(), stack)) {
              		if(!(u.GetDBRec()->GetSneakAttack() == 0)) {	
              			found = true;
              		}
              	}
              	if(!found){
              		Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
              		defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
              	}
              But it won't compile
              Code:
              F:\SVN-Code\trunk\ctp2_code\ai\diplomacy\RegardEvent.cpp(286) : error C2143: syntax error : missing ';' before ')'
              F:\SVN-Code\trunk\ctp2_code\ai\diplomacy\RegardEvent.cpp(286) : error C2143: syntax error : missing ';' before ')'
              when I add ';' to the Get army line to make it more like a for statement I used before it says error converting void to different function. Where am I going wrong here?
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • Originally posted by E
                Code:
                	for(g_theWorld->GetArmy(u.RetPos(), stack)) {
                E how does a for statement look alike in general? And anyway what should this line do?

                Originally posted by E
                Code:
                		if(!(u.GetDBRec()->GetSneakAttack() == 0)) {
                How often do I have to tell you that this is bad code? What does return GetSneakAttack? It isn't an integer, so much I can tell you without telling you the solution to you.

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

                Comment


                • should I make it into an integer, it doesnt have a value. My only other guess would be:

                  Code:
                  	sint32 i;
                  	CellUnitList stack;
                  	bool found;
                  	for(i = 0; i < stack.Num() ; i++) {
                  		if(stack[i].GetDBRec()->GetSneakAttack() > 0){
                  			found = true;
                  		}
                  	}
                  	if(!found){
                  		Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
                  		defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
                  	}
                  but when I do that I get an error saying I cant change the value of the void ???

                  GetARmy is trying to get the whole stack
                  the second line is then to check the units in the stack
                  Last edited by Ekmek; November 25, 2005, 16:58.
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • Originally posted by E
                    should I make it into an integer, it doesnt have a value.
                    but when I do that I get an error saying I cant change the value of the void ???
                    Well my guess was that it returns a bool, but now I am not so sure anymore, so check the source code of GetSneakAttack and see what it returns.

                    Originally posted by E
                    GetARmy is trying to get the whole stack
                    Yes this is required probably it returns a bool or a BOOL indicating whether the variable was filled, but to test this you don't put into a for statement. However the for loop is necessary to test all the units.

                    And by the way all your units in the stack must be fullfill the hidden attribute so that the stack as whole is hidden, not just one unit. Or do you which that one units adds its hidden attribute to the whole stack?

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

                    Comment


                    • thanks martin,

                      after a short break its kind of working and I do want the stack to have all units be hidden to be considered if not. If not then the unit is not hidden (sneakAttack)

                      GetSneakAttack does return a bool. the code that kind of works is this:

                      Code:
                      	sint32 i;
                      	bool found = false;
                      
                      		for(i = 0; i < army.Num(); i++) {
                      			if(army[i].GetDBRec()->GetSneakAttack() == true){
                      				found = true;
                      				break;
                      		}
                      	}
                      	if(!found){
                      		Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
                      		defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
                      	}
                      and it appears to hanndle stacks but crashed in an instance between two sneakattack units. And if a nonSneakAttack unit attacks a sneakattack unit war is still declared which I dont want to happen either (but I may make a separate flag for that).

                      What line is wrong? thanks...
                      Last edited by Ekmek; November 25, 2005, 21:56.
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • Originally posted by E
                        thanks martin,

                        after a short break its kind of working and I do want the stack to have all units be hidden to be considered if not. If not then the unit is not hidden (sneakAttack)
                        I think the last sentence should be rather: "If not then the whole stack is not hidden." Otherwise I don't see much sense in it.

                        However the code does not do this. In your version it is currently enough that just one unit has the flag then the whole stack is hidden. Take a look on the pseudo code again I posted earlier in this thread.

                        Originally posted by E
                        and it appears to hanndle stacks but crashed in an instance between two sneakattack units.
                        Any crash reports? The log files the debug version creates might help. However the only problem canditate is that the army is invalid. But so far this is a guess, and it doesn't get better if I can't see the whole method including your additions.

                        Originally posted by E
                        And if a nonSneakAttack unit attacks a sneakattack unit war is still declared which I dont want to happen either (but I may make a separate flag for that).
                        Probably you have to look at other places for this.

                        Originally posted by E
                        What line is wrong? thanks...
                        At first I have to state once again: Get the indention right. Code with proper indention is better to read. And by the way that is one thing you have to do while you are writing code. Of course this is some kind of surface issure, but if even the surface isn't right, what things will I find when I look under it.

                        Now lets go to the line I cannot accept, well it isn't really wrong, but again a surface issure, and again the question what I will find under it:

                        Code:
                        if(army[i].GetDBRec()->GetSneakAttack() == true){
                        First the if-controlled code is executed if the expression under control of the if is true:

                        Code:
                        if A then do B
                        B is done if and only if A is true. Since it is already a boolean expression that can either the values true or false, there is no need to check again whteher A is true: So you did something like this:

                        Code:
                        if A == true then do B
                        It states the obvious and a good programmer should know this without stating the obvious. Even if the source code is full of stating the obvious examples.

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

                        Comment


                        • this is what the crash text said in a HN vs HN unit
                          Code:
                            0x004cb9c0  [?KillUnitsOverBudget@MilitaryReadiness@@QAEXJAAV?$DynamicArray@VArmy@@@@J@Z + 0x340]
                            0x004841b4  [??0BattleEvent@@QAE@XZ + 0x4]
                            0x00501eb3  [?SaveAdvances@MapFile@@QAE_NPAU_iobuf@@@Z + 0x1c3]
                            0x00482e1b  [?armyevent_Initialize@@YAXXZ + 0x1eb]
                            0x00482eb3  [?armyevent_Initialize@@YAXXZ + 0x283]
                            0x0084085a  [?g_const_token_data@@3PAUTokenData@@A + 0xc0c2]
                            0x005ba5af  [?Serialize@UnitRecord@@QAEXAAVCivArchive@@@Z + 0x49f]
                            0x005ba546  [?Serialize@UnitRecord@@QAEXAAVCivArchive@@@Z + 0x436]
                            0x005bb20a  [?Serialize@UnitRecord@@QAEXAAVCivArchive@@@Z + 0x10fa]
                            0x005b8e64  [?ResolveDBReferences@TerrainRecord@@QAEXXZ + 0xa4]
                            0x005bb068  [?Serialize@UnitRecord@@QAEXAAVCivArchive@@@Z + 0xf58]
                            0x005bb00b  [?Serialize@UnitRecord@@QAEXAAVCivArchive@@@Z + 0xefb]
                            0x0040efe1  [??0ActorPath@@QAE@JJJJ@Z + 0x51]
                            0x00407db0  [?InitializeAppDB@CivApp@@QAEJAAVCivArchive@@@Z + 0xa0]
                            0x00407827  [?New@?$tech_Memory@ULink@?$tech_WLList@PAD@@@@QAEPAULink@?$tech_WLList@PAD@@XZ + 0x7]
                            0x008adf1c  [?g_mapTokenData@@3PAUTokenData@@A + 0x19524]
                            0x7c816d4f  [__onexitbegin + 0x7bd591b7]
                          I think I may have to make a separte line of control that says if the attacker and defender are both hidden then continue


                          However the code does not do this. In your version it is currently enough that just one unit has the flag then the whole stack is hidden. Take a look on the pseudo code again I posted earlier in this thread.
                          I looked at the code and is it the 'break' thats off. I see break in you pseudo code but I remeber that with my goodall code where we tried to check the properties of all listed the break had to be removed whereas the 'goodor' code had the break.
                          Formerly known as "E" on Apolyton

                          See me at Civfanatics.com

                          Comment


                          • Originally posted by E
                            this is what the crash text said in a HN vs HN unit
                            Maybe you should use the debug version to locate the problem, this crash.txt doesn't contain any reasanable stuff, or why should a BattleEvent follow an army initialization. And by the way the debug version brings you much closer to the problem.

                            Originally posted by E
                            I think I may have to make a separte line of control that says if the attacker and defender are both hidden then continue
                            Well try this.

                            Originally posted by E
                            I looked at the code and is it the 'break' thats off. I see break in you pseudo code [...]
                            Yes it contans a break, but unlike your code it does not test whether the unit has hidden nationality, it rather tests whether the unit does not has hidden nationality. It is the way around. And therefore you can leave the loop as you know the stack can't be hidden if at least one unit is not hidden.

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

                            Comment


                            • Originally posted by Martin Gühmann
                              Maybe you should use the debug version to locate the problem, this crash.txt doesn't contain any reasanable stuff, or why should a BattleEvent follow an army initialization. And by the way the debug version brings you much closer to the problem.
                              I remember that the name BattleEvent is used twice:[list=1][*]gs/gameobj/armyevent.cpp[*]ui/interface/battleevent.cpp[/list=1]

                              This caused random crashes on linux due to the destructor defined within the other class being called. That's why I renamed BattleEvent to BattleEventHook in -r433 in armyevent.cpp in /branches/linux, i.e. changed
                              Code:
                              STDEHANDLER(BattleEvent)
                              to
                              Code:
                              STDEHANDLER(BattleEventHook)
                              Now i guess there might be a quite similar problem on windows, though i'm not sure whether it's the only problem you're expecting.

                              See svn diff -r 432:433 svn://ctp2.kaan.dk/ctp2/branches/linux

                              Comment


                              • Martin,

                                I got HN vs HN working but the stacks are still a problem, i reordered the code, but the mix HN and nonHn stack keeps crashing

                                Code:
                                	sint32 i;
                                	bool found = false;
                                	for(i = 0; i < army.Num(); i++) {
                                		if(!(army[i].GetDBRec()->GetSneakAttack())){
                                			found = true;
                                			break;
                                		}
                                	}
                                	if(found){
                                		Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
                                		defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
                                	}
                                	if(!found)
                                		return GEV_HD_Continue;
                                
                                	if(ta.GetDBRec()->GetSneakAttack() && td.GetDBRec()->GetSneakAttack())
                                		return GEV_HD_Continue;

                                and it seems that its the same crash
                                Code:
                                  0x004cb9c0  [?KillUnitsOverBudget@MilitaryReadiness@@QAEXJAAV?$DynamicArray@VArmy@@@@J@Z + 0x340]
                                  0x004841b4  [??0BattleEvent@@QAE@XZ + 0x4]
                                  0x00501eb3  [?SaveAdvances@MapFile@@QAE_NPAU_iobuf@@@Z + 0x1c3]
                                  0x00482e1b  [?armyevent_Initialize@@YAXXZ + 0x1eb]
                                  0x00482eb3  [?armyevent_Initialize@@YAXXZ + 0x283]
                                  0x0084085d  [?g_const_token_data@@3PAUTokenData@@A + 0xc0c5]
                                  0x005ba5af  [?Serialize@UnitRecord@@QAEXAAVCivArchive@@@Z + 0x49f]
                                  0x005ba546  [?Serialize@UnitRecord@@QAEXAAVCivArchive@@@Z + 0x436]
                                  0x005bb20a  [?Serialize@UnitRecord@@QAEXAAVCivArchive@@@Z + 0x10fa]
                                  0x005b8e64  [?ResolveDBReferences@TerrainRecord@@QAEXXZ + 0xa4]
                                  0x005bb068  [?Serialize@UnitRecord@@QAEXAAVCivArchive@@@Z + 0xf58]
                                  0x005bb00b  [?Serialize@UnitRecord@@QAEXAAVCivArchive@@@Z + 0xefb]
                                  0x0040efe1  [??0ActorPath@@QAE@JJJJ@Z + 0x51]
                                  0x00407db0  [?InitializeAppDB@CivApp@@QAEJAAVCivArchive@@@Z + 0xa0]
                                  0x00407827  [?New@?$tech_Memory@ULink@?$tech_WLList@PAD@@@@QAEPAULink@?$tech_WLList@PAD@@XZ + 0x7]
                                  0x008adf5c  [?g_mapTokenData@@3PAUTokenData@@A + 0x19564]
                                  0x7c816d4f  [__onexitbegin + 0x7bd591b7]
                                should I try what ctp2linuxfan suggested? or am I missing something?
                                Formerly known as "E" on Apolyton

                                See me at Civfanatics.com

                                Comment

                                Working...
                                X