Skip to content

Commit

Permalink
Extended search: bugfixes and more filter options for CRE
Browse files Browse the repository at this point in the history
  • Loading branch information
Argent77 committed Jan 29, 2014
1 parent 6b1e187 commit 60529d1
Show file tree
Hide file tree
Showing 5 changed files with 822 additions and 101 deletions.
38 changes: 38 additions & 0 deletions src/infinity/datatype/IwdRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,44 @@ public long getValue()
return value;
}

public long getValue(String ref)
{
if (ref != null && !ref.isEmpty()) {
if (ref.lastIndexOf('.') > 0) {
ref = ref.substring(0, ref.lastIndexOf(',')).toUpperCase();
} else {
ref = ref.toUpperCase();
}
if (idsmap.containsValue(ref)) {
long[] keys = idsmap.keys();
for (int i = 0; i < keys.length; i++) {
if (idsmap.get(keys[i]).equals(ref)) {
return keys[i];
}
}
}
}
return -1L;
}

public String getValueRef()
{
if (idsmap.containsKey(value)) {
return idsmap.get(value).getString() + ".SPL";
} else {
return "None";
}
}

public String getValueRef(long id)
{
if (idsmap.containsKey(id)) {
return idsmap.get(id).getString() + ".SPL";
} else {
return "None";
}
}

// -------------------------- INNER CLASSES --------------------------

private static final class SplRefEntry implements Comparable<SplRefEntry>
Expand Down
156 changes: 150 additions & 6 deletions src/infinity/resource/cre/CreResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import infinity.NearInfinity;
import infinity.datatype.Bitmap;
import infinity.datatype.ColorValue;
import infinity.datatype.Datatype;
import infinity.datatype.DecNumber;
import infinity.datatype.Flag;
import infinity.datatype.HashBitmap;
Expand Down Expand Up @@ -96,11 +97,13 @@ public final class CreResource extends AbstractStruct implements Resource, HasAd
"Subvocal casting",
"Toughness", "Two-weapon fighting", "Weapon finesse", "Wild shape boar", "Wild shape panther",
"Wild shape shambler"};
public static final String s_attributes[] = {
public static final String s_attributes_pst[] = {
"No flags set", "", "Transparent", "", "", "Increment death variable", "Increment kill count",
"Script name only", "Increment faction kills", "Increment team kills", "Invulnerable",
"Good increment on death", "Law increment on death", "Lady increment on death", "Murder increment on death",
"Don't face speaker", "Call for help", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Died"};
public static final String s_attributes_iwd2[] = {"No flags set", "Mental fortitude", "Critical hit immunity",
"Cannot be paladin", "Cannot be monk"};
public static final String s_attacks[] = {"0", "1", "2", "3", "4", "5", "1/2", "3/2", "5/2", "7/2", "9/2"};
public static final String s_noyes[] = {"No", "Yes"};
public static final String s_visible[] = {"Shown", "Hidden"};
Expand Down Expand Up @@ -738,10 +741,7 @@ private int readIWD2(byte buffer[], int offset) throws Exception
list.add(new Unknown(buffer, offset + 746, 15));
list.add(new DecNumber(buffer, offset + 761, 1, "Fade amount"));
list.add(new DecNumber(buffer, offset + 762, 1, "Fade speed"));
list.add(new Flag(buffer, offset + 763, 1, "Attributes",
new String[]{"No flags set", "Mental fortitude",
"Critical hit immunity", "Cannot be paladin",
"Cannot be monk"}));
list.add(new Flag(buffer, offset + 763, 1, "Attributes", s_attributes_iwd2));
list.add(new DecNumber(buffer, offset + 764, 1, "Visibility"));
list.add(new Unknown(buffer, offset + 765, 2));
list.add(new DecNumber(buffer, offset + 767, 1, "Unused skill points"));
Expand Down Expand Up @@ -1233,7 +1233,7 @@ else if (ResourceFactory.getInstance().resourceExists("DIETY.IDS"))
list.add(new DecNumber(buffer, offset + 725, 1, "Collision radius")); // 0x2dd
list.add(new Unknown(buffer, offset + 726, 1));
list.add(new DecNumber(buffer, offset + 727, 1, "# colors"));
list.add(new Flag(buffer, offset + 728, 4, "Attributes", s_attributes));
list.add(new Flag(buffer, offset + 728, 4, "Attributes", s_attributes_pst));
// list.add(new Flag(buffer, offset + 729, 1, "Attribute flags 2",
// new String[]{"No flags set", "", "Invulnerable"}));
// list.add(new Unknown(buffer, offset + 730, 2));
Expand Down Expand Up @@ -1561,10 +1561,86 @@ public static boolean matchSearchOptions(ResourceEntry entry, SearchOptions sear
if (entry != null && searchOptions != null) {
try {
CreResource cre = new CreResource(entry);
AbstractStruct[] effects;
AbstractStruct[] items;
Datatype[] spells;
boolean retVal = true;
String key;
Object o;

// preparing substructures
DecNumber ofs = (DecNumber)cre.getAttribute("Effects offset");
DecNumber cnt = (DecNumber)cre.getAttribute("# effects");
if (ofs != null && ofs.getValue() > 0 && cnt != null && cnt.getValue() > 0) {
effects = new AbstractStruct[cnt.getValue()];
for (int idx = 0; idx < cnt.getValue(); idx++) {
String label = String.format(SearchOptions.getResourceName(SearchOptions.CRE_Effect), idx);
effects[idx] = (AbstractStruct)cre.getAttribute(label);
}
} else {
effects = new AbstractStruct[0];
}

ofs = (DecNumber)cre.getAttribute("Items offset");
cnt = (DecNumber)cre.getAttribute("# items");
if (ofs != null && ofs.getValue() > 0 && cnt != null && cnt.getValue() > 0) {
items = new AbstractStruct[cnt.getValue()];
for (int idx = 0; idx < cnt.getValue(); idx++) {
String label = String.format(SearchOptions.getResourceName(SearchOptions.CRE_Item), idx);
items[idx] = (AbstractStruct)cre.getAttribute(label);
}
} else {
items = new AbstractStruct[0];
}

if (ResourceFactory.getGameID() == ResourceFactory.ID_ICEWIND2) {
final String[] spellTypes = new String[]{
SearchOptions.getResourceName(SearchOptions.CRE_IWD2SpellBard),
SearchOptions.getResourceName(SearchOptions.CRE_IWD2SpellCleric),
SearchOptions.getResourceName(SearchOptions.CRE_IWD2SpellDruid),
SearchOptions.getResourceName(SearchOptions.CRE_IWD2SpellPaladin),
SearchOptions.getResourceName(SearchOptions.CRE_IWD2SpellRanger),
SearchOptions.getResourceName(SearchOptions.CRE_IWD2SpellSorcerer),
SearchOptions.getResourceName(SearchOptions.CRE_IWD2SpellWizard),
SearchOptions.getResourceName(SearchOptions.CRE_IWD2SpellDomain)};
final String spellTypesStruct = SearchOptions.getResourceName(SearchOptions.CRE_IWD2SpellBard_Spell);
final String spellTypesRef = SearchOptions.getResourceName(SearchOptions.CRE_IWD2SpellBard_Spell_ResRef);
List<Datatype> listSpells = new ArrayList<Datatype>(64);
for (int i = 0; i < spellTypes.length; i++) {
for (int j = 1; j < 10; j++) {
String label = String.format(spellTypes[i], j);
AbstractStruct struct1 = (AbstractStruct)cre.getAttribute(label);
if (struct1 != null) {
AbstractStruct struct2 = (AbstractStruct)struct1.getAttribute(spellTypesStruct);
if (struct2 != null) {
Datatype struct3 = (Datatype)struct2.getAttribute(spellTypesRef);
if (struct3 != null) {
listSpells.add(struct3);
}
}
}
}
}
spells = new Datatype[listSpells.size()];
for (int i = 0; i < spells.length; i++) {
spells[i] = listSpells.get(i);
}
} else {
ofs = (DecNumber)cre.getAttribute("Known spells offset");
cnt = (DecNumber)cre.getAttribute("# known spells");
if (ofs != null && ofs.getValue() > 0 && cnt != null && cnt.getValue() > 0) {
spells = new Datatype[cnt.getValue()];
final String spellLabel = SearchOptions.getResourceName(SearchOptions.CRE_Spell_Spell1);
for (int idx = 0; idx < cnt.getValue(); idx++) {
String label = String.format(SearchOptions.getResourceName(SearchOptions.CRE_Spell), idx);
AbstractStruct struct = (AbstractStruct)cre.getAttribute(label);
spells[idx] = (Datatype)struct.getAttribute(spellLabel);
}
} else {
spells = new Datatype[0];
}
}

// checking options
String[] keyList = new String[]{SearchOptions.CRE_Name, SearchOptions.CRE_ScriptName};
for (int idx = 0; idx < keyList.length; idx++) {
Expand Down Expand Up @@ -1638,6 +1714,74 @@ public static boolean matchSearchOptions(ResourceEntry entry, SearchOptions sear
}
}

keyList = new String[]{SearchOptions.CRE_Effect_Type1, SearchOptions.CRE_Effect_Type2,
SearchOptions.CRE_Effect_Type3, SearchOptions.CRE_Effect_Type4};
for (int idx = 0; idx < keyList.length; idx++) {
if (retVal) {
boolean found = false;
key = keyList[idx];
o = searchOptions.getOption(key);
for (int idx2 = 0; idx2 < effects.length; idx2++) {
if (!found) {
if (effects[idx2] != null) {
StructEntry struct = effects[idx2].getAttribute(SearchOptions.getResourceName(key));
found |= SearchOptions.Utils.matchNumber(struct, o);
}
} else {
break;
}
}
retVal &= found || (o == null);
} else {
break;
}
}

keyList = new String[]{SearchOptions.CRE_Item_Item1, SearchOptions.CRE_Item_Item2,
SearchOptions.CRE_Item_Item3, SearchOptions.CRE_Item_Item4};
for (int idx = 0; idx < keyList.length; idx++) {
if (retVal) {
boolean found = false;
key = keyList[idx];
o = searchOptions.getOption(key);
for (int idx2 = 0; idx2 < items.length; idx2++) {
if (!found) {
if (items[idx2] != null) {
StructEntry struct = items[idx2].getAttribute(SearchOptions.getResourceName(key));
found |= SearchOptions.Utils.matchResourceRef(struct, o, false);
}
} else {
break;
}
}
retVal &= found || (o == null);
} else {
break;
}
}

keyList = new String[]{SearchOptions.CRE_Spell_Spell1, SearchOptions.CRE_Spell_Spell2,
SearchOptions.CRE_Spell_Spell3, SearchOptions.CRE_Spell_Spell4};
for (int idx = 0; idx < keyList.length; idx++) {
if (retVal) {
boolean found = false;
key = keyList[idx];
o = searchOptions.getOption(key);
for (int idx2 = 0; idx2 < spells.length; idx2++) {
if (!found) {
if (spells[idx2] != null) {
found |= SearchOptions.Utils.matchResourceRef(spells[idx2], o, false);
}
} else {
break;
}
}
retVal &= found || (o == null);
} else {
break;
}
}

return retVal;
} catch (Exception e) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/infinity/resource/itm/ItmResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public static boolean matchSearchOptions(ResourceEntry entry, SearchOptions sear
for (int idx = 0; idx < keyList.length; idx++) {
if (retVal) {
boolean found = false;
key = SearchOptions.ITM_Effect_Type1;
key = keyList[idx];
o = searchOptions.getOption(key);
for (int idx2 = 0; idx2 < effects.length; idx2++) {
if (!found) {
Expand Down
62 changes: 59 additions & 3 deletions src/infinity/search/SearchOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,45 @@ public class SearchOptions
public static final String CRE_Feats2 = "CRE.Feats (2/3).0";
public static final String CRE_Feats3 = "CRE.Feats (3/3).0";
public static final String CRE_Attributes = "CRE.Attributes.0";
public static final String CRE_Effect = "CRE.Effect %1$d.0"; // marks substructure
public static final String CRE_Effect_Type1 = "CRE.Effect.Type.0";
public static final String CRE_Effect_Type2 = "CRE.Effect.Type.1";
public static final String CRE_Effect_Type3 = "CRE.Effect.Type.2";
public static final String CRE_Effect_Type4 = "CRE.Effect.Type.3";
public static final String CRE_Item = "CRE.Item %1$d.0"; // marks substructure
public static final String CRE_Item_Item1 = "CRE.Item.Item.0";
public static final String CRE_Item_Item2 = "CRE.Item.Item.1";
public static final String CRE_Item_Item3 = "CRE.Item.Item.2";
public static final String CRE_Item_Item4 = "CRE.Item.Item.3";
public static final String CRE_Spell = "CRE.Known spell %1$d.0"; // marks substructure
public static final String CRE_Spell_Spell1 = "CRE.Known spell.Spell.0";
public static final String CRE_Spell_Spell2 = "CRE.Known spell.Spell.1";
public static final String CRE_Spell_Spell3 = "CRE.Known spell.Spell.2";
public static final String CRE_Spell_Spell4 = "CRE.Known spell.Spell.3";
public static final String CRE_IWD2SpellBard = "CRE.Bard spells %1$d.0"; // marks substructure
public static final String CRE_IWD2SpellBard_Spell = "CRE.Bard spells.Spell.0"; // marks substructure
public static final String CRE_IWD2SpellBard_Spell_ResRef = "CRE.Bard spells.Spell.ResRef.0"; // marks substructure
public static final String CRE_IWD2SpellCleric = "CRE.Cleric spells %1$d.0"; // marks substructure
public static final String CRE_IWD2SpellCleric_Spell = "CRE.Cleric spells.Spell.0"; // marks substructure
public static final String CRE_IWD2SpellCleric_Spell_ResRef = "CRE.Cleric spells.Spell.ResRef.0"; // marks substructure
public static final String CRE_IWD2SpellDruid = "CRE.Druid spells %1$d.0"; // marks substructure
public static final String CRE_IWD2SpellDruid_Spell = "CRE.Druid spells.Spell.0"; // marks substructure
public static final String CRE_IWD2SpellDruid_Spell_ResRef = "CRE.Druid spells.Spell.ResRef.0"; // marks substructure
public static final String CRE_IWD2SpellPaladin = "CRE.Paladin spells %1$d.0"; // marks substructure
public static final String CRE_IWD2SpellPaladin_Spell = "CRE.Paladin spells.Spell.0"; // marks substructure
public static final String CRE_IWD2SpellPaladin_Spell_ResRef = "CRE.Paladin spells.Spell.ResRef.0"; // marks substructure
public static final String CRE_IWD2SpellRanger = "CRE.Ranger spells %1$d.0"; // marks substructure
public static final String CRE_IWD2SpellRanger_Spell = "CRE.Ranger spells.Spell.0"; // marks substructure
public static final String CRE_IWD2SpellRanger_Spell_ResRef = "CRE.Ranger spells.Spell.ResRef.0"; // marks substructure
public static final String CRE_IWD2SpellSorcerer = "CRE.Sorcerer spells %1$d.0"; // marks substructure
public static final String CRE_IWD2SpellSorcerer_Spell = "CRE.Sorcerer spells.Spell.0"; // marks substructure
public static final String CRE_IWD2SpellSorcerer_Spell_ResRef = "CRE.Sorcerer spells.Spell.ResRef.0"; // marks substructure
public static final String CRE_IWD2SpellWizard = "CRE.Wizard spells %1$d.0"; // marks substructure
public static final String CRE_IWD2SpellWizard_Spell = "CRE.Wizard spells.Spell.0"; // marks substructure
public static final String CRE_IWD2SpellWizard_Spell_ResRef = "CRE.Wizard spells.Spell.ResRef.0"; // marks substructure
public static final String CRE_IWD2SpellDomain = "CRE.Domain spells %1$d.0"; // marks substructure
public static final String CRE_IWD2SpellDomain_Spell = "CRE.Domain spells.Spell.0"; // marks substructure
public static final String CRE_IWD2SpellDomain_Spell_ResRef = "CRE.Domain spells.Spell.ResRef.0"; // marks substructure

public static final String EFF = "EFF.0"; // marks structure
public static final String EFF_Effect = "EFF.Type.0";
Expand Down Expand Up @@ -398,9 +437,26 @@ public static final class Utils
// Returns whether ref and value are equal, optionally taking case-sensitivity into account.
public static boolean matchResourceRef(StructEntry ref, Object value, boolean caseSensitive)
{
if (ref != null && ref instanceof ResourceRef && value != null && value instanceof String) {
String s1 = (String)value;
String s2 = ((ResourceRef)ref).getResourceName();
// if (ref != null && ref instanceof ResourceRef && value != null && value instanceof String) {
if (ref != null && value != null ) {
String s1, s2;
if (ref instanceof ResourceRef && value instanceof String) {
s1 = (String)value;
s2 = ((ResourceRef)ref).getResourceName();
} else if (ref instanceof IwdRef) {
if (value instanceof Integer) {
s1 = ((IwdRef)ref).getValueRef((Integer)value);
} else if (value instanceof Long) {
s1 = ((IwdRef)ref).getValueRef((Long)value);
} else if (value instanceof String) {
s1 = (String)value;
} else {
return false;
}
s2 = ((IwdRef) ref).getValueRef();
} else {
return false;
}

// special case: "NONE"
if ((s1.isEmpty() || "NONE".equalsIgnoreCase(s1)) &&
Expand Down
Loading

0 comments on commit 60529d1

Please sign in to comment.