source: abuse/branches/lol/src/sensor.cpp @ 732

Last change on this file since 732 was 732, checked in by Sam Hocevar, 8 years ago

build: SDL2 compilation fixes.

File size: 1.5 KB
Line 
1/*
2 *  Abuse - dark 2D side-scrolling platform game
3 *  Copyright (c) 1995 Crack dot Com
4 *  Copyright (c) 2005-2013 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, by
8 *  Jonathan Clark, or by Sam Hocevar.
9 */
10
11#if HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include "common.h"
16
17#include "lisp/lisp.h"
18#include "lisp/lisp_gc.h"
19
20#include "compiled.h"
21#include "objects.h"
22#include "level.h"
23#include "game.h"
24#include "clisp.h"
25
26enum { un_offable };     // vars
27
28void *sensor_ai()
29{
30  GameObject *o=current_object,*b;
31  if (o->aistate()==0)                     // turned off, what for player to enter
32  {
33    if (player_list->next)                 // find closest player
34      b=g_current_level->attacker(current_object);
35    else b=player_list->m_focus;
36    if (lol::abs(b->m_pos - o->m_pos) < o->m_vel) // inside area?
37    {
38      if (!o->hp())
39        o->set_aistate(1);
40      else
41        o->set_aistate(o->hp());
42      o->set_state((character_state)S_blocking);
43    } else if (o->state!=stopped)
44      o->set_state(stopped);
45  } else if (!o->lvars[un_offable])
46  {
47    if (!o->hp())
48    {
49      if (player_list->next)
50        b=g_current_level->attacker(current_object);
51      else b=player_list->m_focus;
52      if (!(lol::abs(o->m_pos - b->m_pos) <= o->m_accel))
53        o->set_aistate(0);
54    } else o->set_aistate(o->aistate()-1);
55  }
56  return true_symbol;
57}
Note: See TracBrowser for help on using the repository browser.