The Battle for Wesnoth  1.15.1+dev
id.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 - 2018 by David White <dave@whitevine.net>
3  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #include "log.hpp"
16 #include "units/id.hpp"
17 
18 #include <cassert>
19 
20 static lg::log_domain log_unit("unit");
21 #define DBG_UT LOG_STREAM(debug, log_unit)
22 
23 namespace n_unit
24 {
26 
28  {
30  DBG_UT << "id: " << next_id_ << "\n";
31  return unit_id::create_real(++next_id_);
32  }
33 
35  {
37  DBG_UT << "fake id: " << fake_id_ << "\n";
38  return unit_id::create_fake(++fake_id_);
39  }
40 
41  std::size_t id_manager::get_save_id() const
42  {
43  return next_id_;
44  }
45 
46  void id_manager::set_save_id(std::size_t id)
47  {
48  clear();
49  DBG_UT << "set save id: " << id << "\n";
50  next_id_ = id;
51  }
52 
54  {
55  fake_id_ = 0;
56  }
57 
59  {
60  next_id_ = 0;
61  reset_fake();
62  }
63 }
unit_id next_fake_id()
Definition: id.cpp:34
static unit_id create_fake(std::size_t val)
Definition: id.hpp:32
#define DBG_UT
Definition: id.cpp:21
std::size_t get_save_id() const
Used for saving id to savegame.
Definition: id.cpp:41
unit_id next_id()
returns id for unit that is created
Definition: id.cpp:27
Definition: id.cpp:23
void clear()
Clears id counter after game.
Definition: id.cpp:58
static unit_id create_real(std::size_t val)
Definition: id.hpp:31
void set_save_id(std::size_t)
Definition: id.cpp:46
static id_manager manager_
Definition: id.hpp:46
static lg::log_domain log_unit("unit")
std::size_t next_id_
Definition: id.hpp:44
Standard logging facilities (interface).
void reset_fake()
Definition: id.cpp:53
std::size_t fake_id_
Definition: id.hpp:45
static const std::size_t highest_bit
Definition: id.hpp:25