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

polserver / polserver / 21100551564

17 Jan 2026 08:40PM UTC coverage: 60.504% (+0.01%) from 60.492%
21100551564

Pull #857

github

turleypol
fixed scope
Pull Request #857: ClangTidy readability-else-after-return

837 of 1874 new or added lines in 151 files covered. (44.66%)

48 existing lines in 26 files now uncovered.

44445 of 73458 relevant lines covered (60.5%)

515341.61 hits per line

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

15.84
/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

54
  for ( DeferList::iterator itr = objStorageManager.deferred_insertions.begin();
×
55
        itr != objStorageManager.deferred_insertions.end(); ++itr )
×
56
  {
57
    if ( --num_until_dot == 0 )
×
58
    {
59
      INFO_PRINT( "." );
×
60
      num_until_dot = 1000;
×
61
    }
62

63
    pol_serial_t container_serial = ( *itr ).first;
×
64
    UObject* obj = ( *itr ).second;
×
65

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

214
    stateManager.gflag_enforce_container_limits = true;
5✔
215

216
    // if (new_parent_cont)
217
    //  parent_conts.push( cont );
218
    // if (item->isa( UObject::CLASS_CONTAINER ))
219
    //  parent_conts.push( static_cast<UContainer*>(item) );
220
  }
221
  else
222
  {
223
    INFO_PRINTLN( "Container type {:#x} contains items, but is not a container class",
×
224
                  cont_item->objtype_ );
×
225
    throw std::runtime_error( "Config file error" );
×
226
  }
227
}
228
}  // 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