Rectangle rectangleMultiply(Rectangle a, int n) { Rectangle out = NULL_RECTANGLE; out.a = pointMultiply(a.a, n); out.b = pointMultiply(a.b, n); return out; }
/** Given an address handle, use the deterministic private key * generator to generate the address and public key associated * with that address handle. * \param out_address The address will be written here (if everything * goes well). This must be a byte array with space for * 20 bytes. * \param out_public_key The public key corresponding to the address will * be written here (if everything goes well). * \param ah The address handle to obtain the address/public key of. * \return #WALLET_NO_ERROR on success, or one of #WalletErrorsEnum if an * error occurred. */ WalletErrors getAddressAndPublicKey(uint8_t *out_address, PointAffine *out_public_key, AddressHandle ah) { uint8_t buffer[32]; HashState hs; WalletErrors r; uint8_t i; if (!wallet_loaded) { last_error = WALLET_NOT_THERE; return last_error; } if (num_addresses == 0) { last_error = WALLET_EMPTY; return last_error; } if ((ah == 0) || (ah > num_addresses) || (ah == BAD_ADDRESS_HANDLE)) { last_error = WALLET_INVALID_HANDLE; return last_error; } // Calculate private key. r = getPrivateKey(buffer, ah); if (r != WALLET_NO_ERROR) { last_error = r; return r; } // Calculate public key. setToG(out_public_key); pointMultiply(out_public_key, buffer); // Calculate address. The Bitcoin convention is to hash the public key in // big-endian format, which is why the counters run backwards in the next // two loops. sha256Begin(&hs); sha256WriteByte(&hs, 0x04); for (i = 32; i--; ) { sha256WriteByte(&hs, out_public_key->x[i]); } for (i = 32; i--; ) { sha256WriteByte(&hs, out_public_key->y[i]); } sha256Finish(&hs); writeHashToByteArray(buffer, &hs, 1); ripemd160Begin(&hs); for (i = 0; i < 32; i++) { ripemd160WriteByte(&hs, buffer[i]); } ripemd160Finish(&hs); writeHashToByteArray(buffer, &hs, 1); memcpy(out_address, buffer, 20); last_error = WALLET_NO_ERROR; return last_error; }
void _do_fire(GameData* game, Entity* e, int index, Direction direction) { FathomData* fathom = &game->fathoms[game->current]; Item* item = &e->inventory[index]; Point vector = directionToPoint(direction); Point pos = pointAddPoint(e->pos, vector); int distance = 3 + sys_randint(3); int i; Entity nullEntity = NULL_ENTITY; switch(item->conchSubtype) { case CONCH_BUBBLE: { int spawnType = sys_randint(ET_MAX_ENEMY); for(i=0; i<distance; i++) { if(sys_randint(4)==0) game_spawnAt(fathom, spawn_entity(spawnType), pos); else game_spawnAt(fathom, spawn_entity(ET_BUBBLE), pos); pos = pointAddPoint(pos, vector); } break; } case CONCH_DIG: { Tile nullTile = NULL_TILE; for(i=0; i<distance; i++) { int index = tilemap_indexFromTilePosition(&fathom->tileMap, pos); if(index != -1) fathom->tileMap.tiles[index] = nullTile; pos = pointAddPoint(pos, vector); } break; } case CONCH_JUMP: { pos = pointAddPoint(pos, pointMultiply(vector, distance)); Point invert = pointInverse(vector); for(i=distance-1; i>0; i--) { if(game_pointFree(fathom, pos)) { e->pos = pos; break; } pos = pointAddPoint(pos, invert); } break; } case CONCH_DEATH: { if(e->o2 > 4) e->o2 = e->o2/4; for(i=0; i<distance; i++) { int index = game_pointEntityIndex(fathom, pos); if(index != -1) fathom->entities[index] = nullEntity; pos = pointAddPoint(pos, vector); } break; } case CONCH_POLYMORPH: { for(i=0; i<distance; i++) { int index = game_pointEntityIndex(fathom, pos); if(index != -1) { bool player = fathom->entities[index].player; fathom->entities[index] = nullEntity; Entity e = spawn_entity(sys_randint(ET_MAX_ENEMY)); e.player = player; game_spawnAt(fathom, e, pos); } int j; for(j=0; j<MAX_ITEMS; j++) { Item* item = &fathom->items[j]; if(!item->active) continue; if(pos.x != item->pos.x || pos.y != item->pos.y) continue; *item = spawn_item(game, item->type); item->pos = pos; item->active = true; } pos = pointAddPoint(pos, vector); } break; } case CONCH_MAPPING: { for(i=0; i<fathom->tileMap.size.x*fathom->tileMap.size.y; i++) fathom->tileMap.tiles[i].seen = true; break; } default: LOG("Trying to cast invalid conch."); break; } game_addMessage(fathom, e->pos, "%s fired %s %s.", _getName(e->name), item_subtypeDescription(item->subtype), item_typeName(item->type)); if(sys_randint(5)==0) { Item nullItem = NULL_ITEM; game_addMessage(fathom, e->pos, "the %s %s falls apart.", item_subtypeDescription(item->subtype), item_typeName(item->type)); *item = nullItem; } }