Merge pull request #135 from jl777/jl777

sync jl777
This commit is contained in:
ca333
2019-02-18 14:29:21 +01:00
committed by GitHub
3 changed files with 72 additions and 58 deletions

View File

@@ -157,37 +157,55 @@ out:
}
}
int32_t num_packitems(struct rogue_state *rs)
{
THING *list = pack;
int32_t type = 0,n = 0,total = 0;
for (; list != NULL; list = next(list))
{
if ( list->o_packch != 0 )
{
n++;
total += list->o_count;
}
}
char str[MAXSTR];
sprintf(str,"strength*3 %d vs total.%d vs %d inventory letters\n",pstats.s_str*3,total,n);
add_line(rs,"%s",str);
if ( total > pstats.s_str*3 )
return(MAXPACK);
return(n);
}
/*
* pack_room:
* See if there's room in the pack. If not, print out an
* appropriate message
*/
bool
pack_room(struct rogue_state *rs,bool from_floor, THING *obj)
bool pack_room(struct rogue_state *rs,bool from_floor, THING *obj)
{
inpack = num_packitems();
if (++inpack > MAXPACK)
inpack = num_packitems(rs);
if ( ++inpack > MAXPACK )
{
if (!terse)
addmsg(rs,"there's ");
addmsg(rs,"no room");
if (!terse)
addmsg(rs," in your pack");
endmsg(rs);
if (from_floor)
move_msg(rs,obj);
inpack = MAXPACK;
return FALSE;
if (!terse)
addmsg(rs,"there's ");
addmsg(rs,"no room");
if (!terse)
addmsg(rs," in your pack");
endmsg(rs);
if (from_floor)
move_msg(rs,obj);
inpack = MAXPACK;
return FALSE;
}
//fprintf(stderr,"inpack.%d vs MAX.%d\n",inpack,MAXPACK), sleep(2);
if (from_floor)
if ( from_floor != 0 )
{
detach(lvl_obj, obj);
mvaddch(hero.y, hero.x, floor_ch());
chat(hero.y, hero.x) = (proom->r_flags & ISGONE) ? PASSAGE : FLOOR;
detach(lvl_obj, obj);
mvaddch(hero.y, hero.x, floor_ch());
chat(hero.y, hero.x) = (proom->r_flags & ISGONE) ? PASSAGE : FLOOR;
}
return TRUE;
}
@@ -247,26 +265,11 @@ pack_char()
* the given type.
*/
int32_t num_packitems()
{
THING *list = pack;
int32_t type = 0,n = 0,total = 0;
for (; list != NULL; list = next(list))
{
if ( list->o_packch != 0 )
{
n++;
total += list->o_count;
}
}
fprintf(stderr,"total.%d vs %d inventory letters\n",total,n); sleep(1);
return(n);
}
bool
inventory(struct rogue_state *rs,THING *list, int type)
{
static char inv_temp[MAXSTR];
char inv_temp[MAXSTR];
n_objs = 0;
for (; list != NULL; list = next(list))

View File

@@ -802,7 +802,7 @@ THING *leave_pack(struct rogue_state *rs,THING *obj, bool newobj, bool all);
THING *new_item(void);
THING *new_thing(struct rogue_state *rs);
void end_line(struct rogue_state *rs);
int32_t num_packitems();
int32_t num_packitems(struct rogue_state *rs);
void runners(struct rogue_state *rs,int);
void land(struct rogue_state *rs,int);

View File

@@ -1234,35 +1234,56 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C
if ( (funcid= rogue_registeropretdecode(gametxid,tokenid,playertxid,scriptPubKey)) == 0 )
{
funcid = 'Q';
fprintf(stderr,"ht.%d couldnt decode tokens opret\n",height);
fprintf(stderr,"ht.%d couldnt decode tokens opret (%c)\n",height,script[1]);
if ( height < 20000 )
e = EVAL_ROGUE;
} else e = EVAL_ROGUE, decoded = 1;
} else e = EVAL_ROGUE, decoded = 1;
}
if ( e == EVAL_ROGUE )
{
fprintf(stderr,"ht.%d rogue.(%c)\n",height,script[1]);
if ( decoded == 0 )
{
switch ( funcid )
{
case 'G':
if ( (funcid= rogue_newgameopreturndecode(buyin,maxplayers,scriptPubKey)) != 'G' )
return eval->Invalid("couldnt decode newgame opret");
{
fprintf(stderr,"height.%d couldnt decode newgame opret\n",height);
if ( height > 20000 )
return eval->Invalid("couldnt decode newgame opret");
}
// validate newgame tx
return(true);
break;
case 'R':
if ( (funcid= rogue_registeropretdecode(gametxid,tokenid,playertxid,scriptPubKey)) != 'R' )
return eval->Invalid("couldnt decode register opret");
{
fprintf(stderr,"height.%d couldnt decode register opret\n",height);
if ( height > 20000 )
return eval->Invalid("couldnt decode register opret");
}
// validation is done below
break;
case 'K':
if ( (funcid= rogue_keystrokesopretdecode(gametxid,batontxid,pk,keystrokes,scriptPubKey)) != 'K' )
return eval->Invalid("couldnt decode keystrokes opret");
{
fprintf(stderr,"height.%d couldnt decode keystrokes opret\n",height);
if ( height > 20000 )
return eval->Invalid("couldnt decode keystrokes opret");
}
// validate keystrokes are from the correct pk. might need to add vin
return(true);
break;
case 'H': case 'Q':
if ( (f= rogue_highlanderopretdecode(gametxid,tokenid,regslot,pk,playerdata,symbol,pname,scriptPubKey)) != funcid )
return eval->Invalid("couldnt decode H/Q opret");
{
fprintf(stderr,"height.%d couldnt decode H/Q opret\n",height);
if ( height > 20000 )
return eval->Invalid("couldnt decode H/Q opret");
}
// validation is done below
break;
default:
return eval->Invalid("illegal rogue non-decoded funcid");
@@ -1271,25 +1292,15 @@ bool rogue_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const C
}
switch ( funcid )
{
case 'R':
// validate register: within 60 blocks, not duplicate, etc.
return(true);
break;
case 'H': // fall through
case 'Q':
// make sure any playerdata is reproduced via replay
if ( funcid == 'Q' )
{
// validate bailout constraints
}
else // 'H'
{
// validate winner constraints
}
case 'G': // newgame
case 'R': // register
case 'K': // keystrokes
case 'H': // win
case 'Q': // bailout
//fprintf(stderr,"ht.%d rogue.(%c)\n",height,script[1]);
return(true);
break;
default:
fprintf(stderr,"ht.%d rogue.(%c)\n",height,script[1]);
return eval->Invalid("illegal rogue funcid");
break;
}