1 // Copyright Hugh Perkins 2006, 2009 2 // hughperkins@gmail.com http://manageddreams.com 3 // 4 // This program is free software; you can redistribute it and/or modify it 5 // under the terms of the GNU General Public License as published by the 6 // Free Software Foundation; either version 2 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, but 10 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 11 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 // more details. 13 // 14 // You should have received a copy of the GNU General Public License along 15 // with this program in the file licence.txt; if not, write to the 16 // Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111- 17 // 1307 USA 18 // You can find the licence also on the web at: 19 // http://www.opensource.org/licenses/gpl-license.php 20 // 21 22 package hughai; 23 24 import java.util.*; 25 import java.util.Map; 26 27 import com.springrts.ai.*; 28 import com.springrts.ai.oo.clb.*; 29 30 import hughai.basictypes.*; 31 import hughai.mapping.*; 32 import hughai.packcoordinators.*; 33 import hughai.unitdata.*; 34 import hughai.utils.*; 35 36 37 public class MobileFusionController 38 { 39 CSAI csai; 40 OOAICallback aicallback; 41 LogFile logfile; 42 UnitController unitController; 43 GiveOrderWrapper giveOrderWrapper; 44 45 Collection<Unit> mobileunits = new ArrayList<Unit>(); 46 MobileFusionController( PlayerObjects playerObjects )47 public MobileFusionController( PlayerObjects playerObjects ) 48 { 49 csai = playerObjects.getCSAI(); 50 aicallback = csai.aicallback; 51 logfile = playerObjects.getLogFile(); 52 unitController = playerObjects.getUnitController(); 53 giveOrderWrapper = playerObjects.getGiveOrderWrapper(); 54 55 unitController.registerListener( new UnitControllerHandler() ); 56 // UnitController.GetInstance().UnitAddedEvent += new UnitController.UnitAddedHandler(MobileFusionController_UnitAddedEvent); 57 // UnitController.GetInstance().AllUnitsLoaded += new UnitController.AllUnitsLoadedHandler(MobileFusionController_AllUnitsLoaded); 58 } 59 60 class UnitControllerHandler extends UnitController.UnitAdapter { 61 @Override AllUnitsLoaded()62 public void AllUnitsLoaded() 63 { 64 for (Unit mobile : mobileunits) 65 { 66 // move them to nearest mex? 67 TerrainPos targetpos = unitController.getPos( unitController.UnitsByName 68 .get("armmex").get(0) ); //aicallback.GiveOrder(mob, new Command(Command.CMD_PATROL, targetpos.ToDoubleArray())); 69 giveOrderWrapper.MoveTo(mobile, targetpos); 70 } 71 } 72 73 @Override UnitAdded( Unit unit )74 public void UnitAdded( Unit unit ) 75 { 76 if (unit.getDef().getName().toLowerCase() == "armmfus") 77 { 78 mobileunits.add( unit ); 79 } 80 } 81 82 } 83 } 84 85