Pol  Revision:cb584c9
testenv.cpp
Go to the documentation of this file.
1 
6 #include "testenv.h"
7 
8 #include "../../bscript/bobject.h"
9 #include "../../clib/cfgelem.h"
10 #include "../../clib/cfgfile.h"
11 #include "../../clib/logfacility.h"
12 #include "../../clib/passert.h"
13 #include "../../clib/rawtypes.h"
14 #include "../globals/object_storage.h"
15 #include "../globals/uvars.h"
16 #include "../item/item.h"
17 #include "../item/itemdesc.h"
18 #include "../mobile/npc.h"
19 #include "../multi/multi.h"
20 #include "../npctmpl.h"
21 #include "../ufunc.h"
22 #include "../uworld.h"
23 
24 namespace Pol
25 {
26 namespace Testing
27 {
28 extern bool static_debug_on;
29 
32 
34 {
35  ++failures;
36 }
37 
39 {
40  ++successes;
41 }
42 
44 {
45  INFO_PRINT << "Successes: " << successes << "\n"
46  << "Failures: " << failures << "\n";
47 }
48 
49 using namespace Items;
50 using namespace Core;
51 
61 
62 Item* add_item( unsigned int objtype, unsigned short x, unsigned short y, short z )
63 {
64  Item* item;
65  item = Item::create( objtype );
66  passert( item );
67  item->x = x;
68  item->y = y;
69  item->z = static_cast<s8>( z );
71  add_item_to_world( item );
72  return item;
73 }
74 
75 void add_multi( unsigned int objtype, unsigned short x, unsigned short y, short z )
76 {
77  Multi::UMulti* multi = Multi::UMulti::create( find_itemdesc( objtype ) );
78  passert( multi );
79  multi->x = x;
80  multi->y = y;
81  multi->z = static_cast<s8>( z );
83  add_multi_to_world( multi );
84 }
85 
86 void add_multi( unsigned int objtype, unsigned short x, unsigned short y, short z, int flags )
87 {
90  static_cast<s8>( z ), realm, flags ) );
91 }
92 
93 Mobile::NPC* add_npc( const char* npctype, unsigned short x, unsigned short y, short z )
94 {
95  Clib::ConfigFile cfile;
96  Clib::ConfigElem elem;
97  if ( !Core::FindNpcTemplate( npctype, cfile, elem ) )
98  {
99  throw std::runtime_error( std::string( "NPC template '" ) + npctype + "' not found" );
100  }
101 
102  auto npc = new Mobile::NPC( elem.remove_ushort( "OBJTYPE" ), elem );
103  elem.clear_prop( "Serial" );
104  elem.clear_prop( "X" );
105  elem.clear_prop( "Y" );
106  elem.clear_prop( "Z" );
107 
108  elem.add_prop( "Serial", GetNextSerialNumber() );
109  elem.add_prop( "X", x );
110  elem.add_prop( "Y", y );
111  elem.add_prop( "Z", z );
112  npc->readPropertiesForNewNPC( elem );
113 
115 
117  return npc;
118 }
119 
121 {
122  // a backpack on a lower level, for testing walking around on the level above.
123  add_item( 0xe75, 1347, 1657, 50 );
124 
125  // a section of portcullis
126  add_item( 0x6f6, 1398, 1625, 29 );
127 
128  // black pearl on a table in Castle Britannia
129  add_item( 0xf7a, 1328, 1644, 78 );
130 
131  // a house way NE of britain
132  add_multi( 0x6064, 2016, 1327, 0 );
133 
134  // a "stone step" outside on the ground.
135  add_item( 0x915, 1309, 1630, 30 );
136 
137  // a dungeon ramp outside on the ground.
138  add_item( 0x11bd, 1311, 1636, 30 );
139 
140  // a stone arch we should be able to walk under
141  add_item( 0x002c, 1311, 1649, 30 );
142 
143  // a secret door we should be able to walk through
144  add_item( 0x00f5, 1316, 1648, 30 );
145 
146  // a weird door we should be able to walk through
147  add_item( 0x022f, 1313, 1654, 30 );
148 
149  // a dungeon arch
150  add_item( 0x0247, 1313, 1657, 30 );
151 
152  // a black pearl
153  add_item( 0x0f7a, 1315, 1658, 30 );
154 
155  // a boat in britain harbor
156  add_multi( 0x6040, 1487, 1768, -5, Multi::CRMULTI_FACING_NORTH );
157  // the call above creates the planks, hold, and tillerman. hm, how to extend the port
158  // gangplank, though...
159  // add_item( 0x3ED5, 1485, 1768, -5 ); // port gangplank, extended
160  // add_item( 0x3eb2, 1489, 1768, -5 ); // starboard gangplank, retracted
161  // add_item( 0xF013, 1487, 1764, -5 ); // hold
162  // add_item( 0x3e4e, 1488, 1772, -5 ); // tillerman
163 
164  // a boat out in deeper water (map water, that is)
165  add_multi( 0x6040, 1497, 1779, -5 );
166  add_item( 0x3ed5, 1495, 1779, -5 ); // its gangplank
167 
168  // a long boat in deep water
169  add_multi( 0x6044, 1495, 1817, -5, Multi::CRMULTI_FACING_WEST );
170  // FIXME: was 4013, so needs turned.
171 
172 
173  test_guard_door = add_item( 0x6e7, 1412, 1621, 30 ); // a door in a guard house at LB's castle
174 
175  test_banker = add_npc( "banker", 1412, 1624, 25 );
176  test_water_elemental = add_npc( "waterelemental", 1482, 1780, -2 );
177  test_seaserpent = add_npc( "seaserpent", 1479, 1763, -5 );
178 
179  // a house in green acres
180  add_multi( 0x6064, 5987, 1998, 0 );
181 
182  // a dungeon teleporter
183  add_item( 0x6200, 1175, 2635, 0 );
184 
185  // two chests at the same location, for LOS testing
186  test_chest1 = add_item( 0xe42, 1479, 1755, -2 );
187  test_chest2 = add_item( 0xe43, 1479, 1755, -2 );
188  test_banker2 = add_npc( "banker", 1479, 1754, -2 );
189 
190  // an orc underneath buc's den
191  test_orclord = add_npc( "orclord", 2648, 2193, -20 );
192  test_banker3 = add_npc( "banker", 2648, 2193, 4 );
193 
194  // couple of black pearls used for LOS checking
195  add_item( 0xf7a, 1618, 3351, 3 );
196  add_item( 0xf7a, 1618, 3340, 4 );
197 
198  // create 100 items outside of one loscheck
199  // and 100 items inbetween
200  for ( int i = 0; i < 100; ++i )
201  {
202  add_item( 0xe42, 1370, 1629, 30 );
203  add_item( 0xe42, 1373, 1625, 30 );
204  }
205 }
206 }
207 }
void add_multi(unsigned int objtype, unsigned short x, unsigned short y, short z)
Definition: testenv.cpp:75
static Item * create(u32 objtype, u32 serial=0)
Definition: itemcr.cpp:53
void clear_prop(const char *propname)
Definition: cfgfile.cpp:483
void add_item_to_world(Items::Item *item)
Definition: uworld.cpp:31
void display_test_results()
Definition: testenv.cpp:43
Item * test_chest1
Definition: testenv.cpp:58
bool FindNpcTemplate(const char *template_name, Clib::ConfigElem &elem)
void SetCharacterWorldPosition(Mobile::Character *chr, Realms::WorldChangeReason reason)
Definition: uworld.cpp:128
u32 GetNextSerialNumber(void)
Definition: ufunc.cpp:119
bool static_debug_on
Definition: uofile02.cpp:29
void inc_failures()
Definition: testenv.cpp:33
Mobile::NPC * test_banker2
Definition: testenv.cpp:53
void create_test_environment()
Definition: testenv.cpp:120
Mobile::NPC * test_seaserpent
Definition: testenv.cpp:57
int successes
Definition: testenv.cpp:31
const ItemDesc & find_itemdesc(unsigned int objtype)
Definition: itemdesc.cpp:933
const int CRMULTI_FACING_WEST
Definition: multi.h:51
void add_multi_to_world(Multi::UMulti *multi)
Definition: uworld.cpp:69
Mobile::NPC * add_npc(const char *npctype, unsigned short x, unsigned short y, short z)
Definition: testenv.cpp:93
void add_prop(std::string propname, std::string propval)
Definition: cfgfile.cpp:490
static Bscript::BObjectImp * scripted_create(const Items::ItemDesc &descriptor, u16 x, u16 y, s8 z, Realms::Realm *realm, int flags)
Definition: multicr.cpp:72
#define passert(exp)
Definition: passert.h:62
signed char s8
Definition: rawtypes.h:29
GameState gamestate
Definition: uvars.cpp:74
static UMulti * create(const Items::ItemDesc &descriptor, u32 serial=0)
Definition: multicr.cpp:38
bool Insert(UObject *obj)
Definition: objecthash.cpp:30
Realms::Realm * realm
Definition: baseobject.h:56
ObjectStorageManager objStorageManager
unsigned short remove_ushort(const char *propname)
Definition: cfgfile.cpp:318
Mobile::NPC * test_orclord
Definition: testenv.cpp:60
const int CRMULTI_FACING_NORTH
Definition: multi.h:48
Item * test_guard_door
Definition: testenv.cpp:55
Mobile::NPC * test_banker3
Definition: testenv.cpp:54
void inc_successes()
Definition: testenv.cpp:38
#define INFO_PRINT
Definition: logfacility.h:223
Realms::Realm * main_realm
Definition: uvars.h:162
Mobile::NPC * test_water_elemental
Definition: testenv.cpp:56
Definition: berror.cpp:12
Item * add_item(unsigned int objtype, unsigned short x, unsigned short y, short z)
Definition: testenv.cpp:62
Item * test_chest2
Definition: testenv.cpp:59
int failures
Definition: testenv.cpp:30
Mobile::NPC * test_banker
Definition: testenv.cpp:52