Ways to permanentely remove commanders

A forum to discuss custom scenarios, campaigns and modding in general.

Moderators: Slitherine Core, The Lordz

Post Reply
Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1259
Joined: Tue Nov 23, 2010 3:35 pm

Ways to permanentely remove commanders

Post by Robotron » Sat Oct 10, 2015 1:25 pm

Right now commanders can only be "wounded" or captured which is the same thing, it only takes them longer to re-appear and only happens rarely, I believe, when their unit gets destroyed with no way to retreat.

I find the idea interesting to include a very small chance to have them removed permanentely either because of retirement / incompetence or getting killed in battle, suicide or special events (maybe causing a moral penalty to prevent gamey tactics).

The only way I could come up with was to raise the wounded time in game_commanders.lua

Code: Select all

function WoundCommander(commander, recoverTime)
  local faction = game:GetFactionById(data.commanders[commander.id+1].faction)
  if recoverTime == nil then
    recoverTime = 3
  end
  faction.luaData.commanders[commander.id].unit = nil
  faction.luaData.commanders[commander.id].turns = math.random(recoverTime, recoverTime + 2)
end
but then all the wounded commanders would probably clog up the production qeue.

Any thoughts on how to properly "kill" a commander? ^^

Sabratha
SPM Contributor
SPM Contributor
Posts: 497
Joined: Thu Jan 05, 2012 2:39 am

Re: Ways to permanentely remove commanders

Post by Sabratha » Sat Oct 10, 2015 4:37 pm

Robotron wrote:Right now commanders can only be "wounded" or captured which is the same thing, it only takes them longer to re-appear and only happens rarely, I believe, when their unit gets destroyed with no way to retreat.

I find the idea interesting to include a very small chance to have them removed permanentely either because of retirement / incompetence or getting killed in battle, suicide or special events (maybe causing a moral penalty to prevent gamey tactics).

The only way I could come up with was to raise the wounded time in game_commanders.lua

Code: Select all

function WoundCommander(commander, recoverTime)
  local faction = game:GetFactionById(data.commanders[commander.id+1].faction)
  if recoverTime == nil then
    recoverTime = 3
  end
  faction.luaData.commanders[commander.id].unit = nil
  faction.luaData.commanders[commander.id].turns = math.random(recoverTime, recoverTime + 2)
end
but then all the wounded commanders would probably clog up the production qeue.

Any thoughts on how to properly "kill" a commander? ^^
Was wondering about this too. Originally wanted to have some leaders at the start of the game, then have them dismissed (Moltke for example) and their replacements come in via event,

Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1259
Joined: Tue Nov 23, 2010 3:35 pm

Re: Ways to permanentely remove commanders

Post by Robotron » Sat Oct 10, 2015 7:12 pm

The solution to this might be found in production_tab.lua

Code: Select all

 -- Commanders
  for faction in playerAlliance.factions do
    if faction.luaData.commanders ~= nil then
      for id, commander in pairs(faction.luaData.commanders) do
        if commander.unlocked ~= 0 and commander.unit == nil then
          if queuePos >= self.scroll*6 and slot < maxSlots then

            itemPanel = self.slots[slot]

            itemPanel:Show()

            if commander.turns == 0 then
              itemPanel.turnIcon:Hide()
              itemPanel.turnText:SetColour(241, 237, 233, 255)
              itemPanel.turnText:SetLocalText("ready")
              itemPanel.unitIcon.tooltip = "clickdeploy"
            else
              itemPanel.turnIcon:Show()
              itemPanel.turnText:SetColour(241, 237, 233, 255)
              itemPanel.turnText:SetNumber(commander.turns)
              itemPanel.unitIcon.tooltip = "commander_not_ready"
            end

            itemPanel.flag:SetImage("graphics/flags", "flag_" .. faction.name .. "_16.png" )
            itemPanel.unitIcon:SetImage("graphics/commanders", "commander_" .. id .. "_queue.png")

            itemPanel.info.queue = id
            itemPanel.info.faction = faction
            itemPanel.info.type = "commander"
            itemPanel.info.turns = commander.turns

            slot = slot + 1
          end
          queuePos = queuePos + 1
        end
      end
    end
  end

Maybe by applying a -1 to "commander.turns" via a new function in game_commanders.lua and then adding a check here for hiding the commander permanently from the production qeue might work (as -1 does for SetEvent("foo", -1).
I'll check that.

Another way could be to set off an automatic "cancel confirmed" in "function ProductionQueueElement:__init(slot)"...hmmmm...puzzling....

@Johnny Bravo: if you are reading this, please share your thoughts :)

operating
Master Sergeant - U-boat
Master Sergeant - U-boat
Posts: 501
Joined: Tue Nov 25, 2008 5:36 pm

Re: Ways to permanentely remove commanders

Post by operating » Sat Oct 10, 2015 9:35 pm

Does the mod you are talking about here: Have more than the standard game's limited number of commanders? Which are not many to begin with in the first place. If you are talking about killing them off permanently, then maybe a commander's range of influence should be increased so as not leave them exposed near fronts, ect.. For they seem to be for the most part to be "theater commanders". Yes, I have lost commanders permanently in standard games due to special circumstances.

Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1259
Joined: Tue Nov 23, 2010 3:35 pm

Re: Ways to permanentely remove commanders

Post by Robotron » Sat Oct 10, 2015 10:18 pm

Do you recall any specific details about those "special circumstances" that led to permanent loss of commanders?

operating
Master Sergeant - U-boat
Master Sergeant - U-boat
Posts: 501
Joined: Tue Nov 25, 2008 5:36 pm

Re: Ways to permanentely remove commanders

Post by operating » Sat Oct 10, 2015 10:56 pm

One clearly comes to mind: If a fleet commander is in a friendly port (with all sea hexes surrounding port are occupied) then the actual port city is captured by the opposition forcing the fleet with the commander to try retreating, which it can not due to all sea hexes being occupied, causes an automatic removal of the fleet from the map including the commander. Neither the fleet nor the commander ever return to the queue or listed as a naval combat loss.

I'm trying to recall how it happened to army and air commanders: It may have happened when a German commander was in a friendly country when the friendly country surrendered. I think the German unit was repatriated to the production queue, but not the commander IIRC, (I could be wrong on that one).

Certainly if a army commander is in transport in friendly port then forced out much the same way as the above fleet commander, the army commander will also be permanently lost (even if it was friendly fleets in the surrounding sea hexes).

I did have other combat situations where a commander was permanently lost (a rare event), but at the moment can not recall exactly how it occurred.

PS: It might have happened on an island

Sabratha
SPM Contributor
SPM Contributor
Posts: 497
Joined: Thu Jan 05, 2012 2:39 am

Re: Ways to permanentely remove commanders

Post by Sabratha » Sun Oct 11, 2015 11:04 am

operating wrote:One clearly comes to mind: If a fleet commander is in a friendly port (with all sea hexes surrounding port are occupied) then the actual port city is captured by the opposition forcing the fleet with the commander to try retreating, which it can not due to all sea hexes being occupied, causes an automatic removal of the fleet from the map including the commander. Neither the fleet nor the commander ever return to the queue or listed as a naval combat loss.
Yeah retreating fleets disappearing if there's no hex left to go is a known issue from vanilla. I tried to look into this, but fialed to find a solution.

DanielHerr
Senior Corporal - Destroyer
Senior Corporal - Destroyer
Posts: 117
Joined: Sun Jan 11, 2015 7:51 pm
Contact:

Re: Ways to permanentely remove commanders

Post by DanielHerr » Mon Nov 02, 2015 11:09 pm

You can use this after you have the faction and commander.

Code: Select all

table.remove(faction.luaData.commanders, commander.id)
danielherr.github.io

DanielHerr
Senior Corporal - Destroyer
Senior Corporal - Destroyer
Posts: 117
Joined: Sun Jan 11, 2015 7:51 pm
Contact:

Re: Ways to permanentely remove commanders

Post by DanielHerr » Mon Nov 02, 2015 11:51 pm

Actually, I think that may only work the first time.
danielherr.github.io

Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1259
Joined: Tue Nov 23, 2010 3:35 pm

Re: Ways to permanentely remove commanders

Post by Robotron » Tue Nov 03, 2015 1:18 am

I tried your proposal after having "Von Hotzendorf" (id #23) attached to a unit at the start of the game by modifying 1914.lua. Then I tried to remove him in gameturn 2 by setting up this event in events.lua

Code: Select all

function Hotz()
 local austria = game:GetFactionById(3)

if game.turn == 2 then
    table.remove(austria.luaData.commanders, 23)
	end
end
But no success. :(

Care to explain how your method is meant to be applied?

DanielHerr
Senior Corporal - Destroyer
Senior Corporal - Destroyer
Posts: 117
Joined: Sun Jan 11, 2015 7:51 pm
Contact:

Re: Ways to permanentely remove commanders

Post by DanielHerr » Tue Nov 03, 2015 4:36 am

It worked when I tested it by putting it in the commander wounded function. But like I said I don't think it will work after the first time.
danielherr.github.io

Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1259
Joined: Tue Nov 23, 2010 3:35 pm

Re: Ways to permanentely remove commanders

Post by Robotron » Wed Nov 11, 2015 3:08 pm

I'm still clueless about how to use

Code: Select all

table.remove(faction.luaData.commanders, commander.id)
to remove a specific commander by using the WoundCommander function.

Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1259
Joined: Tue Nov 23, 2010 3:35 pm

Re: Ways to permanentely remove commanders

Post by Robotron » Thu Dec 03, 2015 10:14 pm

Finally two rather ugly workarounds, which seem to do the trick until something better is found.


The first one replaces the "WoundCommander" function in game_commanders.lua to achieve a small (5% in this example) chance of a commander getting killed if his unit gets destroyed, else the commander gets injured as usual.

Code: Select all

function WoundCommander(commander, recoverTime)
  local faction = game:GetFactionById(data.commanders[commander.id+1].faction)

if math.random(1,20) == 1 then

  table.remove(faction.luaData.commanders, commander.id)

  else

  if recoverTime == nil then
    recoverTime = 3
  end
  faction.luaData.commanders[commander.id].unit = nil
  faction.luaData.commanders[commander.id].turns = math.random(recoverTime, recoverTime + 2)
end
end

While this here is my somewhat successful attempt to create a way to remove a specific commander to be used for special events. In this example's case it's Austria's Hotzendorf (whose commander.id is 23) at the start of the second gameturn.

Code: Select all

function SendCommanderToHell()
local austria = game:GetFactionById(3)

	if game.turn == 2 then
		for unit in austria.units do
			if unit.commander ~= nil then
				local commander = unit.faction.luaData.commanders[commander] 
					if unit.commander.id == 23 then
						unit:DetachCommander()
						table.remove(austria.luaData.commanders[23])				
					end
			end
		end
	end
end


It seems to work alright as long as the commanders is actually placed with some unit at the time the event gets triggered.
However, I still have no idea how to remove a detached or wounded commander from the production tab, so any suggestions on how to solve this or other comments are welcome!

DanielHerr
Senior Corporal - Destroyer
Senior Corporal - Destroyer
Posts: 117
Joined: Sun Jan 11, 2015 7:51 pm
Contact:

Re: Ways to permanentely remove commanders

Post by DanielHerr » Thu Dec 03, 2015 11:43 pm

So you are using table.remove, how much have you tested it? I am not sure, but I think it may cause the ids to be shifted so that when you reference a commander based on its position in the list by their id, you are actually referencing the wrong one.
danielherr.github.io

Robotron
Lieutenant Colonel - Panther D
Lieutenant Colonel - Panther D
Posts: 1259
Joined: Tue Nov 23, 2010 3:35 pm

Re: Ways to permanentely remove commanders

Post by Robotron » Fri Dec 04, 2015 12:04 pm

I tested this with Hotzendorf(id#23), Straussenburg(id#24) and Joffre(id#0) being deployed from gameturn 1 (via AttachCommanderToUnit in 1914.lua), then set up three functions to remove Hotzendorf at the start of gameturn#2 and Straussenburg and Joffre at gameturn#3.

All three were correctly removed. Will have to play a complete game this weekend to verify that this is working consistently for a whole game though.

But as I said: the problem is, that this function will only remove commanders being attached to units and not commanders on the production panel, which have been wounded or detached.

So, if you use this function for events that trigger at a preset gameturn, it may lead to gamey tactics where the player might want to detach a commander just before the event fires to keep him safe from getting removed.

Since I don't yet know how to remove commanders from the production tab, the only method I can think of to prevent this gamey behaviour is to trigger the given event at a random date, but this still seems suboptimal to me.

Post Reply

Return to “Commander the Great War : Mods & Scenario Design”