source: abuse/trunk/src/sensor.cpp @ 494

Last change on this file since 494 was 494, checked in by Sam Hocevar, 11 years ago

style: remove trailing spaces, fix copyright statements.

File size: 1.4 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 *  This software was released into the Public Domain. As with most public
7 *  domain software, no warranty is made or implied by Crack dot Com or
8 *  Jonathan Clark.
9 */
10
11#include "config.h"
12
13#include "lisp.h"
14#include "lisp_gc.h"
15#include "compiled.h"
16#include "objects.h"
17#include "level.h"
18#include "game.h"
19#include "jrand.h"
20#include "clisp.h"
21
22enum { un_offable };     // vars
23
24void *sensor_ai()
25{
26  game_object *o=current_object,*b;
27  if (o->aistate()==0)                     // turned off, what for player to enter
28  {
29    if (player_list->next)                 // find closest player
30      b=current_level->attacker(current_object);
31    else b=player_list->focus;
32    if (abs(b->x-o->x)<o->xvel() && abs(b->y-o->y)<o->yvel())  // inside area?
33    {
34      if (!o->hp())
35        o->set_aistate(1);
36      else
37        o->set_aistate(o->hp());
38      o->set_state((character_state)S_blocking);
39    } else if (o->state!=stopped)
40      o->set_state(stopped);
41  } else if (!o->lvars[un_offable])
42  {
43    if (!o->hp())
44    {
45      if (player_list->next)
46        b=current_level->attacker(current_object);
47      else b=player_list->focus;
48      if (abs(o->x-b->x)>o->xacel() || abs(o->y-b->y)>o->yacel())
49        o->set_aistate(0);
50    } else o->set_aistate(o->aistate()-1);
51  }
52  return true_symbol;
53}
Note: See TracBrowser for help on using the repository browser.