project_files/Android-build/SDL-android-project/src/org/hedgewars/hedgeroid/frontlib/Frontlib.java
changeset 7508 763d3961400b
parent 7485 0481bd74267c
child 7558 983ff426f91e
equal deleted inserted replaced
7504:ed1d52c5aa94 7508:763d3961400b
    10 import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
    10 import org.hedgewars.hedgeroid.Datastructures.MapRecipe;
    11 import org.hedgewars.hedgeroid.Datastructures.MetaScheme;
    11 import org.hedgewars.hedgeroid.Datastructures.MetaScheme;
    12 import org.hedgewars.hedgeroid.Datastructures.MetaScheme.Mod;
    12 import org.hedgewars.hedgeroid.Datastructures.MetaScheme.Mod;
    13 import org.hedgewars.hedgeroid.Datastructures.MetaScheme.Setting;
    13 import org.hedgewars.hedgeroid.Datastructures.MetaScheme.Setting;
    14 import org.hedgewars.hedgeroid.Datastructures.GameConfig;
    14 import org.hedgewars.hedgeroid.Datastructures.GameConfig;
    15 import org.hedgewars.hedgeroid.Datastructures.RoomlistRoom;
    15 import org.hedgewars.hedgeroid.Datastructures.Room;
    16 import org.hedgewars.hedgeroid.Datastructures.Scheme;
    16 import org.hedgewars.hedgeroid.Datastructures.Scheme;
    17 import org.hedgewars.hedgeroid.Datastructures.Team;
    17 import org.hedgewars.hedgeroid.Datastructures.Team;
    18 import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
    18 import org.hedgewars.hedgeroid.Datastructures.TeamInGame;
    19 import org.hedgewars.hedgeroid.Datastructures.TeamIngameAttributes;
    19 import org.hedgewars.hedgeroid.Datastructures.TeamIngameAttributes;
    20 import org.hedgewars.hedgeroid.Datastructures.Weaponset;
    20 import org.hedgewars.hedgeroid.Datastructures.Weaponset;
    24 import com.sun.jna.Memory;
    24 import com.sun.jna.Memory;
    25 import com.sun.jna.NativeLong;
    25 import com.sun.jna.NativeLong;
    26 import com.sun.jna.Pointer;
    26 import com.sun.jna.Pointer;
    27 import com.sun.jna.PointerType;
    27 import com.sun.jna.PointerType;
    28 import com.sun.jna.Structure;
    28 import com.sun.jna.Structure;
    29 import com.sun.jna.ptr.IntByReference;
       
    30 
    29 
    31 /**
    30 /**
    32  * Here is an introduction to the most important aspects of the JNA code.
    31  * Here is an introduction to the most important aspects of the JNA code.
    33  * 
    32  * 
    34  * This interface permits access to the Hedgewars frontend library (frontlib)
    33  * This interface permits access to the Hedgewars frontend library (frontlib)
    49  * via the PointerType classes. They allow you to get at the data of the struct
    48  * via the PointerType classes. They allow you to get at the data of the struct
    50  * with a function called deref(), which creates a plain normal Java object
    49  * with a function called deref(), which creates a plain normal Java object
    51  * representing the data (e.g. SchemePtr.deref() will give you a Scheme object).
    50  * representing the data (e.g. SchemePtr.deref() will give you a Scheme object).
    52  * 
    51  * 
    53  * Remember that you usually have to destroy structs that you receive from the
    52  * Remember that you usually have to destroy structs that you receive from the
    54  * library, because they are owned by the native code, not Java. For example, if
    53  * library, because they are owned by the native code, not Java. The recommended
    55  * you obtain a {@link MetaschemePtr} metaPtr using flib_metascheme_from_ini,
    54  * pattern for most cases is to call deref() on the pointer to get a Java object
    56  * you have to call flib_metascheme_release(metaPtr) after you are done using
    55  * (that you can keep as long as you like), and then immediately destroy the
    57  * it. The recommended pattern for most cases is to call deref() on the pointer
    56  * struct if it needs destroying. To find out whether and how the struct needs
    58  * to get a Java object (that you can keep as long as you like), and then
    57  * to be destroyed, see the library's documentation of the function that you got
    59  * immediately destroy the struct if it needs destroying. To find out whether
    58  * the struct from.
    60  * and how the struct needs to be destroyed, see the library's documentation of
       
    61  * the function that you got the struct from.
       
    62  * 
    59  * 
    63  * To pass new structs to the library, you can use the static createJavaOwned()
    60  * To pass new structs to the library, you can use the static createJavaOwned()
    64  * function in each PointerType, which creates a new struct from the Java object
    61  * function in each PointerType, which creates a new struct from the Java object
    65  * you provide, and returns a pointer to that struct that you can pass to
    62  * you provide, and returns a pointer to that struct that you can pass to
    66  * library functions. This new structure's memory is owned and managed by Java
    63  * library functions. This new structure's memory is owned and managed by Java
   144 			return struct.toMetaScheme();
   141 			return struct.toMetaScheme();
   145 		}
   142 		}
   146 	}
   143 	}
   147 	
   144 	
   148 	public static class RoomArrayPtr extends PointerType { 
   145 	public static class RoomArrayPtr extends PointerType { 
   149 		public RoomlistRoom[] getRooms(int count) {
   146 		public Room[] getRooms(int count) {
   150 			Pointer ptr = getPointer();
   147 			Pointer ptr = getPointer();
   151 			if(ptr == null) {
   148 			if(ptr == null) {
   152 				return new RoomlistRoom[0];
   149 				return new Room[0];
   153 			}
   150 			}
   154 			Pointer[] untypedPtrs = ptr.getPointerArray(0, count);
   151 			Pointer[] untypedPtrs = ptr.getPointerArray(0, count);
   155 			RoomlistRoom[] result = new RoomlistRoom[count];
   152 			Room[] result = new Room[count];
   156 			for(int i=0; i<count; i++) {
   153 			for(int i=0; i<count; i++) {
   157 				result[i] = RoomPtr.deref(untypedPtrs[i]);
   154 				result[i] = RoomPtr.deref(untypedPtrs[i]);
   158 			}
   155 			}
   159 			return result;
   156 			return result;
   160 		}
   157 		}
   161 	}
   158 	}
   162 	
   159 	
   163 	public static class RoomPtr extends PointerType {
   160 	public static class RoomPtr extends PointerType {
   164 		public RoomlistRoom deref() {
   161 		public Room deref() {
   165 			return deref(getPointer());
   162 			return deref(getPointer());
   166 		}
   163 		}
   167 		
   164 		
   168 		public static RoomlistRoom deref(Pointer p) {
   165 		public static Room deref(Pointer p) {
   169 			RoomStruct struct = new RoomStruct(p);
   166 			RoomStruct struct = new RoomStruct(p);
   170 			struct.read();
   167 			struct.read();
   171 			return struct.toRoomlistRoom();
   168 			return struct.toRoomlistRoom();
   172 		}
   169 		}
   173 	}
   170 	}
   418 	}
   415 	}
   419 	
   416 	
   420 	static class WeaponsetStruct extends Structure {
   417 	static class WeaponsetStruct extends Structure {
   421 		public static class ByVal extends WeaponsetStruct implements Structure.ByValue {}
   418 		public static class ByVal extends WeaponsetStruct implements Structure.ByValue {}
   422 		public static class ByRef extends WeaponsetStruct implements Structure.ByReference {}
   419 		public static class ByRef extends WeaponsetStruct implements Structure.ByReference {}
   423 		private static String[] FIELD_ORDER = new String[] {"_referenceCount", "loadout", "crateprob", "crateammo", "delay", "name"};
   420 		private static String[] FIELD_ORDER = new String[] {"loadout", "crateprob", "crateammo", "delay", "name"};
   424 		
   421 		
   425 		public WeaponsetStruct() { super(); setFieldOrder(FIELD_ORDER); }
   422 		public WeaponsetStruct() { super(); setFieldOrder(FIELD_ORDER); }
   426 		public WeaponsetStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   423 		public WeaponsetStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   427 		
   424 		
   428 		public void fillFrom(Weaponset weaponset) {
   425 		public void fillFrom(Weaponset weaponset) {
   429 			_referenceCount = 0;
       
   430 			fillWeaponInfo(loadout, weaponset.loadout);
   426 			fillWeaponInfo(loadout, weaponset.loadout);
   431 			fillWeaponInfo(crateprob, weaponset.crateProb);
   427 			fillWeaponInfo(crateprob, weaponset.crateProb);
   432 			fillWeaponInfo(crateammo, weaponset.crateAmmo);
   428 			fillWeaponInfo(crateammo, weaponset.crateAmmo);
   433 			fillWeaponInfo(delay, weaponset.delay);
   429 			fillWeaponInfo(delay, weaponset.delay);
   434 			name = weaponset.name;
   430 			name = weaponset.name;
   451 			} catch (UnsupportedEncodingException e) {
   447 			} catch (UnsupportedEncodingException e) {
   452 				throw new AssertionError();
   448 				throw new AssertionError();
   453 			}
   449 			}
   454 		}
   450 		}
   455 		
   451 		
   456 		public int _referenceCount;
       
   457 		public byte[] loadout = new byte[Weaponset.WEAPONS_COUNT+1];
   452 		public byte[] loadout = new byte[Weaponset.WEAPONS_COUNT+1];
   458 		public byte[] crateprob = new byte[Weaponset.WEAPONS_COUNT+1];
   453 		public byte[] crateprob = new byte[Weaponset.WEAPONS_COUNT+1];
   459 		public byte[] crateammo = new byte[Weaponset.WEAPONS_COUNT+1];
   454 		public byte[] crateammo = new byte[Weaponset.WEAPONS_COUNT+1];
   460 		public byte[] delay = new byte[Weaponset.WEAPONS_COUNT+1];
   455 		public byte[] delay = new byte[Weaponset.WEAPONS_COUNT+1];
   461 		public String name;
   456 		public String name;
   481 		public WeaponsetListStruct() { super(); setFieldOrder(FIELD_ORDER); }
   476 		public WeaponsetListStruct() { super(); setFieldOrder(FIELD_ORDER); }
   482 		public WeaponsetListStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   477 		public WeaponsetListStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   483 		
   478 		
   484 		public void fillFrom(List<Weaponset> list) {
   479 		public void fillFrom(List<Weaponset> list) {
   485 			weaponsetCount = list.size();
   480 			weaponsetCount = list.size();
   486 			weaponsets = new WeaponsetPointerByReference();
   481 			if(weaponsetCount<=0) {
   487 			Structure[] structs = weaponsets.toArray(weaponsetCount);
   482 				weaponsets = null;
   488 			
   483 			} else {
   489 			for(int i=0; i<weaponsetCount; i++) {
   484 				weaponsets = new WeaponsetPointerByReference();
   490 				WeaponsetPointerByReference pstruct = (WeaponsetPointerByReference)structs[i];
   485 				Structure[] structs = weaponsets.toArray(weaponsetCount);
   491 				pstruct.weaponset = new WeaponsetStruct.ByRef();
   486 				
   492 				pstruct.weaponset.fillFrom(list.get(i));
   487 				for(int i=0; i<weaponsetCount; i++) {
       
   488 					WeaponsetPointerByReference pstruct = (WeaponsetPointerByReference)structs[i];
       
   489 					pstruct.weaponset = new WeaponsetStruct.ByRef();
       
   490 					pstruct.weaponset.fillFrom(list.get(i));
       
   491 				}
   493 			}
   492 			}
   494 		}
   493 		}
   495 		
   494 		
   496 		/**
   495 		/**
   497 		 * Only use on native-owned structs!
   496 		 * Only use on native-owned structs!
   523 		private static String[] FIELD_ORDER = new String[] {"inProgress", "name", "playerCount", "teamCount", "owner", "map", "scheme", "weapons"};
   522 		private static String[] FIELD_ORDER = new String[] {"inProgress", "name", "playerCount", "teamCount", "owner", "map", "scheme", "weapons"};
   524 		
   523 		
   525 		public RoomStruct() { super(); setFieldOrder(FIELD_ORDER); }
   524 		public RoomStruct() { super(); setFieldOrder(FIELD_ORDER); }
   526 		public RoomStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   525 		public RoomStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   527 
   526 
   528 		public RoomlistRoom toRoomlistRoom() {
   527 		public Room toRoomlistRoom() {
   529 			return new RoomlistRoom(name, map, scheme, weapons, owner, playerCount, teamCount, inProgress);
   528 			return new Room(name, map, scheme, weapons, owner, playerCount, teamCount, inProgress);
   530 		}
   529 		}
   531 		
   530 		
   532 	    public boolean inProgress;
   531 	    public boolean inProgress;
   533 	    public String name;
   532 	    public String name;
   534 	    public int playerCount;
   533 	    public int playerCount;
   639 	
   638 	
   640 	static class MetaschemeStruct extends Structure {
   639 	static class MetaschemeStruct extends Structure {
   641 		public static class ByVal extends MetaschemeStruct implements Structure.ByValue {}
   640 		public static class ByVal extends MetaschemeStruct implements Structure.ByValue {}
   642 		public static class ByRef extends MetaschemeStruct implements Structure.ByReference {}
   641 		public static class ByRef extends MetaschemeStruct implements Structure.ByReference {}
   643 
   642 
   644 		private static String[] FIELD_ORDER = new String[] {"_referenceCount", "settingCount", "modCount", "settings", "mods"};
   643 		private static String[] FIELD_ORDER = new String[] {"settingCount", "modCount", "settings", "mods"};
   645 		
   644 		
   646 		public MetaschemeStruct() { super(); setFieldOrder(FIELD_ORDER); }
   645 		public MetaschemeStruct() { super(); setFieldOrder(FIELD_ORDER); }
   647 		public MetaschemeStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   646 		public MetaschemeStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   648 		
       
   649 		public void fillFrom(MetaScheme metascheme) {
       
   650 			settingCount = metascheme.settings.size();
       
   651 			modCount = metascheme.mods.size();
       
   652 			
       
   653 			settings = new MetaschemeSettingStruct.ByRef();
       
   654 			Structure[] settingStructs = settings.toArray(settingCount);
       
   655 			mods = new MetaschemeModStruct.ByRef();
       
   656 			Structure[] modStructs = mods.toArray(modCount);
       
   657 			
       
   658 			for(int i=0; i<settingCount; i++) {
       
   659 				MetaschemeSettingStruct mss = (MetaschemeSettingStruct)settingStructs[i];
       
   660 				mss.fillFrom(metascheme.settings.get(i));
       
   661 			}
       
   662 			
       
   663 			for(int i=0; i<modCount; i++) {
       
   664 				MetaschemeModStruct mms = (MetaschemeModStruct)modStructs[i];
       
   665 				mms.fillFrom(metascheme.mods.get(i));
       
   666 			}
       
   667 		}
       
   668 		
   647 		
   669 		/**
   648 		/**
   670 		 * Only use on native-owned structs!
   649 		 * Only use on native-owned structs!
   671 		 * Calling this method on a Java-owned struct could cause garbage collection of referenced
   650 		 * Calling this method on a Java-owned struct could cause garbage collection of referenced
   672 		 * structures.
   651 		 * structures.
   689 			}
   668 			}
   690 			
   669 			
   691 			return new MetaScheme(modList, settingList);
   670 			return new MetaScheme(modList, settingList);
   692 		}
   671 		}
   693 		
   672 		
   694 		public int _referenceCount;
       
   695 		public int settingCount;
   673 		public int settingCount;
   696 		public int modCount;
   674 		public int modCount;
   697 		public MetaschemeSettingStruct.ByRef settings;
   675 		public MetaschemeSettingStruct.ByRef settings;
   698 		public MetaschemeModStruct.ByRef mods;
   676 		public MetaschemeModStruct.ByRef mods;
   699 	}
   677 	}
   700 	
   678 	
   701 	static class SchemeStruct extends Structure {
   679 	static class SchemeStruct extends Structure {
   702 		public static class ByVal extends SchemeStruct implements Structure.ByValue {}
   680 		public static class ByVal extends SchemeStruct implements Structure.ByValue {}
   703 		public static class ByRef extends SchemeStruct implements Structure.ByReference {}
   681 		public static class ByRef extends SchemeStruct implements Structure.ByReference {}
   704 		private static String[] FIELD_ORDER = new String[] {"meta", "name", "settings", "mod"};
   682 		private static String[] FIELD_ORDER = new String[] {"name", "settings", "mod"};
   705 		
   683 		
   706 		public SchemeStruct() { super(); setFieldOrder(FIELD_ORDER); }
   684 		public SchemeStruct() { super(); setFieldOrder(FIELD_ORDER); }
   707 		public SchemeStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   685 		public SchemeStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   708 		
   686 		
   709 		public void fillFrom(Scheme scheme) {
   687 		public void fillFrom(Scheme scheme) {
   710 			meta = new MetaschemeStruct.ByRef();
   688 			MetaScheme meta = MetaScheme.INSTANCE;
   711 			meta.fillFrom(scheme.metascheme);
       
   712 			name = scheme.name;
   689 			name = scheme.name;
   713 			settings = new Memory(NATIVE_INT_SIZE * scheme.metascheme.settings.size());
   690 			settings = new Memory(NATIVE_INT_SIZE * meta.settings.size());
   714 			for(int i=0; i<scheme.metascheme.settings.size(); i++) {
   691 			for(int i=0; i<meta.settings.size(); i++) {
   715 				Integer value = scheme.settings.get(scheme.metascheme.settings.get(i).name);
   692 				Integer value = scheme.settings.get(meta.settings.get(i).name);
   716 				settings.setInt(NATIVE_INT_SIZE*i, value);
   693 				settings.setInt(NATIVE_INT_SIZE*i, value);
   717 			}
   694 			}
   718 			mods = new Memory(NATIVE_BOOL_SIZE * scheme.metascheme.mods.size());
   695 			mods = new Memory(NATIVE_BOOL_SIZE * meta.mods.size());
   719 			for(int i=0; i<scheme.metascheme.mods.size(); i++) {
   696 			for(int i=0; i<meta.mods.size(); i++) {
   720 				Boolean value = scheme.mods.get(scheme.metascheme.mods.get(i).name);
   697 				Boolean value = scheme.mods.get(meta.mods.get(i).name);
   721 				mods.setByte(NATIVE_BOOL_SIZE*i, (byte)(value ? 1 : 0));
   698 				mods.setByte(NATIVE_BOOL_SIZE*i, (byte)(value ? 1 : 0));
   722 			}
   699 			}
   723 		}
   700 		}
   724 
   701 
   725 		public Scheme toScheme() {
   702 		public Scheme toScheme() {
   726 			MetaScheme metaScheme = meta.toMetaScheme();
       
   727 			Map<String, Integer> settingsMap = new HashMap<String, Integer>();
   703 			Map<String, Integer> settingsMap = new HashMap<String, Integer>();
   728 			for(int i=0; i<metaScheme.settings.size(); i++) {
   704 			MetaScheme meta = MetaScheme.INSTANCE;
   729 				settingsMap.put(metaScheme.settings.get(i).name, settings.getInt(NATIVE_INT_SIZE*i));
   705 			for(int i=0; i<meta.settings.size(); i++) {
       
   706 				settingsMap.put(meta.settings.get(i).name, settings.getInt(NATIVE_INT_SIZE*i));
   730 			}
   707 			}
   731 			Map<String, Boolean> modsMap = new HashMap<String, Boolean>();
   708 			Map<String, Boolean> modsMap = new HashMap<String, Boolean>();
   732 			for(int i=0; i<metaScheme.mods.size(); i++) {
   709 			for(int i=0; i<meta.mods.size(); i++) {
   733 				modsMap.put(metaScheme.mods.get(i).name, mods.getByte(i) != 0 ? Boolean.TRUE : Boolean.FALSE);
   710 				modsMap.put(meta.mods.get(i).name, mods.getByte(i) != 0 ? Boolean.TRUE : Boolean.FALSE);
   734 			}
   711 			}
   735 			return new Scheme(metaScheme, name, settingsMap, modsMap);
   712 			return new Scheme(name, settingsMap, modsMap);
   736 		}
   713 		}
   737 		
   714 		
   738 		public MetaschemeStruct.ByRef meta;
       
   739 		public String name;
   715 		public String name;
   740 		public Pointer settings;
   716 		public Pointer settings;
   741 		public Pointer mods;
   717 		public Pointer mods;
   742 	}
   718 	}
   743 	
   719 	
   761 		public SchemelistStruct() { super(); setFieldOrder(FIELD_ORDER); }
   737 		public SchemelistStruct() { super(); setFieldOrder(FIELD_ORDER); }
   762 		public SchemelistStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   738 		public SchemelistStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   763 		
   739 		
   764 		public void fillFrom(List<Scheme> schemeList) {
   740 		public void fillFrom(List<Scheme> schemeList) {
   765 			schemeCount = schemeList.size();
   741 			schemeCount = schemeList.size();
   766 			schemes = new SchemePointerByReference();
   742 			if(schemeCount<=0) {
   767 			Structure[] schemePtrStructs = schemes.toArray(schemeCount);
   743 				schemes = null;
   768 			
   744 			} else {
   769 			for(int i=0; i<this.schemeCount; i++) {
   745 				schemes = new SchemePointerByReference();
   770 				SchemePointerByReference spbr = (SchemePointerByReference)schemePtrStructs[i];
   746 				Structure[] schemePtrStructs = schemes.toArray(schemeCount);
   771 				spbr.scheme = new SchemeStruct.ByRef();
   747 				
   772 				spbr.scheme.fillFrom(schemeList.get(i));
   748 				for(int i=0; i<this.schemeCount; i++) {
       
   749 					SchemePointerByReference spbr = (SchemePointerByReference)schemePtrStructs[i];
       
   750 					spbr.scheme = new SchemeStruct.ByRef();
       
   751 					spbr.scheme.fillFrom(schemeList.get(i));
       
   752 				}
   773 			}
   753 			}
   774 		}
   754 		}
   775 
   755 
   776 		/**
   756 		/**
   777 		 * Only use on native-owned structs!
   757 		 * Only use on native-owned structs!
   819 		public TeamlistStruct() { super(); setFieldOrder(FIELD_ORDER); }
   799 		public TeamlistStruct() { super(); setFieldOrder(FIELD_ORDER); }
   820 		public TeamlistStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   800 		public TeamlistStruct(Pointer ptr) { super(ptr); setFieldOrder(FIELD_ORDER); }
   821 		
   801 		
   822 		public void fillFrom(List<TeamInGame> teamList, WeaponsetStruct.ByRef weaponset, int initialHealth) {
   802 		public void fillFrom(List<TeamInGame> teamList, WeaponsetStruct.ByRef weaponset, int initialHealth) {
   823 			teamCount = teamList.size();
   803 			teamCount = teamList.size();
   824 			teams = new TeamPointerByReference();
   804 			if(teamCount <= 0) {
   825 			Structure[] teamPtrStructs = teams.toArray(teamCount);
   805 				teams = null;
   826 			
   806 			} else {
   827 			for(int i=0; i<this.teamCount; i++) {
   807 				teams = new TeamPointerByReference();
   828 				TeamPointerByReference tpbr = (TeamPointerByReference)teamPtrStructs[i];
   808 				Structure[] teamPtrStructs = teams.toArray(teamCount);
   829 				tpbr.team = new TeamStruct.ByRef();
   809 				
   830 				tpbr.team.fillFrom(teamList.get(i), weaponset, initialHealth);
   810 				for(int i=0; i<this.teamCount; i++) {
       
   811 					TeamPointerByReference tpbr = (TeamPointerByReference)teamPtrStructs[i];
       
   812 					tpbr.team = new TeamStruct.ByRef();
       
   813 					tpbr.team.fillFrom(teamList.get(i), weaponset, initialHealth);
       
   814 				}
   831 			}
   815 			}
   832 		}
   816 		}
   833 
   817 
   834 		public List<TeamInGame> toTeamInGameList() {
   818 		public List<TeamInGame> toTeamInGameList() {
   835 			if(teamCount<=0) {
   819 			if(teamCount<=0) {
   984     // hwconsts.h
   968     // hwconsts.h
   985     int flib_get_teamcolor(int colorIndex);
   969     int flib_get_teamcolor(int colorIndex);
   986     int flib_get_teamcolor_count();
   970     int flib_get_teamcolor_count();
   987     int flib_get_hedgehogs_per_team();
   971     int flib_get_hedgehogs_per_team();
   988     int flib_get_weapons_count();
   972     int flib_get_weapons_count();
   989     
   973 	MetaschemePtr flib_get_metascheme();
       
   974 	
   990     // net/netconn.h
   975     // net/netconn.h
   991 	static final int NETCONN_STATE_CONNECTING = 0;
   976 	static final int NETCONN_STATE_CONNECTING = 0;
   992 	static final int NETCONN_STATE_LOBBY = 1;
   977 	static final int NETCONN_STATE_LOBBY = 1;
   993 	static final int NETCONN_STATE_ROOM = 2;
   978 	static final int NETCONN_STATE_ROOM = 2;
   994 	static final int NETCONN_STATE_DISCONNECTED = 10;
   979 	static final int NETCONN_STATE_DISCONNECTED = 10;
  1014 	static final int NETCONN_MAPCHANGE_MAZE_SIZE = 4;
   999 	static final int NETCONN_MAPCHANGE_MAZE_SIZE = 4;
  1015 	static final int NETCONN_MAPCHANGE_TEMPLATE = 5;
  1000 	static final int NETCONN_MAPCHANGE_TEMPLATE = 5;
  1016 	static final int NETCONN_MAPCHANGE_THEME = 6;
  1001 	static final int NETCONN_MAPCHANGE_THEME = 6;
  1017 	static final int NETCONN_MAPCHANGE_SEED = 7;
  1002 	static final int NETCONN_MAPCHANGE_SEED = 7;
  1018     
  1003     
  1019 	NetconnPtr flib_netconn_create(String playerName, MetaschemePtr meta, String dataDirPath, String host, int port);
  1004 	NetconnPtr flib_netconn_create(String playerName, String dataDirPath, String host, int port);
  1020 	void flib_netconn_destroy(NetconnPtr conn);
  1005 	void flib_netconn_destroy(NetconnPtr conn);
  1021 
  1006 
  1022 	void flib_netconn_tick(NetconnPtr conn);
  1007 	void flib_netconn_tick(NetconnPtr conn);
  1023 	boolean flib_netconn_is_chief(NetconnPtr conn);
  1008 	boolean flib_netconn_is_chief(NetconnPtr conn);
  1024 	String flib_netconn_get_playername(NetconnPtr conn);
  1009 	String flib_netconn_get_playername(NetconnPtr conn);
  1034 	int flib_netconn_send_renameRoom(NetconnPtr conn, String roomName);
  1019 	int flib_netconn_send_renameRoom(NetconnPtr conn, String roomName);
  1035 	int flib_netconn_send_leaveRoom(NetconnPtr conn, String msg);
  1020 	int flib_netconn_send_leaveRoom(NetconnPtr conn, String msg);
  1036 	int flib_netconn_send_toggleReady(NetconnPtr conn);
  1021 	int flib_netconn_send_toggleReady(NetconnPtr conn);
  1037 	int flib_netconn_send_addTeam(NetconnPtr conn, TeamPtr team);
  1022 	int flib_netconn_send_addTeam(NetconnPtr conn, TeamPtr team);
  1038 	int flib_netconn_send_removeTeam(NetconnPtr conn, String teamname);
  1023 	int flib_netconn_send_removeTeam(NetconnPtr conn, String teamname);
  1039 	int flib_netconn_send_engineMessage(NetconnPtr conn, Buffer message, NativeLong size);
  1024 	int flib_netconn_send_engineMessage(NetconnPtr conn, Pointer message, NativeLong size);
  1040 	int flib_netconn_send_teamHogCount(NetconnPtr conn, String teamname, int hogcount);
  1025 	int flib_netconn_send_teamHogCount(NetconnPtr conn, String teamname, int hogcount);
  1041 	int flib_netconn_send_teamColor(NetconnPtr conn, String teamname, int colorIndex);
  1026 	int flib_netconn_send_teamColor(NetconnPtr conn, String teamname, int colorIndex);
  1042 	int flib_netconn_send_weaponset(NetconnPtr conn, WeaponsetPtr weaponset);
  1027 	int flib_netconn_send_weaponset(NetconnPtr conn, WeaponsetPtr weaponset);
  1043 	int flib_netconn_send_map(NetconnPtr conn, MapRecipePtr map);
  1028 	int flib_netconn_send_map(NetconnPtr conn, MapRecipePtr map);
  1044 	int flib_netconn_send_mapName(NetconnPtr conn, String mapName);
  1029 	int flib_netconn_send_mapName(NetconnPtr conn, String mapName);
  1045 	int flib_netconn_send_mapGen(NetconnPtr conn, int mapGen);
  1030 	int flib_netconn_send_mapGen(NetconnPtr conn, int mapGen);
  1046 	int flib_netconn_send_mapTemplate(NetconnPtr conn, int templateFilter);
  1031 	int flib_netconn_send_mapTemplate(NetconnPtr conn, int templateFilter);
  1047 	int flib_netconn_send_mapMazeSize(NetconnPtr conn, int mazeSize);
  1032 	int flib_netconn_send_mapMazeSize(NetconnPtr conn, int mazeSize);
  1048 	int flib_netconn_send_mapSeed(NetconnPtr conn, String seed);
  1033 	int flib_netconn_send_mapSeed(NetconnPtr conn, String seed);
  1049 	int flib_netconn_send_mapTheme(NetconnPtr conn, String theme);
  1034 	int flib_netconn_send_mapTheme(NetconnPtr conn, String theme);
  1050 	int flib_netconn_send_mapDrawdata(NetconnPtr conn, Buffer drawData, NativeLong size);
  1035 	int flib_netconn_send_mapDrawdata(NetconnPtr conn, Pointer drawData, NativeLong size);
  1051 	int flib_netconn_send_script(NetconnPtr conn, String scriptName);
  1036 	int flib_netconn_send_script(NetconnPtr conn, String scriptName);
  1052 	int flib_netconn_send_scheme(NetconnPtr conn, SchemePtr scheme);
  1037 	int flib_netconn_send_scheme(NetconnPtr conn, SchemePtr scheme);
  1053 	int flib_netconn_send_roundfinished(NetconnPtr conn, boolean withoutError);
  1038 	int flib_netconn_send_roundfinished(NetconnPtr conn, boolean withoutError);
  1054 	int flib_netconn_send_ban(NetconnPtr conn, String playerName);
  1039 	int flib_netconn_send_ban(NetconnPtr conn, String playerName);
  1055 	int flib_netconn_send_kick(NetconnPtr conn, String playerName);
  1040 	int flib_netconn_send_kick(NetconnPtr conn, String playerName);
  1107 
  1092 
  1108 	void flib_gameconn_destroy(GameconnPtr conn);
  1093 	void flib_gameconn_destroy(GameconnPtr conn);
  1109 	int flib_gameconn_getport(GameconnPtr conn);
  1094 	int flib_gameconn_getport(GameconnPtr conn);
  1110 	void flib_gameconn_tick(GameconnPtr conn);
  1095 	void flib_gameconn_tick(GameconnPtr conn);
  1111 
  1096 
  1112 	int flib_gameconn_send_enginemsg(GameconnPtr conn, Buffer data, NativeLong len);
  1097 	int flib_gameconn_send_enginemsg(GameconnPtr conn, Pointer data, NativeLong len);
  1113 	int flib_gameconn_send_textmsg(GameconnPtr conn, int msgtype, String msg);
  1098 	int flib_gameconn_send_textmsg(GameconnPtr conn, int msgtype, String msg);
  1114 	int flib_gameconn_send_chatmsg(GameconnPtr conn, String playername, String msg);
  1099 	int flib_gameconn_send_chatmsg(GameconnPtr conn, String playername, String msg);
  1115 	int flib_gameconn_send_quit(GameconnPtr conn);
  1100 	int flib_gameconn_send_quit(GameconnPtr conn);
  1116 	
  1101 	
  1117 	void flib_gameconn_onConnect(GameconnPtr conn, VoidCallback callback, Pointer context);
  1102 	void flib_gameconn_onConnect(GameconnPtr conn, VoidCallback callback, Pointer context);
  1120 	void flib_gameconn_onChat(GameconnPtr conn, StrBoolCallback callback, Pointer context);
  1105 	void flib_gameconn_onChat(GameconnPtr conn, StrBoolCallback callback, Pointer context);
  1121 	void flib_gameconn_onGameRecorded(GameconnPtr conn, BytesBoolCallback callback, Pointer context);
  1106 	void flib_gameconn_onGameRecorded(GameconnPtr conn, BytesBoolCallback callback, Pointer context);
  1122 	void flib_gameconn_onEngineMessage(GameconnPtr conn, BytesCallback callback, Pointer context);
  1107 	void flib_gameconn_onEngineMessage(GameconnPtr conn, BytesCallback callback, Pointer context);
  1123 	
  1108 	
  1124 	// ipc/mapconn.h
  1109 	// ipc/mapconn.h
       
  1110 	public static final int MAPIMAGE_WIDTH = 256;
       
  1111 	public static final int MAPIMAGE_HEIGHT = 128;
       
  1112 	public static final int MAPIMAGE_BYTES = (MAPIMAGE_WIDTH/8*MAPIMAGE_HEIGHT);
       
  1113 	
  1125 	MapconnPtr flib_mapconn_create(MapRecipePtr mapdesc);
  1114 	MapconnPtr flib_mapconn_create(MapRecipePtr mapdesc);
  1126 	void flib_mapconn_destroy(MapconnPtr conn);
  1115 	void flib_mapconn_destroy(MapconnPtr conn);
  1127 	int flib_mapconn_getport(MapconnPtr conn);
  1116 	int flib_mapconn_getport(MapconnPtr conn);
  1128 	void flib_mapconn_onSuccess(MapconnPtr conn, MapimageCallback callback, Pointer context);
  1117 	void flib_mapconn_onSuccess(MapconnPtr conn, MapimageCallback callback, Pointer context);
  1129 	void flib_mapconn_onFailure(MapconnPtr conn, StrCallback callback, Pointer context);
  1118 	void flib_mapconn_onFailure(MapconnPtr conn, StrCallback callback, Pointer context);
  1147 	public static final int MAZE_SIZE_LARGE_TUNNELS = 2;
  1136 	public static final int MAZE_SIZE_LARGE_TUNNELS = 2;
  1148 	public static final int MAZE_SIZE_SMALL_ISLANDS = 3;
  1137 	public static final int MAZE_SIZE_SMALL_ISLANDS = 3;
  1149 	public static final int MAZE_SIZE_MEDIUM_ISLANDS = 4;
  1138 	public static final int MAZE_SIZE_MEDIUM_ISLANDS = 4;
  1150 	public static final int MAZE_SIZE_LARGE_ISLANDS = 5;
  1139 	public static final int MAZE_SIZE_LARGE_ISLANDS = 5;
  1151 		
  1140 		
  1152 	// model/scheme.h
       
  1153 	MetaschemePtr flib_metascheme_from_ini(String filename);
       
  1154 	MetaschemePtr flib_metascheme_retain(MetaschemePtr metainfo);
       
  1155 	void flib_metascheme_release(MetaschemePtr metainfo);
       
  1156 
       
  1157 	// model/schemelist.h
  1141 	// model/schemelist.h
  1158 	SchemelistPtr flib_schemelist_from_ini(MetaschemePtr meta, String filename);
  1142 	SchemelistPtr flib_schemelist_from_ini(String filename);
  1159 	int flib_schemelist_to_ini(String filename, SchemelistPtr list);
  1143 	int flib_schemelist_to_ini(String filename, SchemelistPtr list);
  1160 	void flib_schemelist_destroy(SchemelistPtr list);
  1144 	void flib_schemelist_destroy(SchemelistPtr list);
  1161 	
  1145 	
  1162 	// model/team.h
  1146 	// model/team.h
  1163 	TeamPtr flib_team_from_ini(String filename);
  1147 	TeamPtr flib_team_from_ini(String filename);
  1166 	
  1150 	
  1167 	// model/weapon.h
  1151 	// model/weapon.h
  1168 	WeaponsetListPtr flib_weaponsetlist_from_ini(String filename);
  1152 	WeaponsetListPtr flib_weaponsetlist_from_ini(String filename);
  1169 	int flib_weaponsetlist_to_ini(String filename, WeaponsetListPtr weaponsets);
  1153 	int flib_weaponsetlist_to_ini(String filename, WeaponsetListPtr weaponsets);
  1170 	void flib_weaponsetlist_destroy(WeaponsetListPtr list);
  1154 	void flib_weaponsetlist_destroy(WeaponsetListPtr list);
       
  1155 	
       
  1156 	// model/gamesetup.h
       
  1157 	void flib_gamesetup_destroy(GameSetupPtr gamesetup);
  1171 	
  1158 	
  1172 	// util/logging.h
  1159 	// util/logging.h
  1173 	public static final int FLIB_LOGLEVEL_ALL = -100;
  1160 	public static final int FLIB_LOGLEVEL_ALL = -100;
  1174 	public static final int FLIB_LOGLEVEL_DEBUG = -1;
  1161 	public static final int FLIB_LOGLEVEL_DEBUG = -1;
  1175 	public static final int FLIB_LOGLEVEL_INFO = 0;
  1162 	public static final int FLIB_LOGLEVEL_INFO = 0;