Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
4
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
openmw
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
525
Issues
525
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
35
Merge Requests
35
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenMW
openmw
Commits
e13e858c
Commit
e13e858c
authored
Feb 23, 2012
by
Marc Zinnschlag
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed container store iterator; new add function
parent
b7ea1106
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
4 deletions
+89
-4
apps/openmw/mwworld/containerstore.cpp
apps/openmw/mwworld/containerstore.cpp
+72
-3
apps/openmw/mwworld/containerstore.hpp
apps/openmw/mwworld/containerstore.hpp
+17
-1
No files found.
apps/openmw/mwworld/containerstore.cpp
View file @
e13e858c
...
...
@@ -2,6 +2,8 @@
#include "containerstore.hpp"
#include <cassert>
#include <typeinfo>
#include <stdexcept>
MWWorld
::
ContainerStoreIterator
MWWorld
::
ContainerStore
::
begin
(
int
mask
)
{
...
...
@@ -10,12 +12,78 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::begin (int mask)
MWWorld
::
ContainerStoreIterator
MWWorld
::
ContainerStore
::
end
()
{
return
ContainerStoreIterator
(
);
return
ContainerStoreIterator
(
this
);
}
void
MWWorld
::
ContainerStore
::
add
(
const
Ptr
&
ptr
)
{
/// \todo implement item stocking
switch
(
getType
(
ptr
))
{
case
Type_Potion
:
potions
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Potion
>
());
break
;
case
Type_Apparatus
:
appas
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Apparatus
>
());
break
;
case
Type_Armor
:
armors
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Armor
>
());
break
;
case
Type_Book
:
books
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Book
>
());
break
;
case
Type_Clothing
:
clothes
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Clothing
>
());
break
;
case
Type_Ingredient
:
ingreds
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Ingredient
>
());
break
;
case
Type_Light
:
lights
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Light
>
());
break
;
case
Type_Lockpick
:
lockpicks
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Tool
>
());
break
;
case
Type_Miscellaneous
:
miscItems
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Miscellaneous
>
());
break
;
case
Type_Probe
:
probes
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Probe
>
());
break
;
case
Type_Repair
:
repairs
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Repair
>
());
break
;
case
Type_Weapon
:
weapons
.
list
.
push_back
(
*
ptr
.
get
<
ESM
::
Weapon
>
());
break
;
}
}
int
MWWorld
::
ContainerStore
::
getType
(
const
Ptr
&
ptr
)
{
if
(
ptr
.
isEmpty
())
throw
std
::
runtime_error
(
"can't put a non-existent object into a container"
);
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Potion
).
name
())
return
Type_Potion
;
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Apparatus
).
name
())
return
Type_Apparatus
;
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Armor
).
name
())
return
Type_Armor
;
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Book
).
name
())
return
Type_Book
;
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Clothing
).
name
())
return
Type_Clothing
;
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Ingredient
).
name
())
return
Type_Ingredient
;
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Light
).
name
())
return
Type_Light
;
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Tool
).
name
())
return
Type_Lockpick
;
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Miscellaneous
).
name
())
return
Type_Miscellaneous
;
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Probe
).
name
())
return
Type_Probe
;
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Repair
).
name
())
return
Type_Repair
;
if
(
ptr
.
getTypeName
()
==
typeid
(
ESM
::
Weapon
).
name
())
return
Type_Weapon
;
throw
std
::
runtime_error
(
"Object of type "
+
ptr
.
getTypeName
()
+
" can not be placed into a container"
);
}
MWWorld
::
ContainerStoreIterator
::
ContainerStoreIterator
()
:
mType
(
-
1
),
mMask
(
0
),
mContainer
(
0
)
MWWorld
::
ContainerStoreIterator
::
ContainerStoreIterator
(
ContainerStore
*
container
)
:
mType
(
-
1
),
mMask
(
0
),
mContainer
(
container
)
{}
MWWorld
::
ContainerStoreIterator
::
ContainerStoreIterator
(
int
mask
,
ContainerStore
*
container
)
...
...
@@ -209,7 +277,7 @@ MWWorld::Ptr MWWorld::ContainerStoreIterator::operator*() const
case
ContainerStore
::
Type_Weapon
:
return
MWWorld
::
Ptr
(
&*
mWeapon
,
0
);
}
return
MWWorld
::
Ptr
(
);
throw
std
::
runtime_error
(
"invalid pointer"
);
}
MWWorld
::
ContainerStoreIterator
&
MWWorld
::
ContainerStoreIterator
::
operator
++
()
...
...
@@ -252,6 +320,7 @@ bool MWWorld::ContainerStoreIterator::isEqual (const ContainerStoreIterator& ite
case
ContainerStore
::
Type_Probe
:
return
mProbe
==
iter
.
mProbe
;
case
ContainerStore
::
Type_Repair
:
return
mRepair
==
iter
.
mRepair
;
case
ContainerStore
::
Type_Weapon
:
return
mWeapon
==
iter
.
mWeapon
;
case
-
1
:
return
true
;
}
return
false
;
...
...
apps/openmw/mwworld/containerstore.hpp
View file @
e13e858c
...
...
@@ -31,6 +31,8 @@ namespace MWWorld
static
const
int
Type_All
=
0xffff
;
// private:
ESMS
::
CellRefList
<
ESM
::
Potion
,
RefData
>
potions
;
ESMS
::
CellRefList
<
ESM
::
Apparatus
,
RefData
>
appas
;
ESMS
::
CellRefList
<
ESM
::
Armor
,
RefData
>
armors
;
...
...
@@ -44,10 +46,24 @@ namespace MWWorld
ESMS
::
CellRefList
<
ESM
::
Repair
,
RefData
>
repairs
;
ESMS
::
CellRefList
<
ESM
::
Weapon
,
RefData
>
weapons
;
public:
ContainerStoreIterator
begin
(
int
mask
=
Type_All
);
ContainerStoreIterator
end
();
void
add
(
const
Ptr
&
ptr
);
///< Add the item pointed to by \a ptr to this container.
///
/// \note The item pointed to is not required to exist beyond this function call.
///
/// \attention Do not add items to an existing stack by increasing the count instead of
/// calling this function!
static
int
getType
(
const
Ptr
&
ptr
);
///< This function throws an exception, if ptr does not point to an object, that can be
/// put into a container.
friend
class
ContainerStoreIterator
;
};
...
...
@@ -76,7 +92,7 @@ namespace MWWorld
private:
ContainerStoreIterator
(
);
ContainerStoreIterator
(
ContainerStore
*
container
);
///< End-iterator
ContainerStoreIterator
(
int
mask
,
ContainerStore
*
container
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment