# Compile error at iuse.cpp, function iuse::portal

**URL:** https://discourse.cataclysmdda.org/t/compile-error-at-iuse-cpp-function-iuse-portal/9603
**Category:** The Garage
**Created:** [May 15, 2015, 11:44am UTC](https://discourse.cataclysmdda.org/t/compile-error-at-iuse-cpp-function-iuse-portal/9603 "2015-05-15T11:44:34Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jcd](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.cataclysmdda.org/jcd/32/338_2.png) [@jcd](https://discourse.cataclysmdda.org/u/jcd)
#### Post date: [May 15, 2015, 11:44am UTC](https://discourse.cataclysmdda.org/t/compile-error-at-iuse-cpp-function-iuse-portal/9603/1 "2015-05-15T11:44:34Z")

</div>

last experimental

error message:

src/iuse.cpp: In member function ‘int iuse::portal(player\*, item\*, bool, const tripoint&)’:  
src/iuse.cpp:5565:30: error: narrowing conversion of ‘(((long int)p-\>player::posx()) + rng(-2l, 2l))’ from ‘long int’ t  
o ‘int’ inside { } [-Werror=narrowing]  
g-\>m.add\_trap({p-\>posx() + rng(-2, 2), p-\>posy() + rng(-2, 2), p-\>posz()}, tr\_portal);  
^  
src/iuse.cpp:5565:54: error: narrowing conversion of ‘(((long int)p-\>player::posy()) + rng(-2l, 2l))’ from ‘long int’ t  
o ‘int’ inside { } [-Werror=narrowing]  
g-\>m.add\_trap({p-\>posx() + rng(-2, 2), p-\>posy() + rng(-2, 2), p-\>posz()}, tr\_portal);  
^  
cc1plus: all warnings being treated as errors  
Makefile:437: recipe for target ‘obj/iuse.o’ failed  
make: \*\*\* [obj/iuse.o] Error 1

quick & dirty fix (although i did not check if they _should_ be cast into long long int instead of just int - or what is int, what is long and why):

int iuse::portal(player \*p, item \*it, bool, const tripoint& )  
{  
if (it-\>charges \< it-\>type-\>charges\_to\_use()) {  
return 0;  
}  
g-\>m.add\_trap({static\_cast(p-\>posx()) + static\_cast(rng(-2, 2)), static\_cast(p-\>posy()) + static\_cast(rng(-2, 2)), p-\>posz()}, tr\_portal);  
return it-\>type-\>charges\_to\_use();  
}
