/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to src/libvqdr/dice.vala

  • Committer: Gustav Hartvigsson
  • Date: 2022-06-01 20:50:29 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20220601205029-cmy0mxi9x59bzymx
Added int32_abs () to Utils.

Made Dice.roll () use uint32 as it's return value. It can never be negative, so...

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    this.modifier = 0;
42
42
  }
43
43
  
44
 
  public int32 roll () {
 
44
  public uint32 roll () {
45
45
    if (faces <= 0) {
46
46
      return modifier;
47
47
    }
51
51
    }
52
52
    
53
53
    if (faces == 1) {
54
 
      return ((int32) times) + modifier;
 
54
      return times + modifier;
55
55
    }
56
56
    
57
 
    int32 retval = modifier;
 
57
    uint32 retval = modifier;
58
58
    for (size_t i = 1; i <= times; i++) {
59
 
      // we have to do this ugly mess, as int32 is missing the abs () method.
60
 
      // bug: https://gitlab.gnome.org/GNOME/vala/-/issues/1328
61
 
      int32 r = ((int)(Utils.Random.get_static_int () % (int)faces)).abs ();
 
59
      uint32 r = Utils.Random.get_static_int () % faces;
62
60
      
63
61
      retval += r;
64
62
    }