/* * UFO Saved Game Editor * Copyright (C) 2010 Christopher Davoren * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.rubikscomplex.ufosge; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import net.rubikscomplex.ufosge.data.ProducibleItem; import net.rubikscomplex.ufosge.data.Research; /** * * @author Chris Davoren */ public class UFOInfo { public static final int MIN_SAVED_GAME = 1; public static final int MAX_SAVED_GAME = 10; public static final String SG_DIR_PREFIX = "GAME_"; public static final String LIGLOB_FILENAME = "LIGLOB.DAT"; public static final String SAVEINFO_FILENAME = "SAVEINFO.DAT"; public static final String SOLDIER_FILENAME = "SOLDIER.DAT"; public static final String BASE_FILENAME = "BASE.DAT"; public static final String PRODUCT_FILENAME = "PRODUCT.DAT"; public static final String RESEARCH_FILENAME = "RESEARCH.DAT"; public static final String FACILITY_FILENAME = "FACIL.DAT"; public static final String UP_FILENAME = "UP.DAT"; public static final String CRAFT_FILENAME = "CRAFT.DAT"; public static final String LOCATION_FILENAME = "LOC.DAT"; public static Map<String, String[]> researchPrerequisites() { HashMap<String, String[]> map = new HashMap<String, String[]>(); map.put("Laser Pistol", new String[]{ "Laser Weapons" }); map.put("Laser Rifle", new String[]{ "Laser Pistol" }); map.put("Heavy Laser", new String[]{ "Laser Rifle" }); map.put("Laser Cannon", new String[]{ "Heavy Laser"}); map.put("Laser Defense", new String[]{ "Laser Cannon" }); map.put("Personal Armor", new String[]{ "Alien Alloys" }); map.put("Power Suit", new String[]{"Elerium 115", "Personal Armor", "UFO Power Source"}); map.put("Flying Suit", new String[]{"Power Suit", "UFO Navigation"}); map.put("UFO Construction", new String[]{"Alien Alloys", "Elerium 115", "UFO Power Source", "UFO Navigation"}); map.put("New Fighter", new String[]{"UFO Construction"}); map.put("New Fighter-Transporter", new String[]{"New Fighter"}); map.put("Grav Shield", new String[]{"New Fighter-Transporter"}); map.put("Ultimate Craft", new String[]{"New Fighter-Transporter"}); map.put("Plasma Cannon", new String[]{"Heavy Plasma", "Heavy Plasma Clip"}); map.put("Plasma Defense", new String[]{"Plasma Cannon"}); map.put("Fusion Missile", new String[]{"Blaster Launcher", "Blaster Bomb"}); return map; } public static boolean processSpecialResearchRequirements(ArrayList<Research> researchItems) { boolean changed = false; /* The plasma cannon is available after completing Heavy Plasma OR Plasma Rifle research */ Research plasmaCannonResearch = researchItems.get(0x21); if (!plasmaCannonResearch.completed) { boolean pr = (researchItems.get(0x04).completed && researchItems.get(0x05).completed) || (researchItems.get(0x06).completed && researchItems.get(0x07).completed); changed |= pr != plasmaCannonResearch.prerequisitesMet; plasmaCannonResearch.prerequisitesMet = pr; } Research psionicLabresearch = researchItems.get(0x28); /* Psionic lab becomes available after interrogating a live psionic-capable alien */ if (!psionicLabresearch.completed) { boolean pr = false; /* Sectoid/Ethereal Leader/Commander */ pr |= researchItems.get(0x3E).completed; pr |= researchItems.get(0x3F).completed; pr |= researchItems.get(0x4A).completed; pr |= researchItems.get(0x4B).completed; changed |= pr != psionicLabresearch.prerequisitesMet; psionicLabresearch.prerequisitesMet = pr; } return changed; } public static ArrayList<Integer> itemPrerequisites(String itemName) { ArrayList<Integer> list = new ArrayList<Integer>(); // String name = ProducibleItem.ITEM_NAMES[item.index]; if (itemName.equals("Fusion Ball Launcher")) { list.add(0x22); } if (itemName.equals("Laser Cannon")) { list.add(0x20); } else if (itemName.equals("Plasma Cannon")) { list.add(0x21); } else if (itemName.equals("Fusion Ball")) { list.add(0x22); } else if (itemName.equals("Tank/Laser Cannon")) { list.add(0x20); } else if (itemName.equals("Hovertank/Plasma")) { list.add(0x21); list.add(0x1A); } else if (itemName.equals("Hovertank/Launcher")) { list.add(0x22); list.add(0x1A); } else if (itemName.equals("HWP Fusion Bomb")) { list.add(0x22); list.add(0x1A); } else if (itemName.equals("Laser Pistol")) { list.add(0x1D); } else if (itemName.equals("Laser Rifle")) { list.add(0x1E); } else if (itemName.equals("Heavy Laser")) { list.add(0x1F); } else if (itemName.equals("Motion Scanner")) { list.add(0x01); } else if (itemName.equals("Medi-kit")) { list.add(0x02); } else if (itemName.equals("Psi-Amp")) { list.add(0x03); } else if (itemName.equals("Heavy Plasma")) { list.add(0x04); list.add(0x05); } else if (itemName.equals("Heavy Plasma Clip")) { list.add(0x04); list.add(0x05); } else if (itemName.equals("Plasma Rifle")) { list.add(0x06); list.add(0x07); } else if (itemName.equals("Plasma Rifle Clip")) { list.add(0x06); list.add(0x07); } else if (itemName.equals("Plasma Pistol")) { list.add(0x08); list.add(0x09); } else if (itemName.equals("Plasma Pistol Clip")) { list.add(0x08); list.add(0x09); } else if (itemName.equals("Blaster Launcher")) { list.add(0x0A); list.add(0x0B); } else if (itemName.equals("Blaster Bomb")) { list.add(0x0A); list.add(0x0B); } else if (itemName.equals("Small Launcher")) { list.add(0x0C); list.add(0x0D); } else if (itemName.equals("Stun Bomb")) { list.add(0x0C); list.add(0x0D); } else if (itemName.equals("Alien Grenade")) { list.add(0x0E); } else if (itemName.equals("Mind Probe")) { list.add(0x10); } else if (itemName.equals("Personal Armour")) { list.add(0x3B); } else if (itemName.equals("Power Suit")) { list.add(0x3C); } else if (itemName.equals("Flying Suit")) { list.add(0x3D); } else if (itemName.equals("Alien Alloys")) { list.add(0x19); } else if (itemName.equals("UFO Power Source")) { list.add(0x11); } else if (itemName.equals("UFO Navigation")) { list.add(0x12); } else if (itemName.equals("FIRESTORM")) { list.add(0x1A); } else if (itemName.equals("LIGHTNING")) { list.add(0x1B); } else if (itemName.equals("AVENGER")) { list.add(0x1C); } return list; } public static Map<String, String[]> itemPrerequisiteMap() { HashMap<String, String[]> map = new HashMap<String, String[]>(); for(int i = 0; i < ProducibleItem.ITEM_NAMES.length; i++) { String itemName = ProducibleItem.ITEM_NAMES[i]; String[] prNames; int pos = 0; ArrayList<Integer> ipr = itemPrerequisites(itemName); Iterator<Integer> ipri = ipr.iterator(); prNames = new String[ipr.size()]; while(ipri.hasNext()) { prNames[pos++] = Research.PROJECT_NAMES[ipri.next().intValue()]; } map.put(itemName, prNames); } return map; } }