1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 /* interface header */
14 #include "CustomGate.h"
15 
16 /* system implementation headers */
17 #include <math.h>
18 
19 /* common interface headers */
20 #include "Teleporter.h"
21 #include "StateDatabase.h"
22 #include "ObstacleMgr.h"
23 
24 
CustomGate(const char * _telename)25 CustomGate::CustomGate(const char* _telename)
26 {
27     telename = _telename;
28     size[0] = 0.5f * BZDB.eval(StateDatabase::BZDB_TELEWIDTH);
29     size[1] = BZDB.eval(StateDatabase::BZDB_TELEBREADTH);
30     size[2] = 2.0f * BZDB.eval(StateDatabase::BZDB_TELEHEIGHT);
31     border = size[0] * 2.0f;
32     horizontal = false;
33 }
34 
35 
read(const char * cmd,std::istream & input)36 bool CustomGate::read(const char *cmd, std::istream& input)
37 {
38     if (strcmp(cmd, "border") == 0)
39         input >> border;
40     else if (strcmp(cmd, "horizontal") == 0)
41         horizontal = true;
42     else
43         return WorldFileObstacle::read(cmd, input);
44     return true;
45 }
46 
47 
writeToGroupDef(GroupDefinition * groupdef) const48 void CustomGate::writeToGroupDef(GroupDefinition *groupdef) const
49 {
50     Teleporter* tele =
51         new Teleporter(pos, rotation,
52                        fabsf(size[0]), fabsf(size[1]), fabsf(size[2]),
53                        border, horizontal, driveThrough, shootThrough, ricochet);
54 
55     if (!telename.size() && name.size())
56         tele->setName(name);
57     else
58         tele->setName(telename);
59 
60     groupdef->addObstacle(tele);
61 }
62 
63 
64 // Local variables: ***
65 // mode: C++ ***
66 // tab-width: 4***
67 // c-basic-offset: 4 ***
68 // indent-tabs-mode: nil ***
69 // End: ***
70 // ex: shiftwidth=4 tabstop=4
71