remove shit
[rmh3093.git] / motsim / TrialDataDynamic.java
blob6e0d012ffd01887c040e9a31218c974374b5758e
1 /**
2 * TrialDataDynamic.java
3 * motsim
4 */
6 import java.awt.Dimension;
7 import java.awt.Point;
8 import java.util.HashSet;
9 import java.util.Iterator;
10 import java.util.Random;
12 public class TrialDataDynamic {
14 Random rand;
15 Dimension screen_size;
17 /**
18 * An array of aircraft operator prefixes.
20 final private String[] callsign_prefixes = {
21 "SWA", "AAL", "UAL", "COA", "DAL", "FDX", "NWA", "UPS", "SKW",
22 "ACA", "BTA", "AWE", "JBU", "USA", "ASA", "TRS", "BAW", "ABX",
23 "EGF", "DLH", "WJA", "AFR", "ASH", "ASQ", "AMF", "FFT", "FLG",
24 "COM", "JZA", "CHQ", "QXE", "KLM", "DHL", "MES", "HAL", "USC",
25 "LOF", "VIR", "CJC", "KAL", "JIA", "VRD", "NKS", "TSC", "RPA",
26 "TCF", "CPA", "AWI", "IBE", "MXA", "EJA", "AZA", "SWR", "MEP",
27 "PEN", "LBQ", "GLA", "EIN", "CAL", "AAY", "AMX", "TCX", "MPH",
28 "CCI", "FLX", "BKA", "JAZ", "AIC", "GJS", "JAL", "ANA", "SCX",
29 "MTN", "FTA", "PDT", "LTU", "CPZ", "REX", "AJM", "MPE", "SIA",
30 "ICE", "SAS", "AEA", "CRL", "SKQ", "CMI", "CLX", "FIV", "TAI",
31 "MRA", "CJT", "ELY", "EVA", "NCB", "PCO", "ATN", "TOM", "CFG",
32 "AAR", "LAN", "MAL", "GTI", "JAI", "ERH", "CMP", "AUA", "RZO",
33 "GSM", "SWG", "AVA", "THT", "WAE", "SNC", "WIG", "LOT", "CCA",
34 "AFL", "XLA", "FRL", "GLR", "TAM", "FCA", "UAE", "GWY", "SVX",
35 "MDS", "SAA", "CWC", "BMA", "CAV", "DCS", "LAL", "OOM", "MUI",
36 "OAL", "KFA", "LYM", "WEW", "CTA", "BBR", "HKI", "MKU", "IWD",
37 "WIS", "RAM", "CPT", "CGC", "SUB", "FAB", "FIN", "CUB", "VTS",
38 "CGL", "CLA", "WAV", "ADH", "RJA", "AAH", "CKK", "SSX", "ANZ",
39 "WOA", "TAP", "THU", "VPB", "LNX", "CES", "KAP", "LPE", "GGN",
40 "NWD", "EXA", "WWI", "CHH", "PCE", "CAP", "SLI", "APW", "ACT",
41 "VPA", "CAO", "THY", "WIA", "CNK", "CGR", "CFN", "FPG", "APC",
42 "FWL", "GRC", "TFL", "UKZ", "NMI", "PRO", "ASP", "CON", "EMD",
43 "ETH", "SSV", "GCO", "AJT", "DNJ", "FRE", "BXR", "TAG", "BVN",
44 "BOS", "CKS", "PRY", "PAC", "PGX", "PAG", "NOA", "JDC", "AIP",
45 "BLS", "GLT", "MAH", "BXH", "CFC", "SQC", "VAL", "MAS", "ARG",
46 "MAX", "CGN", "NRL", "LNE", "ETD", "GUN", "OAE", "QTR", "EJM",
47 "ANT", "NDU", "ISR", "TWY", "MSR", "CCY", "OPT", "TEC", "PWA",
48 "LRC", "BOE", "MPD", "QFA", "CFZ", "CJA", "AVI", "CSA", "GEC",
49 "QUE"
52 public TrialDataDynamic(Dimension screen_size) {
53 rand = new Random();
54 this.screen_size = screen_size;
57 /**
58 * Generate a set of random callsigns using a random prefix from
59 * "callsign_prefixes" and a random 3 digit number.
61 * @param count The number of callsigns to generate.
62 * @return A HashSet of callsigns.
64 private HashSet<String> generate_callsigns(int count) {
66 HashSet<String> callsigns = new HashSet<String>(count);
68 while (callsigns.size() < count) {
69 int randomInt = rand.nextInt(callsign_prefixes.length);
70 int callsign_suffix = 0;
71 while (callsign_suffix < 100) {
72 callsign_suffix = rand.nextInt(1000);
74 callsigns.add(callsign_prefixes[randomInt] +
75 String.valueOf(callsign_suffix));
78 return callsigns;
82 /**
83 * Generate a set of random coordinates between 0.0 and 1.0.
85 * @param count The number of coordinates to generate.
86 * @return A HashSet of coordinates.
88 private HashSet<Point> generate_coordinates(int count) {
90 HashSet<Point> coordinates = new HashSet<Point>(count);
92 while (coordinates.size() < count) {
93 int x = (int)Math.round(screen_size.width * rand.nextDouble());
94 int y = (int)Math.round(screen_size.height * rand.nextDouble());
95 Point point = new Point();
96 point.setLocation(x, y);
97 coordinates.add(point);
100 return coordinates;
105 * Generate a random set of targets.
107 * @param count The number of callsigns to generate.
108 * @return A HashSet of coordinates.
110 protected HashSet<Target> generate_targets( int count ) {
112 HashSet<Target> targets = new HashSet<Target>( count );
113 HashSet<String> callsigns = generate_callsigns( count );
114 HashSet<Point> coordinates = generate_coordinates( count );
115 Iterator<String> callsignsIter = callsigns.iterator();
116 Iterator<Point> coordinatesIter = coordinates.iterator();
118 while ( ( targets.size() < count ) &&
119 ( callsignsIter.hasNext() && callsignsIter.hasNext() ) ) {
120 int angle = rand.nextInt(360);
121 Target target =
122 new Target( callsignsIter.next(), coordinatesIter.next(),
123 angle, calcAngleMoveX(angle), calcAngleMoveY(angle));
124 targets.add( target );
127 return targets;
131 protected void addTarget(HashSet<Target> targets) {
133 HashSet<String> callsigns;
134 HashSet<Point> coordinates;
135 Iterator<String> callsignsIter;
136 Iterator<Point> coordinatesIter;
138 int size = targets.size() + 1;
139 while ( targets.size() < size ) {
140 callsigns = generate_callsigns(1);
141 coordinates = generate_coordinates(1);
142 callsignsIter = callsigns.iterator();
143 coordinatesIter = coordinates.iterator();
144 int angle = rand.nextInt(360);
145 Target target =
146 new Target(callsignsIter.next(), coordinatesIter.next(), angle,
147 calcAngleMoveX(angle), calcAngleMoveY(angle));
148 targets.add( target );
153 public double calcAngleMoveX(double angle) {
154 return (double) (Math.cos(angle * Math.PI / 180));
157 public double calcAngleMoveY(double angle) {
158 return (double) (Math.sin(angle * Math.PI / 180));