Announcement

Collapse

Welcome to the New Server!

Apolyton.net is now pointing to the new server. Please let us know if you spot any oddities or have any suggestions for what to add to the site!
See more
See less

E's Source Code attempts

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

  • My latest testing of the SneakAttack, I turned the battleviews back on to see ow the stack was handled and it seems that the crash occurs because any (attacker or defender) SneakAttack unit causes a crash. The valid code didnt seem to help...

    I think the issue is that Regardevent only tracks an attack event but not the killing of a unit. I'm thinking of taking the KillUnitRegard event code for Civilian and adding something like it to the BattleAftermath and call CAUSES but as I was exploring that I got stumped on how does the game know when to call events? I did a search on the event name and even the file name and it only turned up the regardevent. Can anyone explain how the game knows when to trigger an event and what file does that?


    thanks...
    Last edited by Ekmek; December 4, 2005, 22:46.
    Formerly known as "E" on Apolyton

    See me at Civfanatics.com

    Comment


    • ok I got stacks handled and theattcker stuff, but when a non-SA attacker beats an SA defender its still triggering the war so I have to work on that. for some reason army and the AllSneakAttack isnt working out... but I'll try a few things

      Code:
      	bool AllDefSneakAttack = true;
      	bool AllSneakAttack = true;
      	sint32 i;
      	if(army.IsValid()) {
      		for(i = 0; i < army.Num(); i++) {
      			if(!army[i].GetDBRec()->GetSneakAttack()){
      				AllSneakAttack = false;
      				break;
      			}
      		}
      	}
      	if(!AllSneakAttack){
      ////still didnt work need to find some way...
      
      		sint32 j;
      		if(td.IsValid()) {
      		CellUnitList stack;
      		g_theWorld->GetArmy(td.RetPos(), stack);
      
      			for(j = 0; j < stack.Num(); j++) {
      				if(!stack[j].GetDBRec()->GetSneakAttack()){
      					AllDefSneakAttack = false;
      					break;
      				}
      			}
      		}
      	}
      		if(!AllDefSneakAttack){
      			Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
      			defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
      	}
      Last edited by Ekmek; December 7, 2005, 00:34.
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • Well the code for the attcker works, stacks and all. For the defender I tried several things I tried to do a check after !AllSneakAttack and I also tried to do it right after the GetSnakAttack. BUt in both cases whenever I tried to add an additional check of the defender it seemed like the code just ignored and would skip the logviolation alltogether. I thikits because I added a td.IsValid but then checked the sneakattck and then it would skip. What am I doing wrong.


        Code:
        	bool AllSneakAttack = true;
        	sint32 i;
        	if(army.IsValid()) {
        		for(i = 0; i < army.Num(); i++) {
        			if(!army[i].GetDBRec()->GetSneakAttack()){
        					AllSneakAttack = false;
        //tried here				
        	break;
        			}
        		}
        	}
        	
        	
        	if(!AllSneakAttack){
        //and tried here
        			Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
        			defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
        
        	}
        Formerly known as "E" on Apolyton

        See me at Civfanatics.com

        Comment


        • First thing to do: Get the indention right. How often do I have to repeat this?

          Actually I shouldn't give you this piece of information without seeing fixed the indention first. but anyway, to your problem, I think you only check the attacker army but you don't check the defender army and that might be located somewhere else.

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

          Comment


          • thanks,

            I've actually gotten in a good habit of indention, its just when i post on apolyton and delete some of my other comments/notes it gets all messed and the tabbing doesnt work the same on this site.

            As for checking the attacker army. Thats the weird part, the code only defines Army army then goes into unit ta and unit td (attacker and defender respectively). elsewhere in the code is doesn't address whether army is only for the attacker or defender.



            EDIT: ok i think i know what i got to do now.
            Last edited by Ekmek; December 9, 2005, 18:48.
            Formerly known as "E" on Apolyton

            See me at Civfanatics.com

            Comment


            • well it still doesnt check the defender, I tried this:

              Code:
              STDEHANDLER(BattleAftermathRegardEvent)
              {
              	Army army;
              	Army darmy; //added by E to check defender army
              	MapPoint pos;
              	Unit ta;
              	Unit td;
              	sint32 attack_owner, defense_owner;
              
              	
              	args->GetArmy(0, army);
              
              	args->GetArmy(1, darmy);
              
              	if(!args->GetPos(0, pos))
              		return GEV_HD_Continue;
              
              	args->GetUnit(0, ta);
              	args->GetUnit(1, td);
              
              	if(!args->GetPlayer(0, attack_owner))
              		return GEV_HD_Continue;
              
              	if(!args->GetPlayer(1, defense_owner))
              		return GEV_HD_Continue;
              
              
              	bool AllSneakAttack = true;
              
              	sint32 i;
              	if(army.IsValid()) {
              		for(i = 0; i < army.Num(); i++) {
              			if(!army[i].GetDBRec()->GetSneakAttack()){
              				if(darmy.IsValid()) {
              					if(!darmy[i].GetDBRec()->GetSneakAttack()){
              						AllSneakAttack = false;
              						break;
              					}
              				}
              			}	
              		}
              	}
              
              	if(!AllSneakAttack){
              			Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
              			defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
              	}
              
              	if(AllSneakAttack){
              			return GEV_HD_Continue;
              	}
              
              
              	return GEV_HD_Continue;
              }
              and even simplified it further by trying this..

              Code:
              STDEHANDLER(BattleAftermathRegardEvent)
              {
              	Army army;
              	MapPoint pos;
              	Unit ta;
              	Unit td;
              	sint32 attack_owner, defense_owner;
              
              	
              	args->GetArmy(0, army);
              
              	args->GetArmy(1, army);  //added by E to check defender army
              
              	if(!args->GetPos(0, pos))
              		return GEV_HD_Continue;
              
              	args->GetUnit(0, ta);
              	args->GetUnit(1, td);
              
              	if(!args->GetPlayer(0, attack_owner))
              		return GEV_HD_Continue;
              
              	if(!args->GetPlayer(1, defense_owner))
              		return GEV_HD_Continue;
              
              
              	bool AllSneakAttack = true;
              
              	sint32 i;
              	if(army.IsValid()) {
              		for(i = 0; i < army.Num(); i++) {
              			if(!army[i].GetDBRec()->GetSneakAttack()){
              				AllSneakAttack = false;
              				break;
              
              			}	
              		}
              	}
              
              	if(!AllSneakAttack){
              			Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
              			defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
              	}
              
              
              
              	return GEV_HD_Continue;
              }
              I also tried the first set up with the defender outside of the 'for' in its own and still it would ignire the war declaration, it appears to ignore the (!SneakAttack) whenever I put the defender in it.

              I think I got the defender check down but not sure why its bypassing the logvio. what am i doing wrong?
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • Originally posted by E
                I've actually gotten in a good habit of indention, its just when i post on apolyton and delete some of my other comments/notes it gets all messed and the tabbing doesnt work the same on this site.
                I see. But you can bypass the problem by copying one of the tabs you have in the post-reply box. However you should not do this otherwise I cannot see what is in your working copy and that might be something else you post here. And to have more bits of information available is always better then to less.

                However for your problem, your second code is better than you first code. The second code contains less baloney than the first code. In the second code you retrieve the army twice however this doesn't work since only one army is passed to the event. And it would work anyway since the units at the defender position aren't necessary grouped. So retrieving an army from that postion doesn't help, so you have to cycle through all units at the defender's position. And check the required property and that belongs into a seperate loop.

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

                Comment


                • I assumed my problem was that i wasnt identifying the defender as much as the attcker so I did this:

                  Code:
                  STDEHANDLER(BattleAftermathRegardEvent)
                  {
                  	Army army;
                  	Army darmy; //added by E to check defender army
                  	MapPoint pos;
                  	MapPoint dpos; //added by E to check defender army
                  	Unit ta;
                  	Unit td;
                  	sint32 attack_owner, defense_owner;
                  
                  	
                  	args->GetArmy(0, army);
                  
                  	args->GetArmy(1, darmy);  //added by E to check defender army
                  
                  	if(!args->GetPos(0, pos))
                  		return GEV_HD_Continue;
                  
                  	if(!args->GetPos(1, dpos))
                  	return GEV_HD_Continue;
                  
                  	args->GetUnit(0, ta);
                  	args->GetUnit(1, td);
                  
                  	if(!args->GetPlayer(0, attack_owner))
                  		return GEV_HD_Continue;
                  
                  	if(!args->GetPlayer(1, defense_owner))
                  		return GEV_HD_Continue;
                  
                  
                  	bool AllSneakAttack = true;
                  
                  	sint32 i;
                  	if(army.IsValid()) {
                  		for(i = 0; i < army.Num(); i++) {
                  			if(!army[i].GetDBRec()->GetSneakAttack() && !darmy[i].GetDBRec()->GetSneakAttack()){
                  				AllSneakAttack = false;
                  				break;
                  			}	
                  		}
                  	}
                  
                  	if(!AllSneakAttack){
                  		Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
                  		defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
                  	}
                  
                  	return GEV_HD_Continue;
                  }
                  but still its the same problem, it just bypasses the !sneakattack. and chaning the bool to = false switches it the other way so it seems something is preventing it from switching the bool.
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • Originally posted by E
                    Code:
                    	args->GetArmy(1, darmy);  //added by E to check defender army
                    E, I already told you that this doesn't work, the BattleAftermath event does not have to army arguments only one army is passed. And actually it surprises me that the game doesn't crash.

                    You have to check the defender units at the given position, well given if they are still there. And another possibility is that it might be at other places. Actually you have to do this if you want apply the new feature to slavers.

                    But again you have to check the location of the battle whether there are units with hiiden nationality, if there are all units with hidden nationality then you are happy otherwise you aren't. And in the worst case you ave to deal with 12 armies there, each with one single unit.

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

                    Comment


                    • darn and I thought this would be an easy fix... since i dont have access to my code right now in psuedo would it be somethinglike:

                      mappoint battlepos

                      get cell->battlepos
                      get (m_all_units)
                      unit.dbrec->sneakattack


                      basically using something from player.cpp where they get a position then check all units there. Also should this be a check before i do a return on a bool? I'm assuming yes.
                      Formerly known as "E" on Apolyton

                      See me at Civfanatics.com

                      Comment


                      • Actually it is rather something like this:

                        Code:
                        get cell unit list from pos // you have pos and this should be the battle pos
                        for all units from cell unit list do
                            if unit is not sneak attack do
                                AllSneakAttack set to false
                                break
                            end if
                        end for
                        This piece of code goes directly into gap between the army sneak attack loop and the threaty cease fire violation code. The sneak attack setter is used from the code before.

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

                        Comment


                        • Martin I gave it a shot, the code atleast works for theattacker and it triggers a war execpt it doesnt check the SneakAttack. In bold is the code i settled on. but with the '//' proceeding it is the notes I took (you asked for me to keep them in before). I took them mainly from armydata when i did a search on cellunit list. Am I on the right track? Why is it not seeing the sneak attack flag on the defender?


                          Code:
                          STDEHANDLER(BattleAftermathRegardEvent)
                          {
                          	Army army;
                          //	Army darmy; //added by E to check defender army
                          	MapPoint pos;
                          //	MapPoint dpos; //added by E to check defender army
                          	Unit ta;
                          	Unit td;
                          	sint32 attack_owner, defense_owner;
                          
                          	
                          	args->GetArmy(0, army);
                          
                          //	args->GetArmy(1, darmy);  //added by E to check defender army
                          
                          	if(!args->GetPos(0, pos))
                          		return GEV_HD_Continue;
                          
                          //	if(!args->GetPos(1, dpos)) //added by E
                          //	return GEV_HD_Continue;
                          
                          	args->GetUnit(0, ta);
                          	args->GetUnit(1, td);
                          
                          	if(!args->GetPlayer(0, attack_owner))
                          		return GEV_HD_Continue;
                          
                          	if(!args->GetPlayer(1, defense_owner))
                          		return GEV_HD_Continue;
                          
                          
                          	bool AllSneakAttack = true;
                          
                          	sint32 i;
                          	if(army.IsValid()) {
                          		for(i = 0; i < army.Num(); i++) {
                          			if(!army[i].GetDBRec()->GetSneakAttack()){
                          				AllSneakAttack = false;
                          				break;
                          			}	
                          		}
                          	}
                          
                          //	CellUnitList candidate_units;
                          //	g_theWorld->GetArmy(army->RetPos(), candidate_units);
                          //	for (sint32 j = 0; j < candidate_units.Num(); j++)
                          //		{
                          //			tmp_army = candidate_units[j].GetArmy();
                          //			Assert( g_theArmyPool->IsValid(tmp_army) );
                          
                          
                          //	get cell unit list from pos // you have pos and this should be the battle pos
                          //		for all units from cell unit list do
                          //			if unit is not sneak attack do
                          
                          
                          //	CellUnitList defender;
                          //	for(i = 0; i < cell->GetNumUnits(); i++) {
                          //		if(!cell->AccessUnit(i).GetDBRec()->GetSneakAttack()) {
                          //		if(!ul->Access(i).GetArmy().IsValid()) {
                          
                          	
                          //	CellUnitList defender;
                          //	g_theWorld->GetArmy(pos, defender);
                          
                            //  for(i = 0; i < cell->GetNumUnits(); i++) { 
                          		
                          //        if (!cell->AccessUnit(i).GetDBRec()->GetSneakAttack()) 
                          
                          	Cell *cell = g_theWorld->GetCell(pos);
                          	CellUnitList *defender = g_theWorld->GetCell(pos)->UnitArmy();
                          	for(i = 0; i < defender->Num(); i++) {
                          		if(!defender->Access(i).GetDBRec()->GetSneakAttack()){
                          			AllSneakAttack = false;
                          			break;
                          		}
                          	}
                          
                          
                          	if(!AllSneakAttack){
                          
                          		Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
                          		defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
                          	}
                          
                          	return GEV_HD_Continue;
                          }
                          Formerly known as "E" on Apolyton

                          See me at Civfanatics.com

                          Comment


                          • Originally posted by E
                            Martin I gave it a shot, the code atleast works for theattacker and it triggers a war execpt it doesnt check the SneakAttack. In bold is the code i settled on. but with the '//' proceeding it is the notes I took (you asked for me to keep them in before). I took them mainly from armydata when i did a search on cellunit list. Am I on the right track? Why is it not seeing the sneak attack flag on the defender?
                            Well maybe you would like now to look unto the code while the program is executed. You can't really be sure if the defenders are still there if the battle is over, or if they are killed during the battle or somethingt else. however from a glance at the code it looked like the defenders would be still there when this event is executed.

                            So now it is time to test the debuger. I hope you got the executable working from its creation directory otherwise make it work from there. To use the debugger on the executable you just have to press in MSVS F5. But before you press F5 you should set some break points so that the debugger knows when you want to inspect the code.

                            To do this right click on the edge of the code window in MSVS and a pop up menu appears that's allows you to set a break point and to remove it and to deactivate it, etc..

                            But before you start the program with the debugger you have to do one another thing the executable has to be started with the nonexclusive argument, so that you can reach the debugger when the debugger halts the program. Otherwise you can only kill the program in order to reach the debugger.

                            There is a certain place in MSVC where you can enter the command line arguments, unfortunately I forgot the place and I don't have MSVS6 here.

                            But that are some questions you have to ask yourself, is the working hypothesis correct and of course how to figure out whether it is correct. And of course not always is the debugger the right tool. Other tools are printf statements or simply reading the code.

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

                            Comment


                            • Thanks Martin,
                              I havent gotten around to this yet because I'm just about willing to settle on it being an attacker only thing.

                              but when I thought about that I think I realized tht the event i was playing with only logs an attacker's event, where as the killunit event (where civilian regard cost is found) tracks what happens to defenders

                              There might be a way to mix those two codes but I'm not sure the other option was to add a sneak attack event into the kill unit event but then i get into a similar situation but from the dfender viewpoint. So a check on the defender will determine if war is declared.

                              so i get stuck where if the defender is not sneak attack but the attacker is then war is still declared. not sure how to fix that.
                              Formerly known as "E" on Apolyton

                              See me at Civfanatics.com

                              Comment


                              • Martin,
                                I did try adding breaks and a PRINT statement andd they didnot show in the log but it kept going to armydata and i found this which might be why its only looking at the attack, but looking at how the event is called I don't think I should add a sneakattack here instead of the regard file I've been messing with. Or am i wrong?

                                Code:
                                sint32 ArmyData::Fight(CellUnitList &defender)
                                
                                ...SOMECODE...
                                
                                	if(defenderSucks) {
                                		
                                		if(ta.IsValid()) {
                                			g_director->AddAttack(ta, td);
                                			g_gevManager->AddEvent(GEV_INSERT_AfterCurrent,
                                								   GEV_BattleAftermath,
                                								   GEA_Army, m_id,
                                								   GEA_MapPoint, pos,
                                								   GEA_Unit, ta,
                                								   GEA_Unit, td,
                                								   GEA_Player, m_owner,
                                								   GEA_Player, defense_owner,
                                								   GEA_Int, 0, 
                                								   GEA_End);
                                			for(i = 0; i < defender.Num(); i++) {				
                                				CAUSE_REMOVE_ARMY cause = CAUSE_REMOVE_ARMY_DIED_IN_ATTACK;
                                				if(defender[i ].m_id == td.m_id) {					
                                					cause  = CAUSE_REMOVE_ARMY_DIED_IN_ATTACK_ON_TOP;
                                				}
                                				g_gevManager->AddEvent(GEV_INSERT_AfterCurrent,
                                									   GEV_KillUnit,
                                									   GEA_Unit, defender[i ].m_id,
                                									   GEA_Int, cause,
                                									   GEA_Player, m_owner,
                                									   GEA_End);
                                			}
                                		}
                                ...SOMECODE...
                                Formerly known as "E" on Apolyton

                                See me at Civfanatics.com

                                Comment

                                Working...
                                X