Announcement

Collapse
No announcement yet.

E's Source Code attempts

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

  • Originally posted by E
    Martin,
    I did try adding breaks and a PRINT statement andd they didnot show in the log
    Actually this is the exact syntax:

    Code:
    DPRINTF(k_DBG_GAMESTATE, ("Killing City %lx\n", uint32(m_home_city)));
    Actually the DPRINTF is a makro that writes something to a log file and only if in this case k_DBG_GAMESTATE is defined. But this is very general so it is defined.

    The more interesting part and the part you have to modify is this:

    Code:
    ("Killing City %lx\n", uint32(m_home_city))
    On the left hand we have a constant string that may contain let's say some place holders. And on the right hand we have a comma seperated list of stuff that is filled into the gaps opened by these place holders. Note that you should have as much things on the right hand as you want to fill in on the left hand.

    Now let's come to these place holders in this example it is %lx. The gap here is filled with a hexadecimal number. Instead of this use %i for an integer in decimal format. Or use %s if you want to insert a string. If you want to know more of these place holders use the the help of MS VS and look for sprintf.

    Originally posted by E
    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?
    I think you are right. I would look in the BattleAftermath and KillUnit events first.

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

    Comment


    • Thanks Martin,

      I did copy and paste a DPRINTF statement and changed the inside text before, but I'll try your instructions.

      A quick look on Battleaftermath and KillUnit evets shows a few ODD things:

      1) battleaftermath isnt an event I find, EXCEPT BattleAftermathRegardEvent, so I think this is where its called

      2) Killunit is in armyevent but also as KillUnitRegardEvent.

      3) KillUnitevent in armyevent also has KillUnit events in it which seems circular not sure

      4) the log doesnt call event files from what I see so I guess its some how packaged with the armydata and that callsboth armyevent and regardevents

      I think I'm going to try adding my sneak attack/hidden nationality code in armyData instead but change the events it calls (wish me luck )
      Formerly known as "E" on Apolyton

      See me at Civfanatics.com

      Comment


      • Martin,

        dont know how much time you have for this anymore but I was looking in controlpanel.ldl and trying to find a way to add what tech and how many turns a player is researching at the top menu bar (its a nice feature from Civ4)

        I was thinking of this:

        controlpanel.ldl


        Code:
        ################################################################################
        # Start Domestic Tab Panel
        ################################################################################
        					AdvanceProgress:CTP2_PROGRESS_DISPLAY {
        						# Location.
        						int		xpix			9
        						int		ypix			5
        
        						# Tooltip
        						string	statustext	"STATUSBAR_CIV_NOW_RESEARCHING_DISPLAY"
        					}





        Code:
        
        ##########################################
        #	Main CTP2 Menubar Layout
        ##########################################
        
        MainMenu:CTP2_MENUBAR {
        
        	string pattern "UPtb00.TGA"
         
         	int xpix	100
        	int ypix	100
        
        	int widthpix	80
        	int heightpix	100
        
        	# menu buttons
        	CivActivator:MENU_BUTTON {
        		string	text	"str_ldl_CivMenuTitle"
        		#string objecttype "ctp2_MenuButton"
        	}
        
        	CityActivator:MENU_BUTTON {
        		string text "str_ldl_CitiesMenuTitle"
        		string objecttype "ctp2_MenuButton"
        	}
        
        	UnitsActivator:MENU_BUTTON {
        		string text "str_ldl_UnitsMenuTitle"
        		string objecttype "ctp2_MenuButton"
        	}
        
        	DiplomacyActivator:MENU_BUTTON {
        		string	text	"str_ldl_DiplomacyMenuTitle"
        		string objecttype "ctp2_MenuButton"
        	}
        
        	StatsActivator:MENU_BUTTON {
        		string objecttype "ctp2_MenuButton"
        		string text "str_ldl_InfoMenuTitle"
        	}
        
        	OptionsActivator:MENU_BUTTON {
        		string objecttype "ctp2_MenuButton"
        		string text "str_ldl_OptionsMenuTitle"
        	}
        
        ############ ADD RESEARCH INFO HERE?????????????????
        
        	# Objects other than menu buttons fill in right to left, start with rightmost
        	PollutionBar:MENU_RESOURCE_COUNTER {
        		string objecttype "ctp2_Static"
        		int widthpix 36
        		# Tooltip
        		string	tipwindow	"TOOLTIP_CIV_TOTAL_POLLUTION_DISPLAY"
        		string	statustext	"STATUSBAR_CIV_TOTAL_POLLUTION_DISPLAY"
        	}
        	PollutionIcon:MENU_BAR_ICON {
        		string image00 "upic36.tga"
        	}	
        	
        	HappinessBar:MENU_RESOURCE_COUNTER {
        		string objecttype "ctp2_Static"
        		int widthpix 36
        		# Tooltip
        		string	tipwindow	"TOOLTIP_CIV_TOTAL_HAPPINESS_DISPLAY"
        		string	statustext	"STATUSBAR_CIV_TOTAL_HAPPINESS_DISPLAY"
        	}
        	HappinessIcon:MENU_BAR_ICON {
        		string image00 "upic35.tga"
        	}
        
        	PWStatic:MENU_RESOURCE_COUNTER {
        		# Tooltip
        		string	tipwindow	"TOOLTIP_CIV_TOTAL_PW_DISPLAY"
        		string	statustext	"STATUSBAR_CIV_TOTAL_PW_DISPLAY"
        	}
        	PWIcon:MENU_BAR_ICON {
        		string image00 "upic33.tga"
        	}
        
        	GoldStatic:MENU_RESOURCE_COUNTER {
        		# Tooltip
        		string	tipwindow	"TOOLTIP_CIV_TOTAL_GOLD_DISPLAY"
        		string	statustext	"STATUSBAR_CIV_TOTAL_GOLD_DISPLAY"
        	}
        	GoldIcon:MENU_BAR_ICON {
        		string image00 "upic34.tga"
        	}
        
        }

        but do i need to change anything in the code?
        Formerly known as "E" on Apolyton

        See me at Civfanatics.com

        Comment


        • went back to my Sneak Attck and I have it working with defenders

          Code:
          // EMOD logviolationevent added here like bombard. It required removing logviolationevent from regardevent 
          //  because it goes from armydata to combatevent to regardevent
          // the code works for defenders and attackers BUT if you stack a SneakAttack with a non and attack with it, 
          //	its still a sneak attack thats a TO DO  1-17-2006  
          
          
          	bool AllSneakAttack = true;
          
          	if(!m_array[i].GetDBRec()->GetSneakAttack()){
          		for(i = 0; i < defender.Num(); i++) {
          			if(!defender[i].GetDBRec()->GetSneakAttack()){
          				AllSneakAttack = false;
          				break;
          			}			
          		}
          	}
          		
          	
          	if(!AllSneakAttack){
          
          		Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
          		defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
          	}
          
          // end EMOD

          so it works except the minor exploit of when an attacker groups a sneakattackunit with a non-sneakattack the war isnt declared.

          i believe its because I cut out the break, so I need to reinsert that.
          Last edited by Ekmek; January 18, 2006, 11:31.
          Formerly known as "E" on Apolyton

          See me at Civfanatics.com

          Comment


          • Originally posted by E
            Martin,

            dont know how much time you have for this anymore but I was looking in controlpanel.ldl and trying to find a way to add what tech and how many turns a player is researching at the top menu bar (its a nice feature from Civ4)
            For that you have to add an extra bar, simply, because the lowest screen resolution doesn't leave an space on the existing bar for that. However there is an extra bar that is hidden in the debug version.

            Originally posted by E
            but do i need to change anything in the code?
            You have to modify the code.

            Originally posted by E
            so it works except the minor exploit of when an attacker groups a sneakattackunit with a non-sneakattack the war isnt declared.
            In that case you should check out the attack part of the code again.

            Originally posted by E
            i believe its because I cut out the break, so I need to reinsert that.
            Don't belive, just test it. But anyway it shouldn't presuming it is some sort of code I know more or less. There the break is just there to leave the loop. Some sort of code optimization.

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

            Comment


            • Originally posted by Martin Gühmann


              For that you have to add an extra bar, simply, because the lowest screen resolution doesn't leave an space on the existing bar for that. However there is an extra bar that is hidden in the debug version.


              You have to modify the code.
              Thanks Martin, I'll dig around and get more familiar with it. especially as I work with te diplomacy stuff



              In that case you should check out the attack part of the code again.



              Don't belive, just test it. But anyway it shouldn't presuming it is some sort of code I know more or less. There the break is just there to leave the loop. Some sort of code optimization.
              I played around with it last night, I think in one case I left out the break I think I had that endless loop problem and had to shut down the computer

              i tried a few things but none worked better that what i posted here. For now I'm happy and willl move on to other things until something strikes me again on how to do the loop. Might next approach would probably make it two separate bools, one for the attacker and then for the defender or something to that effect. The code you helped me with before made it either or when I set it up in armydata.cpp so I had to modify it.
              Formerly known as "E" on Apolyton

              See me at Civfanatics.com

              Comment


              • What's this E?

                Code:
                ORDER_RESULT ArmyData::Pillage(BOOL test_ownership)
                {
                	uint32 uindex;
                	if (!CanPillage(uindex))
                		return ORDER_RESULT_ILLEGAL;
                
                	MapPoint pos;
                	MapPoint npos;
                	GetPos(pos);
                	Cell *cell = g_theWorld->GetCell(pos);
                	sint32 cellOwner = cell->GetOwner();
                
                    if (test_ownership && (cellOwner == m_owner)) {
                        SlicObject *so = new SlicObject("17IAPillageOwnLand") ;
                		so->AddRecipient(m_owner) ;
                		so->AddUnit(m_array[0]);
                		so->AddCivilisation(m_owner);
                		g_slicEngine->Execute(so) ;
                        return ORDER_RESULT_ILLEGAL;
                    }        
                    
                
                
                	if(g_player[m_owner]->GetPlayerType() != PLAYER_TYPE_ROBOT ||
                	   (g_network.IsClient() && g_network.IsLocalPlayer(m_owner)))
                		if(test_ownership && !VerifyAttack(UNIT_ORDER_PILLAGE_UNCONDITIONALLY, m_pos, cellOwner))
                			return ORDER_RESULT_ILLEGAL;
                
                
                //InformAI(UNIT_ORDER_PILLAGE, m_pos); //does nothing here but could be implemented
                
                	AddSpecialActionUsed(m_array[uindex]);
                
                
                
                
                
                [b]//EMOD - this fianlly works 20-JAN-2006
                
                	for(sint32 i = 0; i < cell->GetNumDBImprovements(); i++) {
                	sint32 imp = cell->GetDBImprovement(i);
                	const TerrainImprovementRecord *trec = g_theTerrainImprovementDB->Get(imp);
                
                		for(imp = 0; imp < trec->GetCantPillage(); imp++) {
                			if(trec->GetCantPillage()){
                				return ORDER_RESULT_ILLEGAL;
                			}
                			return ORDER_RESULT_SUCCEEDED;
                		}
                	}[/b]
                	
                
                	g_gevManager->AddEvent(GEV_INSERT_AfterCurrent, GEV_PillageUnit,
                						   GEA_Unit, m_array[uindex],
                						   GEA_End);
                
                    g_gevManager->AddEvent(GEV_INSERT_AfterCurrent, GEV_CutImprovements,
                						   GEA_MapPoint, pos,
                						   GEA_End);
                
                	return ORDER_RESULT_SUCCEEDED;
                }
                Look at the code in bold. First the indention sucks. Then what use is this inner loop for? You set the sint32 to zero then you you check against a bool whether it is smaller false or true. Well this can only cause the loop to enter if GetCantPillage() true and then you do the check again and return order not available. And if not, well fortunately that can't happen if this isn't the case you return a success without doing the apropiate actions.

                After this mess of this for-loop, let's talk about what this should rather do, do you think if there is one unpillagable tile improvement all the other tileimps should be unpillagable, too? Actually I prefer that only the unpillagable tileimp can't be pillaged and the others at that location can be pillaged.

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

                Comment


                • Martin,
                  I'll clean up the CantPillage, I did the for loops to check the variables but I see what your saying. As for pillaging only part of the tile. Not sure I will know how to do that. I'm assuming it will involving checking which imps can be pillaged and then a cut improvements order for the imps that can be. thinking like that I think I might run into a loop problem that I have with my sneakattack code in armydata::fight

                  Code:
                  	bool AllSneakAttack = true;
                  	if(ta.IsValid()) {
                  		for(i = 0; i < m_nElements; i++) {
                  			if(!m_array[i].GetDBRec()->GetSneakAttack()){
                  //				AllSneakAttack = false;
                  //				break;
                  				for(i = 0; i < defender.Num(); i++) {
                  					if(!defender[i].GetDBRec()->GetSneakAttack()){
                  						AllSneakAttack = false;
                  						break;
                  					}			
                  				}
                  			} else {
                  				AllSneakAttack = true;
                  				break; 
                  			}
                  		}
                  	}
                  		
                  	
                  	if(!AllSneakAttack){
                  		Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
                  		defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
                  	}
                  this setup causes a constant loop that doesnt break. but if I add the outcommented part then it disables the code by not allowing the defender to be checked. I'm thinking my next attempt will be to put the defender code inside the (!SneakAttack) but not sure it will help.

                  Also i'm still having the problem with the stack of having one sneakattack unit not declaring war (I think I might have to change the switch then?)

                  Is there anything I'm missing here? I'm sure its similar to the issue i'd have with cantpillage (exceppt this code is responsible for a crash or a constantloop)
                  Formerly known as "E" on Apolyton

                  See me at Civfanatics.com

                  Comment


                  • Originally posted by E
                    As for pillaging only part of the tile. Not sure I will know how to do that. I'm assuming it will involving checking which imps can be pillaged and then a cut improvements order for the imps that can be.
                    It means modifying at least two sites of the code, on the one hand the place at that it is determined whether the given spot is pillagable and another site is the CutImporvements event where the actuall tileimp removing happens.

                    Originally posted by E
                    thinking like that I think I might run into a loop problem that I have with my sneakattack code in armydata::fight

                    Code:
                    	bool AllSneakAttack = true;
                    	if(ta.IsValid()) {
                    		for(i = 0; i < m_nElements; i++) {
                    			if(!m_array[i].GetDBRec()->GetSneakAttack()){
                    //				AllSneakAttack = false;
                    //				break;
                    				for(i = 0; i < defender.Num(); i++) {
                    					if(!defender[i].GetDBRec()->GetSneakAttack()){
                    						AllSneakAttack = false;
                    						break;
                    					}			
                    				}
                    			} else {
                    				AllSneakAttack = true;
                    				break; 
                    			}
                    		}
                    	}
                    		
                    	
                    	if(!AllSneakAttack){
                    		Diplomat & defending_diplomat = Diplomat::GetDiplomat(defense_owner);
                    		defending_diplomat.LogViolationEvent(attack_owner, PROPOSAL_TREATY_CEASEFIRE);
                    	}
                    this setup causes a constant loop that doesnt break. but if I add the outcommented part then it disables the code by not allowing the defender to be checked. I'm thinking my next attempt will be to put the defender code inside the (!SneakAttack) but not sure it will help.
                    Actual this is called an endless loop. First to the break if you put it before the second loop then you shouldn't wonder why your code doesn't work, you leave the outer loop before the inner loop is executed.

                    Your second problem is that you use the same variable as counter in both loops. So your i will be in all iterration smaller than m_nElements.

                    However I wonder why you nest these two loops at all. Nothing in the inner loop depends on anything in the outer loop.

                    -Martin
                    Last edited by Martin Gühmann; January 30, 2006, 18:24.
                    Civ2 military advisor: "No complaints, Sir!"

                    Comment


                    • [Deleted: crossposted Martin's explanation.]

                      Comment


                      • Thanks for the help guys! I think I have something stable but I'm sure it has to be optimized
                        Code:
                        	bool AlltaSneakAttack = true;
                        	if(ta.IsValid()) {
                        		for(i = 0; i < m_nElements; i++){
                        			if(!m_array[i].GetDBRec()->GetSneakAttack()){
                        				AlltaSneakAttack = false;
                        				break;
                        			}
                        		}
                        	}
                        	
                        	if (ta.m_id == 0) {
                        		if(!m_array[0].GetDBRec()->GetSneakAttack()){
                        				AlltaSneakAttack = false;
                        		}
                        	}
                        
                        
                        	bool AllDefSneakAttack = true;
                        	for(i = 0; i < defender.Num(); i++) {
                        		if(!defender[i].GetDBRec()->GetSneakAttack()){
                        			AllDefSneakAttack = false;
                        			break;
                        		}
                        	} 
                        
                        	if (td.m_id == 0) {
                        		if(!defender[0].GetDBRec()->GetSneakAttack()){
                        			AllDefSneakAttack = false;
                        		}
                        	}
                        		
                        	
                        	if(!AlltaSneakAttack && !AllDefSneakAttack){
                        		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


                        • Originally posted by E
                          Thanks for the help guys! I think I have something stable but I'm sure it has to be optimized
                          Actually looks OK to me. The only thing I don't understand are the following parts of code.

                          Originally posted by E
                          Code:
                          [...]	
                          	if (ta.m_id == 0) {
                          		if(!m_array[0].GetDBRec()->GetSneakAttack()){
                          				AlltaSneakAttack = false;
                          		}
                          	}
                          
                          [...]
                          
                          	if (td.m_id == 0) {
                          		if(!defender[0].GetDBRec()->GetSneakAttack()){
                          			AllDefSneakAttack = false;
                          		}
                          	}
                          Why do you check the id whether they are zero. (Well you might have a reason here.)

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

                          Comment


                          • ahh because I think this:
                            Code:
                            for(i = 0; i < m_nElements; i++){
                            was giving me a problem. Before I put the td = 0 stuff it would only let me attack with stacks. 1 on 1 wouldnt allow for an attack so i dug back through the fight code and saw that they had to address for stacks and non-stacks. I couldnt figure out a less than or equal to sign so this is what I came up with and it makes stacks work how I want them too. so I guess its good to go...on to cantpillage
                            Formerly known as "E" on Apolyton

                            See me at Civfanatics.com

                            Comment


                            • Martin,
                              First, CANTPILLAGE. I think this code is better. BUT I'm not sure how to only cut some imps and leave the cantpillage imps behind since ctp2 cuts all imps when there is a pillage.

                              Code:
                              		bool CanPillageTileImp = true;
                              
                              		for(sint32 i = 0; i < cell->GetNumDBImprovements(); i++) {
                              		sint32 imp = cell->GetDBImprovement(i);
                              		const TerrainImprovementRecord *trec = g_theTerrainImprovementDB->Get(imp);
                              			if(trec->GetCantPillage()){
                              				CanPillageTileImp = false;
                              				break;
                              			}
                              		}
                              	
                              
                              		if(!CanPillageTileImp){
                              			return ORDER_RESULT_ILLEGAL;
                              		}
                              my best guess is that maybe in my if(!CantPillage) you are thinking of adding an else and cutimp but not sure, besides you may want to post this playtest soon


                              AND SECOND, I was experimenting with an AllTerrainAsImprovement code. Civ3 has AllTerrainAsRoad and I was thinking of haing a flag where the modder can pick which improvement. I'm still working on it but when I did this:

                              Code:
                              // EMOD this code made it so the unit could move infinite on terrain with mvmnt of 1????
                              
                              		}else if(g_theUnitDB->Get(m_array[i]->GetType(), g_player[GetOwner()]->GetGovernmentType())->GetAllTerrainAsImprovement() > 0 ){
                              			for(sint32 ti = 0; ti < g_theTerrainImprovementDB->NumRecords(); ti++) {
                              				const UnitRecord *urec = g_theUnitDB->Get(m_array[i]->GetType(), g_player[GetOwner()]->GetGovernmentType());
                              				sint32 imp = urec->GetAllTerrainAsImprovementIndex();
                              				const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(imp);
                              				const TerrainImprovementRecord::Effect *effect = terrainutil_GetTerrainEffect(rec, pos);
                              				sint32 moveCost;
                              				cost = effect->GetMoveCost(moveCost);
                              			}
                              //EMOD
                              And I added the flag to the abolitionist and gave her a move of 100 (1 space) it allowed the abolitionist to move infinitely on terrain (plains and grass) with a movement of 1. I'm not sure how I did this. Granted I can make this a new flag (especially for barbarian leaders) but can you point out what I did wrong.


                              In the meantime I'm going to outcomment it but commit the new cantpillage and sneakattack
                              Formerly known as "E" on Apolyton

                              See me at Civfanatics.com

                              Comment


                              • Originally posted by E
                                Martin,
                                First, CANTPILLAGE. I think this code is better. BUT I'm not sure how to only cut some imps and leave the cantpillage imps behind since ctp2 cuts all imps when there is a pillage.

                                Code:
                                		bool CanPillageTileImp = true;
                                
                                		for(sint32 i = 0; i < cell->GetNumDBImprovements(); i++) {
                                		sint32 imp = cell->GetDBImprovement(i);
                                		const TerrainImprovementRecord *trec = g_theTerrainImprovementDB->Get(imp);
                                			if(trec->GetCantPillage()){
                                				CanPillageTileImp = false;
                                				break;
                                			}
                                		}
                                	
                                
                                		if(!CanPillageTileImp){
                                			return ORDER_RESULT_ILLEGAL;
                                		}
                                my best guess is that maybe in my if(!CantPillage) you are thinking of adding an else and cutimp but not sure, besides you may want to post this playtest soon


                                Yes this code is better and if you get the indention right then it is good if you want to keep its functionality as it is. However in this case you don't need this boolian varable as you can immediately return ORDER_RESULT_ILLEGAL directly inside the loop.

                                If you want to have the specific pillagability then you have to go through all the tileimps at the spot and if all of them can't be pillaged then you have to return ORDER_RESULT_ILLEGAL. And the actual nonpillagbilty most be moved to the CutImprovements event.

                                Originally posted by E
                                AND SECOND, I was experimenting with an AllTerrainAsImprovement code. Civ3 has AllTerrainAsRoad and I was thinking of haing a flag where the modder can pick which improvement. I'm still working on it but when I did this:

                                Code:
                                // EMOD this code made it so the unit could move infinite on terrain with mvmnt of 1????
                                
                                		}else if(g_theUnitDB->Get(m_array[i]->GetType(), g_player[GetOwner()]->GetGovernmentType())->GetAllTerrainAsImprovement() > 0 ){
                                			for(sint32 ti = 0; ti < g_theTerrainImprovementDB->NumRecords(); ti++) {
                                				const UnitRecord *urec = g_theUnitDB->Get(m_array[i]->GetType(), g_player[GetOwner()]->GetGovernmentType());
                                				sint32 imp = urec->GetAllTerrainAsImprovementIndex();
                                				const TerrainImprovementRecord *rec = g_theTerrainImprovementDB->Get(imp);
                                				const TerrainImprovementRecord::Effect *effect = terrainutil_GetTerrainEffect(rec, pos);
                                				sint32 moveCost;
                                				cost = effect->GetMoveCost(moveCost);
                                			}
                                //EMOD
                                And I added the flag to the abolitionist and gave her a move of 100 (1 space) it allowed the abolitionist to move infinitely on terrain (plains and grass) with a movement of 1. I'm not sure how I did this. Granted I can make this a new flag (especially for barbarian leaders) but can you point out what I did wrong.


                                Probably your problem is that you have no idea what GetMoveCost returns. Not every tileimp has a value for MoveCost. And the other problem in your code is this supperflous for loop.

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

                                Comment

                                Working...
                                X