Author Topic: [PYTHON] LinkCPs suggestion/question  (Read 774 times)

Offline Paasky

  • Sr. Member
  • ****
  • Posts: 1.801
  • DON'T PANIC! DON'T PANIC!
    • View Profile
[PYTHON] LinkCPs suggestion/question
« on: 26-06-2012, 17:06:39 »
Hi there. I'm trying to make a Push map with reinforcements moving with the frontlines. But I've run into a problem: To make this work, I have to use dummy flags obviously, for which I've set up LinkCPs, and it's running well, until...

What I have:
Stage1_dummy is flag that is allied while the "1st Stage" of the map (a naval invasion to capture 3 flags the axis can't recap) is being played, and then switches to being axis once all three flags are capped. This works fine.

However, when I want to switch other dummy flags over, to give the axis more reinforcements and move the allied spawners forward, I have to use Stage1_dummy as one of the linked CPs (as my equipment are spawning on capturable flags so I have to check flag_a is axis & stage1_dummy is axis). This doesn't work though, as when Stage1_dummy is set to a new team, it doesn't register as a flag switch and the next stage doesn't become active.

Is there any way to hook the LinkCP to both a flag being captured and a flag owner being set? Looking at the LinkCPs.py file I believe hooker.register('ControlPointChangedOwner', self.cpchanged) & game.utilities.cp_setTeam(target, team, 0) to be the key.

Is there some way to do this through mapdata.py or do I have to slightly modify LinkCPs.py? It's been a while since I last coded in python (for civ4) so a nudge in the right direction would be greatly appreciated! Hopefully this could also be implemented in FH2 proper as it gives the mappers more options for gameplay styles.
« Last Edit: 26-06-2012, 17:06:44 by Paasky »
It's half naked people on boats. That's all.
Here in Finland we call that "summer".

Offline Natty

  • Developer
  • ******
  • Posts: 3.170
    • View Profile
Re: [PYTHON] LinkCPs suggestion/question
« Reply #1 on: 26-06-2012, 22:06:31 »
It would be easier if I saw a picture of what you want to do, Im sure Spit can help you out

Is there any re-capturing of flags, or is it linearly moving only to one side? (no recap)?

Offline Paasky

  • Sr. Member
  • ****
  • Posts: 1.801
  • DON'T PANIC! DON'T PANIC!
    • View Profile
Re: [PYTHON] LinkCPs suggestion/question
« Reply #2 on: 27-06-2012, 00:06:25 »
Sure:

(Push arrows added in photoshop, the push works perfectly)

Quote
links_64 = [
   plugin(linkCPs, target = 'Stage1_dummy', source = ['Leisi', 'Orissaare'], invert = True, default_zero = False),
   plugin(linkCPs, target = 'Kuivastu_allied_tanks_dummy', source = ['Stage1_dummy', 'Kuivastu'], invert = False, default_zero = False),
   plugin(linkCPs, target = 'Stage2_allied_tanks_dummy', source = ['Stage1_dummy', 'Kuressaare'], invert = True, default_zero = True),
   plugin(linkCPs, target = 'Kuressaare_axis_tanks_dummy', source = ['Stage1_dummy', 'Kuressaare'], invert = False, default_zero = True),
   plugin(linkCPs, target = 'Stage3_axis_equipment_dummy', source = ['Kuressaare', 'Kaubi_Line', 'Koljala_Line'], invert = True, default_zero = True),
]
(suggestion: maybe don't make both the background & text white on the code window?)

In other words:
Stage 1 starts allied, others start gray.

If Kuivastu & Stage1_dummy = Allied, Kuivastu_allied_tanks_dummy -> Allied

If Leisi & Orissaare = Allied, Stage1_dummy -> Axis.

If Stage 1 & Kuressaare = Axis, Stage2_allied_tanks_dummy -> Allied

If Stage 1 & Kuressaare = Axis, Kuressaare_axis_tanks_dummy -> Axis

If Kaubi_Line & Koljala_Line & Kuressaare = Allied, Stage3_axis_equipment_dummy -> Axis



As I said earlier (and this will hopefully clarify), the problem is when the LinkCPs code changes a flag it doesn't trigger the flag changed event that would then change more flags.
« Last Edit: 27-06-2012, 00:06:23 by Paasky »
It's half naked people on boats. That's all.
Here in Finland we call that "summer".

Offline fh_spitfire

  • Developer
  • ******
  • Posts: 421
  • FHer since 0.6 | aka spitfire05
    • View Profile
Re: [PYTHON] LinkCPs suggestion/question
« Reply #3 on: 29-06-2012, 17:06:31 »
Generally, a linkCPs event can't trigger another linkCPs events (in 2.45, in 2.4 it may be even that it can't trigger ANY CP changed events). I'll check if it is really necessary, but IDK if I can get this change into 2.45.

Offline Paasky

  • Sr. Member
  • ****
  • Posts: 1.801
  • DON'T PANIC! DON'T PANIC!
    • View Profile
Re: [PYTHON] LinkCPs suggestion/question
« Reply #4 on: 29-06-2012, 17:06:10 »
The WaW resident python expert has promised to fix it for me, if we get it working can it be included then?

For more complex push/reinforcement code it is seemingly necessary as my map requires it :P

All that's really needed (AFAIK) is that it hooks to both ControlPointChangedOwner & cp_setTeam to trigger it. Or that cp_setTeam also then triggers a ControlPointChangedOwner. The simplicity/difficulty of doing that I don't know though.
It's half naked people on boats. That's all.
Here in Finland we call that "summer".

Offline fh_spitfire

  • Developer
  • ******
  • Posts: 421
  • FHer since 0.6 | aka spitfire05
    • View Profile
Re: [PYTHON] LinkCPs suggestion/question
« Reply #5 on: 02-07-2012, 22:07:46 »
Paasky: you can try enabling the event triggering in pugins simply by editing two lines in python/game/plugins/linkCPs.py:

change lines 68 and 75 to this (mind the original indentation):

Code: [Select]
game.utilities.cp_setTeam(target, -1, 1)
If this works and doesn't break the gamelogic then we're fine (let me know), but I wouldn't advise putting this on public server.

Offline Paasky

  • Sr. Member
  • ****
  • Posts: 1.801
  • DON'T PANIC! DON'T PANIC!
    • View Profile
Re: [PYTHON] LinkCPs suggestion/question
« Reply #6 on: 03-07-2012, 01:07:01 »
Almost ;)
I set 68 to game.utilities.cp_setTeam(target, -1, 1) & 75 to game.utilities.cp_setTeam(target, team, 1) and it works perfectly on local!

We'll test it online on a WaW practice server later on, but everything is perfect on local. Such a simple fix, thanks man!
It's half naked people on boats. That's all.
Here in Finland we call that "summer".