Change command prefix to "." and add "help" command.
[oweals/minetest.git] / src / content_cso.cpp
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "content_cso.h"
21 #include <IBillboardSceneNode.h>
22 #include "client/tile.h"
23 #include "clientenvironment.h"
24 #include "client.h"
25 #include "map.h"
26
27 class SmokePuffCSO: public ClientSimpleObject
28 {
29         float m_age;
30         scene::IBillboardSceneNode *m_spritenode;
31 public:
32         SmokePuffCSO(scene::ISceneManager *smgr,
33                         ClientEnvironment *env, v3f pos, v2f size):
34                 m_age(0),
35                 m_spritenode(NULL)
36         {
37                 infostream<<"SmokePuffCSO: constructing"<<std::endl;
38                 m_spritenode = smgr->addBillboardSceneNode(
39                                 NULL, v2f(1,1), pos, -1);
40                 m_spritenode->setMaterialTexture(0,
41                                 env->getGameDef()->tsrc()->getTextureForMesh("smoke_puff.png"));
42                 m_spritenode->setMaterialFlag(video::EMF_LIGHTING, false);
43                 m_spritenode->setMaterialFlag(video::EMF_BILINEAR_FILTER, false);
44                 //m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
45                 m_spritenode->setMaterialType(video::EMT_TRANSPARENT_ALPHA_CHANNEL);
46                 m_spritenode->setMaterialFlag(video::EMF_FOG_ENABLE, true);
47                 m_spritenode->setColor(video::SColor(255,0,0,0));
48                 m_spritenode->setVisible(true);
49                 m_spritenode->setSize(size);
50                 /* Update brightness */
51                 u8 light;
52                 bool pos_ok;
53                 MapNode n = env->getMap().getNodeNoEx(floatToInt(pos, BS), &pos_ok);
54                 light = pos_ok ? decode_light(n.getLightBlend(env->getDayNightRatio(),
55                                                         env->getGameDef()->ndef()))
56                                : 64;
57                 video::SColor color(255,light,light,light);
58                 m_spritenode->setColor(color);
59         }
60         virtual ~SmokePuffCSO()
61         {
62                 infostream<<"SmokePuffCSO: destructing"<<std::endl;
63                 m_spritenode->remove();
64         }
65         void step(float dtime)
66         {
67                 m_age += dtime;
68                 if(m_age > 1.0){
69                         m_to_be_removed = true;
70                 }
71         }
72 };
73
74 ClientSimpleObject* createSmokePuff(scene::ISceneManager *smgr,
75                 ClientEnvironment *env, v3f pos, v2f size)
76 {
77         return new SmokePuffCSO(smgr, env, pos, size);
78 }
79