• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

polserver / polserver / 21541532363

31 Jan 2026 08:14AM UTC coverage: 60.532% (+0.03%) from 60.507%
21541532363

push

github

web-flow
Tidy modernize for loops (#862)

* trigger loop convert

* Automated clang-tidy change: modernize-loop-convert

* fixed refactor

* Automated clang-tidy change: modernize-loop-convert

* compile

* first look through

* fixes and start to use a few ranges

* revert autogenerated file

* compilation fix

* second pass

* renamed loop variable

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>

164 of 447 new or added lines in 61 files covered. (36.69%)

6 existing lines in 5 files now uncovered.

44377 of 73312 relevant lines covered (60.53%)

499857.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.0
/pol-core/pol/loaddata.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2007/06/17 Shinigami: added config.world_data_path
5
 * - 2008/12/17 MuadDib:   Added item.tile_layer - returns layer entry from tiledata/tiles.cfg
6
 * - 2009/09/14 MuadDib:   Added slot support to equip_loaded_item() and add_loaded_item()
7
 * - 2009/09/18 MuadDib:   Spellbook rewrite to deal with only bits, not scrolls inside them.
8
 */
9

10

11
#include <stddef.h>
12
#include <string>
13

14
#include "../clib/cfgelem.h"
15
#include "../clib/cfgfile.h"
16
#include "../clib/fileutil.h"
17
#include "../clib/logfacility.h"
18
#include "../clib/rawtypes.h"
19
#include "../clib/strutil.h"
20
#include "../clib/timer.h"
21
#include "../plib/clidata.h"
22
#include "../plib/systemstate.h"
23
#include "containr.h"
24
#include "fnsearch.h"
25
#include "globals/object_storage.h"
26
#include "globals/state.h"
27
#include "item/item.h"
28
#include "loaddata.h"
29
#include "mobile/charactr.h"
30
#include "objecthash.h"
31
#include "polclass.h"
32
#include "spelbook.h"
33
#include "uobject.h"
34

35

36
namespace Pol::Core
37
{
38
void defer_item_insertion( Items::Item* item, pol_serial_t container_serial )
×
39
{
40
  objStorageManager.deferred_insertions.insert( std::make_pair( container_serial, item ) );
×
41
}
×
42

43
void insert_deferred_items()
2✔
44
{
45
  if ( objStorageManager.deferred_insertions.empty() )
2✔
46
    return;
2✔
47

48
  int num_until_dot = 1000;
×
49
  unsigned int nobjects = 0;
×
50
  Tools::Timer<> timer;
×
51

52
  INFO_PRINT( "  deferred inserts:" );
×
53

NEW
54
  for ( auto& deferred_insertion : objStorageManager.deferred_insertions )
×
55
  {
56
    if ( --num_until_dot == 0 )
×
57
    {
58
      INFO_PRINT( "." );
×
59
      num_until_dot = 1000;
×
60
    }
61

NEW
62
    pol_serial_t container_serial = deferred_insertion.first;
×
NEW
63
    UObject* obj = deferred_insertion.second;
×
64

65
    if ( IsCharacter( container_serial ) )
×
66
    {
67
      Mobile::Character* chr = system_find_mobile( container_serial );
×
68
      Items::Item* item = static_cast<Items::Item*>( obj );
×
69
      if ( chr != nullptr )
×
70
      {
71
        equip_loaded_item( chr, item );
×
72
      }
73
      else
74
      {
75
        ERROR_PRINTLN(
×
76
            "Item {:#x} is supposed to be on Character {:#x}, but that character cannot be ",
77
            item->serial, container_serial );
×
78

79
        // Austin - Aug. 10, 2006
80
        // Removes the object if ignore_load_errors is enabled and the character can't be found.
81
        if ( !Plib::systemstate.config.ignore_load_errors )
×
82
          throw std::runtime_error( "Data file integrity error" );
×
83

84
        ERROR_PRINTLN( "Ignore load errors enabled. Removing object." );
×
85
        obj->destroy();
×
86
      }
87
    }
88
    else
89
    {
90
      Items::Item* cont_item = system_find_item( container_serial );
×
91
      Items::Item* item = static_cast<Items::Item*>( obj );
×
92
      if ( cont_item != nullptr )
×
93
      {
94
        add_loaded_item( cont_item, item );
×
95
      }
96
      else
97
      {
98
        ERROR_PRINTLN(
×
99
            "Item {:#x} is supposed to be in container {:#x}, but that container cannot be found.",
100
            item->serial, container_serial );
×
101

102
        // Austin - Aug. 10, 2006
103
        // Removes the object if ignore_load_errors is enabled and the character can't be found.
104
        if ( !Plib::systemstate.config.ignore_load_errors )
×
105
          throw std::runtime_error( "Data file integrity error" );
×
106

107
        ERROR_PRINTLN( "Ignore load errors enabled. Removing object." );
×
108
        obj->destroy();
×
109
      }
110
    }
111
    ++nobjects;
×
112
  }
113
  timer.stop();
×
114
  INFO_PRINTLN( " {} elements in {} ms.", nobjects, timer.ellapsed() );
×
115

116
  objStorageManager.deferred_insertions.clear();
×
117
}
×
118

119
void equip_loaded_item( Mobile::Character* chr, Items::Item* item )
×
120
{
121
  item->layer = Plib::tilelayer( item->graphic );  // adjust for tiledata changes
×
122
  item->tile_layer = item->layer;                  // adjust for tiledata changes
×
123

124
  if ( chr->equippable( item ) && item->check_equiptest_scripts( chr, true ) &&
×
125
       item->check_equip_script( chr, true ) &&
×
126
       !item->orphan() )  // dave added 1/28/3, item might be destroyed in RTC script
×
127
  {
128
    chr->equip( item );
×
129
    item->clear_dirty();  // equipping sets dirty
×
130
    return;
×
131
  }
132

133
  ERROR_PRINTLN(
×
134
      "Item {:#x} is supposed to be equipped on Character {:#x}, but is not 'equippable' on that "
135
      "character.",
136
      item->serial, chr->serial );
×
137
  UContainer* bp = chr->backpack();
×
138
  if ( bp )
×
139
  {
140
    stateManager.gflag_enforce_container_limits = false;
×
141
    bool canadd = bp->can_add( *item );
×
142
    u8 slotIndex = item->slot_index();
×
143
    bool add_to_slot = bp->can_add_to_slot( slotIndex );
×
144
    if ( canadd && add_to_slot && item->slot_index( slotIndex ) )
×
145
    {
146
      bp->add_at_random_location( item );
×
147
      // leaving dirty
148
      stateManager.gflag_enforce_container_limits = true;
×
149
      ERROR_PRINTLN( "I'm so cool, I put it in the character's backpack!" );
×
150
      return;
×
151
    }
152

153
    stateManager.gflag_enforce_container_limits = true;
×
154
    ERROR_PRINTLN( "Tried to put it in the character's backpack, but it wouldn't fit." );
×
155
  }
156
  else
157
  {
158
    ERROR_PRINTLN(
×
159
        "Tried to put it in the character's backpack, but there isn't one.  That's naughty..." );
160
  }
161
  throw std::runtime_error( "Data file integrity error" );
×
162
}
163

164
void add_loaded_item( Items::Item* cont_item, Items::Item* item )
5✔
165
{
166
  if ( cont_item->isa( UOBJ_CLASS::CLASS_CONTAINER ) )
5✔
167
  {
168
    UContainer* cont = static_cast<UContainer*>( cont_item );
5✔
169

170
    // Convert spellbook to use bitwise system, not scrolls.
171
    if ( cont->script_isa( POLCLASS_SPELLBOOK ) )
5✔
172
    {
173
      // if can't add, means spell already there.
174
      if ( !cont->can_add( *item ) )
×
175
      {
176
        item->destroy();
×
177
        return;
×
178
      }
179
      // this is an oldschool book, oldschool contents. We need to create the bitwise
180
      // and handle for the first time before destroying the scrolls.
181
      Spellbook* book = static_cast<Spellbook*>( cont );
×
182

183
      u16 spellnum =
184
          USpellScroll::convert_objtype_to_spellnum( item->objtype_, book->spell_school );
×
185
      u8 spellslot = spellnum & 7;
×
186
      if ( spellslot == 0 )
×
187
        spellslot = 8;
×
188
      book->bitwise_contents[( spellnum - 1 ) >> 3] |= 1 << ( spellslot - 1 );
×
189
      item->destroy();
×
190
      return;
×
191
    }
192

193
    stateManager.gflag_enforce_container_limits = false;
5✔
194
    bool canadd = cont->can_add( *item );
5✔
195
    u8 slotIndex = item->slot_index();
5✔
196
    bool add_to_slot = cont->can_add_to_slot( slotIndex );
5✔
197
    if ( !canadd )
5✔
198
    {
199
      ERROR_PRINTLN( "Can't add Item {:#x} to container {:#x}", item->serial, cont->serial );
×
200
      throw std::runtime_error( "Data file error" );
×
201
    }
202

203
    if ( !add_to_slot || !item->slot_index( slotIndex ) )
5✔
204
    {
205
      ERROR_PRINTLN( "Can't add Item {:#x} to container {:#x} at slot {:#x}", item->serial,
×
206
                     cont->serial, slotIndex );
×
207
      throw std::runtime_error( "Data file error" );
×
208
    }
209

210
    cont->add( item, item->pos2d() );
5✔
211
    item->clear_dirty();  // adding sets dirty
5✔
212

213
    stateManager.gflag_enforce_container_limits = true;
5✔
214

215
    // if (new_parent_cont)
216
    //  parent_conts.push( cont );
217
    // if (item->isa( UObject::CLASS_CONTAINER ))
218
    //  parent_conts.push( static_cast<UContainer*>(item) );
219
  }
220
  else
221
  {
222
    INFO_PRINTLN( "Container type {:#x} contains items, but is not a container class",
×
223
                  cont_item->objtype_ );
×
224
    throw std::runtime_error( "Config file error" );
×
225
  }
226
}
227
}  // namespace Pol::Core
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc