home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 24 / AACD 24.iso / AACD / Games / dynAMIte / Developer / E / dynabot.e next >
Encoding:
Text File  |  2001-07-22  |  2.5 KB  |  124 lines

  1. MODULE  'dos/dos'
  2.  
  3. MODULE  '*dynamite'
  4.  
  5. PROC main()
  6.  
  7.   DEF done=FALSE, delay
  8.  
  9.   DEF dynasema=NIL:PTR TO dynamitesemaphore
  10.  
  11.   DEF ourplayer:PTR TO player, oldframe=0
  12.  
  13.   DEF thisbotnum
  14.  
  15.   -> check if dynamite is running
  16.  
  17.   -> try to find the semaphore
  18.   Forbid()
  19.   IF dynasema:=FindSemaphore('dynAMIte.0')
  20.     -> increase opencount to tell dynamite that you are using the
  21.     -> semaphore.  dynamite will remove the semaphore only if opencnt is
  22.     -> 0 at its end
  23.  
  24.     dynasema.opencnt:=dynasema.opencnt+1
  25.     thisbotnum:=dynasema.opencnt
  26.  
  27.     -> set botinfo string
  28.     dynasema.botinfo[thisbotnum]:='dynamite sample bot v1.0 - doing nothing useful'
  29.   ENDIF
  30.   Permit()
  31.  
  32.   IF dynasema
  33.     WriteF('dynAMIte is started\n')
  34.  
  35.     WriteF('Clients using the semaphore: \d\n',dynasema.opencnt)
  36.  
  37.     WHILE done=FALSE
  38.  
  39.       IF CheckSignal(SIGBREAKF_CTRL_C)
  40.  
  41.         done:=TRUE
  42.  
  43.       ELSE
  44.  
  45.         delay:=TRUE
  46.  
  47.         ObtainSemaphore(dynasema) -> lock it
  48.  
  49.         -> check if dynamite wants to quit
  50.         IF dynasema.quit=1
  51.  
  52.           -> dynamite wants to quit, so we do dynamite a favour
  53.           WriteF('dynAMIte is about to quit...\n')
  54.           done:=TRUE
  55.  
  56.         ELSE
  57.  
  58.           -> if a game is running
  59.           IF (dynasema.gamerunning>=GAME_GAME) AND (dynasema.gamerunning<GAME_NOTCONNECTED)
  60.  
  61.             -> and player is no observer
  62.             IF dynasema.thisplayer<8
  63.  
  64.               delay:=FALSE
  65.  
  66.               ourplayer:=dynasema.player[dynasema.thisplayer]
  67.  
  68.               -> and our player is alive
  69.               IF ourplayer.dead>0
  70.  
  71.                 -> and current game frame has been increased
  72.                 IF dynasema.frames<>oldframe
  73.                   oldframe:=dynasema.frames
  74.  
  75.                   -> do your AI stuff
  76.  
  77.                   dynasema.walk:=Rnd(DIR_UP+1)
  78.  
  79.                 ENDIF
  80.               ENDIF
  81.  
  82.             ENDIF
  83.  
  84.           ENDIF
  85.  
  86.         ENDIF
  87.  
  88.         ReleaseSemaphore(dynasema) -> release it
  89.  
  90.         IF delay
  91.           -> no game is running
  92.           -> do a small delay to let the cpu do other things :(
  93.           Delay(10)
  94.         ENDIF
  95.  
  96.       ENDIF
  97.     ENDWHILE
  98.  
  99.     ObtainSemaphore(dynasema) -> lock it
  100.  
  101.     -> reset direction
  102.     dynasema.walk:=DIR_NONE
  103.  
  104.     -> set botinfo entry back to 0
  105.     dynasema.botinfo[thisbotnum]:=NIL
  106.  
  107.     -> decrease opencount to tell dynamite that you no longer need
  108.     -> the semaphore.
  109.     -> dynamite will remove the semaphore only if opencnt is
  110.     -> 0 at the end
  111.  
  112.     dynasema.opencnt:=dynasema.opencnt-1
  113.  
  114.     ReleaseSemaphore(dynasema) -> release it
  115.  
  116.  
  117.   ELSE -> not found
  118.  
  119.     WriteF('dynAMIte is not running\n')
  120.  
  121.   ENDIF
  122.  
  123. ENDPROC
  124.