[med-svn] [Git][med-team/bbmap][upstream] New upstream version 38.94+dfsg

Étienne Mollier (@emollier) gitlab at salsa.debian.org
Tue Oct 5 20:12:37 BST 2021



Étienne Mollier pushed to branch upstream at Debian Med / bbmap


Commits:
73e56967 by Étienne Mollier at 2021-10-05T20:40:27+02:00
New upstream version 38.94+dfsg
- - - - -


6 changed files:

- README.md
- current/jgi/RQCFilter2.java
- current/shared/Shared.java
- − current/star/Ship.java
- − current/star/Simulate.java
- − current/star/Weapon.java


Changes:

=====================================
README.md
=====================================
@@ -3,4 +3,4 @@
 # Language: Java, Bash
 # Information about documentation is in /docs/readme.txt.
 
-# Version 38.93
+# Version 38.94


=====================================
current/jgi/RQCFilter2.java
=====================================
@@ -1144,7 +1144,7 @@ public class RQCFilter2 {
 					final boolean addToOtherStats=(sipStatsFile==null);
 					decontamByMapping(in1z, in2z, out1z, out2z, null, "sipScafStats.txt", inPrefix, outPrefix, ref, step, addToOtherStats, args);
 					if(!addToOtherStats){
-						filterstats.parseSip(sipStatsFile);
+						filterstats.parseSip("sipScafStats.txt");
 						assert(filterstats.toString()!=null);
 					}
 				}


=====================================
current/shared/Shared.java
=====================================
@@ -124,8 +124,8 @@ public class Shared {
 	public static final int GAPCOST=Tools.max(1, GAPLEN/64);
 	public static final byte GAPC='-';
 	
-	public static String BBMAP_VERSION_STRING="38.93";
-	public static String BBMAP_VERSION_NAME="No Null";
+	public static String BBMAP_VERSION_STRING="38.94";
+	public static String BBMAP_VERSION_NAME="Potato Parser";
 	
 	public static boolean TRIM_READ_COMMENTS=false;
 	public static boolean TRIM_RNAME=false; //For mapped sam reads


=====================================
current/star/Ship.java deleted
=====================================
@@ -1,295 +0,0 @@
-package star;
-
-import java.util.ArrayList;
-
-public class Ship implements Cloneable {
-	
-	/*--------------------------------------------------------------*/
-	/*----------------        Initialization        ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	public Ship(String s){
-		this(s.split("[;,]"));//should allow semi or comma delimiters
-	}
-	
-	public Ship(String[] args) {
-		for(int i=0; i<args.length; i++){
-			String arg=args[i];
-			String[] split=arg.split("=");
-			String a=split[0].toLowerCase();
-			String b=split.length>1 ? split[1] : null;
-			if(b!=null && b.equalsIgnoreCase("null")){b=null;}
-
-			if(a.equals("side")){
-				side=Character.toUpperCase(b.charAt(0));
-				assert(side=='A' || side=='B');
-			}else if(a.equals("class") || a.equals("type")){
-				shipClass=b.replace('_', ' ');
-			}else if(a.equals("name")){
-				shipName=b.replace('_', ' ');
-			}else if(a.equals("hull")){
-				maxHull=Integer.parseInt(b);
-			}else if(a.equals("armor")){
-				maxArmor=Integer.parseInt(b);
-			}else if(a.equals("flux")){
-				maxFlux=Integer.parseInt(b);
-			}else if(a.equals("downflux")){
-				downFlux=Integer.parseInt(b);
-			}else if(a.equals("upflux")){
-				upFlux=Integer.parseInt(b);
-			}else if(a.equals("dissipation")){
-				dissipation=Integer.parseInt(b);
-			}else if(a.equals("shield") || a.equals("hasshield")){
-				hasShield=parseBoolean(b);
-			}else if(a.equals("vent") || a.equals("canvent")){
-				canVent=parseBoolean(b);
-			}else if(a.equals("fluxperdamage") || a.equals("efficiency")){
-				fluxPerDamage=Float.parseFloat(b);
-			}else if(a.equals("minarmormodifier")){
-				minArmorModifier=Float.parseFloat(b);
-			}else if(a.equals("strippedarmorfraction")){
-				strippedArmorFraction=Float.parseFloat(b);
-			}else if(a.equals("minarmor") || a.equals("bonusarmor")){
-				bonusArmor=Float.parseFloat(b);
-			}else if(a.equals("shieldflux") || a.equals("upkeep")){
-				shieldFlux=Float.parseFloat(b);
-			}else if(addWeapon(arg)){
-				//do nothing
-			}else{
-				assert(false) : "Unknown parameter "+args[i];
-			}
-		}
-		reset();
-
-		if(upFlux<0){upFlux=(int)(maxFlux*0.5);}
-		if(downFlux<0){downFlux=(int)(maxFlux*0.9);}
-		
-		dissipationPerCenti=dissipation*0.01f;
-		ventingDissipationPerCenti=dissipationPerCenti*2;
-		fluxPerCenti=shieldFlux*0.01f;
-	}
-	
-	public void reset(){
-		
-		hull=maxHull;
-		armor=maxArmor;
-		hardFlux=0;
-		softFlux=0;
-		empDamageTaken=0;
-		
-		shieldsUp=hasShield;
-		venting=false;
-		for(Weapon w : weapons){w.reset();}
-	}
-	
-	public Ship copy(){
-		try {
-			Ship s=(Ship)this.clone();
-			s.weapons=new ArrayList<Weapon>();
-			for(Weapon w : weapons){s.weapons.add(w.copy());}
-			s.reset();
-			return s;
-		} catch (CloneNotSupportedException e) {
-			throw new RuntimeException(e);
-		}
-	}
-	
-	private boolean addWeapon(String s){
-		try {
-			int mult=1;
-			if(Character.isDigit(s.charAt(0))){
-				int x=s.indexOf('x');
-				if(x<0){x=s.indexOf('X');}
-				if(x>0){
-					mult=Integer.parseInt(s.substring(0, x));
-					s=s.substring(x+1);
-				}
-			}
-			Weapon w=Weapon.makeWeapon(s);
-			for(int i=0; i<mult; i++){
-				weapons.add(w.copy());
-			}
-		} catch (NumberFormatException e) {
-			return false;
-		}
-		return true;
-	}
-	
-	/*--------------------------------------------------------------*/
-	/*----------------        Outer Methods         ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	public void process(Ship b){
-		assert(validate()) : this;
-		adjustShields();
-		if(shieldsUp){softFlux+=fluxPerCenti;}
-		if(!venting){fireWeapons(b);}
-		if(venting){softFlux-=dissipationPerCenti;}
-		softFlux-=dissipationPerCenti;
-//		assert(false) : this;
-		if(softFlux<0){
-			hardFlux=max(0, hardFlux+softFlux);
-			softFlux=0;
-		}
-//		assert(false) : this;
-		assert(validate()) : this;
-	}
-	
-	public boolean validate(){
-		assert(!hasShield || shieldFlux>0);
-		assert(hardFlux>=0);
-		assert(softFlux>=0);
-		assert(hull==maxHull || armor==0);
-		return true;
-	}
-	
-	public String toString(){
-		StringBuilder sb=new StringBuilder();
-
-		sb.append("side       \t").append(side).append('\n');
-		sb.append("shipClass  \t").append(shipClass).append('\n');
-		sb.append("shipName   \t").append(shipName).append('\n');
-		sb.append("maxHull    \t").append(maxHull).append('\n');
-		sb.append("maxArmor    \t").append(maxArmor).append('\n');
-		sb.append("maxFlux    \t").append(maxFlux).append('\n');
-		sb.append("downFlux   \t").append(downFlux).append('\n');
-		sb.append("upFlux     \t").append(upFlux).append('\n');
-		sb.append("dissipation\t").append(dissipation).append('\n');
-		sb.append("fluxPerDamage\t").append(fluxPerDamage).append('\n');
-		sb.append("minArmorModifier\t").append(minArmorModifier).append('\n');
-		sb.append("strippedArmorFraction\t").append(strippedArmorFraction).append('\n');
-		sb.append("bonusArmor \t").append(bonusArmor).append('\n');
-		sb.append("shieldFlux \t").append(shieldFlux).append('\n');
-		sb.append("dissipationPerC\t").append(dissipationPerCenti).append('\n');
-		sb.append("fluxPerC   \t").append(fluxPerCenti).append('\n');
-		sb.append("hull       \t").append(hull).append('\n');
-		sb.append("armor      \t").append(armor).append('\n');
-		sb.append("hardFlux   \t").append(hardFlux).append('\n');
-		sb.append("softFlux   \t").append(softFlux).append('\n');
-		sb.append("flux       \t").append(flux()).append('\n');
-		sb.append("hasShield  \t").append(hasShield).append('\n');
-		sb.append("canVent    \t").append(canVent).append('\n');
-		sb.append("shieldsUp  \t").append(shieldsUp).append('\n');
-		sb.append("venting    \t").append(venting);
-		for(Weapon w : weapons){
-			sb.append('\n');
-			sb.append(w);
-		}
-		return sb.toString();
-	}
-	
-	
-	/*--------------------------------------------------------------*/
-	/*----------------        Inner Methods         ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	void adjustShields(){
-		if(flux()+fluxPerCenti>=downFlux){
-			shieldsUp=false;
-			if(canVent){venting=true;}
-		}else if(flux()<=upFlux && !venting){
-			if(hasShield){shieldsUp=true;}
-		}else if(venting && flux()<=0){
-			venting=false;
-			if(hasShield){shieldsUp=true;}
-		}
-	}
-	
-	void fireWeapons(Ship b){
-		assert(!venting);
-		for(Weapon w : weapons){
-			w.use(this, b);
-		}
-	}
-	
-	/*--------------------------------------------------------------*/
-	/*----------------           Helpers            ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	/**
-	 * Parse this argument.  More liberal than Boolean.parseBoolean.
-	 * Null, t, true, or 1 all yield true.
-	 * Everything else, including the String "null", is false.
-	 * @param s Argument to parse
-	 * @return boolean form
-	 */
-	public static boolean parseBoolean(String s){
-		if(s==null || s.length()<1){return true;}
-		if(s.length()==1){
-			char c=Character.toLowerCase(s.charAt(0));
-			return c=='t' || c=='1';
-		}
-		if(s.equalsIgnoreCase("null") || s.equalsIgnoreCase("none")){return false;}
-		return Boolean.parseBoolean(s);
-	}
-	
-	public static final int min(int x, int y){return x<y ? x : y;}
-	public static final int max(int x, int y){return x>y ? x : y;}
-	public static final float min(float x, float y){return x<y ? x : y;}
-	public static final float max(float x, float y){return x>y ? x : y;}
-	public static final int roundUp(float x){return (int)Math.ceil(x);}
-	
-	/*--------------------------------------------------------------*/
-	/*----------------           Fields             ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	/*--------------------------------------------------------------*/
-	/*----------------     Initialized Fields       ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	char side; //A or B
-	
-	String shipClass;
-	String shipName;
-	
-	int maxHull;
-	int maxArmor;
-	int maxFlux;
-	int downFlux=-1; //Flux at which shields drop
-	int upFlux=-1; //Flux at which shields recover
-	int dissipation;
-	boolean hasShield=true;
-	boolean canVent=false;
-	float fluxPerDamage; //typically 1.0f (this is shield efficiency)
-	float minArmorModifier=0.15f; //could be 0.10f
-	float strippedArmorFraction=0.05f; //Residual armor when stripped
-	float bonusArmor=0; //could be 150
-	float shieldFlux=0; //flux per second for shield
-	
-	ArrayList<Weapon> weapons=new ArrayList<Weapon>();
-	
-	/*--------------------------------------------------------------*/
-	/*----------------        Derived Fields        ----------------*/
-	/*--------------------------------------------------------------*/
-
-	final float dissipationPerCenti;
-	final float ventingDissipationPerCenti;
-	final float fluxPerCenti;
-	
-	/*--------------------------------------------------------------*/
-	/*----------------       Mutable Fields         ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	float hull;
-	float armor;
-	float hardFlux;
-	float softFlux;
-	float empDamageTaken;
-	float flux(){return hardFlux+softFlux;}
-
-	boolean shieldsUp=false;
-	boolean venting=false;
-	
-	/*--------------------------------------------------------------*/
-	/*----------------          Constants           ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	public static final int BOLT=0, BEAM=1;
-	public static final int HARD=0, SOFT=1;
-	public static final int KINETIC=0, HE=1, FRAG=2, ENERGY=3;
-
-	public static final String[] types={"bolt", "beam"};
-	public static final String[] fluxTypes={"hard", "soft"};
-	public static final String[] damageTypes={"kinetic", "he", "frag", "energy"};
-	
-}


=====================================
current/star/Simulate.java deleted
=====================================
@@ -1,326 +0,0 @@
-package star;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.Map.Entry;
-import java.util.Random;
-
-/**
- * Simulates combat.
- * @author SC
- * @date September 12, 2020
- *
- */
-public class Simulate {
-	
-	/*--------------------------------------------------------------*/
-	/*----------------        Initialization        ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	/**
-	 * Code entrance from the command line.
-	 * @param args Command line arguments
-	 */
-	public static void main(String[] args){
-		
-		//Create an instance of this class
-		Simulate x=new Simulate(args);
-		
-		//Run the object
-		x.process();
-	}
-	
-	/**
-	 * Constructor.
-	 * @param args Command line arguments
-	 */
-	public Simulate(String[] args){
-		parse(args);
-		assert(sideA.size()>0) : "No ships on side A";
-		assert(sideB.size()>0) : "No ships on side B";
-	}
-	
-	/*--------------------------------------------------------------*/
-	/*----------------    Initialization Helpers    ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	/** Parse arguments from the command line */
-	private void parse(String[] args){
-		for(String s : args){
-			parseTerm(s);
-		}
-	}
-	
-	void parseTerm(String term){
-		if(term==null || term.length()<1 || term.charAt(0)=='#'){return;}
-		
-		int mult=1;
-		if(Character.isDigit(term.charAt(0))){
-			int x=term.indexOf('x');
-			if(x<0){x=term.indexOf('X');}
-			if(x>0){
-				mult=Integer.parseInt(term.substring(0, x));
-				term=term.substring(x+1);
-			}
-		}
-		
-		String[] split=term.split("=");
-		String a=split[0].toLowerCase();
-		String b=split.length>1 ? split[1] : null;
-		
-		if(term.startsWith("ship:")){
-			Ship sh=new Ship(term.substring("ship:".length()));
-			if(sh.shipName==null){sh.shipName=sh.shipClass;}
-			ArrayList<Ship> list=(sh.side=='A' ? sideA : sideB);
-			list.add(sh);
-			for(int i=1; i<mult; i++){
-				Ship sh2=sh.copy();
-				sh2.shipName+=(i+1);
-				list.add(sh2);
-			}
-		}else if(term.startsWith("weapon:")){
-			Weapon.makeWeapon(term.substring("weapon:".length()));
-		}else if(a.equalsIgnoreCase("verbose")){
-			Weapon.verbose=verbose=parseBoolean(b);
-		}else if(a.equalsIgnoreCase("printShips")){
-			printShips=parseBoolean(b);
-		}else if(a.equalsIgnoreCase("useFullName") || a.equalsIgnoreCase("printFullName") || a.equalsIgnoreCase("FullName")){
-			Weapon.useFullName=parseBoolean(b);
-		}else if(a.equalsIgnoreCase("useShortName") || a.equalsIgnoreCase("printShortName") || a.equalsIgnoreCase("ShortName")){
-			Weapon.useFullName=false;
-		}else if(a.equalsIgnoreCase("printShots")){
-			Weapon.printShots=parseBoolean(b);
-		}else if(a.equalsIgnoreCase("preventArmorDestuction")){
-			Weapon.preventArmorDestuction=parseBoolean(b);
-		}else if(a.equalsIgnoreCase("preventTorpedoes") || a.equalsIgnoreCase("preventMissiles")){
-			Weapon.preventTorpedoes=parseBoolean(b);
-		}else{
-			assert(new File(term).exists()) : "Unknown term '"+term+"'";
-			readFile(term);
-		}
-	}
-	
-	void readFile(String fname){
-		File f=new File(fname);
-		assert(f.exists()) : "Can't read "+fname;
-
-		try {
-			BufferedReader br=new BufferedReader(new FileReader(f)); 
-			for(String line=br.readLine(); line!=null; line=br.readLine()){ 
-				parseTerm(line);
-			}
-		} catch (FileNotFoundException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		} catch (IOException e) {
-			// TODO Auto-generated catch block
-			e.printStackTrace();
-		}
-	} 
-	
-	/*--------------------------------------------------------------*/
-	/*----------------         Outer Methods        ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	void process(){
-		long start=System.nanoTime();
-		
-		if(verbose || printShips){
-//			printWeapons();
-			printShips();
-		}
-		
-		long maxRounds=1000000;
-		long rounds=processInner(maxRounds);
-		
-		int dif=sideA.size()-sideB.size();
-		
-		outstream.println("\nFinished in "+String.format("%.2f seconds (simulated)", rounds/100.0));
-		
-		if(rounds>=maxRounds){
-			outstream.println("Stalemate.");
-		}else if(dif==0){
-			outstream.println("Tie.");
-		}else{
-			outstream.println("Side "+(dif>0 ? "A" : "B")+" wins.");
-		}
-
-		outstream.println();
-		printSide(sideA, sideA_dead, 'A');
-		outstream.println();
-		printSide(sideB, sideB_dead, 'B');
-		
-		long elapsed=System.nanoTime()-start;
-		outstream.println(String.format("\nTime: %.3f ms", elapsed/1000000.0));
-	}
-	
-	/*--------------------------------------------------------------*/
-	/*----------------         Inner Methods        ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	void printWeapons(){
-
-		outstream.println("Weapons: "+Weapon.map.keySet());
-		for(Entry<String, Weapon> e : Weapon.map.entrySet()){
-			outstream.println(e.getKey()+" -> "+e.getValue());
-		}
-	}
-	
-	void printShips(){
-		if(sideA.size()>0){
-			outstream.println("Side A live: ");
-			for(Ship s : sideA){outstream.println(s);}
-			outstream.println();
-		}
-
-		if(sideA_dead.size()>0){
-			outstream.println("Side A dead: ");
-			for(Ship s : sideA_dead){outstream.println(s);}
-			outstream.println();
-		}
-
-		if(sideB.size()>0){
-			outstream.println("Side B live: ");
-			for(Ship s : sideB){outstream.println(s);}
-			outstream.println();
-		}
-
-		if(sideB_dead.size()>0){
-			outstream.println("Side B dead: ");
-			for(Ship s : sideB_dead){outstream.println(s);}
-			outstream.println();
-		}
-	}
-	
-	long processInner(long maxRounds){
-		long round=0;
-		while(round<maxRounds && !sideA.isEmpty() && !sideB.isEmpty()){
-			processCenti(round);
-			round++;
-		}
-		return round;
-	}
-	
-	void processCenti(long centi){
-		shotsThisTurn=0;
-		processSide(sideA, sideB);
-		processSide(sideB, sideA);
-		cullSide(sideA, sideA_dead);
-		cullSide(sideB, sideB_dead);
-		if(verbose){
-			if(centi%10==0){
-				outstream.println("\n\n*****   T = "+String.format("%.2fs", centi*0.01)+"   *****\n");
-				printShips();
-			}
-		}else if(Weapon.printShots && shotsThisTurn>0){
-			outstream.println("\n\n*****   T = "+String.format("%.2fs", centi*0.01)+"   *****\n");
-		}
-		
-	}
-	
-	void processSide(ArrayList<Ship> liveA, ArrayList<Ship> liveB){
-		for(Ship a : liveA){
-			int indexB=randy.nextInt(liveB.size());
-			Ship b=liveB.get(indexB);
-			a.process(b);
-		}
-	}
-	
-	void cullSide(ArrayList<Ship> live, ArrayList<Ship> dead){
-		for(int i=0; i<live.size(); i++){
-			Ship a=live.get(i);
-			if(a.hull<=0){
-				live.remove(i);
-				i--;
-				dead.add(a);
-			}
-		}
-	}
-	
-	void printSide(ArrayList<Ship> live, ArrayList<Ship> dead, char side){
-		outstream.println("Side "+Character.toString(side)+":");
-		outstream.println("Class\tName\tHull\tArmor\tFlux\tShield\tVent\tWeapons");
-		for(Ship s : live){
-			outstream.println(summary(s));
-		}
-		for(Ship s : dead){
-			outstream.println(summary(s));
-		}
-	}
-	
-	private String summary(Ship s){
-		return s.shipClass+"\t"+s.shipName+"\t"+
-				String.format("%.1f\t%.1f\t%.1f", s.hull, s.armor, s.flux())+
-				(s.hasShield ? "\tT" : "\tF")+(s.canVent ? "\tT" : "\tF")+
-				"\t"+listWeapons(s);
-	}
-	
-	private String listWeapons(Ship s){
-		StringBuilder sb=new StringBuilder();
-		LinkedHashMap<String, Integer> map=new LinkedHashMap<String, Integer>();
-		for(Weapon w : s.weapons){
-			String name=(w.name2!=null && !Weapon.useFullName ? w.name2 : w.name);
-			Integer count=map.get(name);
-			map.put(name, count==null ? 1 : count+1);
-		}
-		for(Entry<String, Integer> e : map.entrySet()){
-			String name=e.getKey();
-			int count=e.getValue();
-			if(sb.length()>0){sb.append(',');}
-			if(count>1){sb.append(count).append('x');}
-			assert(count>=1) : name+", "+count;
-			sb.append(name);
-		}
-		return sb.toString();
-	}
-	
-	/*--------------------------------------------------------------*/
-	/*----------------           Helpers            ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	/**
-	 * Parse this argument.  More liberal than Boolean.parseBoolean.
-	 * Null, t, true, or 1 all yield true.
-	 * Everything else, including the String "null", is false.
-	 * @param s Argument to parse
-	 * @return boolean form
-	 */
-	public static boolean parseBoolean(String s){
-		if(s==null || s.length()<1){return true;}
-		if(s.length()==1){
-			char c=Character.toLowerCase(s.charAt(0));
-			return c=='t' || c=='1';
-		}
-		if(s.equalsIgnoreCase("null") || s.equalsIgnoreCase("none")){return false;}
-		return Boolean.parseBoolean(s);
-	}
-	
-	/*--------------------------------------------------------------*/
-	/*----------------            Fields            ----------------*/
-	/*--------------------------------------------------------------*/
-
-	public ArrayList<Ship> sideA=new ArrayList<Ship>();
-	public ArrayList<Ship> sideB=new ArrayList<Ship>();
-
-	public ArrayList<Ship> sideA_dead=new ArrayList<Ship>();
-	public ArrayList<Ship> sideB_dead=new ArrayList<Ship>();
-	
-	Random randy=new Random();
-
-	public static boolean printShips=false;
-	public static int shotsThisTurn=0;
-	
-	/*--------------------------------------------------------------*/
-	/*----------------        Common Fields         ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	private PrintStream outstream=System.out;
-	public static boolean verbose=false;
-	
-}


=====================================
current/star/Weapon.java deleted
=====================================
@@ -1,467 +0,0 @@
-package star;
-
-import java.util.Arrays;
-import java.util.HashMap;
-
-public class Weapon implements Cloneable {
-	
-	/*--------------------------------------------------------------*/
-	/*----------------        Initialization        ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	public static Weapon makeWeapon(String s){
-		s=s.replace('_', ' ');
-		Weapon w=map.get(s.toLowerCase());
-		if(w!=null){
-			return w.copy();
-		}
-		w=new Weapon(s);
-		assert(!map.containsKey(w.name)) : "Key collision: "+w.name;
-		assert(!map.containsKey(w.name.toLowerCase())) : "Key collision: "+w.name+"\n"+s;
-		assert(w.name2==null || !map.containsKey(w.name2)) : "Key collision: "+w.name2;
-		assert(w.name2==null || !map.containsKey(w.name2.toLowerCase())) : "Key collision: "+w.name2;
-		map.put(w.name.toLowerCase(), w);
-		map.put(w.name2.toLowerCase(), w);
-		return w;
-	}
-	
-	private Weapon(String s){
-		this(s.split("[;,]"));//should allow semi or comma delimiters
-	}
-	
-	private Weapon(String[] args) {
-		for(int i=0; i<args.length; i++){
-			String arg=args[i];
-			String[] split=arg.split("=");
-			String a=split[0].toLowerCase();
-			String b=split.length>1 ? split[1] : null;
-			if(b!=null && b.equalsIgnoreCase("null")){b=null;}
-
-			if(a.equals("name")){
-				name=b.replace('_', ' ');
-			}else if(a.equals("name2")){
-				name2=b.replace('_', ' ');
-			}else if(a.equals("type")){
-				type=find(b.toLowerCase(), types);
-			}else if(a.equals("fluxtype")){
-				fluxType=find(b.toLowerCase(), fluxTypes);
-			}else if(a.equals("damagetype")){
-				damageType=find(b.toLowerCase(), damageTypes);
-			}else if(a.equals("damage")){
-				damage=Integer.parseInt(b);
-			}else if(a.equals("fluxcost")){
-				fluxCostPerBurstNominal=Integer.parseInt(b);
-			}else if(a.equals("damage")){
-				damage=Integer.parseInt(b);
-			}else if(a.equals("empdamage")){
-				empDamage=Float.parseFloat(b);
-			}else if(a.equals("burst")){
-				burst=Integer.parseInt(b);
-				assert(burst>0);
-			}else if(a.equals("bursttime") || a.equals("burstduration")){
-				burstDuration=Float.parseFloat(b);
-			}else if(a.equals("reload") || a.equals("reloadtime")){
-				reloadTime=Float.parseFloat(b);
-			}else if(a.equals("ammo") || a.equals("maxammo")){
-				maxAmmo=Integer.parseInt(b);
-			}else if(a.equals("regen") || a.equals("ammoregen")){
-				ammoRegen=Float.parseFloat(b);
-			}else if(a.equals("submunitions")){
-				submunitions=Integer.parseInt(b);
-			}else{
-				assert(false) : "Unknown parameter "+args[i];
-			}
-		}
-		
-//		secondsPerBolt=burstDuration/burst;
-		shieldDamagePerBolt=(type==BOLT ? damage : damage*0.01f)*shieldDamageMult();
-		maxArmorDamagePerBolt=(type==BOLT ? damage : damage*0.01f)*armorDamageMult();
-		maxHullDamagePerBolt=(type==BOLT ? damage : damage*0.01f);
-		empDamagePerBolt=(type==BOLT ? empDamage : empDamage*0.01f);
-		hardFluxDamagePerBolt=shieldDamagePerBolt*(fluxType==HARD ? 1 : 0);
-		softFluxDamagePerBolt=shieldDamagePerBolt*(fluxType==SOFT ? 1 : 0);
-		fluxCostPerBurstActual=(type==BOLT ? fluxCostPerBurstNominal : fluxCostPerBurstNominal*0.01f);
-		
-		damageForCalculation=(type==BOLT ? maxArmorDamagePerBolt : damage*0.50f*armorDamageMult());
-		
-		centiPerReload=Math.round(reloadTime*100);
-		centiPerBurst=Math.round(burstDuration*100);
-		centiPerRound=Math.round(burstDuration*100/burst);
-//		assert(false) : "burstDuration="+burstDuration+",centiPerReload="+centiPerReload+",centiPerBurst="+centiPerBurst+",centiPerRound="+centiPerRound;
-		regenPerCenti=ammoRegen*0.01f;
-		
-		reset();
-		
-		assert(reloadTime>0);
-		assert(name!=null);
-	}
-	
-	public Weapon copy(){
-		try {
-			Weapon w=(Weapon)this.clone();
-			w.reset();
-			return w;
-		} catch (CloneNotSupportedException e) {
-			throw new RuntimeException(e);
-		}
-	}
-	
-	/*--------------------------------------------------------------*/
-	/*----------------       Outer Functions        ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	public boolean validate(){
-		assert(type>=0 && type<types.length);
-		assert(fluxType>=0 && fluxType<fluxTypes.length);
-		assert(damageType>=0 && damageType<damageTypes.length);
-
-		assert(fluxCostPerBurstNominal>=0);
-		assert(damage>=0); //TODO: or EMP
-		assert(damage>0); //for now
-		assert(burst>=1 && burst<=999); //At least one shot per burst
-		assert(burstDuration>=0 && burstDuration<99); //can be zero
-		assert(reloadTime>0); //Must be a minimum of 0.01s
-		assert(maxAmmo>=0); //non-negative; 0 means unlimited
-		assert(ammoRegen>=0 && ammoRegen<999); //nonnegative and not crazy
-		assert(submunitions>=1);
-		assert(shieldDamagePerBolt>0); //true in vanilla
-		assert(maxArmorDamagePerBolt>0); //true in vanilla
-		assert(maxHullDamagePerBolt>0); //true in vanilla
-		assert(hardFluxDamagePerBolt+softFluxDamagePerBolt>0); //true in vanilla
-		assert(centiPerBurst>=0);
-		assert(centiPerReload>0);
-		assert(centiPerRound>0 || burstDuration==0);
-//		assert(burst*centiPerRound==centiPerBurst);
-		assert(roundsThisBurst<=burst);
-		return true;
-	}
-	
-	//Reinitialize mutables
-	public void reset(){
-		ammo=maxAmmo;
-		timeToNextBurst=0;
-		timeInBurst=0;
-		timeToNextRound=0;
-		roundsThisBurst=0;
-		inBurst=false;
-		assert(validate());
-	}
-	
-	/**
-	 * Use a weapon on the source ship against the target ship.
-	 * This does everything necessary for the current time cycle.
-	 * @param a Ship holding the weapon
-	 * @param b Target ship
-	 */
-	void use(Ship a, Ship b){
-		assert(validate());
-		timeToNextBurst--;
-		if(timeToNextBurst<=0 && (maxAmmo<=0 || ammo>=burst)){
-			assert(timeInBurst==0);
-			startBurst(a, b);
-		}
-		if(inBurst){
-			continueBurst(a);
-		}
-		if(inBurst && roundsThisBurst>=burst){
-			//This assertion ia not needed and causes problems when bursts don't have good integer divisors
-//			assert(timeInBurst>=centiPerBurst) : timeInBurst+", "+centiPerBurst+", "+roundsThisBurst+", "+burst+"\n"+this+"\n";
-			endBurst(a);
-		}
-		ammo=min(ammo+regenPerCenti, maxAmmo);
-	}
-	
-	public String toString(){
-		StringBuilder sb=new StringBuilder();
-		sb.append(name2==null || useFullName ? name : name2).append('\t');
-		sb.append("ammo="+ammo).append(' ');
-		sb.append("ttNextBurst="+timeToNextBurst).append(' ');
-		sb.append("tiBurst="+timeInBurst).append(' ');
-		sb.append("ttNextRound="+timeToNextRound).append(' ');
-		sb.append("damage="+damage).append(' ');
-		sb.append("flux="+fluxCostPerBurstNominal);
-		return sb.toString();
-	}
-	
-	/*--------------------------------------------------------------*/
-	/*----------------       Inner Functions        ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	/**
-	 * Start a burst from ship a to b.
-	 * It has already been determined that the weapon is ready to start firing and there is flux available.
-	 * @param source Ship holding the weapon
-	 * @param target Target ship
-	 */
-	private void startBurst(Ship a, Ship b){
-		assert(timeInBurst==0);
-		if(a.flux()+fluxCostPerBurstActual>a.maxFlux){return;}
-//		assert(a.flux()+fluxCost<a.maxFlux) : this+"\n"+a;
-		target=b;
-		assert(timeToNextBurst<=0);
-		assert(!inBurst);
-		a.softFlux+=fluxCostPerBurstActual;
-		timeInBurst=0;
-		inBurst=true;
-		//timeToNextBurst=centiPerBurst+centiPerReload;
-		timeToNextBurst=centiPerReload;
-	}
-	
-	private void continueBurst(Ship a){
-		assert(inBurst);
-		if(timeToNextRound<=0){
-			fireBolt();
-			timeToNextRound=centiPerRound;
-		}else{
-			timeToNextRound--;
-		}
-		timeInBurst++;
-	}
-	
-	private void endBurst(Ship a){
-		assert(inBurst);
-		assert(roundsThisBurst==burst) : roundsThisBurst+", "+burst+", "+this;
-		timeInBurst=0;
-		timeToNextRound=0;
-		roundsThisBurst=0;
-		inBurst=false;
-	}
-	
-	private void fireBolt(){
-		if(maxAmmo>0){
-			if(ammo<1){return;}
-			ammo--;
-		}
-		roundsThisBurst++;
-		if(verbose || printShots){
-			Simulate.shotsThisTurn++;
-			System.out.println("\nFiring "+name2+" at "+target.shipName);
-			System.out.println("Before: "+this);
-			System.out.println(target.shipName+": soft="+target.softFlux+", hard="+target.hardFlux+
-					", armor="+target.armor+", hull="+target.hull+", shieldsUp="+target.shieldsUp);
-		}
-		final float shieldDamageEst=estimateShieldDamage();
-		final float shieldRemainingEst=Math.round(target.maxFlux-(target.flux()+shieldDamageEst));
-		
-		final float armorDamageEst=estimateArmorDamage();
-		final float armorRemainingEst=Math.round(target.armor-armorDamageEst);
-		
-		final float hullDamageEst=estimateHullDamage();
-		final float hullRemainingEst=target.hull-hullDamageEst;
-		
-		if(target.shieldsUp && shieldRemainingEst<=0){//Prevent overload
-			target.shieldsUp=false;
-			if(target.canVent){target.venting=true;}
-		}else if(target.hasShield && !target.shieldsUp && !target.venting && 
-				shieldRemainingEst>0 && target.hull>0){//Can raise shields
-				if(hullRemainingEst<=0){//Prevent ship destruction
-					target.shieldsUp=true;
-				}else if(armorRemainingEst<=0 && target.armor>0 && damageType==HE && preventArmorDestuction){
-					target.shieldsUp=true;
-				}else if(maxHullDamagePerBolt>=500 && damageType!=KINETIC && preventTorpedoes){
-					target.shieldsUp=true;
-				}
-		}
-		if(target.shieldsUp){
-			hitShield();
-		}else{
-			hitArmor();
-		}
-
-		if(verbose || printShots){
-			System.out.println("After:  "+this);
-			System.out.println(target.shipName+": soft="+target.softFlux+", hard="+target.hardFlux+
-					", armor="+target.armor+", hull="+target.hull+", shieldsUp="+target.shieldsUp);
-		}
-	}
-	
-	private void hitShield(){
-		assert(target.shieldsUp);
-		target.softFlux+=softFluxDamagePerBolt*target.fluxPerDamage;
-		target.hardFlux+=hardFluxDamagePerBolt*target.fluxPerDamage;
-		assert(target.flux()<target.maxFlux);
-	}
-	
-	private void hitArmor(){
-		if(empDamage>0){
-			applyEmpDamage();
-		}
-		float armorForCalculation=max(target.armor+target.bonusArmor, target.strippedArmorFraction*target.maxArmor);
-		float armorModifier=damageForCalculation/(damageForCalculation+armorForCalculation);
-		armorModifier=max(target.minArmorModifier, armorModifier);
-		float residualFraction=1f; //Amount of hull damage remaining after armor damage is dealt
-		if(target.armor>0){//Reduce armor
-			float modArmorDamage=maxArmorDamagePerBolt*armorModifier;
-			float actualArmorDamage=min(modArmorDamage, target.armor);
-			target.armor-=actualArmorDamage;
-			residualFraction=(modArmorDamage-actualArmorDamage)/modArmorDamage;
-		}
-		float actualHullDamage=maxHullDamagePerBolt*residualFraction*armorModifier;
-		target.hull-=actualHullDamage;
-	}
-	
-	private void applyEmpDamage(){
-		target.empDamageTaken+=empDamagePerBolt;
-	}
-	
-	private float estimateShieldDamage(){
-		return (softFluxDamagePerBolt+hardFluxDamagePerBolt)*target.fluxPerDamage;
-	}
-	
-	private float estimateHullDamage(){
-		float armorForCalculation=max(target.armor+target.bonusArmor, target.strippedArmorFraction*target.maxArmor);
-		float armorModifier=damageForCalculation/(damageForCalculation+armorForCalculation);
-		armorModifier=max(target.minArmorModifier, armorModifier);
-		float residualFraction=1f; //Amount of hull damage remaining after armor damage is dealt
-		if(target.armor>0){//Reduce armor
-			float modArmorDamage=maxArmorDamagePerBolt*armorModifier;
-			float actualArmorDamage=min(modArmorDamage, target.armor);
-			//target.armor-=actualArmorDamage;
-			residualFraction=(modArmorDamage-actualArmorDamage)/modArmorDamage;
-		}
-		float actualHullDamage=maxHullDamagePerBolt*residualFraction*armorModifier;
-		return actualHullDamage;
-	}
-	
-	private float estimateArmorDamage(){
-		if(target.armor<=0){return 0;}
-		float armorForCalculation=max(target.armor+target.bonusArmor, target.strippedArmorFraction*target.maxArmor);
-		float armorModifier=damageForCalculation/(damageForCalculation+armorForCalculation);
-		armorModifier=max(target.minArmorModifier, armorModifier);
-		float modArmorDamage=maxArmorDamagePerBolt*armorModifier;
-		float actualArmorDamage=(float)Math.ceil(min(modArmorDamage, target.armor));
-		return actualArmorDamage;
-	}
-	
-	/*--------------------------------------------------------------*/
-	/*----------------           Helpers            ----------------*/
-	/*--------------------------------------------------------------*/
-
-	final float armorDamageMult(){
-		return damageType==KINETIC ? 0.5f : damageType==HE ? 2f : 
-			damageType==FRAG ? 0.25f : damageType==ENERGY ? 1 : 1;
-	}
-	final float shieldDamageMult(){
-		return damageType==KINETIC ? 2 : damageType==HE ? 0.5f : 
-			damageType==FRAG ? 0.25f : damageType==ENERGY ? 1 : 1;
-	}
-	
-	/**
-	 * Find a String in an array.
-	 * @param a String to find.
-	 * @param array Array of Strings.
-	 * @return Index of element, or -1 if not found.
-	 */
-	public static final int find(String a, String[] array){
-		for(int i=0; i<array.length; i++){
-			if(a.equals(array[i])){return i;}
-		}
-		assert(false) : "Can't find "+a+" in "+Arrays.toString(array);
-		return -1;
-	}
-	
-	/**
-	 * Parse this argument.  More liberal than Boolean.parseBoolean.
-	 * Null, t, true, or 1 all yield true.
-	 * Everything else, including the String "null", is false.
-	 * @param s Argument to parse
-	 * @return boolean form
-	 */
-	public static boolean parseBoolean(String s){
-		if(s==null || s.length()<1){return true;}
-		if(s.length()==1){
-			char c=Character.toLowerCase(s.charAt(0));
-			return c=='t' || c=='1';
-		}
-		if(s.equalsIgnoreCase("null") || s.equalsIgnoreCase("none")){return false;}
-		return Boolean.parseBoolean(s);
-	}
-	
-	public static final int min(int x, int y){return x<y ? x : y;}
-	public static final int max(int x, int y){return x>y ? x : y;}
-	public static final float min(float x, float y){return x<y ? x : y;}
-	public static final float max(float x, float y){return x>y ? x : y;}
-	public static final int roundUp(float x){return (int)Math.ceil(x);}
-	
-	/*--------------------------------------------------------------*/
-	/*----------------           Fields             ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	/*--------------------------------------------------------------*/
-	/*----------------     Initialized Fields       ----------------*/
-	/*--------------------------------------------------------------*/
-
-	String name;
-	String name2;
-	
-	int type=BOLT; //bolt or beam
-	int fluxType=HARD; //hard or soft
-	int damageType=KINETIC; //kinetic, HE, frag, energy
-	int fluxCostPerBurstNominal=-1;
-	final float fluxCostPerBurstActual;//For beams this would be per centi
-	int damage=-1; //per shot; for beams this would be dps
-	float empDamage=0; //per shot; for beams this would be emp dps
-	int burst=1; //shots per burst
-	float burstDuration; //time per burst, in seconds
-	float reloadTime=-1; //in seconds
-	int maxAmmo=-1;
-	float ammoRegen=0; //ammo added per second
-	
-	int rawBurstTime=0; //in 1/100s
-	int rawReloadTime=0; //in 1/100s
-	int rawFluxCost=-1; //per burst; for beams this would be per second
-	
-	int submunitions=1; //for MIRV / splatter / shotguns / etc
-	
-	
-	
-	/*--------------------------------------------------------------*/
-	/*----------------        Derived Fields        ----------------*/
-	/*--------------------------------------------------------------*/
-	
-//	final float secondsPerBolt; //seconds per bolt (i.e. bullet) while firing; derived.
-	final float shieldDamagePerBolt;
-	final float maxArmorDamagePerBolt;
-	final float maxHullDamagePerBolt;
-	final float hardFluxDamagePerBolt;
-	final float softFluxDamagePerBolt;
-	final float damageForCalculation;
-	final float empDamagePerBolt;
-	final int centiPerBurst; //in 1/100 second
-	final int centiPerReload;
-	final int centiPerRound;
-	final float regenPerCenti;
-	
-	/*--------------------------------------------------------------*/
-	/*----------------       Mutable Fields         ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	float ammo;
-	int timeToNextBurst=0; //in centis
-	int timeInBurst=0; //in centis
-	int timeToNextRound=0;
-	int roundsThisBurst=0;
-	boolean inBurst=false;
-	Ship target;
-	
-	/*--------------------------------------------------------------*/
-	/*----------------          Constants           ----------------*/
-	/*--------------------------------------------------------------*/
-	
-	public static final int BOLT=0, BEAM=1;
-	public static final int HARD=0, SOFT=1;
-	public static final int KINETIC=0, HE=1, FRAG=2, ENERGY=3;
-
-	public static final String[] types={"bolt", "beam"};
-	public static final String[] fluxTypes={"hard", "soft"};
-	public static final String[] damageTypes={"kinetic", "he", "frag", "energy"};
-	
-	static final HashMap<String, Weapon> map=new HashMap<String, Weapon>();
-
-	static boolean verbose=false;
-	static boolean printShots=false;
-	static boolean useFullName=false;
-	static boolean preventArmorDestuction=false;
-	static boolean preventTorpedoes=false;
-	
-}



View it on GitLab: https://salsa.debian.org/med-team/bbmap/-/commit/73e56967b72a7e65b1f4e439c81b0d301993fcbb

-- 
View it on GitLab: https://salsa.debian.org/med-team/bbmap/-/commit/73e56967b72a7e65b1f4e439c81b0d301993fcbb
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20211005/2733312a/attachment-0001.htm>


More information about the debian-med-commit mailing list