DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
shot_utils.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 604
4
5#include "shot_utils.hpp"
6
7#include <cstdio>
8
9#include "charaheight.hpp"
10#include "dataalloc.hpp"
11#include "dataread.hpp"
12#include "dranmapfield.hpp"
13#include "dun/gameloop.hpp"
14#include "dungeonmap.hpp"
15#include "fishing.hpp"
16#include "mathutil.hpp"
17#include "mglib.hpp"
18#include "monstorunit.hpp"
19#include "rect.hpp"
20#include "snd.hpp"
21#include "texture.hpp"
22#include "userstatus.hpp"
23
24SHOT_COLLISION_RESULT checkCollision(float *hit_position, float *position, float *movement, s32 target_mode, float radius) {
25 sceVu0FVECTOR destination;
26 int active;
27
29 CCPoly *polygons = (CCPoly *) WorkBuffer__2->Alloc(0x500);
30 int polygon_count = setCollisionData(NowDngMap, polygons, position, 20.0f, 1.5f);
31
32 if (polygon_count >= 256) {
33 printf(fishing_err_format, polygon_count);
34 }
35
36 destination[0] = position[0] + movement[0];
37 destination[1] = position[1] + movement[1];
38 destination[2] = position[2] + movement[2];
39
40 if (target_mode != 2) {
41 sceVu0FVECTOR player_position;
42
43 sceVu0CopyVector(player_position, CharaMain.pos);
44 player_position[1] += CharaHeight(UserStatus);
45
46 if (DistVector(player_position, destination) <= radius + 6.0f) {
47 sceVu0CopyVector(hit_position, player_position);
48 return SHOT_COLLISION_PLAYER;
49 }
50 }
51
52 if (target_mode != 1) {
53 for (int monster_no = 0; monster_no < 16; monster_no++) {
54 if (NowMonstorUnit->monster[monster_no].state == -1) {
55 continue;
56 }
57
58 if (monster_no >= 0 && monster_no < 17) {
59 active = NowMonstorUnit->monster[monster_no].revealed;
60 }
61
62 if (active == 0) {
63 continue;
64 }
65
66 for (int sphere_no = 0; sphere_no < 16; sphere_no++) {
67 if (NowMonstorUnit->effect[monster_no].timer[sphere_no] != 0 && DistVector(NowMonstorUnit->effect[monster_no].position[sphere_no], position) <= radius + NowMonstorUnit->effect[monster_no].radius[sphere_no]) {
68 sceVu0CopyVector(hit_position, NowMonstorUnit->effect[monster_no].position[sphere_no]);
69 return SHOT_COLLISION_MONSTER;
70 }
71 }
72 }
73 }
74
75 int hit = CheckHit(polygons, polygon_count, position, destination, hit_position, 1, 4);
76
77 if (hit >= 0) {
78 CCPoly *poly = &polygons[hit];
79 int field_no = poly->attr.ground_kind;
80
81 if (field_no > 0 && field_no < 13) {
82 DRAN_MAP_FIELD_SET *field_set = (DRAN_MAP_FIELD_SET *) NowDranMapField;
83
84 if (field_set->state[field_no - 1] >= 2) {
85 ((DRAN_MAP_FIELD_SET *) NowDranMapField)->state[field_no - 1]--;
86 }
87 }
88
89 return SHOT_COLLISION_MAP;
90 }
91
92 sceVu0CopyVector(hit_position, position);
93 return SHOT_COLLISION_NONE;
94}
95
96void set3DCellModel(float *world, char *texture_name, float size, s32 x, s32 y, s32 width, s32 height, u8 blend) {
97 sceVu0IVECTOR top_left;
98 sceVu0IVECTOR top_right;
99 sceVu0IVECTOR bottom_left;
100 sceVu0IVECTOR bottom_right;
101 CTexture *texture = TexManager.GetTexture(texture_name, -1);
102
103 world[3] = 1.0f;
104
105 // The sprite stands twice as wide as it is tall.
106 if (MGRotTransPers3DSprite(top_left, bottom_right, world, size, size / 2.0f, 0) == 1) {
107 top_right[0] = bottom_right[0];
108 top_right[1] = top_left[1];
109 top_right[2] = top_left[2];
110 bottom_left[0] = top_left[0];
111 bottom_left[1] = bottom_right[1];
112 bottom_left[2] = bottom_right[2];
113 set3DSprite(Vif1Packet, texture, CRect_i_(x, y, width, height), top_left, top_right, bottom_left, bottom_right, blend);
114 }
115}
s16 ground_kind
Definition collision.hpp:55
MONSTOR_EFFECT_STATE effect[16]
MONSTOR monster[16]
float pos[4]
Definition object.hpp:18
CDataAlloc2< 1 > * WorkBuffer__2
Definition dataread.hpp:250
sceVu0FVECTOR position[16]