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 "xgen.h"
22 #include "xapi.h"
23 #include "game.h"
24 
25 REGISTER_CLASS(XUniversalGen);
26 
Run()27 int XUniversalGen::Run()
28 {
29 	unsigned int cr_count[32];
30 	memset(cr_count, 0, sizeof(int) * 32);
31 
32 
33 	//hack!!!
34 	XObject * o = root;
35 	while (o)
36 	{
37 		if ((o->im & IM_CREATURE) && ((XCreature *)o)->l == l)
38 		{
39 			int n = vGetHighBitNum((((XCreature *)o)->creature_class));
40 			cr_count[n]++;
41 		}
42 		o = o->next;
43 	}
44 
45 	int cmask = 0;
46 	for (int i = 0; i < 32; i++)
47 	{
48 		cmask <<= 1;
49 		if (cr_count[31 - i] < max_creature)
50 			cmask |= 0x01;
51 	}
52 	CREATURE_CLASS n_mask = (CREATURE_CLASS)(cmask & crc);
53 	if (n_mask)
54 	{
55 		XCreature * cr = XCreatureStorage::CreateRnd(n_mask, crl);
56 		XPoint pt;
57 		l->GetFreeXY(&pt);
58 		Game.NewCreature(cr, pt.x, pt.y, l);
59 		cr->xai->SetAIFlag(AIF_ALLOW_MOVE_WAY_DOWN);
60 	}
61 
62 	ttm = ttmb;
63 	return 1;
64 };
65 
Store(XFile * f)66 void XUniversalGen::Store(XFile * f)
67 {
68 	XGenerator::Store(f);
69 	f->Write(&crl, sizeof(CREATURE_LEVEL));
70 	f->Write(&crc, sizeof(CREATURE_CLASS));
71 	f->Write(&max_creature, sizeof(unsigned int));
72 }
73 
Restore(XFile * f)74 void XUniversalGen::Restore(XFile * f)
75 {
76 	XGenerator::Restore(f);
77 	f->Read(&crl, sizeof(CREATURE_LEVEL));
78 	f->Read(&crc, sizeof(CREATURE_CLASS));
79 	f->Read(&max_creature, sizeof(unsigned int));
80 }
81 
82 
83 REGISTER_CLASS(XMainLocationGen);
84 
Run()85 int XMainLocationGen::Run()
86 {
87 	ttm = ttmb;
88 	turns_count++;
89 	if (turns_count == 10000)
90 	{
91 		XRect small_town_area(20, 42, 28, 48);
92 
93 		//hack!!!
94 		XObject * o = root;
95 		while (o)
96 		{
97 			if ((o->im & IM_CREATURE) && ((XCreature *)o)->creature_class & CR_ORC)
98 			{
99 				((XCreature *)(o))->xai->SetArea(&small_town_area, L_MAIN);
100 			}
101 			o = o->next;
102 		}
103 	}
104 	return 0;
105 }
106 
Store(XFile * f)107 void XMainLocationGen::Store(XFile * f)
108 {
109 	XGenerator::Store(f);
110 	f->Write(&turns_count, sizeof(int));
111 }
112 
Restore(XFile * f)113 void XMainLocationGen::Restore(XFile * f)
114 {
115 	XGenerator::Restore(f);
116 	f->Read(&turns_count, sizeof(int));
117 }
118