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

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

imlib: use vec2i for image::size and unroll all necessary changes
everywhere else in the code.

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 "common.h"
14
15#include "lisp.h"
16#include "lisp_gc.h"
17#include "compiled.h"
18#include "objects.h"
19#include "level.h"
20#include "game.h"
21#include "jrand.h"
22#include "clisp.h"
23
24enum { un_offable };     // vars
25
26void *sensor_ai()
27{
28  game_object *o=current_object,*b;
29  if (o->aistate()==0)                     // turned off, what for player to enter
30  {
31    if (player_list->next)                 // find closest player
32      b=current_level->attacker(current_object);
33    else b=player_list->focus;
34    if (abs(b->x-o->x)<o->xvel() && abs(b->y-o->y)<o->yvel())  // inside area?
35    {
36      if (!o->hp())
37        o->set_aistate(1);
38      else
39        o->set_aistate(o->hp());
40      o->set_state((character_state)S_blocking);
41    } else if (o->state!=stopped)
42      o->set_state(stopped);
43  } else if (!o->lvars[un_offable])
44  {
45    if (!o->hp())
46    {
47      if (player_list->next)
48        b=current_level->attacker(current_object);
49      else b=player_list->focus;
50      if (abs(o->x-b->x)>o->xacel() || abs(o->y-b->y)>o->yacel())
51        o->set_aistate(0);
52    } else o->set_aistate(o->aistate()-1);
53  }
54  return true_symbol;
55}
Note: See TracBrowser for help on using the repository browser.