1 /*
2  * Seven Kingdoms: Ancient Adversaries
3  *
4  * Copyright 1997,1998 Enlight Software Ltd.
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, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 //Filename   : OAI_QUER.CPP
22 //Description: AI - query functions
23 
24 #include <ALL.h>
25 #include <OTOWN.h>
26 #include <OFIRM.h>
27 #include <ONATION.h>
28 
29 
30 //--------- Begin of function Nation::check_firm_ready --------//
31 //
32 // <short> xLoc, yLoc - locatino of the firm.
33 // [int]   firmId		 - id. of the firm. If not given, don't
34 //								verify the firm id. (default: 0)
35 //
36 // return 1 means firm exists and belongs to  our nation
37 // return 0 otherwise
38 //
check_firm_ready(short xLoc,short yLoc,int firmId)39 int Nation::check_firm_ready(short xLoc, short yLoc, int firmId)
40 {
41 	Location *locPtr = world.get_loc(xLoc, yLoc);
42 
43 	if(!locPtr->is_firm())
44 		return 0;	// no firm there
45 
46 	short firmRecno = locPtr->firm_recno();
47 
48 	if(firm_array.is_deleted(firmRecno))
49 		return 0;	// firm deleted
50 
51 	Firm *firmPtr = firm_array[firmRecno];
52 
53 	if(firmPtr->nation_recno!=nation_recno)
54 		return 0;	// firm changed nation
55 
56 	if( firmId && firmPtr->firm_id!=firmId )
57 		return 0;
58 
59 	return 1;
60 }
61 //---------- End of function Nation::check_firm_ready --------//
62 
63 
64 //--------- Begin of function Nation::check_town_ready --------//
65 //
66 // return 1 means town exists and belongs to  our nation
67 // return 0 otherwise
68 //
check_town_ready(short xLoc,short yLoc)69 int Nation::check_town_ready(short xLoc, short yLoc)
70 {
71 	Location *locPtr = world.get_loc(xLoc, yLoc);
72 
73 	if(!locPtr->is_town())
74 		return 0;	// no town there
75 
76 	short townRecno = locPtr->town_recno();
77 
78 	if(town_array.is_deleted(townRecno))
79 		return 0;	// town deleted
80 
81 	Town *townPtr = town_array[townRecno];
82 
83 	if(townPtr->nation_recno!=nation_recno)
84 		return 0;	// town changed nation
85 
86 	return 1;
87 }
88 //---------- End of function Nation::check_town_ready --------//
89 
90 
91 //--------- Begin of function Nation::can_ai_build --------//
92 //
93 // Whether the AI can build the specific firm type next to
94 // the current firm.
95 //
can_ai_build(int firmId)96 int Nation::can_ai_build(int firmId)
97 {
98 	//------- check whether the AI has enough cash -----//
99 
100 	if( cash < firm_res[firmId]->setup_cost )
101 		return 0;
102 
103 	return 1;
104 }
105 //--------- End of function Nation::can_ai_build --------//
106 
107 
108 
109