~ubuntu-branches/ubuntu/precise/widelands/precise-backports

« back to all changes in this revision

Viewing changes to src/editor/tools/editor_set_resources_tool.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Quinson
  • Date: 2005-02-14 10:41:12 UTC
  • Revision ID: james.westby@ubuntu.com-20050214104112-6v08iux9fptxpva9
Tags: upstream-build9
Import upstream version build9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2002-4 by the Widelands Development Team
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License
 
6
 * as published by the Free Software Foundation; either version 2
 
7
 * of the License, or (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 *
 
18
 */
 
19
 
 
20
#include "editor_increase_resources_tool.h"
 
21
#include "editor_decrease_resources_tool.h"
 
22
#include "editor_set_resources_tool.h"
 
23
#include "map.h"
 
24
#include "field.h"
 
25
#include "editorinteractive.h"
 
26
#include "world.h"
 
27
#include "overlay_manager.h"
 
28
 
 
29
/*
 
30
=============================
 
31
 
 
32
class Editor_Set_Resources_Tool
 
33
 
 
34
=============================
 
35
*/
 
36
 
 
37
/*
 
38
===========
 
39
Editor_Set_Resources_Tool::handle_click_impl()
 
40
 
 
41
sets the resources of the current to a fixed value
 
42
===========
 
43
*/
 
44
int Editor_Set_Resources_Tool::handle_click_impl(FCoords& fc, Map* map, Editor_Interactive* parent)
 
45
{
 
46
   MapRegion mrc(map, fc, parent->get_fieldsel_radius());
 
47
   FCoords c;
 
48
 
 
49
   while(mrc.next(&c)) {
 
50
      Field* f=map->get_field(c);
 
51
 
 
52
      int res=f->get_resources();
 
53
      int amount=f->get_resources_amount();
 
54
      int max_amount=map->get_world()->get_resource(m_cur_res)->get_max_amount();
 
55
 
 
56
      amount=m_set_to;
 
57
      if(amount<0) amount=0;
 
58
      if(amount>max_amount) amount=max_amount;
 
59
 
 
60
      if(Editor_Change_Resource_Tool_Callback(c,map,m_cur_res)) {
 
61
         // Ok, we're doing something. First remove the current overlays
 
62
         std::string str;
 
63
         str=map->get_world()->get_resource(res)->get_editor_pic(f->get_resources_amount());
 
64
         int picid=g_gr->get_picture(PicMod_Menu, str.c_str(), true);
 
65
         map->get_overlay_manager()->remove_overlay(c,picid);
 
66
 
 
67
         if(!amount) {
 
68
            f->set_resources(0,0);
 
69
            f->set_starting_res_amount(0);
 
70
         } else {
 
71
            f->set_resources(m_cur_res,amount);
 
72
            f->set_starting_res_amount(amount);
 
73
            // set new overlay
 
74
            str=map->get_world()->get_resource(m_cur_res)->get_editor_pic(amount);
 
75
            int picid=g_gr->get_picture(PicMod_Menu, str.c_str(), true);
 
76
            map->get_overlay_manager()->register_overlay(c,picid,4);
 
77
            map->recalc_for_field_area(c,0);
 
78
         }
 
79
      }
 
80
   }
 
81
   return parent->get_fieldsel_radius();
 
82
}