001 package com.croftsoft.apps.mars.ai; 002 003 import java.util.*; 004 005 import com.croftsoft.core.lang.NullArgumentException; 006 import com.croftsoft.core.math.geom.PointXY; 007 import com.croftsoft.core.util.NullIterator; 008 009 /********************************************************************* 010 * TankOperator implementation that requires direction. 011 * 012 * @version 013 * 2003-05-13 014 * @since 015 * 2003-04-17 016 * @author 017 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 018 *********************************************************************/ 019 020 // this should not have to be serializable 021 022 public final class DirectedTankOperator 023 implements TankOperator, java.io.Serializable 024 ////////////////////////////////////////////////////////////////////// 025 ////////////////////////////////////////////////////////////////////// 026 { 027 028 private TankConsole tankConsole; 029 030 private boolean fireRequested; 031 032 private PointXY destination; 033 034 private boolean destinationRequested; 035 036 ////////////////////////////////////////////////////////////////////// 037 ////////////////////////////////////////////////////////////////////// 038 039 public DirectedTankOperator ( TankConsole tankConsole ) 040 ////////////////////////////////////////////////////////////////////// 041 { 042 setTankConsole ( tankConsole ); 043 } 044 045 ////////////////////////////////////////////////////////////////////// 046 ////////////////////////////////////////////////////////////////////// 047 048 public void fire ( ) 049 ////////////////////////////////////////////////////////////////////// 050 { 051 fireRequested = true; 052 } 053 054 public void go ( PointXY destination ) 055 ////////////////////////////////////////////////////////////////////// 056 { 057 // should null destination be allowed to force stop? 058 059 destinationRequested = true; 060 061 this.destination = destination; 062 } 063 064 public Iterator getPath ( ) 065 ////////////////////////////////////////////////////////////////////// 066 { 067 return NullIterator.INSTANCE; 068 } 069 070 ////////////////////////////////////////////////////////////////////// 071 ////////////////////////////////////////////////////////////////////// 072 073 public void setTankConsole ( TankConsole tankConsole ) 074 ////////////////////////////////////////////////////////////////////// 075 { 076 NullArgumentException.check ( this.tankConsole = tankConsole ); 077 } 078 079 public void update ( double timeDelta ) 080 ////////////////////////////////////////////////////////////////////// 081 { 082 if ( fireRequested || destinationRequested ) 083 { 084 if ( fireRequested ) 085 { 086 tankConsole.fire ( ); 087 088 fireRequested = false; 089 } 090 091 if ( destinationRequested ) 092 { 093 tankConsole.go ( destination ); 094 095 tankConsole.rotateTurret ( destination ); 096 097 destinationRequested = false; 098 } 099 } 100 } 101 102 ////////////////////////////////////////////////////////////////////// 103 ////////////////////////////////////////////////////////////////////// 104 }