December 22, 2024, 06:46:11

Author Topic: Shields that prevent their parent ship from firing  (Read 9688 times)

Offline Keldane

  • Specialist
  • *
  • Posts: 73
  • Karma: 0
    • View Profile
    • http://
Shields that prevent their parent ship from firing
« on: May 15, 2010, 07:19:53 »
Would it be possible to create, and if so how would I go about implementing, a set of shields that prevent their parent ship from firing when active?

As some background for the question, in my mod, shields typically take the form of energy screens that cause incoming laser weapons to "bloom" just before impact and in so doing vastly reduce the damage they deal. In the case of a "full defense mode" shield, however, it would actually fully stop and absorb incoming fire, at the expense of also absorbing outgoing shots within its area of effect. Thus, as long as they're up, they prevent their parent ship from being damaged, while also preventing it from attacking - perfect as a "decoy ship" thrown into the AI fleet to draw their fire while the rest of the fleet moves into place, for example. Of course, such would work against the default AI, but would only work against the AI I intend to create for the mod if you keep all other ships out of sight, but that's a matter for a different thread.

Edit: Instead of asking one specific question per thread, and thus likely overwhelming this area with my learning process, I'll limit it to a single thread and post a new question here whenever a new issue comes up.

Offline Mularac

  • Lieutenant
  • ***
  • Posts: 531
  • Karma: 11
    • View Profile
(No subject)
« Reply #1 on: May 15, 2010, 08:07:06 »
Yes, it could be easily be done.
1) Create a regular shield that would those specs (forget about the ship being prevented from firing and all)
2) Create a machine that, when the shield is up, it would effectibly disable all weapons of a given ship (if you need help with as well, let me know. It's not too hard at all)

Offline Keldane

  • Specialist
  • *
  • Posts: 73
  • Karma: 0
    • View Profile
    • http://
(No subject)
« Reply #2 on: May 15, 2010, 08:36:41 »
I had figured that would be what was necessary to make it work. I'll try to get it on my own first, and if I can't figure it out by this time tomorrow, I'll come back and ask for help.  :D

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
(No subject)
« Reply #3 on: May 15, 2010, 10:58:53 »
Quote
Edit: Instead of asking one specific question per thread, and thus likely overwhelming this area with my learning process, I'll limit it to a single thread and post a new question here whenever a new issue comes up.
Actually, I'd prefer opening a new thread for each new question, if it doesn't already fit thematically in the current thread. Having one giant thread filled with dozens of questions and answers dealing with all kinds of topics, it's hard for other people to find the information they're looking for.

Offline Keldane

  • Specialist
  • *
  • Posts: 73
  • Karma: 0
    • View Profile
    • http://
(No subject)
« Reply #4 on: May 16, 2010, 01:08:36 »
Sure thing, Arparso. Topic title changed to reflect that.  :D

Anyway, here's what I came up with for my machine. It works - except that it applies itself to every ship that has shields, rather than just ships with the shld_fulldef device.
Code: [Select]
MACHINE "fdevshld"
STATE watch
RULE event ShieldUp
Condition e.shield:=#shld_fulldef
:action
Weapons:=GetFreeSel();
SelectDevices(Weapons,e.ship,InSet(s.this,31)|InSet(s.this,32)|InSet(s.this,39));
Execlist(Weapons,enabledevice(s.this,0));
:end
END

RULE event ShieldDown
Condition e.shield:=#shld_fulldef
:action
Weapons:=GetFreeSel();
SelectDevices(Weapons,e.ship,Inset(s.this,31)|InSet(s.this,32)|InSet(s.this,39));
Execlist(Weapons,enabledevice(s.this,1));
:end
END
END // STATE watch
END // MACHINE fdevshld

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
(No subject)
« Reply #5 on: May 16, 2010, 03:48:54 »
Your condition looks wrong, try this:
Code: [Select]
condition E.shield:devType=#shld_fulldef;
First: E.shield is referencing the whole device - you can't directly compare it with your devicetype name. Instead, get the devType-variable of the device like seen above.

Second: When comparing two values, never use the assignment operator :=. To compare values (or variables) for equality, just use the equal sign =. The assignment operator should only be used to assign values to variables... you'll get unexpected behaviour when using it for comparisons.

The rest looks good. There's some room for improvement on your weapon selection code, though. Instead of checking the sets of the devices with InSet(), you can use s.this:weapon instead. It'll give an 1, if the device in question is a weapon and 0, if otherwise. That'll include fighters and bombers as well, though, so you may want to filter those out using !s.this:dockType.

Code: [Select]
SelectDevices(Weapons,e.ship, s.this:weapon & !s.this:docktype);

Offline Keldane

  • Specialist
  • *
  • Posts: 73
  • Karma: 0
    • View Profile
    • http://
(No subject)
« Reply #6 on: May 16, 2010, 04:36:22 »
It figures - I tried changing the condition to almost exactly what you suggested, Arparso, but made the mistake of using E.Shield= instead of E.Shield:. Thank you for the help - it now works precisely as intended.  :D