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