Skip to content

Commit

Permalink
Fixed bug with effect 'select', added 'hardStop' and 'rigid' option t…
Browse files Browse the repository at this point in the history
…o effects. Update 2.1.31
  • Loading branch information
emd4600 committed May 22, 2023
1 parent d11a542 commit a4593d6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/sporemodder/UpdateManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class UpdateManager {
*/
public static final TimeZone TIMEZONE = TimeZone.getTimeZone("UTC");

public final VersionInfo versionInfo = new VersionInfo(2, 1, 30, null);
public final VersionInfo versionInfo = new VersionInfo(2, 1, 31, null);

public static UpdateManager get() {
return MainApp.get().getUpdateManager();
Expand Down
2 changes: 1 addition & 1 deletion src/sporemodder/file/cell/CellLootTableFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static class cLootTableEntry
{
public int type;
public int cellID;
public int tableID; // to a .cell file
public int tableID; // to a .lootTable file
public float weight = 1.0f;
public int count;
public int countDelta;
Expand Down
4 changes: 2 additions & 2 deletions src/sporemodder/file/cell/CellPopulateFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static class cMarker
public int clusterCellID;
public int encounterPopulateID;
public int plantType; // ENUM_PLANT_TYPE
public int type;
public int type; // ENUM_TYPE
public float count = -1.0f;
public float count_easy = -1.0f;
public float count_med = -1.0f;
Expand All @@ -88,7 +88,7 @@ public static class cMarker
public float encounterScale;
}

public int scale = 1;
public int scale = 1; // ENUM_SCALE
public int maskTexture;
public final List<cMarker> markers = new ArrayList<>();

Expand Down
37 changes: 35 additions & 2 deletions src/sporemodder/file/effects/VisualEffect.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ public class VisualEffect extends EffectComponent {

public static final EffectComponentFactory FACTORY = new Factory();

public static final int FLAG_HARDSTOP = 0x20;
public static final int FLAG_RIGID = 0x40;
public static final int FLAG_EXTENDED_LOD_WEIGHTS = 0x80000;
public static final int FLAGMASK = FLAG_EXTENDED_LOD_WEIGHTS;
public static final int FLAGMASK = FLAG_EXTENDED_LOD_WEIGHTS | FLAG_HARDSTOP | FLAG_RIGID;

public int flags;
public int componentAppFlagsMask;
Expand Down Expand Up @@ -117,6 +119,13 @@ public void parse(ArgScriptLine line) {
effect.flags = Optional.ofNullable(stream.parseInt(args, 0) & ~FLAGMASK).orElse(0);
}

if (line.hasFlag("hardStop")) {
effect.flags |= FLAG_HARDSTOP;
}
if (line.hasFlag("rigid")) {
effect.flags |= FLAG_RIGID;
}

if (line.getOptionArguments(args, "notifyMessageID", 1)) {
effect.notifyMessageID = Optional.ofNullable(stream.parseInt(args, 0)).orElse(0);
}
Expand Down Expand Up @@ -204,12 +213,33 @@ public void onBlockEnd() {
for (int i = firstIndex; i < effect.blocks.size(); i++) {
VisualEffectBlock block = effect.blocks.get(i);

if (block.selectionChance != 0) {
if (block.selectionChance == 0) {
block.selectionChance = remaining;
}
}
}

// If the total probability is less than 65535, no effect is selected;
// if it is more than 65535, sometimes more than one is selected!
// So we need to normalize them to ensure they add up to 65535

int totalAddUp = 0;
for (int i = firstIndex; i < effect.blocks.size(); i++) {
VisualEffectBlock block = effect.blocks.get(i);
totalAddUp += block.selectionChance;
}

int difference = 65535 - totalAddUp;
int distributedDifference = difference / (effect.blocks.size() - firstIndex);
int finalRemainder = difference - distributedDifference * (effect.blocks.size() - firstIndex);
for (int i = firstIndex; i < effect.blocks.size(); i++) {
VisualEffectBlock block = effect.blocks.get(i);
block.selectionChance += distributedDifference;
if (i == firstIndex) {
block.selectionChance += finalRemainder;
}
}

// Tell the blocks which group to use
for (int i = firstIndex; i < effect.blocks.size(); i++) {
VisualEffectBlock block = effect.blocks.get(i);
Expand Down Expand Up @@ -303,6 +333,9 @@ public void toArgScript(ArgScriptWriter writer) {
int maskedFlags = flags & ~FLAGMASK;
if (maskedFlags != 0) writer.option("flags").arguments("0x" + Integer.toHexString(maskedFlags));

writer.flag("rigid", (flags & FLAG_RIGID) != 0);
writer.flag("hardStop", (flags & FLAG_HARDSTOP) != 0);

int appFlagsMask = 0;
for (VisualEffectBlock block : blocks) appFlagsMask |= block.appFlagsMask;
if (componentAppFlagsMask != appFlagsMask) writer.option("componentAppFlagsMask")
Expand Down

0 comments on commit a4593d6

Please sign in to comment.