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 #include "common.h"
14 
15 // system headers
16 #include <string.h>
17 
18 /* interface header */
19 #include "CustomWaterLevel.h"
20 
21 /* bzfs implementation headers */
22 #include "WorldInfo.h"
23 #include "ParseMaterial.h"
24 
25 /* common implementation headers */
26 #include "BzMaterial.h"
27 #include "TextureMatrix.h"
28 
29 
CustomWaterLevel()30 CustomWaterLevel::CustomWaterLevel(): height(0.0)
31 {
32     modedMaterial = false;
33     return;
34 }
35 
36 
~CustomWaterLevel()37 CustomWaterLevel::~CustomWaterLevel()
38 {
39     return;
40 }
41 
42 
read(const char * cmd,std::istream & input)43 bool CustomWaterLevel::read(const char *cmd, std::istream& input)
44 {
45     bool materror;
46 
47     if (strcasecmp ("height", cmd) == 0)
48     {
49         if (!(input >> height))
50             return false;
51     }
52     else if (parseMaterials(cmd, input, &material, 1, materror))
53     {
54         if (materror)
55             return false;
56         modedMaterial = true;
57     }
58     else
59     {
60         // NOTE: we don't use a WorldFileObstacle
61         return WorldFileObject::read(cmd, input);
62     }
63 
64     return true;
65 }
66 
67 
writeToWorld(WorldInfo * world) const68 void CustomWaterLevel::writeToWorld(WorldInfo* world) const
69 {
70     if (modedMaterial)
71     {
72         const BzMaterial* matref = MATERIALMGR.addMaterial(&material);
73         world->addWaterLevel(height, matref);
74     }
75     else
76     {
77         world->addWaterLevel(height, NULL); // build the material later
78     }
79 
80     return;
81 }
82 
83 
84 // Local variables: ***
85 // mode: C++ ***
86 // tab-width: 4***
87 // c-basic-offset: 4 ***
88 // indent-tabs-mode: nil ***
89 // End: ***
90 // ex: shiftwidth=4 tabstop=4
91