List<WeaponGroupAPI> weaponGroups = engine.getPlayerShip().getWeaponGroupsCopy();
List<WeaponAPI> weapons = weaponGroups.get(0).getWeaponsCopy();
package data.scripts.plugins;
import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.combat.*;
import com.fs.starfarer.api.input.InputEventAPI;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.WeaponAPI;
import com.fs.starfarer.api.combat.WeaponGroupAPI;
import org.json.JSONException;
import org.json.JSONObject;
import org.lazywizard.lazylib.FastTrig;
import org.lazywizard.lazylib.JSONUtils;
import org.lazywizard.lazylib.MathUtils;
import org.lazywizard.lazylib.VectorUtils;
import org.lazywizard.lazylib.opengl.DrawUtils;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector2f;
import java.awt.*;
import java.io.IOException;
import java.util.List;
public class WeaponArcs extends BaseEveryFrameCombatPlugin {
private CombatEngineAPI engine;
private ShipAPI player;
private static Color WEAPON_ARC_COLOR;
private static String[][] DO_NO_DRAW_WEAPONS;
@Override
public void init(CombatEngineAPI engine) {
this.engine = engine;
WEAPON_ARC_COLOR = Global.getSettings().getColor("weaponArcColor");
if (DO_NO_DRAW_WEAPONS == null) {
DO_NO_DRAW_WEAPONS = new String[5][40];
}
}
public void advance(float amount, List<InputEventAPI> events) {
for (InputEventAPI event : events) {
if (event.isAltDown() && event.getEventChar() == '1' || event.getEventChar() == '2' || event.getEventChar() == '3' || event.getEventChar() == '4' || event.getEventChar() == '5') {
int index;
switch (event.getEventChar()) {
case '1':
index = 0;
if (DO_NO_DRAW_WEAPONS[index].length == 0) {
List<WeaponGroupAPI> weaponGroups = engine.getPlayerShip().getWeaponGroupsCopy();
List<WeaponAPI> weapons = weaponGroups.get(0).getWeaponsCopy();
for (int i = 0; i < weapons.size(); i++) {
WeaponAPI weapon = weapons.get(i);
DO_NO_DRAW_WEAPONS[index][i] = weapon.getId();
}
} else {
for (int i = 0; i < DO_NO_DRAW_WEAPONS[index].length; i++) {
DO_NO_DRAW_WEAPONS[index][i] = null;
}
}
break;
case '2':
index = 1;
if (DO_NO_DRAW_WEAPONS[index].length == 0) {
List<WeaponGroupAPI> weaponGroups = engine.getPlayerShip().getWeaponGroupsCopy();
List<WeaponAPI> weapons = weaponGroups.get(0).getWeaponsCopy();
for (int i = 0; i < weapons.size(); i++) {
WeaponAPI weapon = weapons.get(i);
DO_NO_DRAW_WEAPONS[index][i] = weapon.getId();
}
} else {
for (int i = 0; i < DO_NO_DRAW_WEAPONS[index].length; i++) {
DO_NO_DRAW_WEAPONS[index][i] = null;
}
}
break;
case '3':
index = 2;
if (DO_NO_DRAW_WEAPONS[index].length == 0) {
List<WeaponGroupAPI> weaponGroups = engine.getPlayerShip().getWeaponGroupsCopy();
List<WeaponAPI> weapons = weaponGroups.get(0).getWeaponsCopy();
for (int i = 0; i < weapons.size(); i++) {
WeaponAPI weapon = weapons.get(i);
DO_NO_DRAW_WEAPONS[index][i] = weapon.getId();
}
} else {
for (int i = 0; i < DO_NO_DRAW_WEAPONS[index].length; i++) {
DO_NO_DRAW_WEAPONS[index][i] = null;
}
}
break;
case '4':
index = 3;
if (DO_NO_DRAW_WEAPONS[index].length == 0) {
List<WeaponGroupAPI> weaponGroups = engine.getPlayerShip().getWeaponGroupsCopy();
List<WeaponAPI> weapons = weaponGroups.get(0).getWeaponsCopy();
for (int i = 0; i < weapons.size(); i++) {
WeaponAPI weapon = weapons.get(i);
DO_NO_DRAW_WEAPONS[index][i] = weapon.getId();
}
} else {
for (int i = 0; i < DO_NO_DRAW_WEAPONS[index].length; i++) {
DO_NO_DRAW_WEAPONS[index][i] = null;
}
}
break;
case '5':
index = 4;
if (DO_NO_DRAW_WEAPONS[index].length == 0) {
List<WeaponGroupAPI> weaponGroups = engine.getPlayerShip().getWeaponGroupsCopy();
List<WeaponAPI> weapons = weaponGroups.get(0).getWeaponsCopy();
for (int i = 0; i < weapons.size(); i++) {
WeaponAPI weapon = weapons.get(i);
DO_NO_DRAW_WEAPONS[index][i] = weapon.getId();
}
} else {
for (int i = 0; i < DO_NO_DRAW_WEAPONS[index].length; i++) {
DO_NO_DRAW_WEAPONS[index][i] = null;
}
}
break;
}
}
}
if (engine == null || engine.getCombatUI() == null) {
return;
}
if (engine.isUIShowingDialog()) {
return;
}
if (!engine.isSimulation() && !engine.isUIShowingHUD()) {
return;
}
if (engine.getCombatUI().isShowingCommandUI()) {
return;
}
player = engine.getPlayerShip();
if (player == null || !engine.isEntityInPlay(player)) {
return;
}
ViewportAPI viewport = engine.getViewport();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
final int width = (int) (Display.getWidth() * Display.getPixelScaleFactor()), height
= (int) (Display.getHeight()
* Display.getPixelScaleFactor());
GL11.glViewport(0, 0, width, height);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPushMatrix();
GL11.glLoadIdentity();
GL11.glOrtho(viewport.getLLX(), viewport.getLLX() + viewport.getVisibleWidth(), viewport.getLLY(),
viewport.getLLY() + viewport.getVisibleHeight(), -1,
1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPushMatrix();
GL11.glLoadIdentity();
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glTranslatef(0.01f, 0.01f, 0);
this.handleDraw();
GL11.glDisable(GL11.GL_BLEND);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPopMatrix();
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPopMatrix();
GL11.glPopAttrib();
}
private static void glColor(Color color) {
GL11.glColor4ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue(),
(byte) (41f));
}
private void handleDraw() {
List<WeaponAPI> weapons = engine.getPlayerShip().getAllWeapons();
for (WeaponAPI weapon : weapons) {
boolean skip = false;
for (int i = 0; i < DO_NO_DRAW_WEAPONS.length; i++) {
for (int j = 0; j < DO_NO_DRAW_WEAPONS[i].length; j++) {
if (DO_NO_DRAW_WEAPONS[i][j] == weapon.getId()) {
skip = true;
}
}
}
if (skip) {
continue;
}
this.drawWeaponFacing(weapon);
this.drawWeaponArc(weapon);
}
}
private void drawWeaponFacing(WeaponAPI weapon) {
if (!weapon.isDisabled()) {
Vector2f location = weapon.getLocation();
float cangle = weapon.getCurrAngle();
Vector2f toRotate = new Vector2f(location.x + weapon.getRange(), location.y);
Vector2f dest = new Vector2f(0, 0);
VectorUtils.rotateAroundPivot(toRotate, location, cangle, dest);
toRotate = new Vector2f(location.x + 5, location.y);
Vector2f start = new Vector2f(0, 0);
VectorUtils.rotateAroundPivot(toRotate, location, cangle, start);
this.glColor(WEAPON_ARC_COLOR);
this.drawLine(start, dest);
}
}
private void drawWeaponArc(WeaponAPI weapon) {
if (!weapon.isDisabled()) {
Vector2f location = weapon.getLocation();
float arc = weapon.getArc();
float arcFacing = weapon.getArcFacing();
float left = arcFacing - (arc / 2);
float right = arcFacing + (arc / 2);
Vector2f toRotateLeft = new Vector2f(location.x + weapon.getRange(), location.y);
Vector2f destLeft = new Vector2f(0, 0);
VectorUtils.rotateAroundPivot(toRotateLeft, location, left, destLeft);
Vector2f toRotateRight = new Vector2f(location.x + weapon.getRange(), location.y);
Vector2f destRight = new Vector2f(0, 0);
VectorUtils.rotateAroundPivot(toRotateRight, location, right, destRight);
float shipFacing = engine.getPlayerShip().getFacing();
Vector2f finalLeft = new Vector2f(0, 0);
Vector2f finalRight = new Vector2f(0, 0);
VectorUtils.rotateAroundPivot(destLeft, location, shipFacing, finalLeft);
VectorUtils.rotateAroundPivot(destRight, location, shipFacing, finalRight);
Vector2f toRotateLeft2 = new Vector2f(location.x + 10, location.y);
Vector2f destLeft2 = new Vector2f(0, 0);
VectorUtils.rotateAroundPivot(toRotateLeft2, location, left, destLeft2);
Vector2f toRotateRight2 = new Vector2f(location.x + 10, location.y);
Vector2f destRight2 = new Vector2f(0, 0);
VectorUtils.rotateAroundPivot(toRotateRight2, location, right, destRight2);
Vector2f finalLeft2 = new Vector2f(0, 0);
Vector2f finalRight2 = new Vector2f(0, 0);
VectorUtils.rotateAroundPivot(destLeft2, location, shipFacing, finalLeft2);
VectorUtils.rotateAroundPivot(destRight2, location, shipFacing, finalRight2);
this.glColor(WEAPON_ARC_COLOR);
this.drawLine(finalLeft2, finalLeft);
this.drawLine(finalRight2, finalRight);
int segments = (int) arc / 10;
float startArc = right;
float xdif = (finalLeft.x - location.x) / 4;
float ydif = (finalLeft.y - location.y) / 4;
this.drawArc(location,
finalLeft,
arc,
segments);
this.drawArc(location,
new Vector2f(finalLeft.x - xdif, finalLeft.y - ydif),
arc,
segments);
this.drawArc(location,
new Vector2f(finalLeft.x - xdif * 2, finalLeft.y - ydif * 2),
arc,
segments);
this.drawArc(location,
new Vector2f(finalLeft.x - xdif * 3, finalLeft.y - ydif * 3),
arc,
segments);
}
}
private void drawArc(Vector2f center, Vector2f start, float range, int segments) {
Vector2f oldPoint = start;
float rotation = range / segments;
for (int i = 0; i < segments; i++) {
Vector2f newpoint = new Vector2f(0f, 0f);
VectorUtils.rotateAroundPivot(oldPoint, center, rotation, newpoint);
this.drawLine(oldPoint, newpoint);
oldPoint = newpoint;
}
}
private void drawLine(Vector2f start, Vector2f end) {
GL11.glBegin(GL11.GL_LINES);
GL11.glVertex2f(start.x, start.y);
GL11.glVertex2f(end.x, end.y);
GL11.glEnd();
}
}
I've been trying to implement switching weapon groups off, but i hit a snag:
You misunderstand, i meant switching the drawing on and off, not the actual weapon group. So that you could, for example, draw only group 1, 2, 3 but not 4 and 5.
Also implemented version checker support.
weaponarcs.version
WeaponArcs.version
1. Automatically turn off/on vanilla weapon arcs, (even if hotkey is changed) and turn on/off modded ones, every battle.
2. Change and/or toggle transparency of modded arcs.
3. Make .cfg file for configuring those functions. Maybe also turning on arcs for each weapon group separately. Maybe make currently used arc less transparent while other stay transparent.
4. (Is it even possible) Show arcs for hostile/friendly ships with a hotkey for each group.
Also implemented version checker support.
I'm on linux which has case sensitive filenames, and I encountered an error until I changed the filename "weaponarcs.version" to "WeaponArcs.version". Cheers!
696681 [Thread-4] INFO org.histidine.chatter.combat.ChatterCombatPlugin - Chatter plugin initialized
696681 [Thread-4] INFO com.fs.starfarer.loading.LoadingUtils - Loading JSON from [weapon-arcs-settings.json]
698906 [Thread-4] INFO data.scripts.WeaponArcsPlugin - Shipname: RSS Red Dwarf
699365 [Thread-4] ERROR com.fs.starfarer.combat.CombatMain - java.lang.NullPointerException
java.lang.NullPointerException
at data.scripts.WeaponArcsPlugin.advance(WeaponArcsPlugin.java:96)
at com.fs.starfarer.title.C.K$Oo.o00000(Unknown Source)
at com.fs.starfarer.combat.super.OoOO.o00000(Unknown Source)
at com.fs.starfarer.combat.CombatEngine.advanceInner(Unknown Source)
at com.fs.starfarer.combat.CombatEngine.advance(Unknown Source)
at com.fs.starfarer.combat.CombatState.traverse(Unknown Source)
at com.fs.state.AppDriver.begin(Unknown Source)
at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Very often, I'll crash when using the Pocket Gust's ship system (Assume Wing Control) from Diable Avionics, and starsector.log shows this at the very bottom.Spoiler761917 [Thread-4] ERROR com.fs.starfarer.combat.CombatMain - java.lang.NullPointerException
java.lang.NullPointerException
at data.scripts.WeaponArcsPlugin.advance(WeaponArcsPlugin.java:89)
at com.fs.starfarer.title.Object.float$Oo.o00000(Unknown Source)
at com.fs.starfarer.combat.oOOO.B.super(Unknown Source)
at com.fs.starfarer.combat.CombatEngine.advanceInner(Unknown Source)
at com.fs.starfarer.combat.CombatEngine.advance(Unknown Source)
at com.fs.starfarer.combat.CombatState.traverse(Unknown Source)
at com.fs.state.AppDriver.begin(Unknown Source)
at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source[close]
I tested this on a brand new campaign, without displaying any additional weapon groups, and it didn't crash in the simulator, but it did when in a real battle.
I've had it crash inside the simulator before, though, but I don't know if I was displaying weapon groups at the time.
Just to let you know download link needs to be updated, github version is up to date while download link is 1.3.1
Just to let you know download link needs to be updated, github version is up to date while download link is 1.3.1
The download is pointing to the master branch, and when I use it, I get 1.4.0.
Not sure how you're getting 1.3.1.
Mod_info.json correctly shows 1.4.0, but weaponarcs.version is still returning 1.3.1, causing version checker to think it's the old version.
hi, I've noticed you don't cover weapoon groups 6 and 7, will you update it in the future ?
I'm using 1.4.1 and "assume wing control" from diable avionics and sadly it still crashes the game, at least in simulation, the moment I hit the skill the game crashes with a null error, removed the mod and now the system works fine.
I'm not sure if this problem applies to other mods with a similar system that allows you to take control of a secondary craft
I'm using 1.4.1 and "assume wing control" from diable avionics and sadly it still crashes the game, at least in simulation, the moment I hit the skill the game crashes with a null error, removed the mod and now the system works fine.
I'm not sure if this problem applies to other mods with a similar system that allows you to take control of a secondary craft
I'm doing the mission "T minus zero" and there is no issue assuming wing control from the gust. Are you refitting the scenario with some other fighter? I've tested with the default wanzer and a flash bomber wing. No issues.
I'm using 1.4.1 and "assume wing control" from diable avionics and sadly it still crashes the game, at least in simulation, the moment I hit the skill the game crashes with a null error, removed the mod and now the system works fine.
I'm not sure if this problem applies to other mods with a similar system that allows you to take control of a secondary craft
I'm doing the mission "T minus zero" and there is no issue assuming wing control from the gust. Are you refitting the scenario with some other fighter? I've tested with the default wanzer and a flash bomber wing. No issues.
I tested again
funny enough its does not crash in T minus zero or other missions, but when I go onto the simulation in campaign mode it crashes, not sure why, although I didn't test in actual battle
as for fighters so far it crashes no matter what I equip, and stops once I remove this modSpoilerjava.lang.NullPointerException
at data.scripts.WeaponArcsPlugin.advance(WeaponArcsPlugin.java:111)
at com.fs.starfarer.title.Object.L$Oo.super(Unknown Source)
at com.fs.starfarer.combat.oOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.B.super(Unknown Source)
at com.fs.starfarer.combat.CombatEngine.advanceInner(Unknown Source)
at com.fs.starfarer.combat.CombatEngine.advance(Unknown Source)
at com.fs.starfarer.combat.CombatState.traverse(Unknown Source)
at com.fs.state.AppDriver.begin(Unknown Source)
at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
at com.fs.starfarer.StarfarerLauncher.o00000(Unknown Source)
at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)[close]
I'm using 1.4.1 and "assume wing control" from diable avionics and sadly it still crashes the game, at least in simulation, the moment I hit the skill the game crashes with a null error, removed the mod and now the system works fine.
I'm not sure if this problem applies to other mods with a similar system that allows you to take control of a secondary craft
I'm doing the mission "T minus zero" and there is no issue assuming wing control from the gust. Are you refitting the scenario with some other fighter? I've tested with the default wanzer and a flash bomber wing. No issues.
I tested again
funny enough its does not crash in T minus zero or other missions, but when I go onto the simulation in campaign mode it crashes, not sure why, although I didn't test in actual battle
as for fighters so far it crashes no matter what I equip, and stops once I remove this modSpoilerjava.lang.NullPointerException
at data.scripts.WeaponArcsPlugin.advance(WeaponArcsPlugin.java:111)
at com.fs.starfarer.title.Object.L$Oo.super(Unknown Source)
at com.fs.starfarer.combat.oOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO.B.super(Unknown Source)
at com.fs.starfarer.combat.CombatEngine.advanceInner(Unknown Source)
at com.fs.starfarer.combat.CombatEngine.advance(Unknown Source)
at com.fs.starfarer.combat.CombatState.traverse(Unknown Source)
at com.fs.state.AppDriver.begin(Unknown Source)
at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
at com.fs.starfarer.StarfarerLauncher.o00000(Unknown Source)
at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)[close]
What is your modlist? I can not reproduce this.
Any way to make the arcs more round/smooth? I know it's stupid thing, but the vanilla arcs are more smooth and this is annoying me ;D
Working so well and lovely so far, but I'm wondering if there's a chance of using color coded arcs. It would make it easier to tell what weapon has what range if each could be a different color.
Working so well and lovely so far, but I'm wondering if there's a chance of using color coded arcs. It would make it easier to tell what weapon has what range if each could be a different color.
Working so well and lovely so far, but I'm wondering if there's a chance of using color coded arcs. It would make it easier to tell what weapon has what range if each could be a different color.
In version 1.6.0 you can now set individual colors for weapon groups from the settings file.
I've submitted a pull request that adds an option to configure the number of range bands the weapon arcs show - with the default setting of 4, the behaviour is unchanged. Personally I have it set to 1, as it helps improve clarity and reduce visual noise.
With rangeBands = 1 (Showing only the outermost)rangeBands = 10 (I'm not sure why you would do this)Spoiler(https://imgpile.com/images/RX4Y2u.png)[close]rangeBands = 0 (I'm not sure why you would do this either, unless you only care about where your guns are pointing. I might submit another PR with an option to disable the arc edges at some point, because that could be useful.)Spoiler(https://imgpile.com/images/RX4PKi.png)[close]Spoiler(https://imgpile.com/images/RX4iak.png)[close]
The tweaked mod can be found at https://github.com/Lrizika/WeaponArcsStarsector/raw/master/WeaponArcs.zip
I want to apply and extend your mod to display the weapon arcs of a targeted ship. May I please do so?
I like it, however I use Alt as the ship system button so it's annoying that there isn't an option to turn that off.
I'm I hallucinated or you can press "H" key once as a toggle then press group number instead of having to hold LAlt + Group number in one of the version before?