v0.2.4: reworked actor ID system, IDs are now garunteed unique
This commit is contained in:
parent
e4cfe7586a
commit
37af7dfec3
|
@ -142,6 +142,7 @@ public class Dungeon {
|
||||||
Generator.initArtifacts();
|
Generator.initArtifacts();
|
||||||
|
|
||||||
Actor.clear();
|
Actor.clear();
|
||||||
|
Actor.resetNextID();
|
||||||
|
|
||||||
PathFinder.setMapSize( Level.WIDTH, Level.HEIGHT );
|
PathFinder.setMapSize( Level.WIDTH, Level.HEIGHT );
|
||||||
|
|
||||||
|
@ -459,6 +460,8 @@ public class Dungeon {
|
||||||
Potion.save( bundle );
|
Potion.save( bundle );
|
||||||
Wand.save( bundle );
|
Wand.save( bundle );
|
||||||
Ring.save( bundle );
|
Ring.save( bundle );
|
||||||
|
|
||||||
|
Actor.storeNextID( bundle );
|
||||||
|
|
||||||
Bundle badges = new Bundle();
|
Bundle badges = new Bundle();
|
||||||
Badges.saveLocal( badges );
|
Badges.saveLocal( badges );
|
||||||
|
@ -517,6 +520,8 @@ public class Dungeon {
|
||||||
|
|
||||||
Generator.reset();
|
Generator.reset();
|
||||||
|
|
||||||
|
Actor.restoreNextID( bundle );
|
||||||
|
|
||||||
quickslot.reset();
|
quickslot.reset();
|
||||||
QuickSlotButton.reset();
|
QuickSlotButton.reset();
|
||||||
|
|
||||||
|
|
|
@ -79,17 +79,12 @@ public abstract class Actor implements Bundlable {
|
||||||
id = bundle.getInt( ID );
|
id = bundle.getInt( ID );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int nextID = 1;
|
||||||
public int id() {
|
public int id() {
|
||||||
if (id > 0) {
|
if (id > 0) {
|
||||||
return id;
|
return id;
|
||||||
} else {
|
} else {
|
||||||
int max = 0;
|
return (id = nextID++);
|
||||||
for (Actor a : all) {
|
|
||||||
if (a.id > max) {
|
|
||||||
max = a.id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (id = max + 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +142,20 @@ public abstract class Actor implements Bundlable {
|
||||||
|
|
||||||
current = null;
|
current = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final String NEXTID = "nextid";
|
||||||
|
|
||||||
|
public static void storeNextID( Bundle bundle){
|
||||||
|
bundle.put( NEXTID, nextID );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void restoreNextID( Bundle bundle){
|
||||||
|
nextID = bundle.getInt( NEXTID );
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void resetNextID(){
|
||||||
|
nextID = 1;
|
||||||
|
}
|
||||||
|
|
||||||
public static void occupyCell( Char ch ) {
|
public static void occupyCell( Char ch ) {
|
||||||
chars[ch.pos] = ch;
|
chars[ch.pos] = ch;
|
||||||
|
@ -228,9 +237,7 @@ public abstract class Actor implements Bundlable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actor.id > 0) {
|
ids.put( actor.id(), actor );
|
||||||
ids.put( actor.id, actor );
|
|
||||||
}
|
|
||||||
|
|
||||||
all.add( actor );
|
all.add( actor );
|
||||||
actor.time += time;
|
actor.time += time;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user