1 /*
2 This file is part of "Avanor, the Land of Mystery" roguelike game
3 Home page: http://www.avanor.com/
4 Copyright (C) 2000-2003 Vadim Gaidukevich
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20 
21 #include "std_ai.h"
22 #include "los.h"
23 
24 #define NOT_EQUAL(a, b) ((a) - (b)) // is faster than a != b when we need int instead of bool
25 
26 struct opaque_info
27 {
28 	XStandardAI * ai;
29 	XMap        * map;
30 };
31 
grid_callback(void * opaque,int x,int y,int radius,int see_center)32 static int grid_callback(void * opaque, int x, int y, int radius, int see_center)
33 {
34 	opaque_info * info = (opaque_info *)opaque;
35 	if (see_center) info->ai->AnalyzeGrid(x, y, radius);
36 	return NOT_EQUAL(info->map->GetMovability(x, y), MO_WALL);
37 }
38 
AnalyzeView(int radius)39 void XStandardAI::AnalyzeView(int radius)
40 {
41 	opaque_info info = { this, ai_owner->l->map };
42 
43 	LineOfSight(
44 		ai_owner->x,
45 		ai_owner->y,
46 		radius,
47 		&info,
48 		grid_callback);
49 }
50