Remember my former idea, Arparso? about the charging effect for beam weapons?
I found a way to enhance my original coding to make room for effictibly having as many beam weapons as the engine limitations would let you, using the same principle that the previous code.
In this 2.0 version, I saw no need of deleting the weapon, so I disable it instead. That way, it would be like having the weapon at all time, so assigning a place for it shouoldn't be a problem. Lets assume that the ship x has 4 beam weapons, beam_1, 2, 3 and 4. in slots labeled as 32, heavy weapons. then, the ship should have an other 4 "special" (34) slots for this weapons, whereas the 1° 34 slot is in the same place that the first 32 and so on. So when one of the weapons fires, I check which number is it and act accordingly. If the weapon ends with _3 then I install first the 1°, then the 2° and finally the 3°, but those weapons are different, they would be "travel_1", 2 and 3. So if the 4° weapon fires I just add the 4° travel one. Then every "start" weapon has it's own "travel" one already installed and ready to be used.
So the only real issue left is the fact that each beam weapons counts for 2 in placing the hardpoints for the ship...
Anyhow, here's the code, perhaps you can put good use to it, or use your coding magic with it. The code can support multiple of different beams, for example, I made the code with a terrant and vasudan beam in mind, but it can easily be expanded into more than that.
Machine "beam"
State Fire
Rule event in
:action
SelectEx(s.device&InSet(s.this, 32), //I'm wonna work here under the assumption that all the "start" laser weapons have been labeled as "heavy" and that the "travel" terran_beam weapons as "special", in the set category
RequestFiredEvent(s.this,1);
);
:end
END
Rule event Fired
condition IsValid(E.location)&InSet(e.location,32)
:action
Debug("Fired1. The ship is:", e.location:owner, "and the weapon:", e.location);
e.ownr:=e.location:owner;
e.targ:=e.location:target;
ChooseFirst(
e.location:devtype = #terran_beam_start_1,
Timer(Open_Fire_1, 1.9, e.target:=p.targ;e.ownr:=p.ownr;e.Numterran_beams:=p.Numterran_beams;e.race:=1); //1 is for terrans, 2 for vasudans
, e.location:devtype = #vasudan_beam_start_1,
Timer(Open_Fire_1, 1.9, e.target:=p.targ;e.ownr:=p.ownr;e.Numterran_beams:=p.Numterran_beams;e.race:=2);
, e.location:devtype = #terran_beam_start_2,
Timer(Open_Fire_2, 1.9, e.target:=p.targ;e.ownr:=p.ownr;e.Numterran_beams:=p.Numterran_beams;e.race:=1);
, e.location:devtype = #vasudan_beam_start_2,
Timer(Open_Fire_2, 1.9, e.target:=p.targ;e.ownr:=p.ownr;e.Numterran_beams:=p.Numterran_beams;e.race:=2);
, e.location:devtype = #terran_beam_start_3,
Timer(Open_Fire_3, 1.9, e.target:=p.targ;e.ownr:=p.ownr;e.Numterran_beams:=p.Numterran_beams;e.race:=1);
, e.location:devtype = #vasudan_beam_start_3,
Timer(Open_Fire_3, 1.9, e.target:=p.targ;e.ownr:=p.ownr;e.Numterran_beams:=p.Numterran_beams;e.race:=2);
, e.location:devtype = #terran_beam_start_4,
Timer(Open_Fire_4, 1.9, e.target:=p.targ;e.ownr:=p.ownr;e.Numterran_beams:=p.Numterran_beams;e.race:=1);
, e.location:devtype = #vasudan_beam_start_4,
Timer(Open_Fire_4, 1.9, e.target:=p.targ;e.ownr:=p.ownr;e.Numterran_beams:=p.Numterran_beams;e.race:=2);
); //we check with "start" weapon was fired, the 1°, 2°,3° or 4°
:end
END
Rule event Open_Fire_1
condition IsValid(e.target)&IsValid(e.ownr)
:action
Debug("the ship is:", e.ownr, "and the target:", e.target);
If(AllNumOf(1) = 0,
if(e.race = 1,
InstallDevice(e.ownr, #terran_beam_travel_1); //if the ship doesn't have a "travel" weapon, we install one.
SelectDevices(1, e.ownr, s.this:devtype=#terran_beam_travel_1);
,
InstallDevice(e.ownr, #vasudan_beam_travel_1);
SelectDevices(1, e.ownr, s.this:devtype=#vasudan_beam_travel_1);
);
);
ExecList(1,
EnableDevice(s.this,1);
RequestFiredEvent(s.this,1);
TargetWeapon(s.this, e.target);
);
:end
END
Rule event Open_Fire_2
condition IsValid(e.target)&IsValid(e.ownr)
:action
SelectDevices(1, e.ownr, InSet(s.this, 34));
if(e.race = 1,
ChooseFirst(
AllNumOf(1) = 0, //if there weren't any other weapon in the previous slots, I fill the places nontheless, so that when I finall install the corresponding weapon, it'll be on the right spot.
InstallDevice(e.ownr, #terran_beam_travel_1);
InstallDevice(e.ownr, #terran_beam_travel_2);
, AllNumOf(1) = 1,
InstallDevice(e.ownr, #terran_beam_travel_2);
);
SelectDevices(1, e.ownr, s.this:DevType=#terran_beam_travel_2);
,
ChooseFirst(
AllNumOf(1) = 0,
InstallDevice(e.ownr, #vasudan_beam_travel_1);
InstallDevice(e.ownr, #vasudan_beam_travel_2);
, AllNumOf(1) = 1,
InstallDevice(e.ownr, #vasudan_beam_travel_2);
);
SelectDevices(1, e.ownr, s.this:DevType=#vasudan_beam_travel_2);
);
ExecList(1,
EnableDevice(s.this,1); //we enable it, in case it was disabled
RequestFiredEvent(s.this,1);
TargetWeapon(s.this, e.target);
);
:end
END
Rule event Open_Fire_3
condition IsValid(e.target)&IsValid(e.ownr)
:action
SelectDevices(1, e.ownr, InSet(s.this, 34));
if(e.race = 1,
ChooseFirst(
AllNumOf(1) = 0, //if there weren't any other weapon in the previous slots, I fill the places nontheless, so that when I finall install the corresponding weapon, it'll be on the right spot.
InstallDevice(e.ownr, #terran_beam_travel_1);
InstallDevice(e.ownr, #terran_beam_travel_2);
InstallDevice(e.ownr, #terran_beam_travel_3);
, AllNumOf(1) = 1,
InstallDevice(e.ownr, #terran_beam_travel_2);
InstallDevice(e.ownr, #terran_beam_travel_3);
, AllNumOf(1) = 2,
InstallDevice(e.ownr, #terran_beam_travel_3);
);
SelectDevices(1, e.ownr, s.this:DevType=#terran_beam_travel_3);
,
ChooseFirst(
AllNumOf(1) = 0,
InstallDevice(e.ownr, #vasudan_beam_travel_1);
InstallDevice(e.ownr, #vasudan_beam_travel_2);
InstallDevice(e.ownr, #vasudan_beam_travel_3);
, AllNumOf(1) = 1,
InstallDevice(e.ownr, #vasudan_beam_travel_2);
InstallDevice(e.ownr, #vasudan_beam_travel_3);
, AllNumOf(1) = 2,
InstallDevice(e.ownr, #vasudan_beam_travel_3);
);
SelectDevices(1, e.ownr, s.this:DevType=#vasudan_beam_travel_3);
);
ExecList(1,
EnableDevice(s.this,1); //we enable it, in case it was disabled
RequestFiredEvent(s.this,1);
TargetWeapon(s.this, e.target);
);
:end
END
Rule event Open_Fire_4
condition IsValid(e.target)&IsValid(e.ownr)
:action
SelectDevices(1, e.ownr, InSet(s.this, 34));
if(e.race = 1,
ChooseFirst(
AllNumOf(1) = 0, //if there weren't any other weapon in the previous slots, I fill the places nontheless, so that when I finall install the corresponding weapon, it'll be on the right spot.
InstallDevice(e.ownr, #terran_beam_travel_1);
InstallDevice(e.ownr, #terran_beam_travel_2);
InstallDevice(e.ownr, #terran_beam_travel_3);
InstallDevice(e.ownr, #terran_beam_travel_4);
, AllNumOf(1) = 1,
InstallDevice(e.ownr, #terran_beam_travel_2);
InstallDevice(e.ownr, #terran_beam_travel_3);
InstallDevice(e.ownr, #terran_beam_travel_4);
, AllNumOf(1) = 2,
InstallDevice(e.ownr, #terran_beam_travel_3);
InstallDevice(e.ownr, #terran_beam_travel_4);
, AllNumOf(1) = 3,
InstallDevice(e.ownr, #terran_beam_travel_4);
);
SelectDevices(1, e.ownr, s.this:DevType=#terran_beam_travel_4);
,
ChooseFirst(
AllNumOf(1) = 0,
InstallDevice(e.ownr, #vasudan_beam_travel_1);
InstallDevice(e.ownr, #vasudan_beam_travel_2);
InstallDevice(e.ownr, #vasudan_beam_travel_3);
InstallDevice(e.ownr, #vasudan_beam_travel_4);
, AllNumOf(1) = 1,
InstallDevice(e.ownr, #vasudan_beam_travel_2);
InstallDevice(e.ownr, #vasudan_beam_travel_3);
InstallDevice(e.ownr, #vasudan_beam_travel_4);
, AllNumOf(1) = 2,
InstallDevice(e.ownr, #vasudan_beam_travel_3);
InstallDevice(e.ownr, #vasudan_beam_travel_4);
, AllNumOf(1) = 3,
InstallDevice(e.ownr, #vasudan_beam_travel_4);
);
SelectDevices(1, e.ownr, s.this:DevType=#vasudan_beam_travel_4);
);
ExecList(1,
EnableDevice(s.this,1); //we enable it, in case it was disabled
RequestFiredEvent(s.this,1);
TargetWeapon(s.this, e.target);
);
:end
END
Rule event Fired
Condition IsValid(E.location)&InSet(e.location,34)
:action
Debug("The ship that fires is:", e.location:owner, "and the weapon is:", e.location);
EnableDevice(e.location,0);
e.weap:=e.location;
Debug("Fired2. The ship is:", e.location:owner, "and the target:", e.location:target);
Timer(DisableDevice, 3, e.weap:=p.weap);
:end
END
Rule event DisableDevice
:action
EnableDevice(e.weap,0);
:end
END
END
END